#include "printer.hfa" #include "options.hfa" #include #include #include void ?{}( sendfile_stats_t & this ) { this.maxfd = 0; this.close = 0; this.calls = 0; this.tries = 0; this.header = 0; this.splcin = 0; this.splcot = 0; for(i; zipf_cnts) { this.avgrd[i].calls = 0; this.avgrd[i].bytes = 0; }; } void push(sendfile_stats_t & from, sendfile_stats_t & to) { to.maxfd = max( to.maxfd, from.maxfd); to.close += from.close; from.close = 0; to.error += from.error; from.error = 0; to.calls += from.calls; from.calls = 0; to.eagain += from.eagain; from.eagain = 0; to.tries += from.tries; from.tries = 0; to.header += from.header; from.header = 0; to.splcin += from.splcin; from.splcin = 0; to.splcot += from.splcot; from.splcot = 0; for(i; zipf_cnts) { to.avgrd[i].calls += from.avgrd[i].calls; from.avgrd[i].calls = 0; to.avgrd[i].bytes += from.avgrd[i].bytes; from.avgrd[i].bytes = 0; }; } void ?{}( acceptor_stats_t & this ) { this.creates = 0; this.accepts = 0; this.eagains = 0; } void push(acceptor_stats_t & from, acceptor_stats_t & to) { to.creates += from.creates; from.creates = 0; to.accepts += from.accepts; from.accepts = 0; to.eagains += from.eagains; from.eagains = 0; } void ?{}( StatsPrinter & this, ServerCluster * cl ) { ((thread&)this){ "Stats Printer Thread" }; this.cl = cl; memset(&this.stats, 0, sizeof(this.stats));; } void ^?{}( StatsPrinter & mutex this ) {} #define eng3(X) (ws(3, 3, unit(eng( X )))) void main(StatsPrinter & this) { LOOP: for() { wait(this.var, 10`s); for(i; options.clopts.nclusters) print_stats_now( this.cl[i].self, CFA_STATS_READY_Q | CFA_STATS_IO ); { struct { volatile uint64_t calls; volatile uint64_t bytes; } avgrd[zipf_cnts]; memset(avgrd, 0, sizeof(avgrd)); uint64_t tries = this.stats.send.tries; uint64_t calls = this.stats.send.calls; uint64_t header = this.stats.send.header; uint64_t splcin = this.stats.send.splcin; uint64_t splcot = this.stats.send.splcot; for(j; zipf_cnts) { avgrd[j].calls += this.stats.send.avgrd[j].calls; avgrd[j].bytes += this.stats.send.avgrd[j].bytes; } double ratio = ((double)tries) / calls; uint64_t accp_open = this.stats.accpt.accepts; uint64_t accp_clse = this.stats.send.close; uint64_t accp_errs = this.stats.send.error; uint64_t accp_live = accp_open - accp_clse; sout | "-----" | time() | "-----"; sout | "----- Acceptor Stats -----"; sout | "accepts : " | eng3(accp_open) |"opened," | eng3(accp_clse) |"closed," | eng3(accp_live) |"live," | eng3(accp_errs) |"errors"; sout | "accept : " | eng3(this.stats.accpt.accepts) | "calls," | eng3(this.stats.accpt.eagains) | "eagains," | eng3(this.stats.accpt.creates) | " thrds"; sout | nl; sout | "----- Connection Stats -----"; sout | "max fd : " | this.stats.send.maxfd; sout | "sendfile : " | eng3(calls) | "calls," | eng3(tries) | "tries (" | ratio | " try/call)," | eng3(this.stats.send.eagain) | "eagains"; sout | " " | eng3(header) | "header," | eng3(splcin) | "splice in," | eng3(splcot) | "splice out"; // sout | " - zipf sizes:"; // for(i; zipf_cnts) { // double written = avgrd[i].calls > 0 ? ((double)avgrd[i].bytes) / avgrd[i].calls : 0; // sout | " " | zipf_sizes[i] | "bytes," | avgrd[i].calls | "shorts," | written | "written"; // } } waitfor( ^?{} : this) { break LOOP; } or else {} } } StatsPrinter * stats_thrd;