[137974ae] | 1 | #include "printer.hfa" |
---|
[329e26a] | 2 | #include "options.hfa" |
---|
[137974ae] | 3 | |
---|
| 4 | #include <fstream.hfa> |
---|
| 5 | #include <stats.hfa> |
---|
| 6 | |
---|
| 7 | void ?{}( sendfile_stats_t & this ) { |
---|
| 8 | this.calls = 0; |
---|
| 9 | this.tries = 0; |
---|
| 10 | this.header = 0; |
---|
| 11 | this.splcin = 0; |
---|
| 12 | this.splcot = 0; |
---|
| 13 | for(i; zipf_cnts) { |
---|
| 14 | this.avgrd[i].calls = 0; |
---|
| 15 | this.avgrd[i].bytes = 0; |
---|
| 16 | }; |
---|
| 17 | } |
---|
| 18 | |
---|
| 19 | void push(sendfile_stats_t & from, sendfile_stats_t & to) { |
---|
| 20 | __atomic_fetch_add(&to.calls, from.calls, __ATOMIC_RELAXED); from.calls = 0; |
---|
| 21 | __atomic_fetch_add(&to.tries, from.tries, __ATOMIC_RELAXED); from.tries = 0; |
---|
| 22 | __atomic_fetch_add(&to.header, from.header, __ATOMIC_RELAXED); from.header = 0; |
---|
| 23 | __atomic_fetch_add(&to.splcin, from.splcin, __ATOMIC_RELAXED); from.splcin = 0; |
---|
| 24 | __atomic_fetch_add(&to.splcot, from.splcot, __ATOMIC_RELAXED); from.splcot = 0; |
---|
| 25 | for(i; zipf_cnts) { |
---|
| 26 | __atomic_fetch_add(&to.avgrd[i].calls, from.avgrd[i].calls, __ATOMIC_RELAXED); from.avgrd[i].calls = 0; |
---|
| 27 | __atomic_fetch_add(&to.avgrd[i].bytes, from.avgrd[i].bytes, __ATOMIC_RELAXED); from.avgrd[i].bytes = 0; |
---|
| 28 | }; |
---|
| 29 | } |
---|
| 30 | |
---|
| 31 | void ?{}( acceptor_stats_t & this ) { |
---|
| 32 | this.creates = 0; |
---|
| 33 | this.accepts = 0; |
---|
| 34 | this.eagains = 0; |
---|
| 35 | } |
---|
| 36 | |
---|
| 37 | void push(acceptor_stats_t & from, acceptor_stats_t & to) { |
---|
| 38 | __atomic_fetch_add(&to.creates, from.creates, __ATOMIC_RELAXED); from.creates = 0; |
---|
| 39 | __atomic_fetch_add(&to.accepts, from.accepts, __ATOMIC_RELAXED); from.accepts = 0; |
---|
| 40 | __atomic_fetch_add(&to.eagains, from.eagains, __ATOMIC_RELAXED); from.eagains = 0; |
---|
| 41 | } |
---|
| 42 | |
---|
[329e26a] | 43 | void ?{}( StatsPrinter & this, ServerCluster * cl ) { |
---|
[bf7c7ea] | 44 | ((thread&)this){ "Stats Printer Thread" }; |
---|
[329e26a] | 45 | this.cl = cl; |
---|
[137974ae] | 46 | memset(&this.stats, 0, sizeof(this.stats));; |
---|
| 47 | } |
---|
| 48 | |
---|
| 49 | void ^?{}( StatsPrinter & mutex this ) {} |
---|
| 50 | |
---|
| 51 | #define eng3(X) (ws(3, 3, unit(eng( X )))) |
---|
| 52 | |
---|
| 53 | void main(StatsPrinter & this) { |
---|
| 54 | LOOP: for() { |
---|
| 55 | waitfor( ^?{} : this) { |
---|
| 56 | break LOOP; |
---|
| 57 | } |
---|
| 58 | or else {} |
---|
| 59 | |
---|
| 60 | wait(this.var, 10`s); |
---|
| 61 | |
---|
[329e26a] | 62 | for(i; options.clopts.nclusters) print_stats_now( this.cl[i].self, CFA_STATS_READY_Q | CFA_STATS_IO ); |
---|
[137974ae] | 63 | { |
---|
| 64 | struct { |
---|
| 65 | volatile uint64_t calls; |
---|
| 66 | volatile uint64_t bytes; |
---|
| 67 | } avgrd[zipf_cnts]; |
---|
| 68 | memset(avgrd, 0, sizeof(avgrd)); |
---|
| 69 | |
---|
| 70 | uint64_t tries = this.stats.send.tries; |
---|
| 71 | uint64_t calls = this.stats.send.calls; |
---|
| 72 | uint64_t header = this.stats.send.header; |
---|
| 73 | uint64_t splcin = this.stats.send.splcin; |
---|
| 74 | uint64_t splcot = this.stats.send.splcot; |
---|
| 75 | for(j; zipf_cnts) { |
---|
| 76 | avgrd[j].calls += this.stats.send.avgrd[j].calls; |
---|
| 77 | avgrd[j].bytes += this.stats.send.avgrd[j].bytes; |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | double ratio = ((double)tries) / calls; |
---|
| 81 | |
---|
| 82 | if(this.stats.accpt.accepts > 0) { |
---|
| 83 | sout | "----- Acceptor Stats -----"; |
---|
[8419b76] | 84 | sout | "accept : " | eng3(this.stats.accpt.accepts) | "calls," | eng3(this.stats.accpt.eagains) | "eagains," | eng3(this.stats.accpt.creates) | " thrds"; |
---|
| 85 | sout | nl; |
---|
[137974ae] | 86 | } |
---|
| 87 | |
---|
| 88 | sout | "----- Connection Stats -----"; |
---|
[8419b76] | 89 | sout | "sendfile : " | eng3(calls) | "calls," | eng3(tries) | "tries (" | ratio | " try/call)"; |
---|
| 90 | sout | " " | eng3(header) | "header," | eng3(splcin) | "splice in," | eng3(splcot) | "splice out"; |
---|
[137974ae] | 91 | sout | " - zipf sizes:"; |
---|
| 92 | for(i; zipf_cnts) { |
---|
| 93 | double written = avgrd[i].calls > 0 ? ((double)avgrd[i].bytes) / avgrd[i].calls : 0; |
---|
| 94 | sout | " " | zipf_sizes[i] | "bytes," | avgrd[i].calls | "shorts," | written | "written"; |
---|
| 95 | } |
---|
| 96 | } |
---|
| 97 | } |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | StatsPrinter * stats_thrd; |
---|