[6893b5]: libperf_events / operf_stats.cpp  Maximize  Restore  History

Download this file

82 lines (73 with data), 3.2 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/**
* @file libperf_events/operf_stats.cpp
* Management of operf statistics
*
* @remark Copyright 2012 OProfile authors
* @remark Read the file COPYING
*
* Created on: June 11, 2012
* @author Maynard Johnson
* (C) Copyright IBM Corp. 2012
*/
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "operf_stats.h"
#include "op_get_time.h"
unsigned long operf_stats[OPERF_MAX_STATS];
/**
* operf_print_stats - print out latest statistics to operf.log
*/
using namespace std;
void operf_print_stats(string sessiondir, char * starttime, bool throttled)
{
string operf_log (sessiondir);
operf_log.append("/samples/operf.log");
FILE * fp = fopen(operf_log.c_str(), "a");
fprintf(fp, "\nProfiling started at %s", starttime);
fprintf(fp, "Profiling stopped at %s", op_get_time());
fprintf(fp, "\n-- OProfile/operf Statistics --\n");
fprintf(fp, "Nr. non-backtrace samples: %lu\n", operf_stats[OPERF_SAMPLES]);
fprintf(fp, "Nr. kernel samples: %lu\n", operf_stats[OPERF_KERNEL]);
fprintf(fp, "Nr. user space samples: %lu\n", operf_stats[OPERF_PROCESS]);
fprintf(fp, "Nr. samples lost due to sample address not in expected range for domain: %lu\n",
operf_stats[OPERF_INVALID_CTX]);
fprintf(fp, "Nr. lost kernel samples: %lu\n", operf_stats[OPERF_LOST_KERNEL]);
fprintf(fp, "Nr. samples lost due to sample file open failure: %lu\n",
operf_stats[OPERF_LOST_SAMPLEFILE]);
fprintf(fp, "Nr. samples lost due to no permanent mapping: %lu\n",
operf_stats[OPERF_LOST_NO_MAPPING]);
fprintf(fp, "Nr. user context kernel samples lost due to no app info available: %lu\n",
operf_stats[OPERF_NO_APP_KERNEL_SAMPLE]);
fprintf(fp, "Nr. user samples lost due to no app info available: %lu\n",
operf_stats[OPERF_NO_APP_USER_SAMPLE]);
fprintf(fp, "Nr. backtraces skipped due to no file mapping: %lu\n",
operf_stats[OPERF_BT_LOST_NO_MAPPING]);
fprintf(fp, "Nr. hypervisor samples dropped due to address out-of-range: %lu\n",
operf_stats[OPERF_LOST_INVALID_HYPERV_ADDR]);
fprintf(fp, "Nr. samples lost reported by perf_events kernel: %lu\n",
operf_stats[OPERF_RECORD_LOST_SAMPLE]);
if (operf_stats[OPERF_RECORD_LOST_SAMPLE]) {
fprintf(stderr, "\n\n * * * ATTENTION: The kernel lost %lu samples. * * *\n",
operf_stats[OPERF_RECORD_LOST_SAMPLE]);
fprintf(stderr, "Decrease the sampling rate to eliminate (or reduce) lost samples.\n");
} else if (throttled) {
fprintf(stderr, "* * * * WARNING: Profiling rate was throttled back by the kernel * * * *\n");
fprintf(stderr, "The number of samples actually recorded is less than expected, but is\n");
fprintf(stderr, "probably still statistically valid. Decreasing the sampling rate is the\n");
fprintf(stderr, "best option if you want to avoid throttling.");
}
// 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)
fprintf(stderr, "\nSee the %s file for statistics about lost samples.\n", operf_log.c_str());
fflush(fp);
}

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks