/* Warm up CPU. */ static void warm_up_cpu (void) { struct nsec_time start, end; get_nsec_time (&start); do { get_nsec_time (&end); } while (get_time_nsec_diff (&start, &end) < 1000.0 * 1000.0 * 1000.0); }
void start_profiling() { printf("Reset time counters for profiling\n"); last_time = start_time = get_nsec_time(); last_cpu_time = start_cpu_time = get_nsec_cpu_time(); }
void enter_block(const std::string &msg, const bool indent) { if (inhibit_profiling_counters) { return; } block_names.emplace_back(msg); long long t = get_nsec_time(); enter_times[msg] = t; if (inhibit_profiling_info) { return; } #ifdef MULTICORE #pragma omp critical #endif { op_profiling_enter(msg); print_indent(); printf("(enter) %-35s\t[0s]\t(%0.4fs from start)\n", msg.c_str(), (t - start_time) * 1e-9); fflush(stdout); if (indent) { ++indentation; } } }
void leave_block(const std::string &msg, const bool indent) { if (inhibit_profiling_counters) { return; } #ifndef MULTICORE assert(*(--block_names.end()) == msg); #endif block_names.pop_back(); ++invocation_counts[msg]; long long t = get_nsec_time(); last_times[msg] = (t - enter_times[msg]); cumulative_times[msg] += (t - enter_times[msg]); long long cpu_t = get_nsec_cpu_time(); last_cpu_times[msg] = (cpu_t - enter_cpu_times[msg]); #ifdef PROFILE_OP_COUNTS for (std::pair<std::string, long long*> p : op_data_points) { cumulative_op_counts[std::make_pair(msg, p.first)] += *(p.second)-op_counts[std::make_pair(msg, p.first)]; } #endif if (inhibit_profiling_info) { return; } #ifdef MULTICORE #pragma omp critical #endif { if (indent) { --indentation; } print_indent(); printf("(leave) %-35s\t", msg.c_str()); print_times_from_last_and_start(t, enter_times[msg], cpu_t, enter_cpu_times[msg]); print_op_profiling(msg); printf("\n"); fflush(stdout); } }
double do_bench_obj_measurement (struct bench_obj *obj, void *buffer, size_t buflen, double *measurement_raw, unsigned int loop_iterations) { const unsigned int num_repetitions = obj->num_measure_repetitions; const bench_do_run_t do_run = obj->ops->do_run; struct nsec_time start, end; unsigned int rep, loop; double res; if (num_repetitions < 1 || loop_iterations < 1) return 0.0; for (rep = 0; rep < num_repetitions; rep++) { get_nsec_time (&start); for (loop = 0; loop < loop_iterations; loop++) do_run (obj, buffer, buflen); get_nsec_time (&end); measurement_raw[rep] = get_time_nsec_diff (&start, &end); } /* Return median of repeated measurements. */ qsort (measurement_raw, num_repetitions, sizeof (measurement_raw[0]), double_cmp); if (num_repetitions % 2 == 1) return measurement_raw[num_repetitions / 2]; res = measurement_raw[num_repetitions / 2] + measurement_raw[num_repetitions / 2 - 1]; return res / 2; }
void print_time(const char* msg) { if (inhibit_profiling_info) { return; } long long t = get_nsec_time(); printf("%-35s\t[%0.4fs]\t(%0.4fs from start)", msg, (t - last_time) * 1e-9, (t - start_time) * 1e-9); #ifdef PROFILE_OP_COUNTS print_op_profiling(msg); #endif printf("\n"); fflush(stdout); last_time = t; }
void print_time(const char* msg) { if (inhibit_profiling_info) { return; } long long now = get_nsec_time(); long long cpu_now = get_nsec_cpu_time(); printf("%-35s\t", msg); print_times_from_last_and_start(now, last_time, cpu_now, last_cpu_time); #ifdef PROFILE_OP_COUNTS print_op_profiling(msg); #endif printf("\n"); fflush(stdout); last_time = now; last_cpu_time = cpu_now; }
void enter_block(const std::string &msg, const bool indent) { if (inhibit_profiling_counters) { return; } block_names.emplace_back(msg); long long t = get_nsec_time(); enter_times[msg] = t; long long cpu_t = get_nsec_cpu_time(); enter_cpu_times[msg] = cpu_t; if (inhibit_profiling_info) { return; } #ifdef MULTICORE #pragma omp critical #endif { op_profiling_enter(msg); print_indent(); printf("(enter) %-35s\t", msg.c_str()); print_times_from_last_and_start(t, t, cpu_t, cpu_t); printf("\n"); fflush(stdout); if (indent) { ++indentation; } } }