All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
PerfMonAuditor Class Reference

Performance Monitoring Auditor that uses Perfmon2 library to monitor algorithms. More...

Inheritance diagram for PerfMonAuditor:
Collaboration diagram for PerfMonAuditor:

Public Member Functions

virtual void before (StandardEventType evt, INamedInterface *alg)
 The following methods are meant to be implemented by the child class... More...
 
virtual void after (StandardEventType evt, INamedInterface *alg, const StatusCode &sc)
 Audit the end of a standard "event". More...
 
virtual StatusCode initialize ()
 
virtual StatusCode finalize ()
 
int is_nehalem ()
 
 PerfMonAuditor (const std::string &name, ISvcLocator *pSvc)
 
virtual ~PerfMonAuditor ()
 
- Public Member Functions inherited from Auditor
 Auditor (const std::string &name, ISvcLocator *svcloc)
 Constructor. More...
 
virtual ~Auditor ()
 Destructor. More...
 
StatusCode sysInitialize ()
 Initialization method invoked by the framework. More...
 
StatusCode sysFinalize ()
 Finalization method invoked by the framework. More...
 
virtual void before (StandardEventType, const std::string &)
 Audit the start of a standard "event" for callers that do not implement INamedInterface. More...
 
virtual void before (CustomEventTypeRef, INamedInterface *)
 Audit the start of a custom "event". More...
 
virtual void before (CustomEventTypeRef, const std::string &)
 Audit the start of a custom "event" for callers that do not implement INamedInterface. More...
 
virtual void after (StandardEventType, const std::string &, const StatusCode &)
 Audit the end of a standard "event" for callers that do not implement INamedInterface. More...
 
virtual void after (CustomEventTypeRef, INamedInterface *, const StatusCode &)
 Audit the end of a custom "event". More...
 
virtual void after (CustomEventTypeRef, const std::string &, const StatusCode &)
 Audit the end of a custom "event" for callers that do not implement INamedInterface. More...
 
virtual void beforeInitialize (INamedInterface *)
 
virtual void afterInitialize (INamedInterface *)
 
virtual void beforeReinitialize (INamedInterface *)
 
virtual void afterReinitialize (INamedInterface *)
 
virtual void beforeExecute (INamedInterface *)
 
virtual void afterExecute (INamedInterface *, const StatusCode &)
 
virtual void beforeFinalize (INamedInterface *)
 
virtual void afterFinalize (INamedInterface *)
 
virtual void beforeBeginRun (INamedInterface *)
 
virtual void afterBeginRun (INamedInterface *)
 
virtual void beforeEndRun (INamedInterface *)
 
virtual void afterEndRun (INamedInterface *)
 
virtual const std::string & name () const
 Retrieve the name of the instance. More...
 
virtual bool isEnabled () const
 Tell if the auditor is enabled or not. More...
 
SmartIF< IMessageSvc > & msgSvc () const
 The standard message service. More...
 
int outputLevel () const
 Retrieve the output level of current auditor. More...
 
void setOutputLevel (int level)
 Set the output level for current auditor. More...
 
SmartIF< ISvcLocator > & serviceLocator () const
 The standard service locator. More...
 
template<class T >
StatusCode service (const std::string &name, T *&svc, bool createIf=false) const
 Access a service by name, creating it if it doesn't already exist. More...
 
virtual StatusCode setProperty (const Property &p)
 Set a value of a property of an auditor. More...
 
virtual StatusCode setProperty (const std::string &s)
 Implementation of IProperty::setProperty. More...
 
virtual StatusCode setProperty (const std::string &n, const std::string &v)
 Implementation of IProperty::setProperty. More...
 
virtual StatusCode getProperty (Property *p) const
 Get the value of a property. More...
 
virtual const PropertygetProperty (const std::string &name) const
 Get the property by name. More...
 
virtual StatusCode getProperty (const std::string &n, std::string &v) const
 Implementation of IProperty::getProperty. More...
 
const std::vector< Property * > & getProperties () const
 Get all properties. More...
 
template<class TYPE >
StatusCode setProperty (const std::string &name, const TYPE &value)
 set the property form the value More...
 
StatusCode setProperties ()
 Set the auditor's properties. More...
 
template<class T >
PropertydeclareProperty (const std::string &name, T &property, const std::string &doc="none") const
 Declare the named property. More...
 
- Public Member Functions inherited from extend_interfaces2< IAuditor, IProperty >
virtual ~extend_interfaces2 ()
 Virtual destructor. More...
 
- Public Member Functions inherited from IAuditor
 DeclareInterfaceID (IAuditor, 3, 0)
 InterfaceID. More...
 
- Public Member Functions inherited from INamedInterface
 DeclareInterfaceID (INamedInterface, 1, 0)
 InterfaceID. More...
 
virtual ~INamedInterface ()
 Virtual destructor (always needed for abstract classes). More...
 
- Public Member Functions inherited from IInterface
virtual void * i_cast (const InterfaceID &) const =0
 main cast function More...
 
virtual std::vector< std::string > getInterfaceNames () const =0
 Returns a vector of strings containing the names of all the implemented interfaces. More...
 
virtual unsigned long addRef ()=0
 Increment the reference count of Interface instance. More...
 
virtual unsigned long release ()=0
 Release Interface instance. More...
 
virtual unsigned long refCount () const =0
 Current reference count. More...
 
virtual StatusCode queryInterface (const InterfaceID &ti, void **pp)=0
 Set the void** to the pointer to the requested interface of the instance. More...
 
virtual ~IInterface ()
 Virtual destructor. More...
 
- Public Member Functions inherited from IProperty
 DeclareInterfaceID (IProperty, 2, 0)
 InterfaceID. More...
 

Private Types

typedef GaudiUtils::VectorMap
< const INamedInterface *, int > 
Map
 

Private Member Functions

void i_beforeInitialize (INamedInterface *alg)
 
void i_afterInitialize (INamedInterface *alg)
 
void i_beforeExecute (INamedInterface *alg)
 
void i_afterExecute (INamedInterface *alg)
 
 PerfMonAuditor ()
 
 PerfMonAuditor (const PerfMonAuditor &)
 
PerfMonAuditoroperator= (const PerfMonAuditor &)
 
void startpm ()
 
void pausepm ()
 
void stoppm ()
 
void finalizepm ()
 
int detect_unavail_pmu_regs (int fd, pfmlib_regmask_t *r_pmcs, pfmlib_regmask_t *r_pmds)
 
int detect_unavail_pmcs (int fd, pfmlib_regmask_t *r_pmcs)
 
void pfm_bv_set (uint64_t *bv, uint16_t rnum)
 
int pfm_bv_isset (uint64_t *bv, uint16_t rnum)
 
void pfm_bv_copy (uint64_t *d, uint64_t *j, uint16_t n)
 
void start_smpl ()
 
void stop_smpl ()
 
void finalize_smpl ()
 

Static Private Member Functions

static void process_smpl_buf (pfm_dfl_smpl_hdr_t *hdr, size_t entry_size)
 
static void sigio_handler (int, struct siginfo *, struct sigcontext *)
 

Private Attributes

PFMon & m_pfm
 
Map m_map
 
int m_indent
 
bool m_inEvent
 
int is_nehalem_ret
 
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
 
unsigned int i
 
int ret
 
std::string event_str [MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS]
 
std::string prefix
 
std::string family
 
