PfmCodeAnalyser Class Reference

#include <GaudiProfiling/PfmCodeAnalyser.h>

Collaboration diagram for PfmCodeAnalyser:

Public Member Functions

void start ()
 
void stop ()
 
void stop_init ()
 

Static Public Member Functions

static PfmCodeAnalyserInstance (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)
 

Private Member Functions

 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)
 
 PfmCodeAnalyser (PfmCodeAnalyser const &)
 
PfmCodeAnalyseroperator= (PfmCodeAnalyser const &)
 
 ~PfmCodeAnalyser ()
 

Private Attributes

int used_counters_number
 
int nehalem
 
pfmlib_input_param_t inp
 
pfmlib_output_param_t outp
 
pfarg_ctx_t ctx
 
pfarg_pmd_t pd [NUM_PMDS]
 
pfarg_pmc_t pc [NUM_PMCS]
 
pfarg_load_t load_arg
 
int fd
 
char event_str [MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS][MAX_EVT_NAME_LEN]
 
bool inv [MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS]
 
unsigned int cmask [MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS]
 
pfmlib_core_input_param_t params
 
pfmlib_nhm_input_param_t nhm_params
 
int ret
 
unsigned i
 
unsigned long sum [MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS]
 
unsigned count
 
unsigned overhead_avg [MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS]
 

Detailed Description

Definition at line 22 of file PfmCodeAnalyser.h.

Constructor & Destructor Documentation

PfmCodeAnalyser::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 
)
private

Definition at line 64 of file PfmCodeAnalyser.h.

68 {
69  int ax,bx,cx,dx;
70  cpuid(1,ax,bx,cx,dx);
71  int sse4_2_mask = 1 << 20;
72  nehalem = cx & sse4_2_mask;
73  strcpy(event_str[0], event0);
74  strcpy(event_str[1], event1);
75  strcpy(event_str[2], event2);
76  strcpy(event_str[3], event3);
77  cmask[0] = cmask_v0;
78  cmask[1] = cmask_v1;
79  cmask[2] = cmask_v2;
80  cmask[3] = cmask_v3;
81  inv[0] = inv_v0;
82  inv[1] = inv_v1;
83  inv[2] = inv_v2;
84  inv[3] = inv_v3;
87  {
89  }
90  for(int i=0; i<used_counters_number; i++)
91  {
92  sum[i] = 0;
93  overhead_avg[i] = 0;
94  }
95  count = 0;
97  {
98  printf("Cannot initialize perfmon!!\nExiting...\n");
99  exit(0);
100  }
101  while(count<3)
102  {
103  start();
104  stop_init();
105  }
106  for(int i=0; i<used_counters_number; i++)
107  {
108  sum[i] = 0;
109  }
110  count = 0;
111  while(count<10)
112  {
113  start();
114  stop_init();
115  }
116  for(int i=0; i<used_counters_number; i++)
117  {
118  overhead_avg[i] = sum[i]/count;
119  sum[i] = 0;
120  }
121  count = 0;
122 }
#define MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS
#define cpuid(func, eax, ebx, ecx, edx)
#define PFMLIB_SUCCESS
Definition: pfmlib.h:283
char event_str[MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS][MAX_EVT_NAME_LEN]
unsigned int cmask[MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS]
T exit(T...args)
T strlen(T...args)
unsigned overhead_avg[MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS]
unsigned long sum[MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS]
pfm_err_t pfm_initialize(void)
T strcpy(T...args)
bool inv[MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS]
T printf(T...args)
PfmCodeAnalyser::PfmCodeAnalyser ( PfmCodeAnalyser const &  )
private
PfmCodeAnalyser::~PfmCodeAnalyser ( )
private

Definition at line 255 of file PfmCodeAnalyser.h.

256 {
257  for(int i=0; i<used_counters_number; i++)
258  {
259  printf("Event: %s\nTotal count:%lu\nNumber of counts:%u\nAverage count:%f\nOverhead removed:%u\n", event_str[i], sum[i], count, (double)sum[i]/count, overhead_avg[i]);
260  }
261 }
char event_str[MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS][MAX_EVT_NAME_LEN]
unsigned overhead_avg[MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS]
unsigned long sum[MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS]
T printf(T...args)

Member Function Documentation

PfmCodeAnalyser & 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 
)
static

Definition at line 124 of file PfmCodeAnalyser.h.

128 {
129  static PfmCodeAnalyser theSingleton(event0, cmask_v0, inv_v0, event1, cmask_v1, inv_v1, event2, cmask_v2, inv_v2, event3, cmask_v3, inv_v3);
130  return theSingleton;
131 }
PfmCodeAnalyser& PfmCodeAnalyser::operator= ( PfmCodeAnalyser const &  )
private
void PfmCodeAnalyser::start ( )

Definition at line 135 of file PfmCodeAnalyser.h.

