Gaudi Framework, version v24r2

Home   Generated: Wed Dec 4 2013
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
PerfMonAuditor Class Reference

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

Inheritance diagram for PerfMonAuditor:
Inheritance graph
[legend]
Collaboration diagram for PerfMonAuditor:
Collaboration graph
[legend]

Public Member Functions

virtual void before (StandardEventType evt, INamedInterface *alg)
 The following methods are meant to be implemented by the child class...
 
virtual void after (StandardEventType evt, INamedInterface *alg, const StatusCode &sc)
 
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.
 
virtual ~Auditor ()
 Destructor.
 
StatusCode sysInitialize ()
 Initialization method invoked by the framework.
 
StatusCode sysFinalize ()
 Finalization method invoked by the framework.
 
virtual void before (StandardEventType, const std::string &)
 
virtual void before (CustomEventTypeRef, INamedInterface *)
 
virtual void before (CustomEventTypeRef, const std::string &)
 
virtual void after (StandardEventType, const std::string &, const StatusCode &)
 
virtual void after (CustomEventTypeRef, INamedInterface *, const StatusCode &)
 
virtual void after (CustomEventTypeRef, const std::string &, const StatusCode &)
 
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::stringname () const
 
virtual bool isEnabled () const
 
SmartIF< IMessageSvc > & msgSvc () const
 The standard message service.
 
int outputLevel () const
 Retrieve the output level of current auditor.
 
void setOutputLevel (int level)
 Set the output level for current auditor.
 
SmartIF< ISvcLocator > & serviceLocator () const
 The standard service locator.
 
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.
 
virtual StatusCode setProperty (const Property &p)
 Set a value of a property of an auditor.
 
virtual StatusCode setProperty (const std::string &s)
 Implementation of IProperty::setProperty.
 
virtual StatusCode setProperty (const std::string &n, const std::string &v)
 Implementation of IProperty::setProperty.
 
virtual StatusCode getProperty (Property *p) const
 Get the value of a property.
 
virtual const PropertygetProperty (const std::string &name) const
 Get the property by name.
 
virtual StatusCode getProperty (const std::string &n, std::string &v) const
 Implementation of IProperty::getProperty.
 
const std::vector< Property * > & getProperties () const
 Get all properties.
 
template<class TYPE >
StatusCode setProperty (const std::string &name, const TYPE &value)
 set the property form the value
 
StatusCode setProperties ()
 Set the auditor's properties.
 
template<class T >
PropertydeclareProperty (const std::string &name, T &property, const std::string &doc="none") const
 Declare the named property.
 

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 implements2< IAuditor, IProperty >
typedef implements2 base_class
 Typedef to this class.
 
typedef extend_interfaces2
< IAuditor, IProperty
extend_interfaces_base
 Typedef to the base of this class.
 
typedef
extend_interfaces_base::ext_iids 
interfaces
 MPL set of all the implemented interfaces.
 

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 206 of file PerfMonAuditor.cpp.

Member Typedef Documentation

Definition at line 360 of file PerfMonAuditor.cpp.

Constructor & Destructor Documentation

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

Definition at line 278 of file PerfMonAuditor.cpp.

