diff options
author | Nick Mathewson <nickm@torproject.org> | 2013-01-03 13:20:20 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2013-01-03 13:20:20 -0500 |
commit | 30e139389bd8301f62ee24481d0f5484544fc5de (patch) | |
tree | 30cb3ade556412b228c9cf6bf4d6f0dcba55258b /src/or/cpuworker.c | |
parent | b9fb01721a38c2b850f7a0120adc621a9d34b772 (diff) | |
download | tor-30e139389bd8301f62ee24481d0f5484544fc5de.tar.gz tor-30e139389bd8301f62ee24481d0f5484544fc5de.zip |
Record and report the overhead of how we handle onionskins.
Diffstat (limited to 'src/or/cpuworker.c')
-rw-r--r-- | src/or/cpuworker.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/or/cpuworker.c b/src/or/cpuworker.c index a6262241e3..42f7b9572c 100644 --- a/src/or/cpuworker.c +++ b/src/or/cpuworker.c @@ -235,6 +235,54 @@ estimated_usec_for_onionskins(uint32_t n_requests, uint16_t onionskin_type) } } +/** Compute the absolute and relative overhead of using the cpuworker + * framework for onionskins of type <b>onionskin_type</b>.*/ +static int +get_overhead_for_onionskins(uint32_t *usec_out, double *frac_out, + uint16_t onionskin_type) +{ + uint64_t overhead; + + *usec_out = 0; + *frac_out = 0.0; + + if (onionskin_type > MAX_ONION_HANDSHAKE_TYPE) /* should be impossible */ + return -1; + if (onionskins_n_processed[onionskin_type] == 0 || + onionskins_usec_internal[onionskin_type] == 0 || + onionskins_usec_roundtrip[onionskin_type] == 0) + return -1; + + overhead = onionskins_usec_roundtrip[onionskin_type] - + onionskins_usec_internal[onionskin_type]; + + *usec_out = (uint32_t)(overhead / onionskins_n_processed[onionskin_type]); + *frac_out = U64_TO_DBL(overhead) / onionskins_usec_internal[onionskin_type]; + + return 0; +} + +/** If we've measured overhead for onionskins of type <b>onionskin_type</b>, + * log it. */ +void +cpuworker_log_onionskin_overhead(int severity, int onionskin_type, + const char *onionskin_type_name) +{ + uint32_t overhead; + double relative_overhead; + int r; + + r = get_overhead_for_onionskins(&overhead, &relative_overhead, + onionskin_type); + if (!overhead || r<0) + return; + + log_fn(severity, LD_OR, + "%s onionskins have averaged %u usec overhead (%.2f%%) in " + "cpuworker code ", + onionskin_type_name, (unsigned)overhead, relative_overhead*100); +} + /** Called when we get data from a cpuworker. If the answer is not complete, * wait for a complete answer. If the answer is complete, * process it as appropriate. |