char event_cstr [MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS][MAX_EVENT_NAME_LENGTH]
 
char prefix_cstr [MAX_PREFIX_NAME_LENGTH]
 
unsigned int ph_ev_count
 
bool inv [MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS]
 
unsigned int cmask [MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS]
 
unsigned int start_at_event
 
pfmlib_core_input_param_t params
 
pfmlib_nhm_input_param_t nhm_params
 
int used_counters_number
 
bool nehalem
 
bool westmere
 
bool core
 
bool sampling
 
pfm_dfl_smpl_arg_t buf_arg
 
pfarg_load_t load_args
 
void * buf_addr
 
unsigned num_counters
 
unsigned int max_pmd
 
pfmlib_options_t pfmlib_options
 
int level
 
bool first_alg
 
std::string first_alg_name
 
bool event_count_reached
 

Additional Inherited Members

- Public Types inherited from Auditor
typedef
Gaudi::PluginService::Factory
< IAuditor *, const
std::string &, ISvcLocator * > 
Factory
 
- Public Types inherited from implements2< IAuditor, IProperty >
typedef implements2 base_class
 Typedef to this class. More...
 
typedef extend_interfaces2
< IAuditor, IProperty
extend_interfaces_base
 Typedef to the base of this class. More...
 
typedef
extend_interfaces_base::ext_iids 
interfaces
 MPL set of all the implemented interfaces. More...
 
- Public Types inherited from extend_interfaces2< IAuditor, IProperty >
typedef mpl::fold< typename
IAuditor::iid::iids::type,
typename
IProperty::iid::iids::type,
mpl::insert< mpl::_1, mpl::_2 >
>::type 
ext_iids
 MPL set of interfaces extended by this one. More...
 
- Public Types inherited from IAuditor
enum  StandardEventType {
  Initialize, ReInitialize, Execute, BeginRun,
  EndRun, Finalize, Start, Stop,
  ReStart
}
 Defines the standard (= used by the framework) auditable event types. More...
 
typedef std::string CustomEventType
 Type used to allow users to specify a custom event to be audit. More...
 
typedef const CustomEventTypeCustomEventTypeRef
 Used in function calls for optimization purposes. More...
 
- Public Types inherited from IInterface
enum  Status { SUCCESS = 1, NO_INTERFACE, VERSMISMATCH, LAST_ERROR }
 Return status. More...
 
typedef Gaudi::InterfaceId
< IInterface, 0, 0 > 
iid
 Interface ID. More...
 
typedef mpl::set1< iidext_iids
 Extra interfaces. More...
 
- Static Public Member Functions inherited from IInterface
static const InterfaceIDinterfaceID ()
 Return an instance of InterfaceID identifying the interface. More...
 

Detailed Description

Performance Monitoring Auditor that uses Perfmon2 library to monitor algorithms.

Author
Daniele Francesco KRUSE danie.nosp@m.le.f.nosp@m.rance.nosp@m.sco..nosp@m.kruse.nosp@m.@cer.nosp@m.n.ch
Date
2009-10-28

Definition at line 200 of file PerfMonAuditor.cpp.

Member Typedef Documentation

Definition at line 354 of file PerfMonAuditor.cpp.

Constructor & Destructor Documentation

PerfMonAuditor::PerfMonAuditor ( const std::string &  name,
ISvcLocator pSvc 
)
inline

Definition at line 272 of file PerfMonAuditor.cpp.

272  : // standard constructor
273  Auditor(name, pSvc),
274  m_pfm(PFMon::instance()),
275  m_map(),
276  m_indent(0),
277  m_inEvent(false)
278  {
280 declareProperty("EVENT0", event_str[0]);
281 declareProperty("EVENT1", event_str[1]);
282 declareProperty("EVENT2", event_str[2]);
283 declareProperty("EVENT3", event_str[3]);
284 declareProperty("FAMILY", family);
285 declareProperty("PREFIX", prefix);
286 declareProperty("INV0", inv[0]);
287 declareProperty("INV1", inv[1]);
288 declareProperty("INV2", inv[2]);
289 declareProperty("INV3", inv[3]);
290 declareProperty("CMASK0", cmask[0]);
291 declareProperty("CMASK1", cmask[1]);
292 declareProperty("CMASK2", cmask[2]);
293 declareProperty("CMASK3", cmask[3]);
294 declareProperty("SP0", sp[0]);
295 declareProperty("SP1", sp[1]);
296 declareProperty("SP2", sp[2]);
297 declareProperty("SP3", sp[3]);
298 declareProperty("SAMPLE", sampling);
299 declareProperty("START_AT_EVENT", start_at_event);
300 declareProperty("IS_NEHALEM", is_nehalem_ret);
301 
302 // MsgStream log(msgSvc(), name());
303 
305 /*
306 // loading functions from PFM library
307  void* handle = dlopen("libpfm.so", RTLD_NOW);
308  if (!handle) {
309 // log << MSG::ERROR << "Cannot open library: " << dlerror() << endmsg;
310  }
311  typedef void (*hello_t)();
312  hello_t hello = (hello_t) dlsym(handle, "hello");
313  if (!hello) {
314 // log << MSG::ERROR << "Cannot load symbol 'hello': " << dlerror() << endmsg;
315  dlclose(handle);
316  }
317 
318  pfm_start = (pfm_start_t) dlsym(handle, "pfm_start");
319  pfm_stop = (pfm_stop_t) dlsym(handle, "pfm_stop");
320  pfm_self_stop = (pfm_self_stop_t) dlsym(handle, "pfm_stop"); //it's the same
321  pfm_restart = (pfm_restart_t) dlsym(handle, "pfm_restart");
322  //pfm_read_pmds = (pfm_read_pmds_t) dlsym(handle, "pfm_read_pmds");
323  pfm_initialize = (pfm_initialize_t) dlsym(handle, "pfm_initialize");
324  pfm_find_full_event = (pfm_find_full_event_t) dlsym(handle, "pfm_find_full_event");
325  pfm_dispatch_events = (pfm_dispatch_events_t) dlsym(handle, "pfm_dispatch_events");
326  pfm_create_context = (pfm_create_context_t) dlsym(handle, "pfm_create_context");
327  pfm_write_pmcs = (pfm_write_pmcs_t) dlsym(handle, "pfm_write_pmcs");
328  pfm_write_pmds = (pfm_write_pmds_t) dlsym(handle, "pfm_write_pmds");
329  pfm_load_context = (pfm_load_context_t) dlsym(handle, "pfm_load_context");
330  pfm_strerror = (pfm_strerror_t) dlsym(handle, "pfm_strerror");
331  pfm_set_options = (pfm_set_options_t) dlsym(handle, "pfm_set_options");
332  pfm_get_num_counters = (pfm_get_num_counters_t) dlsym(handle, "pfm_get_num_counters");
333  // use it to do the calculation
334 // log << MSG::INFO << "Calling hello..." << endmsg;
335 // hello();
336 
337  // close the library
338 // log << MSG::INFO << "Closing library..." << endmsg;
339  dlclose(handle);
340 */
341 
343 
344  }
virtual const std::string & name() const
Retrieve the name of the instance.
Definition: Auditor.cpp:218
std::string family
bool inv[MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS]
Property * declareProperty(const std::string &name, T &property, const std::string &doc="none") const
Declare the named property.
Definition: Auditor.h:235
std::string event_str[MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS]
Auditor(const std::string &name, ISvcLocator *svcloc)
Constructor.
Definition: Auditor.cpp:14
std::string prefix
unsigned int start_at_event
unsigned int cmask[MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS]
virtual PerfMonAuditor::~PerfMonAuditor ( )
inlinevirtual

