MCPcopy Create free account
hub / github.com/PlatformLab/NanoLog / runBenchmark

Function runBenchmark

benchmarks/Benchmark.cc:51–203  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

49
50using namespace NanoLog::LogLevels;
51void runBenchmark(int id, pthread_barrier_t *barrier)
52{
53 // Number of messages to log repeatedly and take the average latency
54 uint64_t start, stop;
55 double time;
56
57 // PerfUtils::Util::pinThreadToCore(1);
58
59 // Optional optimization: pre-allocates thread-local data structures
60 // needed by NanoLog. This should be invoked once per new
61 // thread that will use the NanoLog system.
62 PerfUtils::TimeTrace::record("Thread[%d]: Preallocation", id);
63 PerfUtils::TimeTrace::record("Thread[%d]: Preallocation", id);
64 NanoLog::preallocate();
65 PerfUtils::TimeTrace::record("Thread[%d]: Preallocation Done", id);
66
67 PerfUtils::TimeTrace::record("Thread[%d]: Waiting for barrier...", id);
68 pthread_barrier_wait(barrier);
69
70 PerfUtils::TimeTrace::record("Thread[%d]: Starting benchmark", id);
71 start = PerfUtils::Cycles::rdtsc();
72
73 for (int i = 0; i < ITERATIONS; ++i) {
74 BENCH_OPS
75 }
76 stop = PerfUtils::Cycles::rdtsc();
77 PerfUtils::TimeTrace::record("Thread[%d]: Benchmark Done", id);
78
79 time = PerfUtils::Cycles::toSeconds(stop - start);
80 printf("Thread[%d]: The total time spent invoking BENCH_OP %lu "
81 "times took %0.2lf seconds (%0.2lf ns/op average)\r\n",
82 id, ITERATIONS, time, (time/ITERATIONS)*1e9);
83
84 // Break abstraction to bring metrics on cycles blocked.
85 uint32_t nBlocks = NanoLogInternal::RuntimeLogger::stagingBuffer->numTimesProducerBlocked;
86 double timeBlocked = 1e9*PerfUtils::Cycles::toSeconds(
87 NanoLogInternal::RuntimeLogger::stagingBuffer->cyclesProducerBlocked);
88 printf("Thread[%d]: Time producer was stuck for = %0.2e ns (avg: %0.2e ns cnt: %u)\r\n",
89 id,
90 timeBlocked,
91 timeBlocked/nBlocks,
92 nBlocks);
93}
94
95int main(int argc, char** argv) {
96 // Optional: Set the output location for the NanoLog system. By default
97 // the log will be output to /tmp/compressedLog
98 // NanoLog::setLogFile("/tmp/logFile");
99 NanoLog::setLogFile(BENCHMARK_OUTPUT_FILE);
100
101 printf("BENCH_OP = %s\r\n", BENCH_OPS_AS_A_STR);
102
103#ifdef PREPROCESSOR_NANOLOG
104 constexpr const char system[] = "PreProc";
105#else
106 constexpr const char system[] = "C++17";
107#endif
108 printf("NanoLog System: %s\r\n", system);

Callers 1

mainFunction · 0.70

Calls 2

preallocateFunction · 0.85
rdtscFunction · 0.85

Tested by

no test coverage detected