136 {
137  memset(&ctx,0, sizeof(ctx));
138  memset(&inp,0, sizeof(inp));
139  memset(&outp,0, sizeof(outp));
140  memset(pd, 0, sizeof(pd));
141  memset(pc, 0, sizeof(pc));
142  memset(&load_arg, 0, sizeof(load_arg));
143  memset(&params, 0, sizeof(params));
144  for(int i=0; i<used_counters_number; i++)
145  {
147  if(ret != PFMLIB_SUCCESS)
148  {
149  fprintf(stderr, "ERROR: cannot find event: %s\naborting...\n", event_str[i]);
150  exit(1);
151  }
152  }
155  for(int i=0; i<used_counters_number; i++)
156  {
157  if(inv[i])
158  {
161  }
162  if(cmask[i]>0)
163  {
164  (params.pfp_core_counters[i]).cnt_mask = cmask[i];
165  (nhm_params.pfp_nhm_counters[i]).cnt_mask = cmask[i];
166  }
167  }
168  if(nehalem)
169  {
170  ret = pfm_dispatch_events(&inp, &nhm_params, &outp, NULL);
171  }
172  else
173  {
174  ret = pfm_dispatch_events(&inp, &params, &outp, NULL);
175  }
176  if(ret != PFMLIB_SUCCESS)
177  {
178  fprintf(stderr, "ERROR: cannot dispatch events: %s\naborting...\n", pfm_strerror(ret));
179  exit(1);
180  }
181  for(unsigned int i=0; i<outp.pfp_pmc_count; i++)
182  {
185  }
186  for(unsigned int i=0; i<outp.pfp_pmd_count; i++)
187  {
189  pd[i].reg_value = 0;
190  }
191  fd = pfm_create_context(&ctx, NULL, 0, 0);
192  if(fd == -1)
193  {
194  fprintf(stderr, "ERROR: Context not created\naborting...\n");
195  exit(1);
196  }
197  if(pfm_write_pmcs(fd, pc, outp.pfp_pmc_count) == -1)
198  {
199  fprintf(stderr, "ERROR: Could not write pmcs\naborting...\n");
200  exit(1);
201  }
202  if(pfm_write_pmds(fd, pd, outp.pfp_pmd_count) == -1)
203  {
204  fprintf(stderr, "ERROR: Could not write pmds\naborting...\n");
205  exit(1);
206  }
207  load_arg.load_pid = getpid();
208  if(pfm_load_context(fd, &load_arg) == -1)
209  {
210  fprintf(stderr, "ERROR: Could not load context\naborting...\n");
211  exit(1);
212  }
213  pfm_start(fd, NULL);
214 }
pfmlib_reg_t pfp_pmds[PFMLIB_MAX_PMDS]
Definition: pfmlib.h:130
pfarg_load_t load_arg
os_err_t pfm_write_pmds(int fd, pfarg_pmd_t *pmds, int count)
#define PFM_NHM_SEL_INV
os_err_t pfm_create_context(pfarg_ctx_t *ctx, char *smpl_name, void *smpl_arg, size_t smpl_size)
#define PFM_PLM3
Definition: pfmlib.h:53
char * pfm_strerror(int code)
pfmlib_nhm_input_param_t nhm_params
pfmlib_event_t pfp_events[PFMLIB_MAX_PMCS]
Definition: pfmlib.h:113
#define PFM_CORE_SEL_INV
Definition: pfmlib_core.h:68
pfmlib_nhm_counter_t pfp_nhm_counters[PMU_NHM_NUM_COUNTERS]
pfarg_ctx_t ctx
#define PFMLIB_SUCCESS
Definition: pfmlib.h:283
char event_str[MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS][MAX_EVT_NAME_LEN]
unsigned int pfp_dfl_plm
Definition: pfmlib.h:110
uint16_t reg_num
Definition: perfmon_v2.h:39
T memset(T...args)
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
Definition: pfmlib.h:127
unsigned long long reg_value
Definition: pfmlib.h:98
unsigned int pfp_pmd_count
Definition: pfmlib.h:128
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]
T exit(T...args)
pfarg_pmc_t pc[NUM_PMCS]
unsigned int reg_num
Definition: pfmlib.h:100
pfarg_pmd_t pd[NUM_PMDS]
uint16_t reg_num
Definition: perfmon_v2.h:28
os_err_t pfm_start(int fd, pfarg_start_t *start)
uint32_t load_pid
Definition: perfmon_v2.h:69
pfmlib_input_param_t inp
os_err_t pfm_load_context(int fd, pfarg_load_t *load)
uint64_t reg_value
Definition: perfmon_v2.h:31
bool inv[MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS]
pfmlib_reg_t pfp_pmcs[PFMLIB_MAX_PMCS]
Definition: pfmlib.h:129
pfmlib_core_counter_t pfp_core_counters[PMU_CORE_NUM_COUNTERS]
Definition: pfmlib_core.h:79
pfmlib_output_param_t outp
T fprintf(T...args)
uint64_t reg_value
Definition: perfmon_v2.h:42
unsigned int pfp_event_count
Definition: pfmlib.h:109
void PfmCodeAnalyser::stop ( )