Definition at line 346 of file PerfMonAuditor.cpp.

346 {} // virtual destructor
PerfMonAuditor::PerfMonAuditor ( )
private
PerfMonAuditor::PerfMonAuditor ( const PerfMonAuditor )
private

Member Function Documentation

void PerfMonAuditor::after ( StandardEventType  ,
INamedInterface ,
const StatusCode sc 
)
virtual

Audit the end of a standard "event".

Reimplemented from Auditor.

Definition at line 1069 of file PerfMonAuditor.cpp.

1070 {
1071  switch(evt)
1072  {
1073  case IAuditor::Initialize:
1074  i_afterInitialize(alg);
1075  break;
1076  case IAuditor::Execute:
1077  i_afterExecute(alg);
1078  break;
1079  default:
1080  break;
1081  }
1082  return;
1083 }
void i_afterExecute(INamedInterface *alg)
void i_afterInitialize(INamedInterface *alg)
void PerfMonAuditor::before ( StandardEventType  evt,
INamedInterface obj 
)
virtual

The following methods are meant to be implemented by the child class...

Reimplemented from Auditor.

Definition at line 1053 of file PerfMonAuditor.cpp.

1054 {
1055  switch(evt)
1056  {
1057  case IAuditor::Initialize:
1058  i_beforeInitialize(alg);
1059  break;
1060  case IAuditor::Execute:
1061  i_beforeExecute(alg);
1062  break;
1063  default:
1064  break;
1065  }
1066  return;
1067 }
void i_beforeExecute(INamedInterface *alg)
void i_beforeInitialize(INamedInterface *alg)
int PerfMonAuditor::detect_unavail_pmcs ( int  fd,
pfmlib_regmask_t r_pmcs 
)
inlineprivate

Definition at line 393 of file PerfMonAuditor.cpp.

393 {return detect_unavail_pmu_regs(fd, r_pmcs, NULL);}
int detect_unavail_pmu_regs(int fd, pfmlib_regmask_t *r_pmcs, pfmlib_regmask_t *r_pmds)
int PerfMonAuditor::detect_unavail_pmu_regs ( int  fd,
pfmlib_regmask_t r_pmcs,
pfmlib_regmask_t r_pmds 
)
private
StatusCode PerfMonAuditor::finalize ( )
virtual

Reimplemented from Auditor.

Definition at line 1045 of file PerfMonAuditor.cpp.

1046 {
1047  if(sampling == 0) finalizepm();
1048  else finalize_smpl();
1049  return Auditor::finalize();
1050 }
virtual StatusCode finalize()
Definition: Auditor.cpp:213
void PerfMonAuditor::finalize_smpl ( )
private

Definition at line 923 of file PerfMonAuditor.cpp.

924 {
925  MsgStream log(msgSvc(), name());
926  char filename[MAX_OUTPUT_FILENAME_LENGTH];
927  bzero(filename, MAX_OUTPUT_FILENAME_LENGTH);
928  char to_cat[50];
929  gzFile outfile;
930  int err;
931  for(int i=0; i<used_counters_number; i++)
932  {
933  sprintf(filename, "%s_%s", prefix_cstr, event_cstr[i]);
934  for(int j=0; j<(int)strlen(filename); j++)
935  {
936  if(filename[j]==':')
937  {
938  filename[j]='-';
939  }
940  }
941  bzero(to_cat, 50);
942  if(inv[i])
943  {
944  strcpy(to_cat, "_INV_1");
945  }
946  if(cmask[i]>0)
947  {
948  sprintf(to_cat, "%s_CMASK_%d", to_cat, cmask[i]);
949  }
950  sprintf(filename, "%s%s.txt.gz", filename, to_cat);
951  outfile = gzopen(filename, "wb");
952  if(outfile!=NULL)
953  {
954  if(nehalem)
955  {
956  gzprintf(outfile, "NHM ");
957  }
958  else if(westmere)
959  {
960  gzprintf(outfile, "WSM ");
961  }
962  else if(core)
963  {
964  gzprintf(outfile, "CORE ");
965  }
966  if(gzprintf(outfile, "%s %d %d %d\n", event_cstr[i], cmask[i], inv[i], sp[i]) < (int)strlen(event_cstr[i]))
967  {
968  log << MSG::ERROR << "ERROR: gzputs err: " << gzerror(outfile, &err) << ". Aborting..." << endmsg;
969  }
970  for(std::map<std::string, std::map<unsigned long, unsigned int> >::iterator it=samples[i].begin(); it!=samples[i].end(); it++)
971  {
972  unsigned long long sum = 0;
973  for(std::map<unsigned long, unsigned int>::iterator jt=(it->second).begin(); jt!=(it->second).end(); jt++)
974  {
975  sum += jt->second;
976  }
977  if(gzprintf(outfile, "%s%%%llu\n", (it->first).c_str(), sum) < (int)((it->first).length()))
978  {
979  log << MSG::ERROR << "ERROR: gzputs err: " << gzerror(outfile, &err) << ". Aborting..." << endmsg;
980  }
981  for(std::map<unsigned long, unsigned int>::iterator jt=(it->second).begin(); jt!=(it->second).end(); jt++)
982  {
983  char sym_name[SYM_NAME_MAX_LENGTH];
984  bzero(sym_name, SYM_NAME_MAX_LENGTH);
985  const char *libName;
986  const char *symbolName;
987  int libOffset = 0;
988  int offset = 0;
989  void *sym_addr = IgHookTrace::tosymbol((void *)(jt->first));
990  if(sym_addr != NULL)
991  {
992  bool success = IgHookTrace::symbol(sym_addr, symbolName, libName, offset, libOffset);
993  if(success)
994  {
995  if(symbolName!=NULL && strlen(symbolName)>0)
996  {
997  strcpy(sym_name, symbolName);
998  strcat(sym_name, " ");
999  }
1000  else
1001  {
1002  strcpy(sym_name, "??? ");
1003  }
1004  if(libName!=NULL && strlen(libName)>0)
1005  {
1006  strcat(sym_name, libName);
1007  strcat(sym_name, " ");
1008  }
1009  else
1010  {
1011  strcat(sym_name, "??? ");
1012  }
1013  sprintf(sym_name, "%s%d ", sym_name, libOffset);
1014  if(strlen(sym_name)<=0)
1015  {
1016  log << MSG::ERROR << "ERROR: Symbol name length is zero. Aborting..." << endmsg;
1017  }
1018  }
1019  else
1020  {
1021  strcpy(sym_name,"??? ??? 0 ");
1022  }
1023  }
1024  else
1025  {
1026  strcpy(sym_name,"??? ??? 0 ");
1027  }
1028  if(gzprintf(outfile, "%s %d\n", sym_name, jt->second) < (int)strlen(sym_name))
1029  {
1030  log << MSG::ERROR << "ERROR: gzputs err: " << gzerror(outfile, &err) << endmsg;
1031  }
1032  }
1033  }
1034  }
1035  else
1036  {
1037  log << MSG::ERROR << "ERROR: Could not open file: " << filename << ". Aborting..." << endmsg;
1038  }
1039  gzclose(outfile);
1040  }
1041  }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
virtual const std::string & name() const
Retrieve the name of the instance.
Definition: Auditor.cpp:218
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
Definition: Auditor.cpp:226
static void * tosymbol(void *address)
double sum(double x, double y, double z)
bool inv[MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS]
#define SYM_NAME_MAX_LENGTH
#define MAX_OUTPUT_FILENAME_LENGTH
struct GAUDI_API map
Parametrisation class for map-like implementation.
static bool symbol(void *address, const char *&sym, const char *&lib, int &offset, int &liboffset)
char event_cstr[MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS][MAX_EVENT_NAME_LENGTH]
tuple end
Definition: IOTest.py:101
char prefix_cstr[MAX_PREFIX_NAME_LENGTH]
unsigned int i
unsigned int cmask[MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS]
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
void PerfMonAuditor::finalizepm ( )
private

