27#include <proc/readproc.h>
34 auto timepoint = std::chrono::high_resolution_clock::now();
35 return std::chrono::duration_cast<std::chrono::nanoseconds>(timepoint.time_since_epoch()).count();
45 if ( ::clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts) )
46 throw ::std::runtime_error(
"clock_gettime(CLOCK_PROCESS_CPUTIME_ID) failed");
49 return ts.tv_sec * 1000000000ll + ts.tv_nsec;
58 printf(
"Reset time counters for profiling\n");
71std::map<std::pair<std::string, std::string>,
long long>
op_counts;
79#ifdef PROFILE_OP_COUNTS
110 const double avg_ms = total_ms / cnt;
111 printf(
" %-45s: %12.5fms = %lld * %0.5fms (%zu invocations, %0.5fms = %lld * %0.5fms per invocation)\n", key.c_str(), total_ms, factor, total_ms/factor, cnt, avg_ms, factor, avg_ms/factor);
116 printf(
"Dumping times:\n");
125#ifdef PROFILE_OP_COUNTS
126 printf(
"Dumping operation counts:\n");
129 printf(
" %-45s: ", msg.first.c_str());
133 if (only_fq && data_point.first.compare(0, 2,
"Fq") != 0)
142 printf(
"%-5s = %7.0f (%3zu)",
143 data_point.first.c_str(),
157#ifdef PROFILE_OP_COUNTS
161 printf(
"(opcounts) = (");
170 printf(
"%s=%lld",
p.first.c_str(), *(
p.second)-
op_counts[std::make_pair(msg,
p.first)]);
179static void print_times_from_last_and_start(
long long now,
long long last,
180 long long cpu_now,
long long cpu_last)
183 long long time_from_last = now - last;
186 long long cpu_time_from_last = cpu_now - cpu_last;
188 if (time_from_last != 0) {
189 double parallelism_from_last = 1.0 * cpu_time_from_last / time_from_last;
190 printf(
"[%0.4fs x%0.2f]", time_from_last * 1e-9, parallelism_from_last);
194 if (time_from_start != 0) {
195 double parallelism_from_start = 1.0 * cpu_time_from_start / time_from_start;
196 printf(
"\t(%0.4fs x%0.2f from start)", time_from_start * 1e-9, parallelism_from_start);
210 printf(
"%-35s\t", msg);
212#ifdef PROFILE_OP_COUNTS
224 printf(
"\n================================================================================\n");
226 printf(
"================================================================================\n\n");
241 op_counts[std::make_pair(msg,
p.first)] = *(
p.second);
270 printf(
"(enter) %-35s\t", msg.c_str());
271 print_times_from_last_and_start(t, t, cpu_t, cpu_t);
303#ifdef PROFILE_OP_COUNTS
325 printf(
"(leave) %-35s\t", msg.c_str());
337 look_up_our_self(&usage);
340 printf(
"* Peak vsize (physical memory+swap) in mebibytes: %lu\n", usage.vsize >> 20);
344 printf(
"* Peak vsize (physical memory+swap) in mebibytes (%s): %lu\n",
s.c_str(), usage.vsize >> 20);
347 printf(
"* Memory profiling not supported in NO_PROCPS mode\n");
354 printf(
"g++ version: %s\n", __VERSION__);
355 printf(
"Compiled on %s %s\n", __DATE__, __TIME__);
358 printf(
"STATIC: yes\n");
360 printf(
"STATIC: no\n");
363 printf(
"MULTICORE: yes\n");
365 printf(
"MULTICORE: no\n");
368 printf(
"DEBUG: yes\n");
370 printf(
"DEBUG: no\n");
372#ifdef PROFILE_OP_COUNTS
373 printf(
"PROFILE_OP_COUNTS: yes\n");
375 printf(
"PROFILE_OP_COUNTS: no\n");
378 printf(
"_GLIBCXX_DEBUG: yes\n");
380 printf(
"_GLIBCXX_DEBUG: no\n");
LOGGING_API void printf(Category category, const char *format,...)
typename EC_ppT::Fq_type Fq
void clear_profiling_counters()
std::map< std::string, size_t > invocation_counts
typename EC_ppT::G1_type G1
std::map< std::string, long long > last_cpu_times
void print_mem(const std::string &s)
std::map< std::string, long long > cumulative_times
typename EC_ppT::Fp_type Fr
std::map< std::pair< std::string, std::string >, long long > cumulative_op_counts
void print_cumulative_op_counts(const bool only_fq)
void print_time(const char *msg)
std::vector< std::string > block_names
std::map< std::string, long long > enter_times
void print_header(const char *msg)
void enter_block(const std::string &msg, const bool indent)
void print_cumulative_time_entry(const std::string &key, const long long factor)
void print_op_profiling(const std::string &msg)
long long get_nsec_time()
void op_profiling_enter(const std::string &msg)
bool inhibit_profiling_info
std::map< std::pair< std::string, std::string >, long long > op_counts
std::list< std::pair< std::string, long long * > > op_data_points
void print_cumulative_times(const long long factor)
std::map< std::string, long long > last_times
bool inhibit_profiling_counters
void leave_block(const std::string &msg, const bool indent)
void print_compilation_info()
long long get_nsec_cpu_time()
std::map< std::string, long long > enter_cpu_times