102 ProfileData::ProfileData(
const char* filename)
103 : m_name((filename) ? filename :
""), m_fs(
NULL)
114 for (const_iterator it = begin(); it != end(); ++it) {
115 const LM* proflm = it->second;
120 for (Metric::SampledDescVec::iterator it =
m_mdescs.begin();
132 if (
m_name.empty() && filename) {
143 iterator it = begin();
152 if (
m_name.empty() && filename) {
161 fseek(
m_fs, 0L, SEEK_SET);
172 DIAG_Assert(
m_fs,
"No open file stream!");
183 DIAG_Assert(count > 0,
"At least one LM must exist in a profile!");
185 for (
uint i = 0; i < count; ++i) {
186 LM* proflm =
new LM();
188 insert(make_pair(proflm->
name(), proflm));
201 DIAG_Assert(
m_fs,
"No open file stream!");
212 DIAG_Assert(count > 0,
"At least one LM must exist in a profile!");
214 LM* proflm =
new LM();
235 for (
uint i = 0; i < sz; ++i) {
246 int ret = stat(filename, &statbuf);
251 FILE* fs =
::fopen(filename,
"r");
279 if ((c = fgetc(fs)) == EOF) {
305 if (sz !=
sizeof(count)) {
319 o << p <<
"--- ProfileData Dump ---" << endl;
320 o << p <<
"{ ProfileData: " <<
m_name <<
" }" << endl;
322 for (const_iterator it = begin(); it != end(); ++it) {
323 const LM* proflm = it->second;
324 proflm->
dump(o, p1.c_str());
326 o << p <<
"--- End ProfileData Dump ---" << endl;
356 if (sz !=
sizeof(m_load_addr)) {
361 << hex << m_load_addr << dec);
368 if (sz !=
sizeof(count)) {
371 m_eventvec.resize(count);
376 for (
uint i = 0; i < count; ++i) {
378 edata.
read(fs, m_load_addr);
396 o << p <<
"{ LM: " <<
m_name <<
", loadAddr: 0x" << hex
397 << m_load_addr << dec <<
" }" << endl;
399 for (
uint i = 0; i < num_events(); ++i) {
401 profevent.
dump(o, p1.c_str());
424 std::string
name, desc;
438 if (sz !=
sizeof(period)) {
442 m_mdesc.nameBase(name);
443 m_mdesc.description(desc);
444 m_mdesc.period(period);
458 if (sz !=
sizeof(ndat)) {
459 PROFFLAT_Throw(
"Error reading <histogram_non_zero_bucket_count>.");
461 m_sparsevec.resize(ndat);
463 DIAG_Msg(6,
" EventData: " << name <<
": " << ndat <<
" entries (cnt,offset)");
469 for (
uint i = 0; i < ndat; ++i) {
471 if (sz !=
sizeof(count)) {
472 PROFFLAT_Throw(
"Error reading <histogram_non_zero_bucket_x_value>.");
476 if (sz !=
sizeof(offset)) {
477 PROFFLAT_Throw(
"Error reading <histogram_non_zero_bucket_x_offset>.");
479 DIAG_Msg(7,
" " << i <<
": (" << count <<
", " << offset <<
")");
481 VMA pc = load_addr + offset;
482 m_sparsevec[i] = make_pair(pc, count);
493 o << p <<
"{ EventData: " << mdesc().name()
494 <<
", period: " << mdesc().period()
495 <<
", outofrange: " << outofrange()
496 <<
", overflow: " << overflow()
499 for (
uint i = 0; i < num_data(); ++i) {
500 const Datum& dat = datum(i);
501 o << p1 <<
"{ 0x" << hex << dat.first <<
": " << dec
502 << dat.second <<
" }" << endl;
522 if (sz !=
sizeof(len)) {
527 for (
uint n = 0;
n < len; ++
n) {
528 if ((c = fgetc(fs)) == EOF) {
540 #ifdef PROFREADER_TEST 542 int main(
int argc,
char **argv)
544 std::string filename = argv[1];
547 int ret = f.read(filename);
550 cerr <<
"successfully read file!";
553 cerr <<
"error reading file!";
556 cout <<
"File dump:" << endl;
const std::string & profileName() const
const EventData & event(uint i) const
string toStr(const int x, int base)
const Metric::SampledDescVec & mdescs()
const std::string & profileRelId() const
static uint read_lm_count(FILE *fs)
#define HPCRUNFLAT_FMT_Endian
Metric::SampledDescVec m_mdescs
static RealPathMgr & singleton()
void openread(const char *filename=NULL)
size_t hpcio_le8_fread(uint64_t *val, FILE *fs)
#define HPCRUNFLAT_FMT_Magic
std::pair< VMA, bucketsz_t > Datum
void read(FILE *, const char *filename=NULL)
const std::string & name() const
bool realpath(std::string &pathNm) const
ProfileData(const char *filename=NULL)
const Metric::SampledDesc & mdesc() const
size_t MONITOR_EXT_WRAP_NAME() fread(void *ptr, size_t size, size_t count, FILE *stream)
int main(int argc, char *argv[])
void dump(std::ostream &o=std::cerr, const char *pre="") const
#define DIAG_Msg(level,...)
void read(FILE *, uint64_t load_addr)
const std::string & name() const
void dump(std::ostream &o=std::cerr, const char *pre="") const
static void read_header(FILE *fs)
size_t hpcio_le4_fread(uint32_t *val, FILE *fs)
#define HPCRUNFLAT_FMT_MagicLen
#define HPCRUNFLAT_Version
const std::string & profileType() const
void open(const char *filename=NULL)
static int read_string(FILE *fp, std::string &str)
static FILE * fopen(const char *filename)
bool implies(bool p, bool q)
<!-- ********************************************************************--> 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
void dump(std::ostream &o=std::cerr, const char *pre="") const
#define PROFFLAT_Throw(streamArgs)
#define HPCRUNFLAT_VersionLen