Definition at line 546 of file PerfMonAuditor.cpp.

547 {
548  MsgStream log(msgSvc(), name());
549  log << MSG::INFO << "start of finalizepm ucn:" << used_counters_number << endmsg;
550  char filename[MAX_OUTPUT_FILENAME_LENGTH];
551  char to_cat[50];
552  FILE *outfile;
553  for(int i=0; i<used_counters_number; i++)
554  {
555  bzero(filename, MAX_OUTPUT_FILENAME_LENGTH);
556  sprintf(filename, "%s_%s", prefix_cstr, event_cstr[i]);
557  for(int j=0; j<(int)strlen(filename); j++)
558  {
559  if(filename[j]==':')
560  {
561  filename[j]='-';
562  }
563  }
564  bzero(to_cat, 50);
565  if(inv[i])
566  {
567  strcpy(to_cat, "_INV_1");
568  }
569  if(cmask[i]>0)
570  {
571  sprintf(to_cat, "%s_CMASK_%d", to_cat, cmask[i]);
572  }
573  sprintf(filename, "%s%s.txt", filename, to_cat);
574  log << MSG::INFO << "Filename:" << filename << endmsg;
575  outfile = fopen(filename, "w");
576  if(nehalem)
577  {
578  fprintf(outfile, "NHM ");
579  }
580  else if(westmere)
581  {
582  fprintf(outfile, "WSM ");
583  }
584  else if(core)
585  {
586  fprintf(outfile, "CORE ");
587  }
588  fprintf(outfile, "%s %d %d %d\n", event_cstr[i], cmask[i], inv[i], sp[i]);
589  for(std::map<std::string, std::vector<unsigned long int> >::iterator it=(results[i]).begin(); it!=(results[i]).end(); it++)
590  {
591  fprintf(outfile, "%s\n", (it->first).c_str());
592  for(std::vector<unsigned long int>::iterator j=(it->second).begin(); j!=(it->second).end(); j++)
593  {
594  fprintf(outfile, "%lu\n", *j);
595  }
596  }
597  fclose(outfile);
598  }
599 }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
virtual const std::string & name() const
Retrieve the name of the instance.
Definition: Auditor.cpp:218
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
Definition: Auditor.cpp:226
bool inv[MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS]
#define MAX_OUTPUT_FILENAME_LENGTH
struct GAUDI_API map
Parametrisation class for map-like implementation.
char event_cstr[MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS][MAX_EVENT_NAME_LENGTH]
tuple end
Definition: IOTest.py:101
char prefix_cstr[MAX_PREFIX_NAME_LENGTH]
unsigned int i
unsigned int cmask[MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS]
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
void PerfMonAuditor::i_afterExecute ( INamedInterface alg)
private

Definition at line 1148 of file PerfMonAuditor.cpp.

1149 {
1150  MsgStream log(msgSvc(), name());
1151  if(alg == 0)
1152  {
1153  return;
1154  }// log << MSG::INFO << "after:inside! " << alg->name() << endmsg;
1155 
1157  {
1158  //log << MSG::INFO << "after:inside! " << alg->name() << endmsg;
1159 
1160  if(sampling == 0) stoppm();
1161  else stop_smpl();
1162  alg_stack.pop();
1163  --m_indent;
1164  if(!alg_stack.empty())
1165  {
1166  if(sampling == 0) startpm();
1167  else start_smpl(); //resuming father algorithm counting
1168  }
1169  }
1170  return;
1171 }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
virtual const std::string & name() const
Retrieve the name of the instance.
Definition: Auditor.cpp:218
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
Definition: Auditor.cpp:226
void PerfMonAuditor::i_afterInitialize ( INamedInterface alg)
private

Definition at line 1094 of file PerfMonAuditor.cpp.

1095 {
1096  if(alg == 0)
1097  {
1098  return;
1099  }
1100  return;
1101 }
void PerfMonAuditor::i_beforeExecute ( INamedInterface alg)
private

Definition at line 1103 of file PerfMonAuditor.cpp.

1104 {
1105  MsgStream log(msgSvc(), name());
1106  if(alg == 0)
1107  {
1108  return;
1109  }
1110  //log << MSG::INFO << "before:inside! " << alg->name() << endmsg;
1111  if(first_alg)
1112  {
1113  first_alg = false;
1114  first_alg_name = alg->name();
1115  //log << MSG::INFO << "first_alg_name= " << alg->name() << endmsg;
1116  }
1117  if(!event_count_reached)
1118  {
1119  if(!first_alg_name.compare(alg->name()))
1120  {
1121  ph_ev_count++;
1122  //log << MSG::INFO << "EVENT COUNT: " << ph_ev_count << endmsg;
1124  {
1125  event_count_reached = true;
1126  //log << MSG::INFO << "!!! EVENT COUNT REACHED: " << ph_ev_count << endmsg;
1127  }
1128  }
1129  }
1131  {
1132  //log << MSG::INFO << "before:inside! " << alg->name() << endmsg;
1133 
1134  if(!alg_stack.empty())
1135  {
1136  if(sampling == 0) pausepm(); //pausing father algorithm counting
1137  else stop_smpl();
1138  }
1139  ++m_indent;
1140  std::vector <unsigned long int> zeroes(4,0);
1141  alg_stack.push(std::make_pair(alg, zeroes));
1142  if(sampling == 0) startpm();
1143  else start_smpl();
1144  }
1145  return;
1146 }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
virtual const std::string & name() const
Retrieve the name of the instance.
Definition: Auditor.cpp:218
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
Definition: Auditor.cpp:226
std::string first_alg_name
virtual const std::string & name() const =0
Retrieve the name of the instance.
unsigned int ph_ev_count
unsigned int start_at_event
void PerfMonAuditor::i_beforeInitialize ( INamedInterface alg)
private

Definition at line 1085 of file PerfMonAuditor.cpp.

1086 {
1087  if(alg == 0)
1088  {
1089  return;
1090  }
1091  return;
1092 }
StatusCode PerfMonAuditor::initialize ( )
virtual

Reimplemented from Auditor.

Definition at line 601 of file PerfMonAuditor.cpp.

