| # Gaudi Framework, version v22r0 |

Home |  | Generated: 9 Feb 2011

# PfmCodeAnalyser Class Reference

`#include <PfmCodeAnalyser.h>`

Collaboration diagram for PfmCodeAnalyser:
[legend]

List of all members.

## Public Member Functions
void | start ()
void | stop ()
void | stop_init ()
## Static Public Member Functions
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)
## 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 &)
PfmCodeAnalyser & | operator= (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.

    00068 {
    00069  int ax,bx,cx,dx;
    00070  cpuid(1,ax,bx,cx,dx);
    00071  int sse4_2_mask = 1 << 20;
    00072  nehalem = cx & sse4_2_mask;
    00073  strcpy(event_str[0], event0);
    00074  strcpy(event_str[1], event1);
    00075  strcpy(event_str[2], event2);
    00076  strcpy(event_str[3], event3);
    00077  cmask[0] = cmask_v0;
    00078  cmask[1] = cmask_v1;
    00079  cmask[2] = cmask_v2;
    00080  cmask[3] = cmask_v3;
    00081  inv[0] = inv_v0;
    00082  inv[1] = inv_v1;
    00083  inv[2] = inv_v2;
    00084  inv[3] = inv_v3;
    00085  used_counters_number = 0;
    00086  for(int i=0; i<MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS; i++)
    00087  {
    00088   if(strlen(event_str[i])>0) used_counters_number++;
    00089  }
    00090  for(int i=0; i<used_counters_number; i++)
    00091  {
    00092   sum[i] = 0;
    00093   overhead_avg[i] = 0;
    00094  }
    00095  count = 0;
    00096  if(pfm_initialize() != PFMLIB_SUCCESS)
    00097  {
    00098   printf("Cannot initialize perfmon!!\nExiting...\n");
    00099   exit(0);
    00100  }
    00101  while(count<3)
    00102  {
    00103   start();
    00104   stop_init();
    00105  }
    00106  for(int i=0; i<used_counters_number; i++)
    00107  {
    00108   sum[i] = 0;
    00109  }
    00110  count = 0;
    00111  while(count<10)
    00112  {
    00113   start();
    00114   stop_init();
    00115  }
    00116  for(int i=0; i<used_counters_number; i++)
    00117  {
    00118   overhead_avg[i] = sum[i]/count;
    00119   sum[i] = 0;
    00120  }
    00121  count = 0;
    00122 }

PfmCodeAnalyser::PfmCodeAnalyser | ( | PfmCodeAnalyser const & |  | ) | `[private]`

PfmCodeAnalyser::~PfmCodeAnalyser | ( |  | ) | `[private]`

Definition at line 255 of file PfmCodeAnalyser.h.

    00256 {
    00257  for(int i=0; i<used_counters_number; i++)
    00258  {
    00259   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]);
    00260  }
    00261 }

## 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.

    00128 {
    00129  static PfmCodeAnalyser theSingleton(event0, cmask_v0, inv_v0, event1, cmask_v1, inv_v1, event2, cmask_v2, inv_v2, event3, cmask_v3, inv_v3);
    00130  return theSingleton;
    00131 }

PfmCodeAnalyser& PfmCodeAnalyser::operator= | ( | PfmCodeAnalyser const & |  | ) | `[private]`

void PfmCodeAnalyser::start | ( |  | ) |

