26 #include <proc/readproc.h>
34 auto timepoint = std::chrono::high_resolution_clock::now();
35 return std::chrono::duration_cast<std::chrono::nanoseconds>(
36 timepoint.time_since_epoch())
48 if (::clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts))
49 throw ::std::runtime_error(
50 "clock_gettime(CLOCK_PROCESS_CPUTIME_ID) failed");
58 return ts.tv_sec * 1000000000ll + ts.tv_nsec;
67 printf(
"Reset time counters for profiling\n");
81 std::map<std::pair<std::string, std::string>,
long long>
op_counts;
82 std::map<std::pair<std::string, std::string>,
long long>
91 #ifdef PROFILE_OP_COUNTS
122 const double avg_ms = total_ms / cnt;
124 " %-45s: %12.5fms = %lld * %0.5fms (%zu invocations, %0.5fms = %lld "
125 "* %0.5fms per invocation)\n",
138 printf(
"Dumping times:\n");
146 #ifdef PROFILE_OP_COUNTS
147 printf(
"Dumping operation counts:\n");
149 printf(
" %-45s: ", msg.first.c_str());
152 if (only_fq && data_point.first.compare(0, 2,
"Fq") != 0) {
160 "%-5s = %7.0f (%3zu)",
161 data_point.first.c_str(),
164 msg.first, data_point.first)] /
178 #ifdef PROFILE_OP_COUNTS
182 printf(
"(opcounts) = (");
192 *(p.second) -
op_counts[std::make_pair(msg, p.first)]);
201 static void print_times_from_last_and_start(
202 long long now,
long long last,
long long cpu_now,
long long cpu_last)
205 long long time_from_last = now - last;
208 long long cpu_time_from_last = cpu_now - cpu_last;
210 if (time_from_last != 0) {
211 double parallelism_from_last =
212 1.0 * cpu_time_from_last / time_from_last;
213 printf(
"[%0.4fs x%0.2f]", time_from_last * 1e-9, parallelism_from_last);
217 if (time_from_start != 0) {
218 double parallelism_from_start =
219 1.0 * cpu_time_from_start / time_from_start;
221 "\t(%0.4fs x%0.2f from start)",
222 time_from_start * 1e-9,
223 parallelism_from_start);
236 printf(
"%-35s\t", msg);
238 #ifdef PROFILE_OP_COUNTS
250 printf(
"\n================================================================="
251 "===============\n");
253 printf(
"==================================================================="
254 "=============\n\n");
267 op_counts[std::make_pair(msg, p.first)] = *(p.second);
294 printf(
"(enter) %-35s\t", msg.c_str());
295 print_times_from_last_and_start(t, t, cpu_t, cpu_t);
325 #ifdef PROFILE_OP_COUNTS
328 *(p.second) -
op_counts[std::make_pair(msg, p.first)];
345 printf(
"(leave) %-35s\t", msg.c_str());
346 print_times_from_last_and_start(
358 look_up_our_self(&
usage);
361 "* Peak vsize (physical memory+swap) in mebibytes: %lu\n",
365 "* Peak vsize (physical memory+swap) in mebibytes (%s): %lu\n",
371 printf(
"* Memory profiling not supported in NO_PROCPS mode\n");
378 printf(
"g++ version: %s\n", __VERSION__);
379 printf(
"Compiled on %s %s\n", __DATE__, __TIME__);
382 printf(
"STATIC: yes\n");
384 printf(
"STATIC: no\n");
387 printf(
"MULTICORE: yes\n");
389 printf(
"MULTICORE: no\n");
392 printf(
"DEBUG: yes\n");
394 printf(
"DEBUG: no\n");
396 #ifdef PROFILE_OP_COUNTS
397 printf(
"PROFILE_OP_COUNTS: yes\n");
399 printf(
"PROFILE_OP_COUNTS: no\n");
401 #ifdef _GLIBCXX_DEBUG
402 printf(
"_GLIBCXX_DEBUG: yes\n");
404 printf(
"_GLIBCXX_DEBUG: no\n");