602 {
603  MsgStream log(msgSvc(), name());
604 
605  if (!m_pfm.loaded) {
606  log << MSG::ERROR << "pfm library could not be loaded" << endmsg;
607  return false;
608  }
609 
610  log << MSG::INFO << "Initializing..." << endmsg;
612  if(sc.isFailure())
613  {
614  return sc;
615  }
618  {
619  if(event_str[i].length()>0) used_counters_number++;
620  }
622  {
623  strcpy(event_cstr[i], event_str[i].c_str());
624  }
625  strcpy(prefix_cstr, prefix.c_str());
626 
627  if(m_pfm.pfm_initialize() != PFMLIB_SUCCESS)
628  {
629  log << MSG::ERROR << "Cannot initialize perfmon!!" << endmsg;
630  }
631  ph_ev_count = 0;
632  first_alg = true;
633  event_count_reached = false;
634  nehalem = false;
635  core = false;
636  westmere = false;
637  if(family.compare("CORE")==0) core = true;
638  else if(family.compare("NEHALEM")==0) nehalem = true;
639  else if(family.compare("WESTMERE")==0) westmere = true;
640  else
641  {
642  log << MSG::ERROR << "ERROR: Unsupported processor family " << family << ". aborting..." << endmsg;
643  }
644 
645  log << MSG::INFO << "Initialized!" << endmsg;
646  return StatusCode::SUCCESS ;
647 }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
virtual const std::string & name() const
Retrieve the name of the instance.
Definition: Auditor.cpp:218
std::string family
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
Definition: Auditor.cpp:226
#define PFMLIB_SUCCESS
Definition: pfmlib.h:283
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:85
std::string event_str[MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS]
std::string prefix
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
char event_cstr[MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS][MAX_EVENT_NAME_LENGTH]
char prefix_cstr[MAX_PREFIX_NAME_LENGTH]
unsigned int i
unsigned int ph_ev_count
virtual StatusCode initialize()
Definition: Auditor.cpp:97
#define MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
int PerfMonAuditor::is_nehalem ( )
inline

Definition at line 217 of file PerfMonAuditor.cpp.

217  {
218 #ifdef __ICC
219 // Disable ICC remark #593: variable "x" was set but never used
220 #pragma warning(push)
221 #pragma warning(disable:593)
222 #endif
223  int a,b,c,d;
224  cpuid(1,a,b,c,d);
225  int sse4_2_mask = 1 << 20;
226  if(c & sse4_2_mask) return 1; else return 0;
227 #ifdef __ICC
228 #pragma warning(pop)
229 #endif
230  }
tuple c
Definition: gaudirun.py:341
#define cpuid(func, ax, bx, cx, dx)
PerfMonAuditor& PerfMonAuditor::operator= ( const PerfMonAuditor )
private
void PerfMonAuditor::pausepm ( )
private

Definition at line 525 of file PerfMonAuditor.cpp.

526 {
527  MsgStream log(msgSvc(), name());
528  m_pfm.pfm_stop(fd);
529  if(m_pfm.pfm_read_pmds(fd, pd, inp.pfp_event_count) == -1)
530  {
531  log << MSG::ERROR << "Could not read pmds" << endmsg;
532  }
533 
534  for(int i=0; i<used_counters_number; i++)
535  {
536  alg_stack.top().second[i] += pd[i].reg_value;
537  }
538 
539  close(fd);
540 }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
virtual const std::string & name() const
Retrieve the name of the instance.
Definition: Auditor.cpp:218
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
Definition: Auditor.cpp:226
pfmlib_input_param_t inp
pfarg_pmd_t pd[NUM_PMDS]
unsigned int i
uint64_t reg_value
Definition: perfmon_v2.h:42
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
unsigned int pfp_event_count
Definition: pfmlib.h:109
void PerfMonAuditor::pfm_bv_copy ( uint64_t *  d,
uint64_t *  j,
uint16_t  n 
)
inlineprivate

Definition at line 396 of file PerfMonAuditor.cpp.

396 {if(n<=BPL) *d = *j; else {memcpy(d, j, (n>>LBPL)*sizeof(uint64_t));}}
#define LBPL
#define BPL
int PerfMonAuditor::pfm_bv_isset ( uint64_t *  bv,
uint16_t  rnum 
)
inlineprivate

Definition at line 395 of file PerfMonAuditor.cpp.

395 {return bv[rnum>>LBPL] & (1UL <<(rnum&(BPL-1))) ? 1 : 0;}
#define LBPL
#define BPL
void PerfMonAuditor::pfm_bv_set ( uint64_t *  bv,
uint16_t  rnum 
)
inlineprivate

Definition at line 394 of file PerfMonAuditor.cpp.

394 {bv[rnum>>LBPL] |= 1UL << (rnum&(BPL-1));}
#define LBPL
#define BPL
void PerfMonAuditor::process_smpl_buf ( pfm_dfl_smpl_hdr_t hdr,
size_t  entry_size 
)
staticprivate

Definition at line 653 of file PerfMonAuditor.cpp.

654 {
657  size_t pos, count;
658  uint64_t entry;
659  if(hdr->hdr_overflows == last_overflow && hdr->hdr_count == last_count)
660  {
661  printf("skipping identical set of samples...\n");
662  return;
663  }
664  count = hdr->hdr_count;
665  ent = (pfm_dfl_smpl_entry_t *)(hdr+1);
666  pos = (unsigned long)ent;
667  entry = collected_samples;
668  while(count--)
669  {
670  //if(ent->ovfl_pmd>=0 && ent->ovfl_pmd<=3)
671  if(ent->ovfl_pmd<=3)
672  {
673  ((samples[ent->ovfl_pmd])[(alg_stack.top().first)->name()])[(unsigned long)(ent->ip)]++;
674  }
675  pos += entry_size;
676  ent = (pfm_dfl_smpl_entry_t *)pos;
677  entry++;
678  }
679  collected_samples = entry;
680  last_overflow = hdr->hdr_overflows;
681  if (last_count != hdr->hdr_count && (last_count || last_overflow == 0))
682  {
683  collected_partial += hdr->hdr_count;
684  }
685  last_count = hdr->hdr_count;
686  return;
687 }
virtual const std::string & name() const
Retrieve the name of the instance.
Definition: Auditor.cpp:218
uint16_t ovfl_pmd
uint64_t ip
void PerfMonAuditor::sigio_handler ( int  ,
struct siginfo *  ,
struct sigcontext *   
)
staticprivate

Definition at line 694 of file PerfMonAuditor.cpp.

695 {
696  //MsgStream log(msgSvc(), name());
697  PFMon& pfm = PFMon::instance();
699  int fd = ctx_fd;
700  int r;
701  if(fd != ctx_fd)
702  {
703  //log << MSG::ERROR << "ERROR: handler does not get valid file descriptor. Aborting..." << endmsg;
704  }
705  if(pfm.pfm_read_pmds(fd, pd_smpl+1, 1) == -1)
706  {
707  //log << MSG::ERROR << "ERROR: pfm_read_pmds: " << strerror(errno) << ". Aborting..." << endmsg;
708  }
709  while(true)
710  {
711  r = read(fd, &msg, sizeof(msg));
712  if(r!=sizeof(msg))
713  {
714  if(r==-1 && errno==EINTR)
715  {
716  printf("read interrupted, retrying\n");
717  continue;
718  }
719  //log << MSG::ERROR << "ERROR: cannot read overflow message: " << strerror(errno) << ". Aborting..." << endmsg;
720  }
721  break;
722  }
723  switch(msg.type)
724  {
725  case PFM_MSG_OVFL: // the sampling buffer is full
726  process_smpl_buf(hdr, entry_size);
727  ovfl_count++;
728  if(pfm.pfm_restart(fd))
729  {
730  if(errno!=EBUSY)
731  {
732  //log << MSG::ERROR << "ERROR: pfm_restart error errno " << errno << ". Aborting..." << endmsg;
733  }
734  else
735  {
736  printf("pfm_restart: task probably terminated \n");
737  }
738  }
739  break;
740  default:
741  //log << MSG::ERROR << "ERROR: unknown message type " << msg.type << ". Aborting..." << endmsg;
742  break;
743  }
744 
745 }
uint32_t type
Definition: perfmon.h:209
static void process_smpl_buf(pfm_dfl_smpl_hdr_t *hdr, size_t entry_size)
#define PFM_MSG_OVFL
Definition: perfmon.h:213
void PerfMonAuditor::start_smpl ( )
private