: // standard constructor
Auditor(name, pSvc),
m_pfm(PFMon::instance()),
m_map(),
m_inEvent(false)
{
declareProperty("EVENT0", event_str[0]);
declareProperty("EVENT1", event_str[1]);
declareProperty("EVENT2", event_str[2]);
declareProperty("EVENT3", event_str[3]);
declareProperty("INV0", inv[0]);
declareProperty("INV1", inv[1]);
declareProperty("INV2", inv[2]);
declareProperty("INV3", inv[3]);
declareProperty("CMASK0", cmask[0]);
declareProperty("CMASK1", cmask[1]);
declareProperty("CMASK2", cmask[2]);
declareProperty("CMASK3", cmask[3]);
declareProperty("SP0", sp[0]);
declareProperty("SP1", sp[1]);
declareProperty("SP2", sp[2]);
declareProperty("SP3", sp[3]);
declareProperty("START_AT_EVENT", start_at_event);
// MsgStream log(msgSvc(), name());
/*
// loading functions from PFM library
void* handle = dlopen("libpfm.so", RTLD_NOW);
if (!handle) {
// log << MSG::ERROR << "Cannot open library: " << dlerror() << endmsg;
}
typedef void (*hello_t)();
hello_t hello = (hello_t) dlsym(handle, "hello");
if (!hello) {
// log << MSG::ERROR << "Cannot load symbol 'hello': " << dlerror() << endmsg;
dlclose(handle);
}
pfm_start = (pfm_start_t) dlsym(handle, "pfm_start");
pfm_stop = (pfm_stop_t) dlsym(handle, "pfm_stop");
pfm_self_stop = (pfm_self_stop_t) dlsym(handle, "pfm_stop"); //it's the same
pfm_restart = (pfm_restart_t) dlsym(handle, "pfm_restart");
//pfm_read_pmds = (pfm_read_pmds_t) dlsym(handle, "pfm_read_pmds");
pfm_initialize = (pfm_initialize_t) dlsym(handle, "pfm_initialize");
pfm_find_full_event = (pfm_find_full_event_t) dlsym(handle, "pfm_find_full_event");
pfm_dispatch_events = (pfm_dispatch_events_t) dlsym(handle, "pfm_dispatch_events");
pfm_create_context = (pfm_create_context_t) dlsym(handle, "pfm_create_context");
pfm_write_pmcs = (pfm_write_pmcs_t) dlsym(handle, "pfm_write_pmcs");
pfm_write_pmds = (pfm_write_pmds_t) dlsym(handle, "pfm_write_pmds");
pfm_load_context = (pfm_load_context_t) dlsym(handle, "pfm_load_context");
pfm_strerror = (pfm_strerror_t) dlsym(handle, "pfm_strerror");
pfm_set_options = (pfm_set_options_t) dlsym(handle, "pfm_set_options");
pfm_get_num_counters = (pfm_get_num_counters_t) dlsym(handle, "pfm_get_num_counters");
// use it to do the calculation
// log << MSG::INFO << "Calling hello..." << endmsg;
// hello();
// close the library
// log << MSG::INFO << "Closing library..." << endmsg;
dlclose(handle);
*/
}
virtual PerfMonAuditor::~PerfMonAuditor ( )
inlinevirtual

Definition at line 352 of file PerfMonAuditor.cpp.

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

Member Function Documentation

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

Reimplemented from Auditor.

Definition at line 1075 of file PerfMonAuditor.cpp.

{
switch(evt)
{
break;
break;
default:
break;
}
return;
}
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 1059 of file PerfMonAuditor.cpp.

{
switch(evt)
{
break;
break;
default:
break;
}
return;
}
int PerfMonAuditor::detect_unavail_pmcs ( int  fd,
pfmlib_regmask_t r_pmcs 
)
inlineprivate

Definition at line 399 of file PerfMonAuditor.cpp.

{return detect_unavail_pmu_regs(fd, r_pmcs, NULL);}
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 1051 of file PerfMonAuditor.cpp.

{
if(sampling == 0) finalizepm();
else finalize_smpl();
}
void PerfMonAuditor::finalize_smpl ( )
private

Definition at line 929 of file PerfMonAuditor.cpp.

