|
Gaudi Framework, version v23r2 |
| Home | Generated: Thu Jun 28 2012 |
Performance Monitoring Auditor that uses Perfmon2 library to monitor algorithms. More...


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 () |
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 &) | |
| PerfMonAuditor & | operator= (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 |
Performance Monitoring Auditor that uses Perfmon2 library to monitor algorithms.
Definition at line 196 of file PerfMonAuditor.cpp.
typedef GaudiUtils::VectorMap<const INamedInterface*,int> PerfMonAuditor::Map [private] |
Definition at line 350 of file PerfMonAuditor.cpp.
| PerfMonAuditor::PerfMonAuditor | ( | const std::string & | name, |
| ISvcLocator * | pSvc | ||
| ) | [inline] |
Definition at line 268 of file PerfMonAuditor.cpp.
: // standard constructor Auditor(name, pSvc), m_pfm(PFMon::instance()), m_map(), m_indent(0), m_inEvent(false) { is_nehalem_ret = is_nehalem(); declareProperty("EVENT0", event_str[0]); declareProperty("EVENT1", event_str[1]); declareProperty("EVENT2", event_str[2]); declareProperty("EVENT3", event_str[3]); declareProperty("FAMILY", family); declareProperty("PREFIX", prefix); 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("SAMPLE", sampling); declareProperty("START_AT_EVENT", start_at_event); declareProperty("IS_NEHALEM", is_nehalem_ret); // 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 | ( | ) | [inline, virtual] |
Definition at line 342 of file PerfMonAuditor.cpp.
{} // virtual destructor
| PerfMonAuditor::PerfMonAuditor | ( | ) | [private] |
| PerfMonAuditor::PerfMonAuditor | ( | const PerfMonAuditor & | ) | [private] |
| void PerfMonAuditor::after | ( | StandardEventType | evt, |
| INamedInterface * | alg, | ||
| const StatusCode & | sc | ||
| ) | [virtual] |
Reimplemented from Auditor.
Definition at line 1065 of file PerfMonAuditor.cpp.
{
switch(evt)
{
case IAuditor::Initialize:
i_afterInitialize(alg);
break;
case IAuditor::Execute:
i_afterExecute(alg);
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 1049 of file PerfMonAuditor.cpp.
{
switch(evt)
{
case IAuditor::Initialize:
i_beforeInitialize(alg);
break;
case IAuditor::Execute:
i_beforeExecute(alg);
break;
default:
break;
}
return;
}
| int PerfMonAuditor::detect_unavail_pmcs | ( | int | fd, |
| pfmlib_regmask_t * | r_pmcs | ||
| ) | [inline, private] |
Definition at line 389 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 1041 of file PerfMonAuditor.cpp.
{
if(sampling == 0) finalizepm();
else finalize_smpl();
return Auditor::finalize();
}
| void PerfMonAuditor::finalize_smpl | ( | ) | [private] |
Definition at line 919 of file PerfMonAuditor.cpp.
{
MsgStream log(msgSvc(), name());
char filename[MAX_OUTPUT_FILENAME_LENGTH];
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 542 of file PerfMonAuditor.cpp.
{
MsgStream log(msgSvc(), name());
log << MSG::INFO << "start of finalizepm ucn:" << used_counters_number << endmsg;
char filename[MAX_OUTPUT_FILENAME_LENGTH];
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 1144 of file PerfMonAuditor.cpp.
{
MsgStream log(msgSvc(), name());
if(alg == 0)
{
return;
}// log << MSG::INFO << "after:inside! " << alg->name() << endmsg;
if(event_count_reached)
{
//log << MSG::INFO << "after:inside! " << alg->name() << endmsg;
if(sampling == 0) stoppm();
else stop_smpl();
alg_stack.pop();
--m_indent;
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 1090 of file PerfMonAuditor.cpp.
{
if(alg == 0)
{
return;
}
return;
}
| void PerfMonAuditor::i_beforeExecute | ( | INamedInterface * | alg ) | [private] |
Definition at line 1099 of file PerfMonAuditor.cpp.
{
MsgStream log(msgSvc(), name());
if(alg == 0)
{
return;
}
//log << MSG::INFO << "before:inside! " << alg->name() << endmsg;
if(first_alg)
{
first_alg = false;
first_alg_name = alg->name();
//log << MSG::INFO << "first_alg_name= " << alg->name() << endmsg;
}
if(!event_count_reached)
{
if(!first_alg_name.compare(alg->name()))
{
ph_ev_count++;
//log << MSG::INFO << "EVENT COUNT: " << ph_ev_count << endmsg;
if(ph_ev_count==start_at_event)
{
event_count_reached = true;
//log << MSG::INFO << "!!! EVENT COUNT REACHED: " << ph_ev_count << endmsg;
}
}
}
if(event_count_reached)
{
//log << MSG::INFO << "before:inside! " << alg->name() << endmsg;
if(!alg_stack.empty())
{
if(sampling == 0) pausepm(); //pausing father algorithm counting
else stop_smpl();
}
++m_indent;
std::vector <unsigned long int> zeroes(4,0);
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 1081 of file PerfMonAuditor.cpp.
{
if(alg == 0)
{
return;
}
return;
}
| StatusCode PerfMonAuditor::initialize | ( | ) | [virtual] |
Reimplemented from Auditor.
Definition at line 597 of file PerfMonAuditor.cpp.
{
MsgStream log(msgSvc(), name());
if (!m_pfm.loaded) {
log << MSG::ERROR << "pfm library could not be loaded" << endmsg;
return false;
}
log << MSG::INFO << "Initializing..." << endmsg;
StatusCode sc = Auditor::initialize() ;
if(sc.isFailure())
{
return sc;
}
used_counters_number = 0;
for(int i=0; i<MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS; i++)
{
if(event_str[i].length()>0) used_counters_number++;
}
for(int i=0; i<MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS; i++)
{
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;
}
ph_ev_count = 0;
first_alg = true;
event_count_reached = false;
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;
return StatusCode::SUCCESS ;
}
| int PerfMonAuditor::is_nehalem | ( | ) | [inline] |
Definition at line 213 of file PerfMonAuditor.cpp.
| PerfMonAuditor& PerfMonAuditor::operator= | ( | const PerfMonAuditor & | ) | [private] |
| void PerfMonAuditor::pausepm | ( | ) | [private] |
Definition at line 521 of file PerfMonAuditor.cpp.
| void PerfMonAuditor::pfm_bv_copy | ( | uint64_t * | d, |
| uint64_t * | j, | ||
| uint16_t | n | ||
| ) | [inline, private] |
Definition at line 392 of file PerfMonAuditor.cpp.
| int PerfMonAuditor::pfm_bv_isset | ( | uint64_t * | bv, |
| uint16_t | rnum | ||
| ) | [inline, private] |
Definition at line 391 of file PerfMonAuditor.cpp.
| void PerfMonAuditor::pfm_bv_set | ( | uint64_t * | bv, |
| uint16_t | rnum | ||
| ) | [inline, private] |
Definition at line 390 of file PerfMonAuditor.cpp.
| void PerfMonAuditor::process_smpl_buf | ( | pfm_dfl_smpl_hdr_t * | hdr, |
| size_t | entry_size | ||
| ) | [static, private] |
Definition at line 649 of file PerfMonAuditor.cpp.
{
pfm_dfl_smpl_entry_t *ent;
size_t pos, count;
uint64_t entry;
if(hdr->hdr_overflows == last_overflow && hdr->hdr_count == last_count)
{
printf("skipping identical set of samples...\n");
return;
}
count = hdr->hdr_count;
ent = (pfm_dfl_smpl_entry_t *)(hdr+1);
pos = (unsigned long)ent;
entry = collected_samples;
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++;
}
collected_samples = entry;
last_overflow = hdr->hdr_overflows;
if (last_count != hdr->hdr_count && (last_count || last_overflow == 0))
{
collected_partial += hdr->hdr_count;
}
last_count = hdr->hdr_count;
return;
}
| void PerfMonAuditor::sigio_handler | ( | int | , |
| struct siginfo * | , | ||
| struct sigcontext * | |||
| ) | [static, private] |
Definition at line 690 of file PerfMonAuditor.cpp.
{
//MsgStream log(msgSvc(), name());
PFMon& pfm = PFMon::instance();
pfarg_msg_t msg;
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
process_smpl_buf(hdr, entry_size);
ovfl_count++;
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 752 of file PerfMonAuditor.cpp.
{
MsgStream log(msgSvc(), name());
ovfl_count = 0;
num_smpl_pmds = 0;
last_overflow = ~0;
max_pmd = 0;
memset(&pfmlib_options, 0, sizeof(pfmlib_options));
pfmlib_options.pfm_debug = 0;
pfmlib_options.pfm_verbose = 0;
m_pfm.pfm_set_options(&pfmlib_options);
ret = m_pfm.pfm_initialize();
if(ret != PFMLIB_SUCCESS)
{
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(¶ms, 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]);
if(ret != PFMLIB_SUCCESS)
{
log << MSG::ERROR << "ERROR: cannot find event: " << event_cstr[i] << ". Aborting..." << endmsg;
}
}
inp.pfp_dfl_plm = PFM_PLM3;
inp.pfp_event_count = 4;
for(int i=0; i<used_counters_number; i++)
{
if(inv[i])
{
(params.pfp_core_counters[i]).flags |= PFM_CORE_SEL_INV;
(nhm_params.pfp_nhm_counters[i]).flags |= PFM_NHM_SEL_INV;
}
if(cmask[i]>0)
{
(params.pfp_core_counters[i]).cnt_mask = cmask[i];
(nhm_params.pfp_nhm_counters[i]).cnt_mask = cmask[i];
}
}
if(nehalem || westmere)
{
ret = m_pfm.pfm_dispatch_events(&inp, &nhm_params, &outp, NULL);
}
else
{
ret = m_pfm.pfm_dispatch_events(&inp, ¶ms, &outp, NULL);
}
if(ret != PFMLIB_SUCCESS)
{
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++)
{
pc[i].reg_num = outp.pfp_pmcs[i].reg_num;
pc[i].reg_value = outp.pfp_pmcs[i].reg_value;
}
for(unsigned int i=0; i<outp.pfp_pmd_count; i++)
{
pd_smpl[i].reg_num = outp.pfp_pmds[i].reg_num;
if(i)
{
pfm_bv_set(pd_smpl[0].reg_smpl_pmds, pd_smpl[i].reg_num);
if(pd_smpl[i].reg_num>max_pmd)
{
max_pmd = pd_smpl[i].reg_num;
}
num_smpl_pmds++;
}
}
for(int i=0; i<used_counters_number; i++)
{
pd_smpl[i].reg_flags |= PFM_REGFL_OVFL_NOTIFY | PFM_REGFL_RANDOM;
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
}
entry_size = sizeof(pfm_dfl_smpl_entry_t)+(num_smpl_pmds<<3);
ctx.ctx_flags = 0;
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;
}
hdr = (pfm_dfl_smpl_hdr_t *)buf_addr;
if(PFM_VERSION_MAJOR(hdr->hdr_version)<1)
{
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 416 of file PerfMonAuditor.cpp.
{
MsgStream log(msgSvc(), name());
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(¶ms, 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]);
if(ret != PFMLIB_SUCCESS)
{
log << MSG::ERROR << "ERROR: cannot find event: " << event_cstr[i] << ". Aborting..." << endmsg;
}
}
inp.pfp_dfl_plm = PFM_PLM3;
inp.pfp_event_count = 4;
for(int i=0; i<used_counters_number; i++)
{
if(inv[i])
{
(params.pfp_core_counters[i]).flags |= PFM_CORE_SEL_INV;
(nhm_params.pfp_nhm_counters[i]).flags |= PFM_NHM_SEL_INV;
}
if(cmask[i]>0)
{
(params.pfp_core_counters[i]).cnt_mask = cmask[i];
(nhm_params.pfp_nhm_counters[i]).cnt_mask = cmask[i];
}
}
if(nehalem || westmere)
{
ret = m_pfm.pfm_dispatch_events(&inp, &nhm_params, &outp, NULL);
}
else
{
ret = m_pfm.pfm_dispatch_events(&inp, ¶ms, &outp, NULL);
}
if(ret != PFMLIB_SUCCESS)
{
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++)
{
pc[i].reg_num = outp.pfp_pmcs[i].reg_num;
pc[i].reg_value = outp.pfp_pmcs[i].reg_value;
}
for(unsigned int i=0; i<outp.pfp_pmd_count; i++)
{
pd[i].reg_num = outp.pfp_pmds[i].reg_num;
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 900 of file PerfMonAuditor.cpp.
| void PerfMonAuditor::stoppm | ( | ) | [private] |
Definition at line 504 of file PerfMonAuditor.cpp.
{
MsgStream log(msgSvc(), name());
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);
}
void* PerfMonAuditor::buf_addr [private] |
Definition at line 401 of file PerfMonAuditor.cpp.
pfm_dfl_smpl_arg_t PerfMonAuditor::buf_arg [private] |
Definition at line 399 of file PerfMonAuditor.cpp.
unsigned int PerfMonAuditor::cmask[MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS] [private] |
Definition at line 378 of file PerfMonAuditor.cpp.
bool PerfMonAuditor::core [private] |
Definition at line 385 of file PerfMonAuditor.cpp.
pfarg_ctx_t PerfMonAuditor::ctx [private] |
Definition at line 360 of file PerfMonAuditor.cpp.
bool PerfMonAuditor::event_count_reached [private] |
Definition at line 411 of file PerfMonAuditor.cpp.
char PerfMonAuditor::event_cstr[MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS][MAX_EVENT_NAME_LENGTH] [private] |
Definition at line 374 of file PerfMonAuditor.cpp.
std::string PerfMonAuditor::event_str[MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS] [private] |
Definition at line 371 of file PerfMonAuditor.cpp.
std::string PerfMonAuditor::family [private] |
Definition at line 373 of file PerfMonAuditor.cpp.
int PerfMonAuditor::fd [private] |
Definition at line 364 of file PerfMonAuditor.cpp.
bool PerfMonAuditor::first_alg [private] |
Definition at line 409 of file PerfMonAuditor.cpp.
std::string PerfMonAuditor::first_alg_name [private] |
Definition at line 410 of file PerfMonAuditor.cpp.
unsigned int PerfMonAuditor::i [private] |
Definition at line 365 of file PerfMonAuditor.cpp.
pfmlib_input_param_t PerfMonAuditor::inp [private] |
Definition at line 358 of file PerfMonAuditor.cpp.
bool PerfMonAuditor::inv[MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS] [private] |
Definition at line 377 of file PerfMonAuditor.cpp.
int PerfMonAuditor::is_nehalem_ret [private] |
Definition at line 356 of file PerfMonAuditor.cpp.
int PerfMonAuditor::level [private] |
Definition at line 407 of file PerfMonAuditor.cpp.
pfarg_load_t PerfMonAuditor::load_arg [private] |
Definition at line 363 of file PerfMonAuditor.cpp.
pfarg_load_t PerfMonAuditor::load_args [private] |
Definition at line 400 of file PerfMonAuditor.cpp.
int PerfMonAuditor::m_indent [private] |
Definition at line 352 of file PerfMonAuditor.cpp.
bool PerfMonAuditor::m_inEvent [private] |
Definition at line 353 of file PerfMonAuditor.cpp.
Map PerfMonAuditor::m_map [private] |
Definition at line 351 of file PerfMonAuditor.cpp.
PFMon& PerfMonAuditor::m_pfm [private] |
Definition at line 229 of file PerfMonAuditor.cpp.
unsigned int PerfMonAuditor::max_pmd [private] |
Definition at line 403 of file PerfMonAuditor.cpp.
bool PerfMonAuditor::nehalem [private] |
Definition at line 383 of file PerfMonAuditor.cpp.
Definition at line 381 of file PerfMonAuditor.cpp.
unsigned PerfMonAuditor::num_counters [private] |
Definition at line 402 of file PerfMonAuditor.cpp.
pfmlib_output_param_t PerfMonAuditor::outp [private] |
Definition at line 359 of file PerfMonAuditor.cpp.
Definition at line 380 of file PerfMonAuditor.cpp.
pfarg_pmc_t PerfMonAuditor::pc[NUM_PMCS] [private] |
Definition at line 362 of file PerfMonAuditor.cpp.
pfarg_pmd_t PerfMonAuditor::pd[NUM_PMDS] [private] |
Definition at line 361 of file PerfMonAuditor.cpp.
Definition at line 404 of file PerfMonAuditor.cpp.
unsigned int PerfMonAuditor::ph_ev_count [private] |
Definition at line 376 of file PerfMonAuditor.cpp.
std::string PerfMonAuditor::prefix [private] |
Definition at line 372 of file PerfMonAuditor.cpp.
char PerfMonAuditor::prefix_cstr[MAX_PREFIX_NAME_LENGTH] [private] |
Definition at line 375 of file PerfMonAuditor.cpp.
int PerfMonAuditor::ret [private] |
Definition at line 366 of file PerfMonAuditor.cpp.
bool PerfMonAuditor::sampling [private] |
Definition at line 387 of file PerfMonAuditor.cpp.
unsigned int PerfMonAuditor::start_at_event [private] |
Definition at line 379 of file PerfMonAuditor.cpp.
int PerfMonAuditor::used_counters_number [private] |
Definition at line 382 of file PerfMonAuditor.cpp.
bool PerfMonAuditor::westmere [private] |
Definition at line 384 of file PerfMonAuditor.cpp.