Definition at line 756 of file PerfMonAuditor.cpp.

757 {
758  MsgStream log(msgSvc(), name());
759  ovfl_count = 0;
760  num_smpl_pmds = 0;
761  last_overflow = ~0;
762  max_pmd = 0;
763  memset(&pfmlib_options, 0, sizeof(pfmlib_options));
766  m_pfm.pfm_set_options(&pfmlib_options);
767  ret = m_pfm.pfm_initialize();
768  if(ret != PFMLIB_SUCCESS)
769  {
770  log << MSG::ERROR << "ERROR: Cannot initialize library: " << m_pfm.pfm_strerror(ret) << ". Aborting..." << endmsg;
771  }
772  struct sigaction act;
773  memset(&act, 0, sizeof(act));
774  act.sa_handler = (sig_t)sigio_handler; // dlopen() ==>
775  //act.sa_handler = (sig_t)&sigio_handler;
776  sigaction(SIGIO, &act, 0);
777  memset(&ctx, 0, sizeof(ctx));
778  memset(&buf_arg, 0, sizeof(buf_arg));
779  memset(&inp,0, sizeof(inp));
780  memset(&outp,0, sizeof(outp));
781  memset(pd_smpl, 0, sizeof(pd_smpl));
782  memset(pc, 0, sizeof(pc));
783  memset(&load_args, 0, sizeof(load_args));
784  m_pfm.pfm_get_num_counters(&num_counters);
785  memset(&params, 0, sizeof(params));
786  memset(&nhm_params, 0, sizeof(nhm_params));
787 
788  for(int i=0; i<used_counters_number; i++)
789  {
790  ret = m_pfm.pfm_find_full_event(event_cstr[i], &inp.pfp_events[i]);
791  if(ret != PFMLIB_SUCCESS)
792  {
793  log << MSG::ERROR << "ERROR: cannot find event: " << event_cstr[i] << ". Aborting..." << endmsg;
794  }
795  }
797  inp.pfp_event_count = 4;
798  for(int i=0; i<used_counters_number; i++)
799  {
800  if(inv[i])
801  {
804  }
805  if(cmask[i]>0)
806  {
807  (params.pfp_core_counters[i]).cnt_mask = cmask[i];
808  (nhm_params.pfp_nhm_counters[i]).cnt_mask = cmask[i];
809  }
810  }
811  if(nehalem || westmere)
812  {
813  ret = m_pfm.pfm_dispatch_events(&inp, &nhm_params, &outp, NULL);
814  }
815  else
816  {
817  ret = m_pfm.pfm_dispatch_events(&inp, &params, &outp, NULL);
818  }
819  if(ret != PFMLIB_SUCCESS)
820  {
821  log << MSG::ERROR << "ERROR: cannot configure events: " << m_pfm.pfm_strerror(ret) << ". Aborting..." << endmsg;
822  }
823  for(unsigned int i=0; i<outp.pfp_pmc_count; i++)
824  {
827  }
828  for(unsigned int i=0; i<outp.pfp_pmd_count; i++)
829  {
830  pd_smpl[i].reg_num = outp.pfp_pmds[i].reg_num;
831  if(i)
832  {
833  pfm_bv_set(pd_smpl[0].reg_smpl_pmds, pd_smpl[i].reg_num);
834  if(pd_smpl[i].reg_num>max_pmd)
835  {
836  max_pmd = pd_smpl[i].reg_num;
837  }
838  num_smpl_pmds++;
839  }
840  }
841  for(int i=0; i<used_counters_number; i++)
842  {
844  pfm_bv_copy(pd_smpl[i].reg_reset_pmds, pd_smpl[i].reg_smpl_pmds, max_pmd);
845  pd_smpl[i].reg_value = (uint64_t)(sp[i] * -1);
846  pd_smpl[i].reg_short_reset = (uint64_t)(sp[i] * -1);
847  pd_smpl[i].reg_long_reset = (uint64_t)(sp[i] * -1);
848  pd_smpl[i].reg_random_seed = 5; //tocheck
849  pd_smpl[i].reg_random_mask = 0xff; //tocheck
850  }
851  entry_size = sizeof(pfm_dfl_smpl_entry_t)+(num_smpl_pmds<<3);
852  ctx.ctx_flags = 0;
853  buf_arg.buf_size = 3*getpagesize()+512;
854  ctx_fd = m_pfm.pfm_create_context(&ctx, (char *)FMT_NAME, &buf_arg, sizeof(buf_arg));
855  if(ctx_fd==-1)
856  {
857  if(errno==ENOSYS)
858  {
859  log << MSG::ERROR << "ERROR: Your kernel does not have performance monitoring support! Aborting..." << endmsg;
860  }
861  log << MSG::ERROR << "ERROR: Can't create PFM context " << strerror(errno) << ". Aborting..." << endmsg;
862  }
863  buf_addr = mmap(NULL, (size_t)buf_arg.buf_size, PROT_READ, MAP_PRIVATE, ctx_fd, 0);
864  if(buf_addr==MAP_FAILED)
865  {
866  log << MSG::ERROR << "ERROR: cannot mmap sampling buffer: " << strerror(errno) << ". Aborting..." << endmsg;
867  }
868  hdr = (pfm_dfl_smpl_hdr_t *)buf_addr;
869  if(PFM_VERSION_MAJOR(hdr->hdr_version)<1)
870  {
871  log << MSG::ERROR << "ERROR: invalid buffer format version. Aborting..." << endmsg;
872  }
873  if(m_pfm.pfm_write_pmcs(ctx_fd, pc, outp.pfp_pmc_count))
874  {
875  log << MSG::ERROR << "ERROR: pfm_write_pmcs error errno " << strerror(errno) << ". Aborting..." << endmsg;
876  }
877  if(m_pfm.pfm_write_pmds(ctx_fd, pd_smpl, outp.pfp_pmd_count))
878  {
879  log << MSG::ERROR << "ERROR: pfm_write_pmds error errno " << strerror(errno) << ". Aborting..." << endmsg;
880  }
881  load_args.load_pid = getpid();
882  if(m_pfm.pfm_load_context(ctx_fd, &load_args))
883  {
884  log << MSG::ERROR << "ERROR: pfm_load_context error errno " << strerror(errno) << ". Aborting..." << endmsg;
885  }
886  ret = fcntl(ctx_fd, F_SETFL, fcntl(ctx_fd, F_GETFL, 0) | O_ASYNC);
887  if(ret == -1)
888  {
889  log << MSG::ERROR << "ERROR: cannot set ASYNC: " << strerror(errno) << ". Aborting..." << endmsg;
890  }
891  ret = fcntl(ctx_fd, F_SETOWN, getpid());
892  if(ret == -1)
893  {
894  log << MSG::ERROR << "ERROR: cannot setown: " << strerror(errno) << ". Aborting..." << endmsg;
895  }
896  //pfm_self_start(ctx_fd); ==>
897  m_pfm.pfm_start(ctx_fd, NULL);
898  }
pfmlib_reg_t pfp_pmds[PFMLIB_MAX_PMDS]
Definition: pfmlib.h:130
pfarg_load_t load_args
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
uint64_t reg_short_reset
Definition: perfmon_v2.h:44
pfmlib_core_input_param_t params
#define PFM_REGFL_OVFL_NOTIFY
Definition: perfmon.h:113
#define PFM_NHM_SEL_INV
#define PFM_PLM3
Definition: pfmlib.h:53
virtual const std::string & name() const
Retrieve the name of the instance.
Definition: Auditor.cpp:218
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
Definition: Auditor.cpp:226
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]
bool inv[MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS]
#define PFMLIB_SUCCESS
Definition: pfmlib.h:283
unsigned int pfm_verbose
Definition: pfmlib.h:139
unsigned int pfp_dfl_plm
Definition: pfmlib.h:110
uint16_t reg_num
Definition: perfmon_v2.h:39
pfmlib_input_param_t inp
unsigned int pfp_pmc_count
Definition: pfmlib.h:127
pfmlib_options_t pfmlib_options
unsigned long long reg_value
Definition: pfmlib.h:98
unsigned int pfp_pmd_count
Definition: pfmlib.h:128
static void sigio_handler(int, struct siginfo *, struct sigcontext *)
uint32_t reg_random_seed
Definition: perfmon_v2.h:51
uint64_t reg_long_reset
Definition: perfmon_v2.h:43
pfmlib_nhm_input_param_t nhm_params
#define PFM_VERSION_MAJOR(x)
Definition: perfmon.h:216
uint32_t ctx_flags
Definition: perfmon_v2.h:19
void pfm_bv_copy(uint64_t *d, uint64_t *j, uint16_t n)
void pfm_bv_set(uint64_t *bv, uint16_t rnum)
uint32_t reg_flags
Definition: perfmon_v2.h:41
unsigned int pfm_debug
Definition: pfmlib.h:138
unsigned int reg_num
Definition: pfmlib.h:100
pfmlib_output_param_t outp
uint16_t reg_num
Definition: perfmon_v2.h:28
char event_cstr[MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS][MAX_EVENT_NAME_LENGTH]
uint32_t load_pid
Definition: perfmon_v2.h:69
unsigned int i
pfarg_pmc_t pc[NUM_PMCS]
#define FMT_NAME
#define PFM_REGFL_RANDOM
Definition: perfmon.h:114
pfm_dfl_smpl_arg_t buf_arg
uint64_t reg_value
Definition: perfmon_v2.h:31
unsigned int max_pmd
pfmlib_reg_t pfp_pmcs[PFMLIB_MAX_PMCS]
Definition: pfmlib.h:129
uint64_t reg_random_mask
Definition: perfmon_v2.h:50
pfmlib_core_counter_t pfp_core_counters[PMU_CORE_NUM_COUNTERS]
Definition: pfmlib_core.h:79
unsigned int cmask[MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS]
uint64_t reg_value
Definition: perfmon_v2.h:42
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
unsigned int pfp_event_count
Definition: pfmlib.h:109
void PerfMonAuditor::startpm ( )
private