{
bzero(filename, MAX_OUTPUT_FILENAME_LENGTH);
char to_cat[50];
gzFile outfile;
int err;
for(int i=0; i<used_counters_number; i++)
{
sprintf(filename, "%s_%s", prefix_cstr, event_cstr[i]);
for(int j=0; j<(int)strlen(filename); j++)
{
if(filename[j]==':')
{
filename[j]='-';
}
}
bzero(to_cat, 50);
if(inv[i])
{
strcpy(to_cat, "_INV_1");
}
if(cmask[i]>0)
{
sprintf(to_cat, "%s_CMASK_%d", to_cat, cmask[i]);
}
sprintf(filename, "%s%s.txt.gz", filename, to_cat);
outfile = gzopen(filename, "wb");
if(outfile!=NULL)
{
if(nehalem)
{
gzprintf(outfile, "NHM ");
}
else if(westmere)
{
gzprintf(outfile, "WSM ");
}
else if(core)
{
gzprintf(outfile, "CORE ");
}
if(gzprintf(outfile, "%s %d %d %d\n", event_cstr[i], cmask[i], inv[i], sp[i]) < (int)strlen(event_cstr[i]))
{
log << MSG::ERROR << "ERROR: gzputs err: " << gzerror(outfile, &err) << ". Aborting..." << endmsg;
}
for(std::map<std::string, std::map<unsigned long, unsigned int> >::iterator it=samples[i].begin(); it!=samples[i].end(); it++)
{
unsigned long long sum = 0;
for(std::map<unsigned long, unsigned int>::iterator jt=(it->second).begin(); jt!=(it->second).end(); jt++)
{
sum += jt->second;
}
if(gzprintf(outfile, "%s%%%llu\n", (it->first).c_str(), sum) < (int)((it->first).length()))
{
log << MSG::ERROR << "ERROR: gzputs err: " << gzerror(outfile, &err) << ". Aborting..." << endmsg;
}
for(std::map<unsigned long, unsigned int>::iterator jt=(it->second).begin(); jt!=(it->second).end(); jt++)
{
char sym_name[SYM_NAME_MAX_LENGTH];
bzero(sym_name, SYM_NAME_MAX_LENGTH);
const char *libName;
const char *symbolName;
int libOffset = 0;
int offset = 0;
void *sym_addr = IgHookTrace::tosymbol((void *)(jt->first));
if(sym_addr != NULL)
{
bool success = IgHookTrace::symbol(sym_addr, symbolName, libName, offset, libOffset);
if(success)
{
if(symbolName!=NULL && strlen(symbolName)>0)
{
strcpy(sym_name, symbolName);
strcat(sym_name, " ");
}
else
{
strcpy(sym_name, "??? ");
}
if(libName!=NULL && strlen(libName)>0)
{
strcat(sym_name, libName);
strcat(sym_name, " ");
}
else
{
strcat(sym_name, "??? ");
}
sprintf(sym_name, "%s%d ", sym_name, libOffset);
if(strlen(sym_name)<=0)
{
log << MSG::ERROR << "ERROR: Symbol name length is zero. Aborting..." << endmsg;
}
}
else
{
strcpy(sym_name,"??? ??? 0 ");
}
}
else
{
strcpy(sym_name,"??? ??? 0 ");
}
if(gzprintf(outfile, "%s %d\n", sym_name, jt->second) < (int)strlen(sym_name))
{
log << MSG::ERROR << "ERROR: gzputs err: " << gzerror(outfile, &err) << endmsg;
}
}
}
}
else
{
log << MSG::ERROR << "ERROR: Could not open file: " << filename << ". Aborting..." << endmsg;
}
gzclose(outfile);
}
}
void PerfMonAuditor::finalizepm ( )
private

Definition at line 552 of file PerfMonAuditor.cpp.

{
log << MSG::INFO << "start of finalizepm ucn:" << used_counters_number << endmsg;
char to_cat[50];
FILE *outfile;
for(int i=0; i<used_counters_number; i++)
{
bzero(filename, MAX_OUTPUT_FILENAME_LENGTH);
sprintf(filename, "%s_%s", prefix_cstr, event_cstr[i]);
for(int j=0; j<(int)strlen(filename); j++)
{
if(filename[j]==':')
{
filename[j]='-';
}
}
bzero(to_cat, 50);
if(inv[i])
{
strcpy(to_cat, "_INV_1");
}
if(cmask[i]>0)
{
sprintf(to_cat, "%s_CMASK_%d", to_cat, cmask[i]);
}
sprintf(filename, "%s%s.txt", filename, to_cat);
log << MSG::INFO << "Filename:" << filename << endmsg;
outfile = fopen(filename, "w");
if(nehalem)
{
fprintf(outfile, "NHM ");
}
else if(westmere)
{
fprintf(outfile, "WSM ");
}
else if(core)
{
fprintf(outfile, "CORE ");
}
fprintf(outfile, "%s %d %d %d\n", event_cstr[i], cmask[i], inv[i], sp[i]);
for(std::map<std::string, std::vector<unsigned long int> >::iterator it=(results[i]).begin(); it!=(results[i]).end(); it++)
{
fprintf(outfile, "%s\n", (it->first).c_str());
for(std::vector<unsigned long int>::iterator j=(it->second).begin(); j!=(it->second).end(); j++)
{
fprintf(outfile, "%lu\n", *j);
}
}
fclose(outfile);
}
}
void PerfMonAuditor::i_afterExecute ( INamedInterface alg)
private

