1 #ifndef PfmCodeAnalyserH 2 #define PfmCodeAnalyserH 1 12 #include <sys/types.h> 15 #define MAX_EVT_NAME_LEN 256 16 #define NUM_PMCS PFMLIB_MAX_PMCS 17 #define NUM_PMDS PFMLIB_MAX_PMDS 18 #define FMT_NAME PFM_DFL_SMPL_NAME 19 #define MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS 4 20 #define cpuid( func, eax, ebx, ecx, edx ) \ 21 __asm__ __volatile__( "cpuid" : "=a"( eax ), "=b"( ebx ), "=c"( ecx ), "=d"( edx ) : "a"( func ) ); 47 PfmCodeAnalyser(
const char* event0,
unsigned int cmask_v0,
bool inv_v0,
const char* event1,
unsigned int cmask_v1,
48 bool inv_v1,
const char* event2,
unsigned int cmask_v2,
bool inv_v2,
const char* event3,
49 unsigned int cmask_v3,
bool inv_v3 );
56 bool inv_v0 =
false,
const char* event1 =
"",
unsigned int cmask_v1 = 0,
57 bool inv_v1 =
false,
const char* event2 =
"",
unsigned int cmask_v2 = 0,
58 bool inv_v2 =
false,
const char* event3 =
"",
unsigned int cmask_v3 = 0,
59 bool inv_v3 =
false );
66 unsigned int cmask_v1,
bool inv_v1,
const char* event2,
unsigned int cmask_v2,
67 bool inv_v2,
const char* event3,
unsigned int cmask_v3,
bool inv_v3 )
70 cpuid( 1, ax, bx, cx, dx );
71 int sse4_2_mask = 1 << 20;
95 printf(
"Cannot initialize perfmon!!\nExiting...\n" );
106 while (
count < 10 ) {
118 unsigned int cmask_v1,
bool inv_v1,
const char* event2,
119 unsigned int cmask_v2,
bool inv_v2,
const char* event3,
120 unsigned int cmask_v3,
bool inv_v3 )
122 static PfmCodeAnalyser theSingleton( event0, cmask_v0, inv_v0, event1, cmask_v1, inv_v1, event2, cmask_v2, inv_v2,
123 event3, cmask_v3, inv_v3 );
131 memset( &
ctx, 0,
sizeof(
ctx ) );
132 memset( &
inp, 0,
sizeof(
inp ) );
134 memset(
pd, 0,
sizeof(
pd ) );
135 memset(
pc, 0,
sizeof(
pc ) );
141 fprintf( stderr,
"ERROR: cannot find event: %s\naborting...\n",
event_str[i] );
152 if (
cmask[i] > 0 ) {
163 fprintf( stderr,
"ERROR: cannot dispatch events: %s\naborting...\n",
pfm_strerror(
ret ) );
176 fprintf( stderr,
"ERROR: Context not created\naborting...\n" );
180 fprintf( stderr,
"ERROR: Could not write pmcs\naborting...\n" );
184 fprintf( stderr,
"ERROR: Could not write pmds\naborting...\n" );
189 fprintf( stderr,
"ERROR: Could not load context\naborting...\n" );
203 fprintf( stderr,
"ERROR: Could not read pmds\naborting...\n" );
218 fprintf( stderr,
"ERROR: Could not read pmds\naborting...\n" );
232 printf(
"Event: %s\nTotal count:%lu\nNumber of counts:%u\nAverage count:%f\nOverhead removed:%u\n",
event_str[
i],
237 #endif // PfmCodeAnalyserH pfmlib_reg_t pfp_pmds[PFMLIB_MAX_PMDS]
os_err_t pfm_write_pmds(int fd, pfarg_pmd_t *pmds, int count)
os_err_t pfm_create_context(pfarg_ctx_t *ctx, char *smpl_name, void *smpl_arg, size_t smpl_size)
char * pfm_strerror(int code)
pfmlib_nhm_input_param_t nhm_params
#define MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS
char event_str[MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS][MAX_EVT_NAME_LEN]
os_err_t pfm_write_pmcs(int fd, pfarg_pmc_t *pmcs, int count)
pfm_err_t pfm_dispatch_events(pfmlib_input_param_t *p, void *model_in, pfmlib_output_param_t *q, void *model_out)
unsigned int pfp_pmc_count
unsigned long long reg_value
unsigned int pfp_pmd_count
pfm_err_t pfm_find_full_event(const char *str, pfmlib_event_t *e)
pfmlib_core_input_param_t params
unsigned int cmask[MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS]
PfmCodeAnalyser & operator=(PfmCodeAnalyser const &)
unsigned overhead_avg[MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS]
unsigned long sum[MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS]
os_err_t pfm_start(int fd, pfarg_start_t *start)
pfm_err_t pfm_initialize(void)
#define cpuid(func, eax, ebx, ecx, edx)
os_err_t pfm_load_context(int fd, pfarg_load_t *load)
PfmCodeAnalyser(const char *event0, unsigned int cmask_v0, bool inv_v0, const char *event1, unsigned int cmask_v1, bool inv_v1, const char *event2, unsigned int cmask_v2, bool inv_v2, const char *event3, unsigned int cmask_v3, bool inv_v3)
os_err_t pfm_read_pmds(int fd, pfarg_pmd_t *pmds, int count)
bool inv[MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS]
pfmlib_reg_t pfp_pmcs[PFMLIB_MAX_PMCS]
pfmlib_output_param_t outp
os_err_t pfm_stop(int fd)
static PfmCodeAnalyser & Instance(const char *event0="UNHALTED_CORE_CYCLES", unsigned int cmask_v0=0, bool inv_v0=false, const char *event1="", unsigned int cmask_v1=0, bool inv_v1=false, const char *event2="", unsigned int cmask_v2=0, bool inv_v2=false, const char *event3="", unsigned int cmask_v3=0, bool inv_v3=false)