HPCToolkit
Flat-ProfileData.hpp
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 // Class for reading and representing papirun profile data.
54 //
55 // Description:
56 // [The set of functions, macros, etc. defined in the file]
57 //
58 // Author:
59 // Written by John Mellor-Crummey and Nathan Tallent, Rice University.
60 //
61 //***************************************************************************
62 
63 #ifndef prof_Prof_Flat_ProfileData_hpp
64 #define prof_Prof_Flat_ProfileData_hpp
65 
66 //************************* System Include Files ****************************
67 
68 #include <vector>
69 #include <map>
70 #include <string>
71 #include <utility>
72 
73 #include <cstdlib>
74 #include <cstdio>
75 
76 #include <sys/time.h>
77 
78 //*************************** User Include Files ****************************
79 
80 #include <include/gcc-attr.h>
81 #include <include/uint.h>
82 
83 #include "Metric-ADesc.hpp"
84 
85 #include <lib/isa/ISATypes.hpp>
86 
88 
89 //*************************** Forward Declarations **************************
90 
91 //***************************************************************************
92 
93 
94 namespace Prof {
95 
96 namespace Flat {
97 
98 
99 //***************************************************************************
100 // Basic format for the hpcprof data file:
101 // A profile file (ProfileData) contains one or more load module sections
102 // (LM) with each load module section containi*ng one or more
103 // profiling data sets, one for each event/metric. (EventData).
104 //***************************************************************************
105 
106 class LM;
107 
108 //---------------------------------------------------------------------------
109 // ProfileData: represents flat profile information
110 //
111 // NOTE: it would be nice to support the invariant that "a load
112 // module appears once". However, doing this requires merging data
113 // from load module segments potentially mapped in a non-contiguous
114 // manner. For now, we do not promise this and use a std::multimap
115 //
116 //---------------------------------------------------------------------------
117 
119  : public std::multimap<std::string, LM*> {
120 public:
121  ProfileData(const char* filename = NULL);
122  ~ProfileData();
123 
124  const std::string&
125  name() const
126  { return m_name; }
127 
128  // -------------------------------------------------------
129  // LM: iterator, find/insert, etc
130  // -------------------------------------------------------
131  // use inherited std::map routines
132 
133  // -------------------------------------------------------
134  // Metrics
135  // -------------------------------------------------------
138  { return m_mdescs; }
139 
140  // -------------------------------------------------------
141  // open/read: Throws an exception on an error!
142  // -------------------------------------------------------
143  // Two ways of using:
144  // 1. open(fnm): open fnm and read metrics information only
145  // read() : read (rest of) contents
146  //
147  // 2. openread(fnm): opens and reads fnm
148  //
149  // NOTE: in either case, fnm may be supplied by constructor
150 
151  void
152  openread(const char* filename = NULL);
153 
154  void
155  open(const char* filename = NULL);
156 
157  void
158  read();
159 
160  // -------------------------------------------------------
161  //
162  // -------------------------------------------------------
163 
164  void
165  dump(std::ostream& o = std::cerr, const char* pre = "") const;
166 
167 private:
168  ProfileData(const ProfileData& x);
169 
170  ProfileData&
172  { return *this; }
173 
174  void
175  read_metrics();
176  void mdescs(LM* proflm);
177 
178  static FILE*
179  fopen(const char* filename);
180 
181  static void
182  read_header(FILE* fs);
183 
184  static uint
185  read_lm_count(FILE* fs);
186 
187 private:
188  std::string m_name;
190 
191  // temporary data
192  FILE* m_fs;
193 };
194 
195 
196 //***************************************************************************
197 
198 typedef uint32_t bucketsz_t;
199 
200 // <VMA, count>
201 typedef std::pair<VMA, bucketsz_t> Datum;
202 
203 
204 //***************************************************************************
205 
206 // EventData: contains event description and profiling data
207 class EventData {
208 public:
209  EventData();
210  ~EventData();
211 
212  const Metric::SampledDesc&
213  mdesc() const
214  { return m_mdesc; }
215 
218  { return m_mdesc; }
219 
220  int
221  bucket_size() const
222  { return sizeof(bucketsz_t); }
223 
224  uint
225  outofrange() const
226  { return m_outofrange; }
227 
228  uint
229  overflow() const
230  { return m_overflow; }
231 
232  // -------------------------------------------------------
233  //
234  // -------------------------------------------------------
235 
236  // 0 based indexing
237  uint
238  num_data() const
239  { return m_sparsevec.size(); }
240 
241  // <VMA, count> where VMA is a *relocated* VMA
242  const Datum&
243  datum(uint i) const
244  { return m_sparsevec[i]; }
245 
246  // -------------------------------------------------------
247  // read: Throws an exception on an error!
248  // -------------------------------------------------------
249  void
250  read(FILE*, uint64_t load_addr);
251 
252  // -------------------------------------------------------
253  //
254  // -------------------------------------------------------
255  void
256  dump(std::ostream& o = std::cerr, const char* pre = "") const;
257 
258 private:
262  std::vector<Datum> m_sparsevec;
263 };
264 
265 
266 //***************************************************************************
267 
268 //---------------------------------------------------------------------------
269 // LM: represents flat profile information for a load module
270 //
271 // FIXME: should use Prof::LoadMap
272 //---------------------------------------------------------------------------
273 
274 class LM {
275 public:
276  LM();
277  ~LM();
278 
279  const std::string&
280  name() const
281  { return m_name; }
282 
283  uint64_t
284  load_addr() const
285  { return m_load_addr; }
286 
287  // 0 based indexing
288  uint
289  num_events() const
290  { return m_eventvec.size(); }
291 
292  const EventData&
293  event(uint i) const
294  { return m_eventvec[i]; }
295 
296 
297  // -------------------------------------------------------
298  // read: Throws an exception on an error!
299  // -------------------------------------------------------
300  void
301  read(FILE*, const char* filename = NULL);
302 
303  // -------------------------------------------------------
304  //
305  // -------------------------------------------------------
306  void
307  dump(std::ostream& o = std::cerr, const char* pre = "") const;
308 
309 private:
310  std::string m_name; // module name
311  uint64_t m_load_addr; // load offset during runtime
312  std::vector<EventData> m_eventvec; // events
313 };
314 
315 
316 //***************************************************************************
317 // Exception
318 //***************************************************************************
319 
320 #define PROFFLAT_Throw(streamArgs) DIAG_ThrowX(Prof::Flat::Exception, streamArgs)
321 
323 public:
324  Exception(const std::string x, const char* filenm = NULL, uint lineno = 0)
325  : Diagnostics::Exception(x, filenm, lineno)
326  { }
327 
328  virtual std::string
329  message() const
330  { return "[Prof::Flat]: " + what(); }
331 
332 private:
333 };
334 
335 //***************************************************************************
336 
337 } // namespace Flat
338 
339 } // namespace Prof
340 
341 
342 //***************************************************************************
343 
344 #endif /* prof_Prof_Flat_ProfileData_hpp */
virtual std::string message() const
uint32_t bucketsz_t
const EventData & event(uint i) const
uint64_t load_addr() const
Metric::SampledDesc & mdesc()
const Metric::SampledDescVec & mdescs()
static uint read_lm_count(FILE *fs)
Metric::SampledDescVec m_mdescs
void openread(const char *filename=NULL)
ProfileData & operator=(const ProfileData &GCC_ATTR_UNUSED x)
Exception(const std::string x, const char *filenm=NULL, uint lineno=0)
std::pair< VMA, bucketsz_t > Datum
const std::string & name() const
std::vector< Datum > m_sparsevec
ProfileData(const char *filename=NULL)
unsigned int uint
Definition: uint.h:124
const Metric::SampledDesc & mdesc() const
Metric::SampledDesc m_mdesc
void dump(std::ostream &o=std::cerr, const char *pre="") const
uint num_events() const
const std::string & name() const
const Datum & datum(uint i) const
#define NULL
Definition: ElfHelper.cpp:85
static void read_header(FILE *fs)
void open(const char *filename=NULL)
std::vector< EventData > m_eventvec
static FILE * fopen(const char *filename)
#define GCC_ATTR_UNUSED
Definition: gcc-attr.h:80