Definition at line 1154 of file PerfMonAuditor.cpp.

{
if(alg == 0)
{
return;
}// log << MSG::INFO << "after:inside! " << alg->name() << endmsg;
{
//log << MSG::INFO << "after:inside! " << alg->name() << endmsg;
if(sampling == 0) stoppm();
else stop_smpl();
alg_stack.pop();
if(!alg_stack.empty())
{
if(sampling == 0) startpm();
else start_smpl(); //resuming father algorithm counting
}
}
return;
}
void PerfMonAuditor::i_afterInitialize ( INamedInterface alg)
private

Definition at line 1100 of file PerfMonAuditor.cpp.

{
if(alg == 0)
{
return;
}
return;
}
void PerfMonAuditor::i_beforeExecute ( INamedInterface alg)
private

Definition at line 1109 of file PerfMonAuditor.cpp.

{
if(alg == 0)
{
return;
}
//log << MSG::INFO << "before:inside! " << alg->name() << endmsg;
{
first_alg = false;
first_alg_name = alg->name();
//log << MSG::INFO << "first_alg_name= " << alg->name() << endmsg;
}
{
if(!first_alg_name.compare(alg->name()))
{
//log << MSG::INFO << "EVENT COUNT: " << ph_ev_count << endmsg;
{
//log << MSG::INFO << "!!! EVENT COUNT REACHED: " << ph_ev_count << endmsg;
}
}
}
{
//log << MSG::INFO << "before:inside! " << alg->name() << endmsg;
if(!alg_stack.empty())
{
if(sampling == 0) pausepm(); //pausing father algorithm counting
else stop_smpl();
}
alg_stack.push(std::make_pair(alg, zeroes));
if(sampling == 0) startpm();
else start_smpl();
}
return;
}
void PerfMonAuditor::i_beforeInitialize ( INamedInterface alg)
private

Definition at line 1091 of file PerfMonAuditor.cpp.

{
if(alg == 0)
{
return;
}
return;
}
StatusCode PerfMonAuditor::initialize ( )
virtual

Reimplemented from Auditor.

Definition at line 607 of file PerfMonAuditor.cpp.

{
if (!m_pfm.loaded) {
log << MSG::ERROR << "pfm library could not be loaded" << endmsg;
return false;
}
log << MSG::INFO << "Initializing..." << endmsg;
if(sc.isFailure())
{
return sc;
}
{
if(event_str[i].length()>0) used_counters_number++;
}
{
strcpy(event_cstr[i], event_str[i].c_str());
}
strcpy(prefix_cstr, prefix.c_str());
if(m_pfm.pfm_initialize() != PFMLIB_SUCCESS)
{
log << MSG::ERROR << "Cannot initialize perfmon!!" << endmsg;
}
first_alg = true;
nehalem = false;
core = false;
westmere = false;
if(family.compare("CORE")==0) core = true;
else if(family.compare("NEHALEM")==0) nehalem = true;
else if(family.compare("WESTMERE")==0) westmere = true;
else
{
log << MSG::ERROR << "ERROR: Unsupported processor family " << family << ". aborting..." << endmsg;
}
log << MSG::INFO << "Initialized!" << endmsg;
}
int PerfMonAuditor::is_nehalem ( )
inline

Definition at line 223 of file PerfMonAuditor.cpp.

{
#ifdef __ICC
// Disable ICC remark #593: variable "x" was set but never used
#pragma warning(push)
#pragma warning(disable:593)
#endif
int a,b,c,d;
cpuid(1,a,b,c,d);
int sse4_2_mask = 1 << 20;
if(c & sse4_2_mask) return 1; else return 0;
#ifdef __ICC
#pragma warning(pop)
#endif
}
PerfMonAuditor& PerfMonAuditor::operator= ( const PerfMonAuditor )
private
void PerfMonAuditor::pausepm ( )
private

Definition at line 531 of file PerfMonAuditor.cpp.

{
m_pfm.pfm_stop(fd);
if(m_pfm.pfm_read_pmds(fd, pd, inp.pfp_event_count) == -1)
{
log << MSG::ERROR << "Could not read pmds" << endmsg;
}
for(int i=0; i<used_counters_number; i++)
{
alg_stack.top().second[i] += pd[i].reg_value;
}
close(fd);
}
void PerfMonAuditor::pfm_bv_copy ( uint64_t *  d,
uint64_t *  j,
uint16_t  n 
)
inlineprivate

