From: Carl E. L. <ce...@li...> - 2012-08-01 17:36:56
|
operf report: print lost sample warning only if lost samples exceeds threshold Currently a warning is printed if there are any lost samples when collecting data using the operf tool. This patch changes the code to print the warning when the total number of lost samples, for whatever reason, exceeds a threshold of the total number of samples. Initially, the threshold has been set to 0.01% of the total number of samples. Signed-off-by: Carl Love <ce...@us...> --- libperf_events/operf_stats.cpp | 15 +++++++-------- libperf_events/operf_stats.h | 5 +++++ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/libperf_events/operf_stats.cpp b/libperf_events/operf_stats.cpp index ba2db25..0b4c7f5 100644 --- a/libperf_events/operf_stats.cpp +++ b/libperf_events/operf_stats.cpp @@ -27,6 +27,8 @@ using namespace std; void operf_print_stats(string sessiondir, char * starttime, bool throttled) { string operf_log (sessiondir); + int total_lost_samples = 0; + operf_log.append("/samples/operf.log"); FILE * fp = fopen(operf_log.c_str(), "a"); fprintf(fp, "\nProfiling started at %s", starttime); @@ -67,14 +69,11 @@ void operf_print_stats(string sessiondir, char * starttime, bool throttled) // TODO: handle extended stats //operf_ext_print_stats(); - bool print_log_info_msg = false; - for (int i = OPERF_INDEX_OF_FIRST_LOST_STAT; i < OPERF_MAX_STATS; i++) { - if (operf_stats[i]) { - print_log_info_msg = true; - break; - } - } - if (print_log_info_msg) + for (int i = OPERF_INDEX_OF_FIRST_LOST_STAT; i < OPERF_MAX_STATS; i++) + total_lost_samples += operf_stats[i]; + + if (total_lost_samples > (int)(OPERF_WARN_LOST_SAMPLES_THRESHOLD + * operf_stats[OPERF_SAMPLES])) fprintf(stderr, "\nSee the %s file for statistics about lost samples.\n", operf_log.c_str()); fflush(fp); diff --git a/libperf_events/operf_stats.h b/libperf_events/operf_stats.h index 48dbc1b..15d39b3 100644 --- a/libperf_events/operf_stats.h +++ b/libperf_events/operf_stats.h @@ -33,6 +33,11 @@ enum { OPERF_SAMPLES, /**< nr. samples */ }; #define OPERF_INDEX_OF_FIRST_LOST_STAT 3 +/* Warn on lost samples if number of lost samples is greater the this fraction + * of the total samples +*/ +#define OPERF_WARN_LOST_SAMPLES_THRESHOLD 0.0001 + void operf_print_stats(std::string sampledir, char * starttime, bool throttled); #endif /* OPERF_STATS_H */ -- 1.7.11.2.249.g31c7954 |