| 182 | |
| 183 | |
| 184 | void BenchMark::ResStat() { |
| 185 | timeval now; |
| 186 | gettimeofday(&now, nullptr); |
| 187 | long diff_ms{(now.tv_sec - impl_->last_stat_time.tv_sec) * 1000 + (now.tv_usec - impl_->last_stat_time.tv_usec) / 1000}; |
| 188 | impl_->last_stat_time = now; |
| 189 | |
| 190 | const uint32_t time_split[] = {1, 2, 5, 10, 20, 50, 100, 200, 500, 1000}; |
| 191 | const int time_split_size = sizeof(time_split) / sizeof(int); |
| 192 | int time_split_cnt[sizeof(time_split) / sizeof(int) + 1]; |
| 193 | memset(time_split_cnt, 0, sizeof(time_split_cnt)); |
| 194 | |
| 195 | map<int, uint32_t> m; |
| 196 | uint32_t total{0}; |
| 197 | uint64_t total_time_ms{0}; |
| 198 | uint32_t nroutine_sleep{0}; |
| 199 | for (int i{0}; i < impl_->nthread; ++i) { |
| 200 | StatData *stat = &impl_->stats[i]; |
| 201 | MutexGuard guard(&stat->mutex); |
| 202 | |
| 203 | for (auto &&it : stat->res_st) { |
| 204 | m[it.first] += it.second; |
| 205 | total += it.second; |
| 206 | } |
| 207 | stat->res_st.clear(); |
| 208 | |
| 209 | for (auto &&it : stat->time_st) { |
| 210 | int j{0}; |
| 211 | for (; j < time_split_size; ++j) |
| 212 | if (it.first < time_split[j]) break; |
| 213 | time_split_cnt[j] += it.second; |
| 214 | total_time_ms += (uint64_t)it.first * it.second; |
| 215 | } |
| 216 | stat->time_st.clear(); |
| 217 | |
| 218 | nroutine_sleep += stat->nroutine_sleep; |
| 219 | stat->nroutine_sleep = 0; |
| 220 | } |
| 221 | |
| 222 | // log |
| 223 | printf("\n-------------------------------------------\n"); |
| 224 | printf("--\ttotal:\t%u\n", total); |
| 225 | printf("--\ttime(ms):\t%ld\n", diff_ms); |
| 226 | printf("--\tqps:\t%.2lf\n", (double)total / diff_ms * 1000); |
| 227 | printf("--\troutine_sleep:\t%.2lf%%\n", (double)nroutine_sleep / total * 100.0); |
| 228 | printf("--\tretcode\tcnt\tpercent\n"); |
| 229 | for (auto it : m) { |
| 230 | printf("--\t%d\t%u\t%.2lf\n", it.first, it.second, (double)it.second / total * 100.0); |
| 231 | } |
| 232 | |
| 233 | printf("--\tusetime(ms)\tcnt\tpercent\n"); |
| 234 | for (int i{0}; i < time_split_size; ++i) { |
| 235 | printf("--\t< %d\t\t%u\t%.2lf\n", time_split[i], time_split_cnt[i], (double)time_split_cnt[i] / total * 100.0); |
| 236 | } |
| 237 | printf("--\t>= %d\t\t%u\t%.2lf\n", time_split[time_split_size - 1], time_split_cnt[time_split_size], (double)time_split_cnt[time_split_size] / total * 100.0); |
| 238 | printf("--\tavg_usetime(ms):\t%.2lf\n", (double)total_time_ms / total); |
| 239 | } |
| 240 | |
| 241 |
nothing calls this directly
no outgoing calls
no test coverage detected