Definition at line 402 of file PerfMonAuditor.cpp.

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

Definition at line 401 of file PerfMonAuditor.cpp.

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

Definition at line 400 of file PerfMonAuditor.cpp.

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

Definition at line 659 of file PerfMonAuditor.cpp.

{
size_t pos, count;
uint64_t entry;
{
printf("skipping identical set of samples...\n");
return;
}
count = hdr->hdr_count;
ent = (pfm_dfl_smpl_entry_t *)(hdr+1);
pos = (unsigned long)ent;
while(count--)
{
//if(ent->ovfl_pmd>=0 && ent->ovfl_pmd<=3)
if(ent->ovfl_pmd<=3)
{
((samples[ent->ovfl_pmd])[(alg_stack.top().first)->name()])[(unsigned long)(ent->ip)]++;
}
pos += entry_size;
ent = (pfm_dfl_smpl_entry_t *)pos;
entry++;
}
if (last_count != hdr->hdr_count && (last_count || last_overflow == 0))
{
}
return;
}
void PerfMonAuditor::sigio_handler ( int  ,
struct siginfo *  ,
struct sigcontext *   
)
staticprivate

Definition at line 700 of file PerfMonAuditor.cpp.

{
//MsgStream log(msgSvc(), name());
PFMon& pfm = PFMon::instance();
int fd = ctx_fd;
int r;
if(fd != ctx_fd)
{
//log << MSG::ERROR << "ERROR: handler does not get valid file descriptor. Aborting..." << endmsg;
}
if(pfm.pfm_read_pmds(fd, pd_smpl+1, 1) == -1)
{
//log << MSG::ERROR << "ERROR: pfm_read_pmds: " << strerror(errno) << ". Aborting..." << endmsg;
}
while(true)
{
r = read(fd, &msg, sizeof(msg));
if(r!=sizeof(msg))
{
if(r==-1 && errno==EINTR)
{
printf("read interrupted, retrying\n");
continue;
}
//log << MSG::ERROR << "ERROR: cannot read overflow message: " << strerror(errno) << ". Aborting..." << endmsg;
}
break;
}
switch(msg.type)
{
case PFM_MSG_OVFL: // the sampling buffer is full
if(pfm.pfm_restart(fd))
{
if(errno!=EBUSY)
{
//log << MSG::ERROR << "ERROR: pfm_restart error errno " << errno << ". Aborting..." << endmsg;
}
else
{
printf("pfm_restart: task probably terminated \n");
}
}
break;
default:
//log << MSG::ERROR << "ERROR: unknown message type " << msg.type << ". Aborting..." << endmsg;
break;
}
}
void PerfMonAuditor::start_smpl ( )
private

Definition at line 762 of file PerfMonAuditor.cpp.