Definition at line 221 of file PfmCodeAnalyser.h.

222 {
223  pfm_stop(fd);
224  if(pfm_read_pmds(fd, pd, inp.pfp_event_count) == -1)
225  {
226  fprintf(stderr, "ERROR: Could not read pmds\naborting...\n");
227  exit(1);
228  }
229 
230  for(int i=0; i<used_counters_number; i++)
231  {
232  sum[i] += (pd[i].reg_value - overhead_avg[i]);
233  }
234  count++;
235  close(fd);
236 }
T exit(T...args)
pfarg_pmd_t pd[NUM_PMDS]
unsigned overhead_avg[MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS]
unsigned long sum[MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS]
pfmlib_input_param_t inp
os_err_t pfm_read_pmds(int fd, pfarg_pmd_t *pmds, int count)
os_err_t pfm_stop(int fd)
T fprintf(T...args)
uint64_t reg_value
Definition: perfmon_v2.h:42
unsigned int pfp_event_count
Definition: pfmlib.h:109
void PfmCodeAnalyser::stop_init ( )

Definition at line 238 of file PfmCodeAnalyser.h.

239 {
240  pfm_stop(fd);
241  if(pfm_read_pmds(fd, pd, inp.pfp_event_count) == -1)
242  {
243  fprintf(stderr, "ERROR: Could not read pmds\naborting...\n");
244  exit(1);
245  }
246 
247  for(int i=0; i<used_counters_number; i++)
248  {
249  sum[i] += (pd[i].reg_value);
250  }
251  count++;
252  close(fd);
253 }
T exit(T...args)
pfarg_pmd_t pd[NUM_PMDS]
unsigned long sum[MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS]
pfmlib_input_param_t inp
os_err_t pfm_read_pmds(int fd, pfarg_pmd_t *pmds, int count)
os_err_t pfm_stop(int fd)
T fprintf(T...args)
uint64_t reg_value
Definition: perfmon_v2.h:42
unsigned int pfp_event_count
Definition: pfmlib.h:109

Member Data Documentation

unsigned int PfmCodeAnalyser::cmask[MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS]
private

Definition at line 36 of file PfmCodeAnalyser.h.

unsigned PfmCodeAnalyser::count
private

Definition at line 42 of file PfmCodeAnalyser.h.

pfarg_ctx_t PfmCodeAnalyser::ctx
private

Definition at line 29 of file PfmCodeAnalyser.h.

char PfmCodeAnalyser::event_str[MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS][MAX_EVT_NAME_LEN]
private

Definition at line 34 of file PfmCodeAnalyser.h.

int PfmCodeAnalyser::fd
private

Definition at line 33 of file PfmCodeAnalyser.h.

unsigned PfmCodeAnalyser::i
private

Definition at line 40 of file PfmCodeAnalyser.h.

pfmlib_input_param_t PfmCodeAnalyser::inp
private

Definition at line 27 of file PfmCodeAnalyser.h.

bool PfmCodeAnalyser::inv[MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS]
private

Definition at line 35 of file PfmCodeAnalyser.h.

pfarg_load_t PfmCodeAnalyser::load_arg
private

Definition at line 32 of file PfmCodeAnalyser.h.

int PfmCodeAnalyser::nehalem
private

Definition at line 26 of file PfmCodeAnalyser.h.

pfmlib_nhm_input_param_t PfmCodeAnalyser::nhm_params
private

Definition at line 38 of file PfmCodeAnalyser.h.

pfmlib_output_param_t PfmCodeAnalyser::outp
private

Definition at line 28 of file PfmCodeAnalyser.h.

unsigned PfmCodeAnalyser::overhead_avg[MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS]
private

Definition at line 43 of file PfmCodeAnalyser.h.

pfmlib_core_input_param_t PfmCodeAnalyser::params
private

Definition at line 37 of file PfmCodeAnalyser.h.

pfarg_pmc_t PfmCodeAnalyser::pc[NUM_PMCS]
private

Definition at line 31 of file PfmCodeAnalyser.h.

pfarg_pmd_t PfmCodeAnalyser::pd[NUM_PMDS]
private

Definition at line 30 of file PfmCodeAnalyser.h.

int PfmCodeAnalyser::ret
private

Definition at line 39 of file PfmCodeAnalyser.h.

unsigned long PfmCodeAnalyser::sum[MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS]
private

Definition at line 41 of file PfmCodeAnalyser.h.

int PfmCodeAnalyser::used_counters_number
private

Definition at line 25 of file PfmCodeAnalyser.h.


The documentation for this class was generated from the following file: