HPCToolkit
Raw.cpp
Go to the documentation of this file.
1 // -*-Mode: C++;-*-
2 
3 // * BeginRiceCopyright *****************************************************
4 //
5 // $HeadURL$
6 // $Id$
7 //
8 // --------------------------------------------------------------------------
9 // Part of HPCToolkit (hpctoolkit.org)
10 //
11 // Information about sources of support for research and development of
12 // HPCToolkit is at 'hpctoolkit.org' and in 'README.Acknowledgments'.
13 // --------------------------------------------------------------------------
14 //
15 // Copyright ((c)) 2002-2019, Rice University
16 // All rights reserved.
17 //
18 // Redistribution and use in source and binary forms, with or without
19 // modification, are permitted provided that the following conditions are
20 // met:
21 //
22 // * Redistributions of source code must retain the above copyright
23 // notice, this list of conditions and the following disclaimer.
24 //
25 // * Redistributions in binary form must reproduce the above copyright
26 // notice, this list of conditions and the following disclaimer in the
27 // documentation and/or other materials provided with the distribution.
28 //
29 // * Neither the name of Rice University (RICE) nor the names of its
30 // contributors may be used to endorse or promote products derived from
31 // this software without specific prior written permission.
32 //
33 // This software is provided by RICE and contributors "as is" and any
34 // express or implied warranties, including, but not limited to, the
35 // implied warranties of merchantability and fitness for a particular
36 // purpose are disclaimed. In no event shall RICE or contributors be
37 // liable for any direct, indirect, incidental, special, exemplary, or
38 // consequential damages (including, but not limited to, procurement of
39 // substitute goods or services; loss of use, data, or profits; or
40 // business interruption) however caused and on any theory of liability,
41 // whether in contract, strict liability, or tort (including negligence
42 // or otherwise) arising in any way out of the use of this software, even
43 // if advised of the possibility of such damage.
44 //
45 // ******************************************************* EndRiceCopyright *
46 
47 //***************************************************************************
48 //
49 // File:
50 // $HeadURL$
51 //
52 // Purpose:
53 // [The purpose of this file]
54 //
55 // Description:
56 // [The set of functions, macros, etc. defined in the file]
57 //
58 //***************************************************************************
59 
60 //************************* System Include Files ****************************
61 
62 #include <iostream>
63 #include <string>
64 using std::string;
65 
66 #define __STDC_FORMAT_MACROS
67 #include <inttypes.h>
68 
69 //*************************** User Include Files ****************************
70 
71 #include "Raw.hpp"
72 #include "Util.hpp"
73 
76 
77 #include <lib/prof-lean/hpcio.h>
78 #include <lib/prof-lean/hpcfmt.h>
80 
82 
83 //*************************** Forward Declarations ***************************
84 
85 //****************************************************************************
86 
87 void
88 Analysis::Raw::writeAsText(/*destination,*/ const char* filenm)
89 {
90  using namespace Analysis::Util;
91 
92  ProfType_t ty = getProfileType(filenm);
93  if (ty == ProfType_Callpath) {
94  writeAsText_callpath(filenm);
95  }
96  else if (ty == ProfType_CallpathMetricDB) {
98  }
99  else if (ty == ProfType_CallpathTrace) {
101  }
102  else if (ty == ProfType_Flat) {
103  writeAsText_flat(filenm);
104  }
105  else {
107  }
108 }
109 
110 
111 void
113 {
114  if (!filenm) { return; }
115 
117  try {
118  prof = Prof::CallPath::Profile::make(filenm, 0/*rFlags*/, stdout);
119  }
120  catch (...) {
121  DIAG_EMsg("While reading '" << filenm << "'...");
122  throw;
123  }
124  delete prof;
125 }
126 
127 
128 void
130 {
131  if (!filenm) { return; }
132 
133  try {
134  FILE* fs = hpcio_fopen_r(filenm);
135  if (!fs) {
136  DIAG_Throw("error opening metric-db file '" << filenm << "'");
137  }
138 
140  int ret = hpcmetricDB_fmt_hdr_fread(&hdr, fs);
141  if (ret != HPCFMT_OK) {
142  DIAG_Throw("error reading metric-db file '" << filenm << "'");
143  }
144 
145  hpcmetricDB_fmt_hdr_fprint(&hdr, stdout);
146 
147  for (uint nodeId = 1; nodeId < hdr.numNodes + 1; ++nodeId) {
148  fprintf(stdout, "(%6u: ", nodeId);
149  for (uint mId = 0; mId < hdr.numMetrics; ++mId) {
150  double mval = 0;
151  ret = hpcfmt_real8_fread(&mval, fs);
152  if (ret != HPCFMT_OK) {
153  DIAG_Throw("error reading trace file '" << filenm << "'");
154  }
155  fprintf(stdout, "%12g ", mval);
156  }
157  fprintf(stdout, ")\n");
158  }
159 
160  hpcio_fclose(fs);
161  }
162  catch (...) {
163  DIAG_EMsg("While reading '" << filenm << "'...");
164  throw;
165  }
166 }
167 
168 
169 void
171 {
172  if (!filenm) { return; }
173 
174  try {
175  FILE* fs = hpcio_fopen_r(filenm);
176  if (!fs) {
177  DIAG_Throw("error opening trace file '" << filenm << "'");
178  }
179 
180  hpctrace_fmt_hdr_t hdr;
181 
182  int ret = hpctrace_fmt_hdr_fread(&hdr, fs);
183  if (ret != HPCFMT_OK) {
184  DIAG_Throw("error reading trace file '" << filenm << "'");
185  }
186 
187  hpctrace_fmt_hdr_fprint(&hdr, stdout);
188 
189  // Read trace records and exit on EOF
190  while ( !feof(fs) ) {
191  hpctrace_fmt_datum_t datum;
192  ret = hpctrace_fmt_datum_fread(&datum, hdr.flags, fs);
193  if (ret == HPCFMT_EOF) {
194  break;
195  }
196  else if (ret == HPCFMT_ERR) {
197  DIAG_Throw("error reading trace file '" << filenm << "'");
198  }
199 
200  hpctrace_fmt_datum_fprint(&datum, hdr.flags, stdout);
201  }
202 
203  hpcio_fclose(fs);
204  }
205  catch (...) {
206  DIAG_EMsg("While reading '" << filenm << "'...");
207  throw;
208  }
209 }
210 
211 
212 void
214 {
215  if (!filenm) { return; }
216 
218  try {
219  prof.openread(filenm);
220  }
221  catch (...) {
222  DIAG_EMsg("While reading '" << filenm << "'...");
223  throw;
224  }
225 
226  prof.dump(std::cout);
227 }
228 
int hpcmetricDB_fmt_hdr_fread(hpcmetricDB_fmt_hdr_t *hdr, FILE *infs)
Definition: hpcrun-fmt.c:1000
#define DIAG_EMsg(...)
Definition: diagnostics.h:251
int hpctrace_fmt_hdr_fprint(hpctrace_fmt_hdr_t *hdr, FILE *fs)
Definition: hpcrun-fmt.c:882
const char * DIAG_Unimplemented
Analysis::Util::ProfType_t getProfileType(const std::string &filenm)
Definition: Util.cpp:141
static int hpcfmt_real8_fread(double *val, FILE *infs)
Definition: hpcfmt.h:194
void writeAsText_callpathTrace(const char *filenm)
Definition: Raw.cpp:170
void openread(const char *filename=NULL)
unsigned int uint
Definition: uint.h:124
void writeAsText_callpathMetricDB(const char *filenm)
Definition: Raw.cpp:129
int hpctrace_fmt_datum_fprint(hpctrace_fmt_datum_t *x, hpctrace_hdr_flags_t flags, FILE *fs)
Definition: hpcrun-fmt.c:979
void dump(std::ostream &o=std::cerr, const char *pre="") const
void writeAsText(const char *filenm)
Definition: Raw.cpp:88
static Profile * make(uint rFlags)
hpctrace_hdr_flags_t flags
Definition: hpcrun-fmt.h:668
#define NULL
Definition: ElfHelper.cpp:85
FILE * hpcio_fopen_r(const char *fnm)
Definition: hpcio.c:134
int hpctrace_fmt_hdr_fread(hpctrace_fmt_hdr_t *hdr, FILE *infs)
Definition: hpcrun-fmt.c:795
int hpcio_fclose(FILE *fs)
Definition: hpcio.c:152
void writeAsText_callpath(const char *filenm)
Definition: Raw.cpp:112
int hpctrace_fmt_datum_fread(hpctrace_fmt_datum_t *x, hpctrace_hdr_flags_t flags, FILE *fs)
Definition: hpcrun-fmt.c:901
#define DIAG_Die(...)
Definition: diagnostics.h:267
int hpcmetricDB_fmt_hdr_fprint(hpcmetricDB_fmt_hdr_t *hdr, FILE *outfs)
Definition: hpcrun-fmt.c:1057
void writeAsText_flat(const char *filenm)
Definition: Raw.cpp:213