{
max_pmd = 0;
memset(&pfmlib_options, 0, sizeof(pfmlib_options));
m_pfm.pfm_set_options(&pfmlib_options);
ret = m_pfm.pfm_initialize();
{
log << MSG::ERROR << "ERROR: Cannot initialize library: " << m_pfm.pfm_strerror(ret) << ". Aborting..." << endmsg;
}
struct sigaction act;
memset(&act, 0, sizeof(act));
act.sa_handler = (sig_t)sigio_handler; // dlopen() ==>
//act.sa_handler = (sig_t)&sigio_handler;
sigaction(SIGIO, &act, 0);
memset(&ctx, 0, sizeof(ctx));
memset(&buf_arg, 0, sizeof(buf_arg));
memset(&inp,0, sizeof(inp));
memset(&outp,0, sizeof(outp));
memset(pd_smpl, 0, sizeof(pd_smpl));
memset(pc, 0, sizeof(pc));
memset(&load_args, 0, sizeof(load_args));
m_pfm.pfm_get_num_counters(&num_counters);
memset(&params, 0, sizeof(params));
memset(&nhm_params, 0, sizeof(nhm_params));
for(int i=0; i<used_counters_number; i++)
{
ret = m_pfm.pfm_find_full_event(event_cstr[i], &inp.pfp_events[i]);
{
log << MSG::ERROR << "ERROR: cannot find event: " << event_cstr[i] << ". Aborting..." << endmsg;
}
}
for(int i=0; i<used_counters_number; i++)
{
if(inv[i])
{
}
if(cmask[i]>0)
{
(params.pfp_core_counters[i]).cnt_mask = cmask[i];
(nhm_params.pfp_nhm_counters[i]).cnt_mask = cmask[i];
}
}
{
ret = m_pfm.pfm_dispatch_events(&inp, &nhm_params, &outp, NULL);
}
else
{
ret = m_pfm.pfm_dispatch_events(&inp, &params, &outp, NULL);
}
{
log << MSG::ERROR << "ERROR: cannot configure events: " << m_pfm.pfm_strerror(ret) << ". Aborting..." << endmsg;
}
for(unsigned int i=0; i<outp.pfp_pmc_count; i++)
{
}
for(unsigned int i=0; i<outp.pfp_pmd_count; i++)
{
if(i)
{
pfm_bv_set(pd_smpl[0].reg_smpl_pmds, pd_smpl[i].reg_num);
if(pd_smpl[i].reg_num>max_pmd)
{
}
}
}
for(int i=0; i<used_counters_number; i++)
{
pfm_bv_copy(pd_smpl[i].reg_reset_pmds, pd_smpl[i].reg_smpl_pmds, max_pmd);
pd_smpl[i].reg_value = (uint64_t)(sp[i] * -1);
pd_smpl[i].reg_short_reset = (uint64_t)(sp[i] * -1);
pd_smpl[i].reg_long_reset = (uint64_t)(sp[i] * -1);
pd_smpl[i].reg_random_seed = 5; //tocheck
pd_smpl[i].reg_random_mask = 0xff; //tocheck
}
buf_arg.buf_size = 3*getpagesize()+512;
ctx_fd = m_pfm.pfm_create_context(&ctx, (char *)FMT_NAME, &buf_arg, sizeof(buf_arg));
if(ctx_fd==-1)
{
if(errno==ENOSYS)
{
log << MSG::ERROR << "ERROR: Your kernel does not have performance monitoring support! Aborting..." << endmsg;
}
log << MSG::ERROR << "ERROR: Can't create PFM context " << strerror(errno) << ". Aborting..." << endmsg;
}
buf_addr = mmap(NULL, (size_t)buf_arg.buf_size, PROT_READ, MAP_PRIVATE, ctx_fd, 0);
if(buf_addr==MAP_FAILED)
{
log << MSG::ERROR << "ERROR: cannot mmap sampling buffer: " << strerror(errno) << ". Aborting..." << endmsg;
}
{
log << MSG::ERROR << "ERROR: invalid buffer format version. Aborting..." << endmsg;
}
if(m_pfm.pfm_write_pmcs(ctx_fd, pc, outp.pfp_pmc_count))
{
log << MSG::ERROR << "ERROR: pfm_write_pmcs error errno " << strerror(errno) << ". Aborting..." << endmsg;
}
if(m_pfm.pfm_write_pmds(ctx_fd, pd_smpl, outp.pfp_pmd_count))
{
log << MSG::ERROR << "ERROR: pfm_write_pmds error errno " << strerror(errno) << ". Aborting..." << endmsg;
}
load_args.load_pid = getpid();
if(m_pfm.pfm_load_context(ctx_fd, &load_args))
{
log << MSG::ERROR << "ERROR: pfm_load_context error errno " << strerror(errno) << ". Aborting..." << endmsg;
}
ret = fcntl(ctx_fd, F_SETFL, fcntl(ctx_fd, F_GETFL, 0) | O_ASYNC);
if(ret == -1)
{
log << MSG::ERROR << "ERROR: cannot set ASYNC: " << strerror(errno) << ". Aborting..." << endmsg;
}
ret = fcntl(ctx_fd, F_SETOWN, getpid());
if(ret == -1)
{
log << MSG::ERROR << "ERROR: cannot setown: " << strerror(errno) << ". Aborting..." << endmsg;
}
//pfm_self_start(ctx_fd); ==>
m_pfm.pfm_start(ctx_fd, NULL);
}
void PerfMonAuditor::startpm ( )
private