Definition at line 420 of file PerfMonAuditor.cpp.

421 {
422  MsgStream log(msgSvc(), name());
423  memset(&ctx,0, sizeof(ctx));
424  memset(&inp,0, sizeof(inp));
425  memset(&outp,0, sizeof(outp));
426  memset(pd, 0, sizeof(pd));
427  memset(pc, 0, sizeof(pc));
428  memset(&load_arg, 0, sizeof(load_arg));
429  memset(&params, 0, sizeof(params));
430  memset(&nhm_params, 0, sizeof(nhm_params));
431 
432  for(int i=0; i<used_counters_number; i++)
433  {
434  ret = m_pfm.pfm_find_full_event(event_cstr[i], &inp.pfp_events[i]);
435  if(ret != PFMLIB_SUCCESS)
436  {
437  log << MSG::ERROR << "ERROR: cannot find event: " << event_cstr[i] << ". Aborting..." << endmsg;
438  }
439  }
441  inp.pfp_event_count = 4;
442  for(int i=0; i<used_counters_number; i++)
443  {
444  if(inv[i])
445  {
448  }
449  if(cmask[i]>0)
450  {
451  (params.pfp_core_counters[i]).cnt_mask = cmask[i];
452  (nhm_params.pfp_nhm_counters[i]).cnt_mask = cmask[i];
453  }
454  }
455  if(nehalem || westmere)
456  {
457  ret = m_pfm.pfm_dispatch_events(&inp, &nhm_params, &outp, NULL);
458  }
459  else
460  {
461  ret = m_pfm.pfm_dispatch_events(&inp, &params, &outp, NULL);
462  }
463  if(ret != PFMLIB_SUCCESS)
464  {
465  log << MSG::ERROR << "ERROR: cannot dispatch events: " << m_pfm.pfm_strerror(ret) << ". Aborting..." << endmsg;
466  }
467  for(unsigned int i=0; i<outp.pfp_pmc_count; i++)
468  {
471  }
472  for(unsigned int i=0; i<outp.pfp_pmd_count; i++)
473  {
475  pd[i].reg_value = 0;
476  }
477  fd = m_pfm.pfm_create_context(&ctx, NULL, 0, 0);
478  if(fd == -1)
479  {
480  log << MSG::ERROR << "ERROR: Context not created. Aborting..." << endmsg;
481  }
482  if(m_pfm.pfm_write_pmcs(fd, pc, outp.pfp_pmc_count) == -1)
483  {
484  log << MSG::ERROR << "ERROR: Could not write pmcs. Aborting..." << endmsg;
485  }
486  if(m_pfm.pfm_write_pmds(fd, pd, outp.pfp_pmd_count) == -1)
487  {
488  log << MSG::ERROR << "ERROR: Could not write pmds. Aborting..." << endmsg;
489  }
490  load_arg.load_pid = getpid();
491  if(m_pfm.pfm_load_context(fd, &load_arg) == -1)
492  {
493  log << MSG::ERROR << "ERROR: Could not load context. Aborting..." << endmsg;
494 // MsgStream log(msgSvc(), name());
495 // log << MSG::ERROR << "Could not read pmds" << endmsg;
496  }
497 
498  m_pfm.pfm_start(fd, NULL);
499 }
pfmlib_reg_t pfp_pmds[PFMLIB_MAX_PMDS]
Definition: pfmlib.h:130
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
pfmlib_core_input_param_t params
#define PFM_NHM_SEL_INV
#define PFM_PLM3
Definition: pfmlib.h:53
virtual const std::string & name() const
Retrieve the name of the instance.
Definition: Auditor.cpp:218
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
Definition: Auditor.cpp:226
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]
bool inv[MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS]
#define PFMLIB_SUCCESS
Definition: pfmlib.h:283
unsigned int pfp_dfl_plm
Definition: pfmlib.h:110
uint16_t reg_num
Definition: perfmon_v2.h:39
pfmlib_input_param_t inp
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
pfmlib_nhm_input_param_t nhm_params
unsigned int reg_num
Definition: pfmlib.h:100
pfmlib_output_param_t outp
uint16_t reg_num
Definition: perfmon_v2.h:28
char event_cstr[MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS][MAX_EVENT_NAME_LENGTH]
pfarg_pmd_t pd[NUM_PMDS]
uint32_t load_pid
Definition: perfmon_v2.h:69
unsigned int i
pfarg_pmc_t pc[NUM_PMCS]
uint64_t reg_value
Definition: perfmon_v2.h:31
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
unsigned int cmask[MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS]
pfarg_load_t load_arg
uint64_t reg_value
Definition: perfmon_v2.h:42
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
unsigned int pfp_event_count
Definition: pfmlib.h:109
void PerfMonAuditor::stop_smpl ( )
private

