98 uint Driver::profileBatchSz = 16;
103 :
Unique(), m_args(args), m_mMgr(mMgr), m_structure(structure)
123 DIAG_Msg(2,
"Initializing structure...");
135 DIAG_Msg(2,
"Creating and correlating metrics with program structure: ...");
147 bool db_use = !db_dir.empty() && db_dir !=
"-";
154 DIAG_Msg(1,
"Copying source files reached by PATH/REPLACE options to " << db_dir);
160 const string out_path = (db_use) ? (db_dir +
"/") :
"";
164 DIAG_Msg(1,
"Writing final scope tree (in XML) to " << fnm);
165 string fpath = out_path + fnm;
166 const char* osnm = (fnm ==
"-") ?
NULL : fpath.c_str();
174 DIAG_Msg(1,
"Writing final scope tree (in CSV) to " << fnm);
175 string fpath = out_path + fnm;
176 const char* osnm = (fnm ==
"-") ?
NULL : fpath.c_str();
184 string fpath = out_path + fnm;
185 const char* osnm = (fnm ==
"-") ?
NULL : fpath.c_str();
194 string fpath = out_path + fnm;
195 DIAG_Msg(1,
"Writing configuration file to " << fpath);
197 const char* osnm = (fnm ==
"-") ?
NULL : fpath.c_str();
217 if (strlen(oldpath) > length &&
221 DIAG_Msg(3,
"replacePath: Found a match! New path: " << s);
226 DIAG_Msg(3,
"replacePath: Nothing matched! Init path: " << oldpath);
227 return string(oldpath);
234 static const char* experimentDTD =
237 os <<
"<?xml version=\"1.0\"?>" << std::endl;
238 os <<
"<!DOCTYPE HPCToolkitExperiment [\n" << experimentDTD <<
"]>" 240 os <<
"<HPCToolkitExperiment version=\"2.0\">\n";
250 os <<
"<SecHeader>\n";
252 os <<
" <MetricTable>\n";
260 <<
" show=\"" << ((m->
isVisible()) ?
"1" :
"0") <<
"\">\n";
262 <<
"<NV n=\"units\" v=\"events\"/>" 263 <<
"<NV n=\"percent\" v=\"" << ((m->
doDispPercent()) ?
"1" :
"0") <<
"\"/>" 265 os <<
" </Metric>\n";
267 os <<
" </MetricTable>\n";
269 os <<
" <Info n=\"SearchPaths\">\n";
271 for (
uint i = 0; i < searchPaths.size(); i++) {
272 const string& path = searchPaths[i].first;
277 os <<
"</SecHeader>\n";
285 os <<
"<SecFlatProfileData>\n";
287 os <<
"</SecFlatProfileData>\n";
289 os <<
"</SecFlatProfile>\n";
290 os <<
"</HPCToolkitExperiment>\n";
298 os <<
"File name,Routine name,Start line,End line,Loop level";
301 os <<
"," << m->
name();
303 os <<
"," << m->
name() <<
" (%)";
318 using namespace Prof;
323 DIAG_Assert(m_sortby,
"INVARIANT: at least on sort-by metric must exist");
327 ColumnFormatter colFmt(
m_mMgr, os, 2, 0);
329 os << std::setfill(
'=') << std::setw(77) <<
"=" << std::endl;
330 colFmt.genColHeaderSummary();
334 string nm =
"Program summary (row 1: sample count for raw metrics): " 340 string nm =
"Load module summary:";
346 string nm =
"File summary:";
352 string nm =
"Procedure summary:";
358 string nm =
"Loop summary (dependent on structure information):";
364 string nm =
"Statement summary:";
371 bool hasFnmGlobs = !fnmGlobs.empty();
377 const string& fnm = fileStrct->
name();
378 if (fnm != Struct::Tree::UnknownFileNm
390 const std::string& title,
394 using namespace Prof;
408 double smpl = rootStrct->
metric(i) / (double)mm->
period();
430 os <<
" " << strct->
nameQual() << std::endl;
442 const string& fnm = fileStrct->
name();
443 const string& fnm_qual = fileStrct->
nameQual();
445 string title =
"Annotated file (statement/line level): " + fnm_qual;
448 std::istream* is =
NULL;
453 os <<
" Cannot open.\n" << std::endl;
462 const uint linew = 5;
476 while (ln_file < ln_metric && is->good()) {
477 std::getline(*is, linetxt);
478 os << std::setw(linew) << std::setfill(
' ') << ln_file;
480 os <<
" " << linetxt << std::endl;
488 os << std::setw(linew) << std::setfill(
' ') << ln_metric;
495 std::getline(*is, linetxt);
496 os <<
" " << linetxt;
503 for ( ; is->good(); ln_file++) {
504 std::getline(*is, linetxt);
505 os << std::setw(linew) << std::setfill(
' ') << ln_file;
507 os <<
" " << linetxt << std::endl;
521 os << std::setfill(
'=') << std::setw(77) <<
"=" << std::endl
523 << std::setfill(
'-') << std::setw(77) <<
"-" << std::endl;
530 os <<
"<HPCPROF>\n\n";
533 os <<
"<TITLE name=\"" <<
m_args.
title <<
"\"/>\n\n";
538 os <<
"<PATH name=\"" << x.first <<
"\" viewname=\"" << x.second <<
"\"/>\n";
556 using namespace Prof;
560 const char* sortbystr = ((i == 0) ?
" sortBy=\"true\"" :
"");
561 os <<
"<METRIC name=\"" << m->
name()
562 <<
"\" displayName=\"" << m->
name() <<
"\"" 563 << sortbystr <<
">\n";
567 os <<
"</METRIC>\n\n";
572 os <<
"</HPCPROF>\n";
579 string s = string(
"Driver: " )
590 std::cerr <<
toString() << std::endl;
662 Prof::Metric::Mgr::StringToADescVecMap::const_iterator it =
663 fnameToFMetricMap.begin();
673 string prev_lmname_orig;
679 for (Prof::Flat::ProfileData::const_iterator it1 = prof->begin();
680 it1 != prof->end(); ++it1) {
682 const string lmname_orig = it1->first;
683 if (lmname_orig == prev_lmname_orig) {
688 prev_lmname_orig = lmname_orig;
692 bool useStruct =
hasStructure(lmname, structure, hasStructureTbl);
708 for (
uint i = 0; i < mMgr.
size(); i++) {
721 it1 != ivalset.end(); ++it1) {
741 std::set<std::string> dir;
748 for (
uint i = 0; i < profToMetricsVec.size(); ++i) {
755 std::pair<ProfileData::iterator, ProfileData::iterator> fnd =
756 prof->equal_range(lmname_orig);
757 if (fnd.first == prof->end()) {
758 DIAG_WMsg(1,
"Cannot find LM " << lmname_orig <<
" within " 759 << prof->
name() <<
".");
766 for (ProfileData::iterator it = fnd.first; it != fnd.second; ++it) {
772 using namespace Prof;
773 for (Metric::ADescVec::iterator it1 = metrics->begin();
774 it1 != metrics->end(); ++it1) {
776 DIAG_Assert(m->
isUnitsEvents(),
"Assume metric's units is events!");
785 structure, lmStrct, lm, useStruct);
814 uint32_t samples = dat.second;
815 double events = samples * (double)period;
818 VMA vma_ur = (doUnrelocate) ? (vma - lm_load_addr) : vma;
826 << metric->
name() <<
":0x" << hex << vma_ur << dec
827 <<
" --> +" << events <<
"=" 837 Prof::Metric::Mgr::StringToADescVecMap::const_iterator& it,
838 const Prof::Metric::Mgr::StringToADescVecMap::const_iterator& it_end)
842 const string& fnm = it->first;
846 batchJob.push_back(make_pair(prof, &metrics));
854 bool haswork = !batchJob.empty();
862 for (
uint i = 0; i < batchJob.size(); ++i) {
875 StringToBoolMap::iterator it = hasStructureTbl.find(lmname);
876 if (it != hasStructureTbl.end()) {
882 bool hasStruct = (!lmStrct->
isLeaf());
883 hasStructureTbl.insert(make_pair(lmname, hasStruct));
885 DIAG_WMsg(2,
"No STRUCTURE for " << lmname <<
".");
898 using namespace Prof;
908 for (
uint i = 0; i < mMgr.
size(); i++) {
913 mExprVec[i] = mm->
expr();
921 it != ivalset.end(); ++it) {
943 for (
uint mId = mBegId; mId < mEndId; ++mId) {
946 double val = expr->
eval(*it.current());
948 it.current()->demandMetric(mId, numMetrics) = val;
986 lm->
open(fnm.c_str());
992 DIAG_EMsg(
"Exception encountered while opening " << fnm.c_str());
const std::string & profileName() const
void write_txt(std::ostream &os) const
std::vector< std::string > groupFiles
Metric::AExpr * expr() const
void write_txt_hdr(std::ostream &os, const std::string &hdr) const
void CloseStream(std::istream *s)
PathTupleVec searchPathTpls
std::string replacePath(const char *path)
static struct perf_mem_metric metric
void genCol(uint mid, double metricVal, double metricTot, Flag flg=Flag_NULL)
const EventData & event(uint i) const
std::vector< ProfToMetricsTuple > ProfToMetricsTupleVec
Prof::Flat::ProfileData * readProf(const string &fnm)
uint64_t load_addr() const
std::istream * OpenIStream(const char *filenm)
uint64_t toUInt64(const char *str, unsigned *endidx)
void write_txt_secSummary(std::ostream &os, Analysis::TextUtil::ColumnFormatter &colFmt, const std::string &title, const Prof::Struct::ANodeFilter *filter) const
Prof::Metric::Mgr & m_mMgr
static const char * ADescTyToXMLString(ADescTy type)
void computeRawMetrics(Prof::Metric::Mgr &mMgr, Prof::Struct::Tree &structure)
bool doUnrelocate(VMA loadAddr) const
std::vector< std::string > structureFiles
const std::string & profileRelId() const
void write_experiment(std::ostream &os) const
void computeRawBatchJob_LM(const string &lmname, const string &lmname_orig, Prof::Struct::Tree &structure, ProfToMetricsTupleVec &profToMetricsVec, bool useStruct)
std::vector< ADesc * > ADescVec
Metric::ADesc * findSortKey() const
void write_csv(std::ostream &os) const
bool isValid(SrcFile::ln line)
virtual const std::string & name() const
bool fnmatch(const std::vector< std::string > &patternVec, const char *string, int flags)
virtual void read(const std::set< std::string > &directorySet, ReadFlg readflg)
BinUtil::LM * openLM(const string &fnm)
bool profflat_computeFinalMetricValues
double metric(size_t mId) const
void correlateMetricsWithStructure(Prof::Metric::Mgr &mMgr, Prof::Struct::Tree &structure)
bool hasStructure(const string &lmname, Prof::Struct::Tree &structure, StringToBoolMap &hasStructureTbl)
bool getNextRawBatch(ProfToMetricsTupleVec &batchJob, Prof::Metric::Mgr::StringToADescVecMap::const_iterator &it, const Prof::Metric::Mgr::StringToADescVecMap::const_iterator &it_end)
void openread(const char *filename=NULL)
virtual std::ostream & writeXML(std::ostream &os=std::cout, uint oFlags=0, const char *pre="") const
bool doDispPercent() const
virtual const std::string & name() const
const ANodeFilter ANodeTyFilter[ANode::TyNUMBER]
const Analysis::Args & m_args
std::pair< VMA, bucketsz_t > Datum
virtual std::string toXML(uint oFlags=0) const
std::ostream * OpenOStream(const char *filenm)
std::string MakeAttrStr(const char *x, int flags=ESC_TRUE)
std::string out_db_experiment
void copySourceFiles(Prof::Struct::Root *structure, const Analysis::PathTupleVec &pathVec, const string &dstDir)
virtual std::string nameQual() const
const std::string & name() const
const StringToADescVecMap & fnameToFMetricMap() const
std::string toString(const char *pfx="") const
void computeDerivedBatch(Prof::Struct::Tree &structure, const Prof::Metric::AExpr **mExprVec, uint mBegId, uint mEndId)
Prof::Struct::Tree & m_structure
bool isUnitsEvents() const
virtual std::string toValueTyStringXML() const
const Metric::SampledDesc & mdesc() const
SrcFile::ln begLine() const
std::pair< Prof::Flat::ProfileData *, Prof::Metric::ADescVec * > ProfToMetricsTuple
ComputedTy computedType() const
Prof::Struct::ACodeNode * demandStructure(VMA vma, Prof::Struct::LM *lmStrct, BinUtil::LM *lm, bool useStruct, const string *unknownProcNm)
std::map< std::string, Metric::ADescVec > StringToADescVecMap
void write_txt_annotateFile(std::ostream &os, Analysis::TextUtil::ColumnFormatter &colFmt, const Prof::Struct::File *fileStrct) const
std::vector< std::string > replaceInPath
std::map< string, bool > StringToBoolMap
virtual double eval(const Metric::IData &mdata) const =0
virtual std::string nameQual() const
std::string out_db_config
std::vector< PathTuple > PathTupleVec
static int cmpByLine(const void *x, const void *y)
std::pair< string, bool > mkdirUnique(const char *dirnm)
void aggregateMetrics(uint mBegId, uint mEndId)
std::pair< iterator, bool > insert(const VMA beg, const VMA end)
#define DIAG_DevMsg(level,...)
void populateStructure(Prof::Struct::Tree &structure)
#define DIAG_Msg(level,...)
static LM * demand(Root *pgm, const std::string &lm_fnm)
double demandMetric(size_t mId, size_t size=0) const
static uint profileBatchSz
void correlateRaw(Prof::Metric::ADesc *metric, const Prof::Flat::EventData &profevent, VMA lm_load_addr, Prof::Struct::Tree &structure, Prof::Struct::LM *lmStrct, BinUtil::LM *lm, bool useStruct)
const Datum & datum(uint i) const
int metrics[MAX_EVENTS][MAX_METRICS]
std::string MakeAttrNum(int x)
virtual std::string message() const
void write_config(std::ostream &os=std::cout) const
std::vector< std::string > replaceOutPath
Metric::ADesc * metric(uint i)
void computeDerivedMetrics(Prof::Metric::Mgr &mMgr, Prof::Struct::Tree &structure)
virtual NonUniformDegreeTreeNode * Current() const
void genBlankCol(uint mid)
const std::string & profileType() const
void clearRawBatch(ProfToMetricsTupleVec &batchJob)
std::string toString() const
const ANodeFilter ANodeTyFilter[ANode::TyNUMBER]
std::pair< std::string, std::string > PathTuple
std::vector< std::string > txt_srcFileGlobs
void CSV_TreeDump(std::ostream &os=std::cout) const
void readStructure(Struct::Tree &structure, const std::vector< string > &structureFiles, PGMDocHandler::Doc_t docty, DocHandlerArgs &docargs)
virtual void open(const char *filenm)