Definition at line 426 of file PerfMonAuditor.cpp.

{
memset(&ctx,0, sizeof(ctx));
memset(&inp,0, sizeof(inp));
memset(&outp,0, sizeof(outp));
memset(pd, 0, sizeof(pd));
memset(pc, 0, sizeof(pc));
memset(&load_arg, 0, sizeof(load_arg));
memset(&params, 0, sizeof(params));
memset(&nhm_params, 0, sizeof(nhm_params));
for(int i=0; i<used_counters_number; i++)
{
ret = m_pfm.pfm_find_full_event(event_cstr[i], &inp.pfp_events[i]);
{
log << MSG::ERROR << "ERROR: cannot find event: " << event_cstr[i] << ". Aborting..." << endmsg;
}
}
for(int i=0; i<used_counters_number; i++)
{
if(inv[i])
{
}
if(cmask[i]>0)
{
(params.pfp_core_counters[i]).cnt_mask = cmask[i];
(nhm_params.pfp_nhm_counters[i]).cnt_mask = cmask[i];
}
}
{
ret = m_pfm.pfm_dispatch_events(&inp, &nhm_params, &outp, NULL);
}
else
{
ret = m_pfm.pfm_dispatch_events(&inp, &params, &outp, NULL);
}
{
log << MSG::ERROR << "ERROR: cannot dispatch events: " << m_pfm.pfm_strerror(ret) << ". Aborting..." << endmsg;
}
for(unsigned int i=0; i<outp.pfp_pmc_count; i++)
{
}
for(unsigned int i=0; i<outp.pfp_pmd_count; i++)
{
pd[i].reg_value = 0;
}
fd = m_pfm.pfm_create_context(&ctx, NULL, 0, 0);
if(fd == -1)
{
log << MSG::ERROR << "ERROR: Context not created. Aborting..." << endmsg;
}
if(m_pfm.pfm_write_pmcs(fd, pc, outp.pfp_pmc_count) == -1)
{
log << MSG::ERROR << "ERROR: Could not write pmcs. Aborting..." << endmsg;
}
if(m_pfm.pfm_write_pmds(fd, pd, outp.pfp_pmd_count) == -1)
{
log << MSG::ERROR << "ERROR: Could not write pmds. Aborting..." << endmsg;
}
load_arg.load_pid = getpid();
if(m_pfm.pfm_load_context(fd, &load_arg) == -1)
{
log << MSG::ERROR << "ERROR: Could not load context. Aborting..." << endmsg;
// MsgStream log(msgSvc(), name());
// log << MSG::ERROR << "Could not read pmds" << endmsg;
}
m_pfm.pfm_start(fd, NULL);
}
void PerfMonAuditor::stop_smpl ( )
private

Definition at line 910 of file PerfMonAuditor.cpp.

{
m_pfm.pfm_self_stop(ctx_fd);
close(ctx_fd);
ret = munmap(hdr, (size_t)buf_arg.buf_size);
if(ret)
{
log << MSG::ERROR << "Cannot unmap buffer: %s" << strerror(errno) << endmsg;
}
return;
}
void PerfMonAuditor::stoppm ( )
private

Definition at line 514 of file PerfMonAuditor.cpp.

{
m_pfm.pfm_stop(fd);
if(m_pfm.pfm_read_pmds(fd, pd, inp.pfp_event_count) == -1)
{
log << MSG::ERROR << "Could not read pmds" << endmsg;
}
for(int i=0; i<used_counters_number; i++)
{
results[i][(alg_stack.top().first)->name()].push_back(alg_stack.top().second[i] + pd[i].reg_value);
}
close(fd);
}

Member Data Documentation

void* PerfMonAuditor::buf_addr
private

Definition at line 411 of file PerfMonAuditor.cpp.

pfm_dfl_smpl_arg_t PerfMonAuditor::buf_arg
private

Definition at line 409 of file PerfMonAuditor.cpp.

unsigned int PerfMonAuditor::cmask[MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS]
private

Definition at line 388 of file PerfMonAuditor.cpp.

bool PerfMonAuditor::core
private

Definition at line 395 of file PerfMonAuditor.cpp.

pfarg_ctx_t PerfMonAuditor::ctx
private

Definition at line 370 of file PerfMonAuditor.cpp.

