| 32 | } |
| 33 | |
| 34 | void InfoThread::run() { |
| 35 | int64_t i = 0; |
| 36 | int64_t last_sent_count = 0; |
| 37 | int64_t last_succ_count = 0; |
| 38 | int64_t last_error_count = 0; |
| 39 | int64_t start_time = butil::cpuwide_time_us(); |
| 40 | while (!_stop) { |
| 41 | int64_t end_time = 0; |
| 42 | while (!_stop && |
| 43 | (end_time = butil::cpuwide_time_us()) < start_time + 1000000L) { |
| 44 | BAIDU_SCOPED_LOCK(_mutex); |
| 45 | if (!_stop) { |
| 46 | timespec ts = butil::microseconds_to_timespec(end_time); |
| 47 | pthread_cond_timedwait(&_cond, &_mutex, &ts); |
| 48 | } |
| 49 | } |
| 50 | start_time = butil::cpuwide_time_us(); |
| 51 | char buf[64]; |
| 52 | const time_t tm_s = start_time / 1000000L; |
| 53 | struct tm lt; |
| 54 | strftime(buf, sizeof(buf), "%Y/%m/%d-%H:%M:%S", |
| 55 | localtime_r(&tm_s, <)); |
| 56 | |
| 57 | const int64_t cur_sent_count = _options.sent_count->get_value(); |
| 58 | const int64_t cur_succ_count = _options.latency_recorder->count(); |
| 59 | const int64_t cur_error_count = _options.error_count->get_value(); |
| 60 | printf("%s\tsent:%-10dsuccess:%-10derror:%-6dtotal_error:%-10lldtotal_sent:%-10lld\n", |
| 61 | buf, |
| 62 | (int)(cur_sent_count - last_sent_count), |
| 63 | (int)(cur_succ_count - last_succ_count), |
| 64 | (int)(cur_error_count - last_error_count), |
| 65 | (long long)cur_error_count, |
| 66 | (long long)cur_sent_count); |
| 67 | last_sent_count = cur_sent_count; |
| 68 | last_succ_count = cur_succ_count; |
| 69 | last_error_count = cur_error_count; |
| 70 | |
| 71 | if (_stop || ++i % 10 == 0) { |
| 72 | printf("[Latency]\n" |
| 73 | " avg %10lld us\n" |
| 74 | " 50%% %10lld us\n" |
| 75 | " 70%% %10lld us\n" |
| 76 | " 90%% %10lld us\n" |
| 77 | " 95%% %10lld us\n" |
| 78 | " 97%% %10lld us\n" |
| 79 | " 99%% %10lld us\n" |
| 80 | " 99.9%% %10lld us\n" |
| 81 | " 99.99%% %10lld us\n" |
| 82 | " max %10lld us\n", |
| 83 | (long long)_options.latency_recorder->latency(), |
| 84 | (long long)_options.latency_recorder->latency_percentile(0.5), |
| 85 | (long long)_options.latency_recorder->latency_percentile(0.7), |
| 86 | (long long)_options.latency_recorder->latency_percentile(0.9), |
| 87 | (long long)_options.latency_recorder->latency_percentile(0.95), |
| 88 | (long long)_options.latency_recorder->latency_percentile(0.97), |
| 89 | (long long)_options.latency_recorder->latency_percentile(0.99), |
| 90 | (long long)_options.latency_recorder->latency_percentile(0.999), |
| 91 | (long long)_options.latency_recorder->latency_percentile(0.9999), |
no test coverage detected