Ignore:
Timestamp:
Jun 9, 2022, 10:56:34 AM (2 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, ast-experimental, master, pthread-emulation, qualifiedEnum
Children:
430ce61
Parents:
8c58e73
Message:

Moved stats printer to it's own file and now using push-stats rather than pull

File:
1 edited

Legend:

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

    r8c58e73 r137974ae  
    2525#include "options.hfa"
    2626#include "socket.hfa"
     27#include "printer.hfa"
    2728#include "worker.hfa"
    2829
     
    3132Duration default_preemption() {
    3233        return 0;
    33 }
    34 
    35 //=============================================================================================
    36 // Stats Printer
    37 //============================================================================================='
    38 
    39 thread StatsPrinter {
    40         connection ** conns;
    41         volatile int conn_cnt;
    42         condition_variable(fast_block_lock) var;
    43 };
    44 
    45 void ?{}( StatsPrinter & this, cluster & cl ) {
    46         ((thread&)this){ "Stats Printer Thread", cl };
    47         this.conn_cnt = 0;
    48 }
    49 
    50 void ^?{}( StatsPrinter & mutex this ) {}
    51 
    52 #define eng3(X) (ws(3, 3, unit(eng( X ))))
    53 
    54 void main(StatsPrinter & this) {
    55         LOOP: for() {
    56                 waitfor( ^?{} : this) {
    57                         break LOOP;
    58                 }
    59                 or else {}
    60 
    61                 wait(this.var, 10`s);
    62 
    63                 print_stats_now( *active_cluster(), CFA_STATS_READY_Q | CFA_STATS_IO );
    64                 if(this.conn_cnt != 0) {
    65                         uint64_t tries = 0;
    66                         uint64_t calls = 0;
    67                         uint64_t header = 0;
    68                         uint64_t splcin = 0;
    69                         uint64_t splcot = 0;
    70                         struct {
    71                                 volatile uint64_t calls;
    72                                 volatile uint64_t bytes;
    73                         } avgrd[zipf_cnts];
    74                         memset(avgrd, 0, sizeof(avgrd));
    75 
    76                         for(i; this.conn_cnt) {
    77                                 tries += this.conns[i]->stats.sendfile.tries;
    78                                 calls += this.conns[i]->stats.sendfile.calls;
    79                                 header += this.conns[i]->stats.sendfile.header;
    80                                 splcin += this.conns[i]->stats.sendfile.splcin;
    81                                 splcot += this.conns[i]->stats.sendfile.splcot;
    82                                 for(j; zipf_cnts) {
    83                                         avgrd[j].calls += this.conns[i]->stats.sendfile.avgrd[j].calls;
    84                                         avgrd[j].bytes += this.conns[i]->stats.sendfile.avgrd[j].bytes;
    85                                 }
    86                         }
    87 
    88                         double ratio = ((double)tries) / calls;
    89 
    90                         sout | "----- Connection Stats -----";
    91                         sout | "sendfile  : " | calls | "calls," | tries | "tries (" | ratio | " try/call)";
    92                         sout | "            " | header | "header," | splcin | "splice in," | splcot | "splice out";
    93                         sout | " - zipf sizes:";
    94                         for(i; zipf_cnts) {
    95                                 double written = avgrd[i].calls > 0 ? ((double)avgrd[i].bytes) / avgrd[i].calls : 0;
    96                                 sout | "        " | zipf_sizes[i] | "bytes," | avgrd[i].calls | "shorts," | written | "written";
    97                         }
    98                 }
    99                 else {
    100                         sout | "No Connections!";
    101                 }
    102         }
    10334}
    10435
     
    10940        cluster self;
    11041        processor    * procs;
    111         // io_context   * ctxs;
    112         StatsPrinter * prnt;
    11342
    11443};
     
    15281        }
    15382
    154         if(options.stats) {
    155                 this.prnt = alloc();
    156                 (*this.prnt){ this.self };
    157         } else {
    158                 this.prnt = 0p;
    159         }
    160 
    16183        #if !defined(__CFA_NO_STATISTICS__)
    16284                print_stats_at_exit( this.self, CFA_STATS_READY_Q | CFA_STATS_IO );
     
    16789
    16890void ^?{}( ServerCluster & this ) {
    169         delete(this.prnt);
    170 
    17191        for(i; options.clopts.nprocs) {
    17292                ^(this.procs[i]){};
     
    268188                        Q * queues = 0p;
    269189                        ServerCluster cl;
     190
     191                        if(options.stats) {
     192                                stats_thrd = alloc();
     193                                (*stats_thrd){ cl.self };
     194                        } else {
     195                                stats_thrd = 0p;
     196                        }
    270197
    271198                        init_protocol();
     
    319246                                        }
    320247                                }
    321                                 cl.prnt->conns = conns;
    322                                 cl.prnt->conn_cnt = options.clopts.nworkers;
     248
    323249                                sout | options.clopts.nworkers | "workers started on" | options.clopts.nprocs | "processors";
    324250                                sout | nl;
     
    436362
    437363                        sout | "Stopping printer threads..." | nonl; flush( sout );
    438                         StatsPrinter * p = cl.prnt;
    439                         if(p) {
    440                                 notify_one(p->var);
    441                                 join(*p);
    442                         }
     364                        if(stats_thrd) {
     365                                notify_one(stats_thrd->var);
     366                        }
     367                        delete(stats_thrd);
    443368                        sout | "done";
    444369
Note: See TracChangeset for help on using the changeset viewer.