bool PerfMonAuditor::event_count_reached
private

Definition at line 421 of file PerfMonAuditor.cpp.

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

Definition at line 384 of file PerfMonAuditor.cpp.

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

Definition at line 381 of file PerfMonAuditor.cpp.

std::string PerfMonAuditor::family
private

Definition at line 383 of file PerfMonAuditor.cpp.

int PerfMonAuditor::fd
private

Definition at line 374 of file PerfMonAuditor.cpp.

bool PerfMonAuditor::first_alg
private

Definition at line 419 of file PerfMonAuditor.cpp.

std::string PerfMonAuditor::first_alg_name
private

Definition at line 420 of file PerfMonAuditor.cpp.

unsigned int PerfMonAuditor::i
private

Definition at line 375 of file PerfMonAuditor.cpp.

pfmlib_input_param_t PerfMonAuditor::inp
private

Definition at line 368 of file PerfMonAuditor.cpp.

bool PerfMonAuditor::inv[MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS]
private

Definition at line 387 of file PerfMonAuditor.cpp.

int PerfMonAuditor::is_nehalem_ret
private

Definition at line 366 of file PerfMonAuditor.cpp.

int PerfMonAuditor::level
private

Definition at line 417 of file PerfMonAuditor.cpp.

pfarg_load_t PerfMonAuditor::load_arg
private

Definition at line 373 of file PerfMonAuditor.cpp.

pfarg_load_t PerfMonAuditor::load_args
private

Definition at line 410 of file PerfMonAuditor.cpp.

int PerfMonAuditor::m_indent
private

Definition at line 362 of file PerfMonAuditor.cpp.

bool PerfMonAuditor::m_inEvent
private

Definition at line 363 of file PerfMonAuditor.cpp.

Map PerfMonAuditor::m_map
private

Definition at line 361 of file PerfMonAuditor.cpp.

PFMon& PerfMonAuditor::m_pfm
private

Definition at line 239 of file PerfMonAuditor.cpp.

unsigned int PerfMonAuditor::max_pmd
private

Definition at line 413 of file PerfMonAuditor.cpp.

bool PerfMonAuditor::nehalem
private

Definition at line 393 of file PerfMonAuditor.cpp.

pfmlib_nhm_input_param_t PerfMonAuditor::nhm_params
private

Definition at line 391 of file PerfMonAuditor.cpp.

unsigned PerfMonAuditor::num_counters
private

Definition at line 412 of file PerfMonAuditor.cpp.

pfmlib_output_param_t PerfMonAuditor::outp
private

Definition at line 369 of file PerfMonAuditor.cpp.

pfmlib_core_input_param_t PerfMonAuditor::params
private

Definition at line 390 of file PerfMonAuditor.cpp.

pfarg_pmc_t PerfMonAuditor::pc[NUM_PMCS]
private

Definition at line 372 of file PerfMonAuditor.cpp.

pfarg_pmd_t PerfMonAuditor::pd[NUM_PMDS]
private

Definition at line 371 of file PerfMonAuditor.cpp.

pfmlib_options_t PerfMonAuditor::pfmlib_options
private

Definition at line 414 of file PerfMonAuditor.cpp.

unsigned int PerfMonAuditor::ph_ev_count
private

Definition at line 386 of file PerfMonAuditor.cpp.

std::string PerfMonAuditor::prefix
private

Definition at line 382 of file PerfMonAuditor.cpp.

char PerfMonAuditor::prefix_cstr[MAX_PREFIX_NAME_LENGTH]
private

Definition at line 385 of file PerfMonAuditor.cpp.

int PerfMonAuditor::ret
private

Definition at line 376 of file PerfMonAuditor.cpp.

bool PerfMonAuditor::sampling
private

Definition at line 397 of file PerfMonAuditor.cpp.

unsigned int PerfMonAuditor::start_at_event
private

Definition at line 389 of file PerfMonAuditor.cpp.

int PerfMonAuditor::used_counters_number
private

Definition at line 392 of file PerfMonAuditor.cpp.

bool PerfMonAuditor::westmere
private

Definition at line 394 of file PerfMonAuditor.cpp.


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

Generated at Wed Dec 4 2013 14:33:18 for Gaudi Framework, version v24r2 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004