|
| 1 | +// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary. |
| 2 | + |
| 3 | +#include <chrono> |
| 4 | +#include <iostream> |
| 5 | +#include <vector> |
| 6 | +#include "time/fbclock/fbclock.h" |
| 7 | + |
| 8 | +int main() { |
| 9 | + std::vector<uint32_t> |
| 10 | + time_histogram; // create a histogramm of call time in us |
| 11 | + |
| 12 | + time_histogram.resize(1001, 0); |
| 13 | + fbclock_lib fbclock = {}; |
| 14 | + int res = fbclock_init(&fbclock, FBCLOCK_PATH); |
| 15 | + if (res != 0) { |
| 16 | + std::cout << "Failed to init fbclock library: errno " << res << std::endl; |
| 17 | + exit(0); |
| 18 | + } |
| 19 | + for (int i = 0; i < 1000000; i++) { |
| 20 | + fbclock_truetime true_time = {}; |
| 21 | + auto start_time = std::chrono::steady_clock::now(); |
| 22 | + fbclock_gettime_utc(&fbclock, &true_time); |
| 23 | + auto end_time = std::chrono::steady_clock::now(); |
| 24 | + auto duration = std::chrono::duration_cast<std::chrono::microseconds>( |
| 25 | + end_time - start_time); |
| 26 | + if (duration.count() >= 1000) |
| 27 | + time_histogram[1000]++; |
| 28 | + else |
| 29 | + time_histogram[duration.count()]++; |
| 30 | + if (true_time.earliest_ns + 10000 <= true_time.latest_ns) |
| 31 | + std::cout << "WoU is more than 10us [" << true_time.earliest_ns << "," |
| 32 | + << true_time.latest_ns << "] " << std::endl; |
| 33 | + } |
| 34 | + std::cout << "Histogram of query time:" << std::endl; |
| 35 | + for (int i = 0; i < 1001; i++) { |
| 36 | + if (time_histogram[i]) |
| 37 | + std::cout << i << "us: " << time_histogram[i] << std::endl; |
| 38 | + } |
| 39 | + fbclock_destroy(&fbclock); |
| 40 | +} |
0 commit comments