111 #define DEBUG_COALESCING 0 132 return pathname && strstr(pathname,
"vdso");
143 int mergeTy,
uint rFlags,
uint mrgFlags)
146 if (profileFiles.empty()) {
152 uint groupId = (groupMap) ? (*groupMap)[0] : 0;
158 for (
uint i = 1; i < profileFiles.size(); ++i) {
159 groupId = (groupMap) ? (*groupMap)[i] : 0;
161 prof->
merge(*p, mergeTy, mrgFlags);
184 DIAG_MsgIf(0,
"Reading: '" << prof_fnm <<
"'");
188 DIAG_EMsg(
"While reading profile '" << prof_fnm <<
"'...");
198 for (
uint i = 0; i < metricMgr->
size(); ++i) {
270 typedef std::map<SrcFile::ln, Prof::Struct::Stmt*> LineToStmtMap;
277 LineToStmtMap stmtMap;
294 LineToStmtMap::iterator it_stmt = stmtMap.find(line);
295 if (it_stmt != stmtMap.end()) {
303 stmtMap.insert(std::make_pair(line, n_stmt));
348 string agent,
bool doNormalizeTy,
361 i <= loadmap->
size(); ++i) {
365 const string& lm_nm = lm->
name();
372 errors +=
" " + x.
what() +
"\n";
377 if (!errors.empty()) {
378 DIAG_WMsgIf(1,
"Cannot fully process samples because of errors reading load modules:\n" << errors);
400 const string& lm_nm = loadmap_lm->
name();
406 DIAG_MsgIf(printProgress,
"STRUCTURE: " << lm_nm);
410 DIAG_WMsgIf(printProgress,
"Cannot fully process samples for virtual load module " << lm_nm);
415 lm->
open(lm_nm.c_str());
421 DIAG_WMsgIf(printProgress,
"Cannot fully process samples for load module " <<
422 lm_nm <<
": " << x.
what());
424 if (lm)
DIAG_MsgIf(printProgress,
"Line map : " << lm_nm);
465 const string& lm_nm = loadmap_lm->
name();
468 DIAG_Assert(lmStrct,
"failed to find Struct::LM: " << lm_nm);
476 DIAG_EMsg(
"Analysis::CallPath::noteStaticStructureOnLeaves: failed to find structure for: " 498 if (!node) {
return; }
500 bool useStruct = (!lm);
507 (*Analysis::CallPath::dbgOs) <<
"overlayStaticStructure: node (";
510 (*Analysis::CallPath::dbgOs) << node_dyn->
lmId() <<
", " << hex << node_dyn->
lmIP() << dec;
512 (*Analysis::CallPath::dbgOs) <<
"): " << node->
toStringMe() << std::endl;
533 if (n_dyn && (n_dyn->
lmId() == loadmap_lm->
id())) {
534 using namespace Prof;
538 unkProcNm = &Struct::Tree::PartialUnwindProcNm;
544 unkProcNm = &Struct::Tree::UnknownGlobalVariable;
556 DIAG_MsgIf(0,
"overlayStaticStructure: dyn (" << n_dyn->
lmId() <<
", " << hex << lm_ip <<
") --> struct " << strct << dec <<
" " << strct->
toStringMe());
558 (*Analysis::CallPath::dbgOs) <<
"dyn (" << n_dyn->
lmId() <<
", " << hex << lm_ip << dec <<
") --> struct " << strct->
toStringMe() << std::endl;
563 Struct::ANode::TyAlien,
564 Struct::ANode::TyProc);
572 n->
link(scope_frame);
583 delete strctToCCTMap;
599 StructToCCTMap::iterator it = strctToCCTMap.find(strct);
600 if (it != strctToCCTMap.end()) {
601 frameScope = (*it).second;
605 makeFrame(node, procStrct, strctToCCTMap);
607 it = strctToCCTMap.find(strct);
608 DIAG_Assert(it != strctToCCTMap.end(),
"");
609 frameScope = (*it).second;
643 strctToCCTMap.insert(std::make_pair(procStrct, frame));
682 strctToCCTMap.insert(std::make_pair(n_strct, n_frame));
683 DIAG_DevMsgIf(0,
"makeFrameStructure: " << hex <<
" [" << n_strct <<
" -> " << n_frame <<
"]" << dec);
712 typedef std::map<SrcFile::ln, Prof::CCT::Stmt*> LineToStmtMap;
723 LineToStmtMap* stmtMap =
new LineToStmtMap;
739 LineToStmtMap::iterator it_stmt = stmtMap->find(line);
740 if (it_stmt != stmtMap->end()) {
766 DIAG_Assert(effct.
isNoop(),
"Analysis::CallPath::coalesceStmts: trace ids lost (" << effct.
toString() <<
") when merging y into x:\n" 777 stmtMap->insert(std::make_pair(line, n_stmt));
806 uint8_t* prunedNodes)
811 for (
uint mId = 0; mId < mMgrGbl.
size(); ++mId) {
815 && (m->
nameBase().find(
"Sum") != string::npos)) {
832 if (agent ==
"agent-cilk") {
886 using namespace Prof;
888 if (!node) {
return; }
899 bool isPrunableTy = (
typeid(*x) ==
typeid(
CCT::ProcFrm) ||
906 if (isPrunableTy || isSynthetic) {
908 DIAG_DevMsgIf(0,
"pruneTrivialNodes: " << hex << x << dec <<
" (sid: " << x->
structureId() <<
")");
925 using namespace Prof;
944 for ( ; it.Current(); ) {
961 using namespace Prof;
970 strct->
demandMetric(CallPath::Profile::StructMetricIdFlg) += 1.0;
990 if (!agent.empty()) {
992 if (agent ==
"agent-cilk") {
995 else if (agent ==
"agent-mpi") {
998 else if (agent ==
"agent-pthread") {
1002 DIAG_Die(
"Bad value for 'agent': " << agent);
1005 if (metricComponentsFact) {
1006 metricComponentsFact->
make(prof);
1007 delete metricComponentsFact;
1018 if (!agent.empty()) {
1020 if (agent ==
"agent-mpi") {
1024 if (metricComponentsFact) {
1025 metricComponentsFact->
make(prof);
1026 delete metricComponentsFact;
1053 std::vector<uint> retCntId;
1059 for (
uint i = 0; i < metricMgr->
size(); ++i) {
1062 retCntId.push_back(m->
id());
1068 if (retCntId.empty()) {
1081 for (
uint i = 0; i < retCntId.size(); ++i) {
1082 uint mId = retCntId[i];
1084 n->metric(mId) = 0.0;
1097 namespace CallPath {
1108 const string& db_dir = args.
db_dir;
1110 DIAG_Msg(1,
"Populating Experiment database: " << db_dir);
1126 std::streambuf* os_buf = os->rdbuf();
1141 static const char* experimentDTD =
1144 using namespace Prof;
1148 oFlags |= CCT::Tree::OFlg_Compressed;
1151 oFlags |= CCT::Tree::OFlg_Debug;
1155 oFlags |= CCT::Tree::OFlg_StructId;
1158 uint metricBegId = 0;
1164 metricBegId = (mBeg) ? mBeg->
id() : Metric::Mgr::npos;
1165 metricEndId = (mEnd) ? mEnd->
id() + 1 : Metric::Mgr::npos;
1170 os <<
"<?xml version=\"1.0\"?>\n";
1171 os <<
"<!DOCTYPE HPCToolkitExperiment [\n" << experimentDTD <<
"]>\n";
1173 os <<
"<HPCToolkitExperiment version=\"2.1\">\n";
1176 os <<
"</Header>\n";
1178 os <<
"<SecCallPathProfile i=\"0\" n" <<
MakeAttrStr(name) <<
">\n";
1183 os <<
"<SecHeader>\n";
1184 prof.
writeXML_hdr(os, metricBegId, metricEndId, oFlags);
1186 os <<
"</SecHeader>\n";
1192 os <<
"<SecCallPathProfileData>\n";
1194 os <<
"</SecCallPathProfileData>\n";
1196 os <<
"</SecCallPathProfile>\n";
1197 os <<
"</HPCToolkitExperiment>\n";
Struct::ACodeNode * structure() const
static void makeFrameStructure(Prof::CCT::ANode *node_frame, Prof::Struct::ACodeNode *node_strct, StructToCCTMap &strctToCCTMap)
LM * findLM(const char *nm) const
static const std::string cilkmain
void CloseStream(std::istream *s)
ssize_t MONITOR_EXT_WRAP_NAME() write(int fd, const void *buf, size_t count)
void readStructure(Prof::Struct::Tree *structure, const Analysis::Args &args)
virtual MergeEffect mergeMe(const ANode &y, MergeContext *mrgCtxt=NULL, uint metricBegIdx=0, bool mayConflict=true)
PathTupleVec searchPathTpls
static void makeReturnCountMetric(Prof::CallPath::Profile &prof)
void pruneByMetrics(const Metric::Mgr &mMgr, const VMAIntervalSet &ivalset, const ANode *root, double thresholdPct, uint8_t *prunedNodes=NULL)
void applySummaryMetricAgents(Prof::CallPath::Profile &prof, string agent)
virtual std::string toStringMe(uint oFlags=0) const
void normalize(Prof::CallPath::Profile &prof, string agent, bool doNormalizeTy)
void mergePerfEventStatistics(Mgr *source)
string toStr(const int x, int base)
static int cmpById(const void *x, const void *y)
virtual const std::string & what() const
static bool hasMergeEffects(const ADynNode &x, const ADynNode &y)
ANode * ancestor(ANodeTy type) const
std::vector< std::string > structureFiles
static void coalesceStmts(Prof::Struct::Tree &structure)
void computeVMAMaps() const
virtual void make(Prof::CallPath::Profile &prof)
void overlayStaticStructureMain(Prof::CallPath::Profile &prof, string agent, bool doNormalizeTy, bool printProgress)
static void overlayStaticStructure(Prof::CCT::ANode *node, Prof::LoadMap::LM *loadmap_lm, Prof::Struct::LM *lmStrct, BinUtil::LM *lm)
void pruneStructTree(Prof::CallPath::Profile &prof)
virtual void read(const std::set< std::string > &directorySet, ReadFlg readflg)
int Diagnostics_GetDiagnosticFilterLevel()
const StringSet & traceFileNameSet() const
std::vector< uint > UIntVec
static RealPathMgr & singleton()
void mergePerfEventStatistics_finalize(int num_profiles)
void makeDatabase(Prof::CallPath::Profile &prof, const Analysis::Args &args)
std::ostream & writeXML_hdr(std::ostream &os, uint metricBeg, uint metricEnd, uint oFlags, const char *pfx="") const
static const std::string UnknownProcNm
std::ostream * OpenOStream(const char *filenm)
std::string MakeAttrStr(const char *x, int flags=ESC_TRUE)
std::string out_db_experiment
#define DIAG_MsgIf(ifexpr,...)
const std::string & name() const
void copySourceFiles(Prof::Struct::Root *structure, const Analysis::PathTupleVec &pathVec, const string &dstDir)
static Prof::CCT::ANode * demandScopeInFrame(Prof::CCT::ADynNode *node, Prof::Struct::ANode *strct, StructToCCTMap &strctToCCTMap)
static Prof::CCT::ProcFrm * makeFrame(Prof::CCT::ADynNode *node, Prof::Struct::Proc *procStrct, StructToCCTMap &strctToCCTMap)
const char * pretty_name() const
const std::string & nameBase() const
const std::string & name() const
void copyTraceFiles(const std::string &dstDir, const std::set< string > &srcFiles)
SrcFile::ln begLine() const
ComputedTy computedType() const
Prof::Struct::ACodeNode * demandStructure(VMA vma, Prof::Struct::LM *lmStrct, BinUtil::LM *lm, bool useStruct, const string *unknownProcNm)
#define HPCRUN_METRIC_RetCnt
static const LMId_t LMId_NULL
#define NODE_TYPE_GLOBAL_VARIABLE
Metric::ADesc * findFirstVisible() const
virtual const std::string & procName() const
static int cmpByDynInfo(const void *x, const void *y)
uint merge(Profile &y, int mergeTy, uint mrgFlag=0)
const LoadMap * loadmap() const
void aggregateMetrics(uint mBegId, uint mEndId)
std::pair< iterator, bool > insert(const VMA beg, const VMA end)
std::string toString(const char *pfx="") const
LoadMap::LMId_t lmId() const
bool isSecondarySynthRoot() const
static const int StructMetricIdFlg
static void pruneTrivialNodes(Prof::CallPath::Profile &prof)
static void mergeCilkMain(Prof::CallPath::Profile &prof)
const Metric::Mgr * metricMgr() const
std::string toStringMe(uint oFlags=0, const char *pre="") const
#define DIAG_Msg(level,...)
Prof::Struct::Tree * structure() const
StringSet & directorySet()
static Profile * make(uint rFlags)
static LM * demand(Root *pgm, const std::string &lm_fnm)
static bool vdso_loadmodule(const char *pathname)
double demandMetric(size_t mId, size_t size=0) const
static void noteStaticStructure(Prof::CallPath::Profile &prof)
void pruneBySummaryMetrics(Prof::CallPath::Profile &prof, uint8_t *prunedNodes)
void hpcrun_node_type(uint16_t type)
ssize_t MONITOR_EXT_WRAP_NAME() read(int fd, void *buf, size_t count)
virtual std::string toStringMe(uint oFlags=0) const
void noteStaticStructureOnLeaves(Prof::CallPath::Profile &prof)
const std::string & namePfx() const
void addDirectory(std::string filename)
#define NODE_TYPE_REGULAR
ACodeNode * findByVMA(VMA vma) const
Metric::ADesc * metric(uint i)
void overlayStaticStructure(Prof::CallPath::Profile &prof, Prof::LoadMap::LM *loadmap_lm, Prof::Struct::LM *lmStrct, BinUtil::LM *lm)
std::ostream & writeXML(std::ostream &os, const Metric::Mgr *metricMgr, uint metricBeg=Metric::IData::npos, uint metricEnd=Metric::IData::npos, uint oFlags=0) const
SrcFile::ln begLine() const
<!-- ********************************************************************--> n<!-- HPCToolkit Experiment DTD --> n<!-- Version 2.1 --> n<!-- ********************************************************************--> n<!ELEMENT HPCToolkitExperiment(Header,(SecCallPathProfile|SecFlatProfile) *)> n<!ATTLIST HPCToolkitExperiment\n version CDATA #REQUIRED > n n<!-- ******************************************************************--> n n<!-- Info/NV:flexible name-value pairs:(n) ame;(t) ype;(v) alue --> n<!ELEMENT Info(NV *)> n<!ATTLIST Info\n n CDATA #IMPLIED > n<!ELEMENT NV EMPTY > n<!ATTLIST NV\n n CDATA #REQUIRED\n t CDATA #IMPLIED\n v CDATA #REQUIRED > n n<!-- ******************************************************************--> n<!-- Header --> n<!-- ******************************************************************--> n<!ELEMENT Header(Info *)> n<!ATTLIST Header\n n CDATA #REQUIRED > n n<!-- ******************************************************************--> n<!-- Section Header --> n<!-- ******************************************************************--> n<!ELEMENT SecHeader(MetricTable?, MetricDBTable?, TraceDBTable?, LoadModuleTable?, FileTable?, ProcedureTable?, Info *)> n n<!-- MetricTable:--> n<!ELEMENT MetricTable(Metric) * > n n<!-- Metric:(i) d;(n) ame --> n<!--(v) alue-type:transient type of values --> n<!--(t) ype:persistent type of metric --> n<!-- fmt:format;show;--> n<!ELEMENT Metric(MetricFormula *, Info?)> n<!ATTLIST Metric\n i CDATA #REQUIRED\n n CDATA #REQUIRED\n es CDATA #IMPLIED\n em CDATA #IMPLIED\n ep CDATA #IMPLIED\n v(raw|final|derived-incr|derived) \"raw\\ t (inclusive|exclusive|nil) \nil\\ partner CDATA #IMPLIED\ fmt CDATA #IMPLIED\ show (1|0) \1\\ show-percent (1|0) \1> n n<!-- MetricFormula represents derived metrics: (t)ype; (frm): formula --> n<!ELEMENT MetricFormula (Info?)> n<!ATTLIST MetricFormula\ t (combine|finalize) \finalize\\ i CDATA #IMPLIED\ frm CDATA #REQUIRED> n n<!-- Metric data, used in sections: (n)ame [from Metric]; (v)alue --> n<!ELEMENT M EMPTY> n<!ATTLIST M\ n CDATA #REQUIRED\ v CDATA #REQUIRED> n n<!-- MetricDBTable: --> n<!ELEMENT MetricDBTable (MetricDB)*> n n<!-- MetricDB: (i)d; (n)ame --> n<!-- (t)ype: persistent type of metric --> n<!-- db-glob: file glob describing files in metric db --> n<!-- db-id: id within metric db --> n<!-- db-num-metrics: number of metrics in db --> n<!-- db-header-sz: size (in bytes) of a db file header --> n<!ELEMENT MetricDB EMPTY> n<!ATTLIST MetricDB\ i CDATA #REQUIRED\ n CDATA #REQUIRED\ t (inclusive|exclusive|nil) \nil\\ partner CDATA #IMPLIED\ db-glob CDATA #IMPLIED\ db-id CDATA #IMPLIED\ db-num-metrics CDATA #IMPLIED\ db-header-sz CDATA #IMPLIED> n n<!-- TraceDBTable: --> n<!ELEMENT TraceDBTable (TraceDB)> n n<!-- TraceDB: (i)d --> n<!-- db-min-time: min beginning time stamp (global) --> n<!-- db-max-time: max ending time stamp (global) --> n<!ELEMENT TraceDB EMPTY> n<!ATTLIST TraceDB\ i CDATA #REQUIRED\ db-glob CDATA #IMPLIED\ db-min-time CDATA #IMPLIED\ db-max-time CDATA #IMPLIED\ db-header-sz CDATA #IMPLIED> n n<!-- LoadModuleTable assigns a short name to a load module --> n<!ELEMENT LoadModuleTable (LoadModule)*> n n<!ELEMENT LoadModule (Info?)> n<!ATTLIST LoadModule\ i CDATA #REQUIRED\ n CDATA #REQUIRED> n n<!-- FileTable assigns a short name to a file --> n<!ELEMENT FileTable (File)*> n n<!ELEMENT File (Info?)> n<!ATTLIST File\ i CDATA #REQUIRED\ n CDATA #REQUIRED> n n<!-- ProcedureTable assigns a short name to a procedure --> n<!ELEMENT ProcedureTable (Procedure)*> n n<!-- Info/NV: flexible name-value pairs: (n)ame; (t)ype; (v)alue --> n<!-- f: family of the procedure (fake, root, ...)--> n<!ELEMENT Procedure (Info?)> n<!ATTLIST Procedure\ i CDATA #REQUIRED\ n CDATA #REQUIRED\ f CDATA #IMPLIED> n n<!-- ****************************************************************** --> n<!-- Section: Call path profile --> n<!-- ****************************************************************** --> n<!ELEMENT SecCallPathProfile (SecHeader, SecCallPathProfileData)> n<!ATTLIST SecCallPathProfile\ i CDATA #REQUIRED\ n CDATA #REQUIRED> n n<!ELEMENT SecCallPathProfileData (PF|M)*> n<!-- Procedure frame --> n<!-- (i)d: unique identifier for cross referencing --> n<!-- (s)tatic scope id --> n<!-- (n)ame: a string or an id in ProcedureTable --> n<!-- (lm) load module: a string or an id in LoadModuleTable --> n<!-- (f)ile name: a string or an id in LoadModuleTable --> n<!-- (l)ine range: \beg-end\ (inclusive range) --> n<!-- (a)lien: whether frame is alien to enclosing P --> n<!-- (str)uct: hpcstruct node id --> n<!-- (t)ype: hpcrun node type: memory access, variable declaration, ... --> n<!-- (v)ma-range-set: \{[beg-end), [beg-end)...}\ --> n<!ELEMENT PF (PF|Pr|L|C|S|M)*> n<!ATTLIST PF\ i CDATA #IMPLIED\ s CDATA #IMPLIED\ n CDATA #REQUIRED\ lm CDATA #IMPLIED\ f CDATA #IMPLIED\ l CDATA #IMPLIED\ str CDATA #IMPLIED\ v CDATA #IMPLIED> n<!-- Procedure (static): GOAL: replace with 'P' --> n<!ELEMENT Pr (Pr|L|C|S|M)*> n<!ATTLIST Pr\ i CDATA #IMPLIED\ s CDATA #IMPLIED\ n CDATA #REQUIRED\ lm CDATA #IMPLIED\ f CDATA #IMPLIED\ l CDATA #IMPLIED\ a (1|0) \0\\ str CDATA #IMPLIED\ v CDATA #IMPLIED> n<!-- Callsite (a special StatementRange) --> n<!ELEMENT C (PF|M)*> n<!ATTLIST C\ i CDATA #IMPLIED\ s CDATA #IMPLIED\ l CDATA #IMPLIED\ str CDATA #IMPLIED\ v CDATA #IMPLIED> n n<!-- ****************************************************************** --> n<!-- Section: Flat profile --> n<!-- ****************************************************************** --> n<!ELEMENT SecFlatProfile (SecHeader, SecFlatProfileData)> n<!ATTLIST SecFlatProfile\ i CDATA #REQUIRED\ n CDATA #REQUIRED> n n<!ELEMENT SecFlatProfileData (LM|M)*> n<!-- Load module: (i)d; (n)ame; (v)ma-range-set --> n<!ELEMENT LM (F|P|M)*> n<!ATTLIST LM\ i CDATA #IMPLIED\ n CDATA #REQUIRED\ v CDATA #IMPLIED> n<!-- File --> n<!ELEMENT F (P|L|S|M)*> n<!ATTLIST F\ i CDATA #IMPLIED\ n CDATA #REQUIRED> n<!-- Procedure (Note 1) --> n<!ELEMENT P (P|A|L|S|C|M)*> n<!ATTLIST P\ i CDATA #IMPLIED\ n CDATA #REQUIRED\ l CDATA #IMPLIED\ str CDATA #IMPLIED\ v CDATA #IMPLIED> n<!-- Alien (Note 1) --> n<!ELEMENT A (A|L|S|C|M)*> n<!ATTLIST A\ i CDATA #IMPLIED\ f CDATA #IMPLIED\ n CDATA #IMPLIED\ l CDATA #IMPLIED\ str CDATA #IMPLIED\ v CDATA #IMPLIED> n<!-- Loop (Note 1,2) --> n<!ELEMENT L (A|Pr|L|S|C|M)*> n<!ATTLIST L\ i CDATA #IMPLIED\ s CDATA #IMPLIED\ l CDATA #IMPLIED\ f CDATA #IMPLIED\ str CDATA #IMPLIED\ v CDATA #IMPLIED> n<!-- Statement (Note 2) --> n<!-- (it): trace record identifier --> n<!ELEMENT S (S|M)*> n<!ATTLIST S\ i CDATA #IMPLIED\ it CDATA #IMPLIED\ s CDATA #IMPLIED\ l CDATA #IMPLIED\ str CDATA #IMPLIED\ v CDATA #IMPLIED> n<!-- Note 1: Contained Cs may not contain PFs --> n<!-- Note 2: The 's' attribute is not used for flat profiles --> n
const std::string & name() const
const ANodeFilter ANodeTyFilter[ANode::TyNUMBER]
Proc * ancestorProc() const
Metric::ADesc * findLastVisible() const
static void write(Prof::CallPath::Profile &prof, std::ostream &os, const Analysis::Args &args)
std::map< Prof::Struct::ANode *, Prof::CCT::ANode * > StructToCCTMap
virtual NonUniformDegreeTreeNode * Current() const
std::vector< std::string > StringVec
MergeEffect merge(ANode *y)
static bool merge(ANode *node_dst, ANode *node_src)
void readStructure(Struct::Tree &structure, const std::vector< string > &structureFiles, PGMDocHandler::Doc_t docty, DocHandlerArgs &docargs)
void applyThreadMetricAgents(Prof::CallPath::Profile &prof, string agent)
virtual void open(const char *filenm)
virtual NonUniformDegreeTreeNode * Current() const