Definition at line 904 of file PerfMonAuditor.cpp.

905  {
906  MsgStream log(msgSvc(), name());
907  m_pfm.pfm_self_stop(ctx_fd);
908  process_smpl_buf(hdr, entry_size);
909  close(ctx_fd);
910  ret = munmap(hdr, (size_t)buf_arg.buf_size);
911  if(ret)
912  {
913  log << MSG::ERROR << "Cannot unmap buffer: %s" << strerror(errno) << endmsg;
914  }
915  return;
916  }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
virtual const std::string & name() const
Retrieve the name of the instance.
Definition: Auditor.cpp:218
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
Definition: Auditor.cpp:226
static void process_smpl_buf(pfm_dfl_smpl_hdr_t *hdr, size_t entry_size)
pfm_dfl_smpl_arg_t buf_arg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
void PerfMonAuditor::stoppm ( )
private

Definition at line 508 of file PerfMonAuditor.cpp.

509 {
510  MsgStream log(msgSvc(), name());
511  m_pfm.pfm_stop(fd);
512  if(m_pfm.pfm_read_pmds(fd, pd, inp.pfp_event_count) == -1)
513  {
514  log << MSG::ERROR << "Could not read pmds" << endmsg;
515  }
516  for(int i=0; i<used_counters_number; i++)
517  {
518  results[i][(alg_stack.top().first)->name()].push_back(alg_stack.top().second[i] + pd[i].reg_value);
519  }
520 
521  close(fd);
522 }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
virtual const std::string & name() const
Retrieve the name of the instance.
Definition: Auditor.cpp:218
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
Definition: Auditor.cpp:226
pfmlib_input_param_t inp
pfarg_pmd_t pd[NUM_PMDS]
unsigned int i
uint64_t reg_value
Definition: perfmon_v2.h:42
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
unsigned int pfp_event_count
Definition: pfmlib.h:109

Member Data Documentation

void* PerfMonAuditor::buf_addr
private

Definition at line 405 of file PerfMonAuditor.cpp.

pfm_dfl_smpl_arg_t PerfMonAuditor::buf_arg
private

Definition at line 403 of file PerfMonAuditor.cpp.

unsigned int PerfMonAuditor::cmask[MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS]
private

Definition at line 382 of file PerfMonAuditor.cpp.

bool PerfMonAuditor::core
private

Definition at line 389 of file PerfMonAuditor.cpp.

pfarg_ctx_t PerfMonAuditor::ctx
private

Definition at line 364 of file PerfMonAuditor.cpp.

bool PerfMonAuditor::event_count_reached
private

Definition at line 415 of file PerfMonAuditor.cpp.

char PerfMonAuditor::event_cstr[MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS][MAX_EVENT_NAME_LENGTH]
private

Definition at line 378 of file PerfMonAuditor.cpp.

std::string PerfMonAuditor::event_str[MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS]
private

Definition at line 375 of file PerfMonAuditor.cpp.

std::string PerfMonAuditor::family
private

Definition at line 377 of file PerfMonAuditor.cpp.

int PerfMonAuditor::fd
private

Definition at line 368 of file PerfMonAuditor.cpp.

bool PerfMonAuditor::first_alg
private

Definition at line 413 of file PerfMonAuditor.cpp.

std::string PerfMonAuditor::first_alg_name
private

Definition at line 414 of file PerfMonAuditor.cpp.

unsigned int PerfMonAuditor::i
private

Definition at line 369 of file PerfMonAuditor.cpp.

pfmlib_input_param_t PerfMonAuditor::inp
private

Definition at line 362 of file PerfMonAuditor.cpp.

bool PerfMonAuditor::inv[MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS]
private

Definition at line 381 of file PerfMonAuditor.cpp.

int PerfMonAuditor::is_nehalem_ret
private

Definition at line 360 of file PerfMonAuditor.cpp.

int PerfMonAuditor::level
private

Definition at line 411 of file PerfMonAuditor.cpp.

pfarg_load_t PerfMonAuditor::load_arg
private

Definition at line 367 of file PerfMonAuditor.cpp.

pfarg_load_t PerfMonAuditor::load_args
private

Definition at line 404 of file PerfMonAuditor.cpp.

int PerfMonAuditor::m_indent
private

Definition at line 356 of file PerfMonAuditor.cpp.

bool PerfMonAuditor::m_inEvent
private

Definition at line 357 of file PerfMonAuditor.cpp.

Map PerfMonAuditor::m_map
private

Definition at line 355 of file PerfMonAuditor.cpp.

PFMon& PerfMonAuditor::m_pfm
private

Definition at line 233 of file PerfMonAuditor.cpp.

unsigned int PerfMonAuditor::max_pmd
private

Definition at line 407 of file PerfMonAuditor.cpp.

bool PerfMonAuditor::nehalem
private

Definition at line 387 of file PerfMonAuditor.cpp.

pfmlib_nhm_input_param_t PerfMonAuditor::nhm_params
private

Definition at line 385 of file PerfMonAuditor.cpp.

unsigned PerfMonAuditor::num_counters
private

Definition at line 406 of file PerfMonAuditor.cpp.

pfmlib_output_param_t PerfMonAuditor::outp
private

Definition at line 363 of file PerfMonAuditor.cpp.

pfmlib_core_input_param_t PerfMonAuditor::params
private

Definition at line 384 of file PerfMonAuditor.cpp.

pfarg_pmc_t PerfMonAuditor::pc[NUM_PMCS]
private

Definition at line 366 of file PerfMonAuditor.cpp.

pfarg_pmd_t PerfMonAuditor::pd[NUM_PMDS]
private

Definition at line 365 of file PerfMonAuditor.cpp.

pfmlib_options_t PerfMonAuditor::pfmlib_options
private

Definition at line 408 of file PerfMonAuditor.cpp.

unsigned int PerfMonAuditor::ph_ev_count
private

Definition at line 380 of file PerfMonAuditor.cpp.

std::string PerfMonAuditor::prefix
private

Definition at line 376 of file PerfMonAuditor.cpp.

char PerfMonAuditor::prefix_cstr[MAX_PREFIX_NAME_LENGTH]
private

Definition at line 379 of file PerfMonAuditor.cpp.

int PerfMonAuditor::ret
private

Definition at line 370 of file PerfMonAuditor.cpp.

bool PerfMonAuditor::sampling
private

Definition at line 391 of file PerfMonAuditor.cpp.

unsigned int PerfMonAuditor::start_at_event
private

Definition at line 383 of file PerfMonAuditor.cpp.

int PerfMonAuditor::used_counters_number
private

Definition at line 386 of file PerfMonAuditor.cpp.

bool PerfMonAuditor::westmere
private

Definition at line 388 of file PerfMonAuditor.cpp.


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