Changeset 8c43d05 for benchmark/io/http


Ignore:
Timestamp:
Jan 15, 2021, 2:26:35 PM (4 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
b7664a0
Parents:
804c0ff
Message:

httpforall now uses sout rather than printf

Location:
benchmark/io/http
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • benchmark/io/http/filecache.cfa

    r804c0ff r8c43d05  
    44#include <string.h>
    55
     6#include <fstream.hfa>
    67#include <stdlib.hfa>
    78
     
    182183                conflicts += put_file( raw[i], fd );
    183184        }
    184         printf("Filled cache from path \"%s\" with %zu files\n", path, fcount);
     185        sout | "Filled cache from path \"" | path | "\" with" | fcount | "files";
    185186        if( conflicts > 0 ) {
    186                 printf("Found %d conflicts (seed: %u)\n", conflicts, options.file_cache.hash_seed);
     187                sout | "Found" | conflicts | "conflicts (seed: " | options.file_cache.hash_seed | ")";
    187188                #if defined(REJECT_CONFLICTS)
    188189                        abort("Conflicts found in the cache");
     
    191192
    192193        if(options.file_cache.list) {
    193                 printf("Listing files and exiting\n");
     194                sout | "Listing files and exiting";
    194195                for(i; fcount) {
    195196                        int s; char u;
    196197                        [s, u] = human_size(raw[i].size);
    197                         printf("%4d%c - %s\n", s, u, raw[i].file);
     198                        sout | s | u | "-" | raw[i].file;
    198199                        free(raw[i].file);
    199200                }
  • benchmark/io/http/main.cfa

    r804c0ff r8c43d05  
    1010}
    1111
     12#include <fstream.hfa>
    1213#include <kernel.hfa>
    1314#include <iofwd.hfa>
     
    8384        //===================
    8485        // Open Files
    85         printf("Filling cache from %s\n", path);
     86        sout | "Filling cache from" | path;
    8687        fill_cache( path );
    8788
    8889        //===================
    8990        // Open Socket
    90         printf("%ld : Listening on port %d\n", getpid(), options.socket.port);
     91        sout | getpid() | ": Listening on port" | options.socket.port;
    9192        int server_fd = socket(AF_INET, SOCK_STREAM, 0);
    9293        if(server_fd < 0) {
     
    108109                        if(errno == EADDRINUSE) {
    109110                                if(waited == 0) {
    110                                         printf("Waiting for port\n");
     111                                        sout | "Waiting for port";
    111112                                } else {
    112                                         printf("\r%d", waited);
    113                                         fflush(stdout);
     113                                        sout | "\r" | waited | nonl;
     114                                        flush( sout );
    114115                                }
    115116                                waited ++;
     
    173174                                        unpark( workers[i] );
    174175                                }
    175                                 printf("%d workers started on %d processors\n", options.clopts.nworkers, options.clopts.nprocs);
     176                                sout | options.clopts.nworkers | "workers started on" | options.clopts.nprocs | "processors";
    176177                                {
    177178                                        char buffer[128];
     
    180181                                        }
    181182
    182                                         printf("Shutting Down\n");
    183                                 }
    184 
     183                                        sout | "Shutdown received";
     184                                }
     185
     186                                sout | "Notifying connections";
    185187                                for(i; options.clopts.nworkers) {
    186188                                        workers[i].done = true;
     
    188190                                }
    189191
    190                                 printf("Shutting down socket\n");
     192                                sout | "Shutting down socket";
    191193                                int ret = shutdown( server_fd, SHUT_RD );
    192194                                if( ret < 0 ) { abort( "shutdown error: (%d) %s\n", (int)errno, strerror(errno) ); }
     
    194196                                //===================
    195197                                // Close Socket
    196                                 printf("Closing Socket\n");
     198                                sout | "Closing Socket";
    197199                                ret = close( server_fd );
    198200                                if(ret < 0) {
    199201                                        abort( "close socket error: (%d) %s\n", (int)errno, strerror(errno) );
    200202                                }
     203                                sout | "Stopping connection threads..." | nonl;
    201204                        }
    202                         printf("Workers Closed\n");
    203 
     205                        sout | "done";
     206
     207                        sout | "Stopping protocol threads..." | nonl;
    204208                        deinit_protocol();
    205                 }
    206 
     209                        sout | "done";
     210
     211                        sout | "Stopping processors..." | nonl;
     212                }
     213                sout | "done";
     214
     215                sout | "Closing splice fds..." | nonl;
    207216                for(i; pipe_cnt) {
    208217                        ret = close( fds[pipe_off + i] );
     
    212221                }
    213222                free(fds);
    214 
    215         }
     223                sout | "done";
     224
     225                sout | "Stopping processors..." | nonl;
     226        }
     227        sout | "done";
    216228
    217229        //===================
    218230        // Close Files
    219         printf("Closing Files\n");
     231        sout | "Closing open files..." | nonl;
    220232        close_cache();
    221 }
     233        sout | "done";
     234}
  • benchmark/io/http/protocol.cfa

    r804c0ff r8c43d05  
    55        #include <fcntl.h>
    66}
     7
     8#include <fstream.hfa>
    79#include <iofwd.hfa>
    810
     
    1113extern "C" {
    1214      int snprintf ( char * s, size_t n, const char * format, ... );
    13         #include <linux/io_uring.h>
     15        // #include <linux/io_uring.h>
    1416}
    1517#include <string.h>
     
    115117        }
    116118
    117         if( options.log ) printf("%.*s\n", rlen, buffer);
     119        if( options.log ) {
     120                write(sout, buffer, rlen);
     121                sout | nl;
     122        }
    118123
    119124        it = buffer;
  • benchmark/io/http/worker.cfa

    r804c0ff r8c43d05  
    66#include <unistd.h>
    77
     8#include <fstream.hfa>
    89#include <iofwd.hfa>
    910
     
    3334        CONNECTION:
    3435        for() {
    35                 if( options.log ) printf("=== Accepting connection ===\n");
     36                if( options.log ) sout | "=== Accepting connection ===";
    3637                int fd = cfa_accept4( this.[sockfd, addr, addrlen, flags], 0, -1`s, &this.cancel, 0p );
    3738                // int fd = accept4( this.[sockfd, addr, addrlen, flags] );
     
    4243                }
    4344
    44                 if( options.log ) printf("=== New connection %d, waiting for requests ===\n", fd);
     45                if( options.log ) sout | "=== New connection" | fd | "" | ", waiting for requests ===";
    4546                REQUEST:
    4647                for() {
     
    5354                        size_t len = options.socket.buflen;
    5455                        char buffer[len];
    55                         if( options.log ) printf("=== Reading request ===\n");
     56                        if( options.log ) sout | "=== Reading request ===";
    5657                        [code, closed, file, name_size] = http_read(fd, buffer, len, &this.cancel);
    5758
     
    6162                        // If this wasn't a request retrun 400
    6263                        if( code != OK200 ) {
    63                                 printf("=== Invalid Request : %d ===\n", code_val(code));
     64                                sout | "=== Invalid Request :" | code_val(code) | "===";
    6465                                answer_error(fd, code);
    6566                                continue REQUEST;
     
    6768
    6869                        if(0 == strncmp(file, "plaintext", min(name_size, sizeof("plaintext") ))) {
    69                                 if( options.log ) printf("=== Request for /plaintext ===\n");
     70                                if( options.log ) sout | "=== Request for /plaintext ===";
    7071
    7172                                char text[] = "Hello, World!\n";
     
    7576                                if( ret == -ECONNRESET ) break REQUEST;
    7677
    77                                 if( options.log ) printf("=== Answer sent ===\n");
     78                                if( options.log ) sout | "=== Answer sent ===";
    7879                                continue REQUEST;
    7980                        }
    8081
    8182                        if(0 == strncmp(file, "ping", min(name_size, sizeof("ping") ))) {
    82                                 if( options.log ) printf("=== Request for /ping ===\n");
     83                                if( options.log ) sout | "=== Request for /ping ===";
    8384
    8485                                // Send the header
     
    8687                                if( ret == -ECONNRESET ) break REQUEST;
    8788
    88                                 if( options.log ) printf("=== Answer sent ===\n");
     89                                if( options.log ) sout | "=== Answer sent ===";
    8990                                continue REQUEST;
    9091                        }
    9192
    92                         if( options.log ) printf("=== Request for file %.*s ===\n", (int)name_size, file);
     93                        if( options.log ) {
     94                                sout | "=== Request for file " | nonl;
     95                                write(sout, file, name_size);
     96                                sout | " ===";
     97                        }
    9398
    9499                        // Get the fd from the file cache
     
    99104                        // If we can't find the file, return 404
    100105                        if( ans_fd < 0 ) {
    101                                 printf("=== File Not Found ===\n");
     106                                sout | "=== File Not Found (" | nonl;
     107                                write(sout, file, name_size);
     108                                sout | ") ===";
    102109                                answer_error(fd, E404);
    103110                                continue REQUEST;
     
    112119                        if( ret == -ECONNRESET ) break REQUEST;
    113120
    114                         if( options.log ) printf("=== Answer sent ===\n");
     121                        if( options.log ) sout | "=== Answer sent ===";
    115122                }
    116123
    117                 if( options.log ) printf("=== Connection closed ===\n");
     124                if( options.log ) sout | "=== Connection closed ===";
    118125                close(fd);
    119126                continue CONNECTION;
Note: See TracChangeset for help on using the changeset viewer.