HPCToolkit
LoadMap.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 // [The purpose of this file]
54 //
55 // Description:
56 // [The set of functions, macros, etc. defined in the file]
57 //
58 //***************************************************************************
59 
60 #ifndef prof_Prof_LoadMap_hpp
61 #define prof_Prof_LoadMap_hpp
62 
63 //************************* System Include Files ****************************
64 
65 #include <iostream>
66 
67 #include <string>
68 
69 #include <vector>
70 #include <set>
71 
72 #include <algorithm>
73 
74 
75 //*************************** User Include Files ****************************
76 
77 #include <include/uint.h>
78 
79 #include <lib/isa/ISATypes.hpp>
80 
81 #include <lib/binutils/LM.hpp>
82 
84 
86 #include <lib/support/Unique.hpp>
87 
88 
89 //*************************** Forward Declarations ***************************
90 
91 
92 //****************************************************************************
93 // LoadMap
94 //****************************************************************************
95 
96 namespace Prof {
97 
98 
99 class LoadMap
100  : public Unique {
101 
102 public:
103 
104  //*************************************************************************
105 
106  // N.B.: Life is much easier if this is consistent with hpcrun-fmt
107  typedef uint LMId_t;
108  static const LMId_t LMId_NULL = HPCRUN_FMT_LMId_NULL;
109 
110  //*************************************************************************
111 
112  class LM
113  : public Unique {
114 
115  public:
116  LM(const std::string& name = "");
117  //LM(const char* name = NULL);
118 
119  virtual ~LM();
120 
121 
122  LMId_t
123  id() const
124  { return m_id; }
125 
126 
127  const std::string&
128  name() const
129  { return m_name; }
130 
131  void
132  name(std::string x)
133  { m_name = x; }
134 
135  void
136  name(const char* x)
137  { m_name = (x) ? x: ""; }
138 
139 
140  // isUsed: e.g., does this LoadMap::LM have associated measurement data
141  bool
142  isUsed() const
143  { return m_isUsed; }
144 
145  void
146  isUsed(bool x)
147  { m_isUsed = x; }
148 
149  void
150  isUsedMrg(bool x)
151  { m_isUsed = (m_isUsed || x); }
152 
153 
154  std::string
155  toString() const;
156 
157  void
158  dump(std::ostream& os = std::cerr) const;
159 
160  void
161  ddump() const;
162 
163  private:
164  void
165  id(LMId_t x)
166  { m_id = x; }
167 
168  friend class LoadMap;
169  friend class LoadMapMgr;
170 
171  private:
172  LMId_t m_id;
173  std::string m_name;
174  bool m_isUsed;
175  };
176 
177  //*************************************************************************
178 
179  struct MergeEffect {
180  MergeEffect(LMId_t old_, LMId_t new_) : old_id(old_), new_id(new_) { }
181  LMId_t old_id /*in y*/, new_id /*in x */;
182  };
183 
184 
185  //*************************************************************************
186 
187  typedef std::vector<LM*> LMVec;
188 
189  struct lt_LM_nm
190  {
191  inline bool
192  operator()(const LoadMap::LM* x, const LoadMap::LM* y) const
193  {
194  return (x->name() < y->name());
195  }
196  };
197 
198  typedef std::set<LoadMap::LM*, LoadMap::lt_LM_nm> LMSet_nm;
199 
200 
201 public:
202 
203  //*************************************************************************
204 
205  LoadMap(const uint i = 32);
206 
207  ~LoadMap();
208 
209  // assumes ownership
210  void
212 
213 
214  // ------------------------------------------------------------
215  // Access by id (1-based)
216  //
217  // The typical iteration idiom for a LoadMap 'loadmap' is:
218  // for (LoadMap::LMId_t i = 1; i <= loadmap.size(); ++i) { ... }
219  //
220  // (A LoadMap::LM with id x is stored in slot x. Thus 0 points to a
221  // 'NULL' LoadMap::LM.)
222  // ------------------------------------------------------------
223 
224  LMId_t
225  size() const
226  { return m_lm_byId.size() - 1; }
227 
228  // N.B.: LMId_t's are 1-based since 0 is a NULL value
229  LM*
230  lm(LMId_t id) const
231  { return m_lm_byId[id]; }
232 
233 
234  // ------------------------------------------------------------
235  // Access by name
236  // ------------------------------------------------------------
237  LMSet_nm::iterator
238  lm_find(const std::string& nm) const;
239 
240  LMSet_nm::iterator
242  { return m_lm_byName.begin(); }
243 
244  LMSet_nm::const_iterator
245  lm_begin_nm() const
246  { return m_lm_byName.begin(); }
247 
248  LMSet_nm::iterator
250  { return m_lm_byName.end(); }
251 
252  LMSet_nm::const_iterator
253  lm_end_nm() const
254  { return m_lm_byName.end(); }
255 
256 
257  // ------------------------------------------------------------
258  //
259  // ------------------------------------------------------------
260 
261  // merge: Given a LoadMap y, merge y into x = 'this'. Returns a
262  // vector of MergeEffect describing changes that were made. The
263  // vector contains at most one MergeEffect for each LMId_t (old_id)
264  // in y.
265  std::vector<LoadMap::MergeEffect>*
266  merge(const LoadMap& y);
267 
268 
269  // ------------------------------------------------------------
270  //
271  // ------------------------------------------------------------
272 
273  std::string
274  toString() const;
275 
276  void
277  dump(std::ostream& os = std::cerr) const;
278 
279  void
280  ddump() const;
281 
282 protected:
283  LMVec m_lm_byId;
284  LMSet_nm m_lm_byName;
285 };
286 
287 
288 } // namespace Prof
289 
290 
291 inline bool
293 {
294  return (x.id() < y.id());
295 }
296 
297 
298 //***************************************************************************
299 
300 #endif /* prof_Prof_LoadMap_hpp */
LM(const std::string &name="")
Definition: LoadMap.cpp:196
virtual ~LM()
Definition: LoadMap.cpp:202
LM * lm(LMId_t id) const
Definition: LoadMap.hpp:230
LMSet_nm::const_iterator lm_begin_nm() const
Definition: LoadMap.hpp:245
void name(const char *x)
Definition: LoadMap.hpp:136
MergeEffect(LMId_t old_, LMId_t new_)
Definition: LoadMap.hpp:180
LMSet_nm::iterator lm_end_nm()
Definition: LoadMap.hpp:249
std::vector< LM * > LMVec
Definition: LoadMap.hpp:187
void name(std::string x)
Definition: LoadMap.hpp:132
LMId_t id() const
Definition: LoadMap.hpp:123
bool operator<(const Prof::LoadMap::LM x, const Prof::LoadMap::LM y)
Definition: LoadMap.hpp:292
LMVec m_lm_byId
Definition: LoadMap.hpp:283
const std::string & name() const
Definition: LoadMap.hpp:128
LMSet_nm::iterator lm_find(const std::string &nm) const
Definition: LoadMap.cpp:119
friend class LoadMapMgr
Definition: LoadMap.hpp:169
void lm_insert(LoadMap::LM *x)
Definition: LoadMap.cpp:107
unsigned int uint
Definition: uint.h:124
LMSet_nm::const_iterator lm_end_nm() const
Definition: LoadMap.hpp:253
std::set< LoadMap::LM *, LoadMap::lt_LM_nm > LMSet_nm
Definition: LoadMap.hpp:198
void id(LMId_t x)
Definition: LoadMap.hpp:165
static const LMId_t LMId_NULL
Definition: LoadMap.hpp:108
LMSet_nm m_lm_byName
Definition: LoadMap.hpp:284
LMId_t size() const
Definition: LoadMap.hpp:225
void ddump() const
Definition: LoadMap.cpp:224
void dump(std::ostream &os=std::cerr) const
Definition: LoadMap.cpp:217
LMSet_nm::iterator lm_begin_nm()
Definition: LoadMap.hpp:241
friend class LoadMap
Definition: LoadMap.hpp:168
void isUsed(bool x)
Definition: LoadMap.hpp:146
void isUsedMrg(bool x)
Definition: LoadMap.hpp:150
bool isUsed() const
Definition: LoadMap.hpp:142
std::vector< LoadMap::MergeEffect > * merge(const LoadMap &y)
Definition: LoadMap.cpp:130
std::string m_name
Definition: LoadMap.hpp:173
#define HPCRUN_FMT_LMId_NULL
Definition: hpcrun-fmt.h:523
std::string toString() const
Definition: LoadMap.cpp:208
bool operator()(const LoadMap::LM *x, const LoadMap::LM *y) const
Definition: LoadMap.hpp:192