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