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