Definition at line 135 of file PfmCodeAnalyser.h.

    00136 {
    00137  memset(&ctx,0, sizeof(ctx));
    00138  memset(&inp,0, sizeof(inp));
    00139  memset(&outp,0, sizeof(outp));
    00140  memset(pd, 0, sizeof(pd));
    00141  memset(pc, 0, sizeof(pc));
    00142  memset(&load_arg, 0, sizeof(load_arg));
    00143  memset(&params, 0, sizeof(params));
    00144  for(int i=0; i<used_counters_number; i++)
    00145  {
    00146   ret = pfm_find_full_event(event_str[i], &inp.pfp_events[i]);
    00147   if(ret != PFMLIB_SUCCESS)
    00148   {
    00149    fprintf(stderr, "ERROR: cannot find event: %s\naborting...\n", event_str[i]);
    00150    exit(1);
    00151   }
    00152  }
    00153  inp.pfp_dfl_plm = PFM_PLM3;
    00154  inp.pfp_event_count = used_counters_number;
    00155  for(int i=0; i<used_counters_number; i++)
    00156  {
    00157   if(inv[i])
    00158   {
    00159    (params.pfp_core_counters[i]).flags |= PFM_CORE_SEL_INV;
    00160    (nhm_params.pfp_nhm_counters[i]).flags |= PFM_NHM_SEL_INV;
    00161   }
    00162   if(cmask[i]>0)
    00163   {
    00164    (params.pfp_core_counters[i]).cnt_mask = cmask[i];
    00165    (nhm_params.pfp_nhm_counters[i]).cnt_mask = cmask[i];
    00166   }
    00167  }
    00168  if(nehalem)
    00169  {
    00170   ret = pfm_dispatch_events(&inp, &nhm_params, &outp, NULL);
    00171  }
    00172  else
    00173  {
    00174   ret = pfm_dispatch_events(&inp, &params, &outp, NULL);
    00175  }
    00176  if(ret != PFMLIB_SUCCESS)
    00177  {
    00178   fprintf(stderr, "ERROR: cannot dispatch events: %s\naborting...\n", pfm_strerror(ret));
    00179   exit(1);
    00180  }
    00181  for(unsigned int i=0; i<outp.pfp_pmc_count; i++)
    00182  {
    00183   pc[i].reg_num = outp.pfp_pmcs[i].reg_num;
    00184   pc[i].reg_value = outp.pfp_pmcs[i].reg_value;
    00185  }
    00186  for(unsigned int i=0; i<outp.pfp_pmd_count; i++)
    00187  {
    00188   pd[i].reg_num = outp.pfp_pmds[i].reg_num;
    00189   pd[i].reg_value = 0;
    00190  }
    00191  fd = pfm_create_context(&ctx, NULL, 0, 0);
    00192  if(fd == -1)
    00193  {
    00194   fprintf(stderr, "ERROR: Context not created\naborting...\n");
    00195   exit(1);
    00196  }
    00197  if(pfm_write_pmcs(fd, pc, outp.pfp_pmc_count) == -1)
    00198  {
    00199   fprintf(stderr, "ERROR: Could not write pmcs\naborting...\n");
    00200   exit(1);
    00201  }
    00202  if(pfm_write_pmds(fd, pd, outp.pfp_pmd_count) == -1)
    00203  {
    00204   fprintf(stderr, "ERROR: Could not write pmds\naborting...\n");
    00205   exit(1);
    00206  }
    00207  load_arg.load_pid = getpid();
    00208  if(pfm_load_context(fd, &load_arg) == -1)
    00209  {
    00210   fprintf(stderr, "ERROR: Could not load context\naborting...\n");
    00211   exit(1);
    00212  }
    00213  pfm_start(fd, NULL);
    00214 }

void PfmCodeAnalyser::stop | ( |  | ) |

Definition at line 221 of file PfmCodeAnalyser.h.

    00222 {
    00223  pfm_stop(fd);
    00224  if(pfm_read_pmds(fd, pd, inp.pfp_event_count) == -1)
    00225  {
    00226   fprintf(stderr, "ERROR: Could not read pmds\naborting...\n");
    00227   exit(1);
    00228  }
    00229
    00230  for(int i=0; i<used_counters_number; i++)
    00231  {
    00232   sum[i] += (pd[i].reg_value - overhead_avg[i]);
    00233  }
    00234  count++;
    00235  close(fd);
    00236 }

void PfmCodeAnalyser::stop_init | ( |  | ) |

Definition at line 238 of file PfmCodeAnalyser.h.

    00239 {
    00240  pfm_stop(fd);
    00241  if(pfm_read_pmds(fd, pd, inp.pfp_event_count) == -1)
    00242  {
    00243   fprintf(stderr, "ERROR: Could not read pmds\naborting...\n");
    00244   exit(1);
    00245  }
    00246
    00247  for(int i=0; i<used_counters_number; i++)
    00248  {
    00249   sum[i] += (pd[i].reg_value);
    00250  }
    00251  count++;
    00252  close(fd);
    00253 }

## 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:

- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v22r0/GaudiProfiling/GaudiProfiling/PfmCodeAnalyser.h

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines