HPCToolkit
Metric-ADesc.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 
64 #include <string>
65 using std::string;
66 
67 #include <typeinfo>
68 
69 //*************************** User Include Files ****************************
70 
71 #include <include/uint.h>
72 
73 #include "Metric-ADesc.hpp"
74 
76 #include <lib/support/StrUtil.hpp>
77 
78 //*************************** Forward Declarations **************************
79 
80 
81 //***************************************************************************
82 
83 namespace Prof {
84 namespace Metric {
85 
86 
87 //***************************************************************************
88 // ADesc
89 //***************************************************************************
90 
91 const string ADesc::s_nameNULL = "";
92 const string ADesc::s_nameIncl = " (I)";
93 const string ADesc::s_nameExcl = " (E)";
94 
95 const string ADesc::s_nameFmtTag = "{formatted}";
96 
97 
98 const std::string&
100 {
101  switch (type) {
102  case TyNULL: return s_nameNULL;
103  case TyIncl: return s_nameIncl;
104  case TyExcl: return s_nameExcl;
105  default: DIAG_Die(DIAG_Unimplemented);
106  }
107 }
108 
109 
110 const char*
112 {
113  switch (type) {
114  case TyNULL: return "nil";
115  case TyIncl: return "inclusive";
116  case TyExcl: return "exclusive";
117  default: DIAG_Die(DIAG_Unimplemented);
118  }
119 }
120 
121 
123 ADesc::stringToADescTy(const std::string& x)
124 {
125  if (x == s_nameNULL) {
126  return TyNULL;
127  }
128  else if (x == s_nameIncl) {
129  return TyIncl;
130  }
131  else if (x == s_nameExcl) {
132  return TyExcl;
133  }
134  else {
136  }
137 }
138 
139 
140 std::string
142 {
143  // acceptable to create on demand
144  std::string nm;
145 
146  // {nameFmtTag}
147  // <prefix><base><suffix><type>
148  // <dbId><dbNumMetrics>
149 
150  nm += s_nameFmtTag;
151 
156 
159 
160  return nm;
161 }
162 
163 
164 void
165 ADesc::nameFromString(const string& x)
166 {
167  // {nameFmtTag}
168  // <prefix><base><suffix><type>
169  // <dbId><dbNumMetrics>
170 
171  if (x.compare(0, s_nameFmtTag.length(), s_nameFmtTag) == 0) {
172  // parse formatted name
173  size_t fmtBeg = s_nameFmtTag.length();
174  for (uint i_seg = 1; i_seg <= 6; ++i_seg) {
175  size_t segBeg = x.find_first_of(s_nameFmtSegBeg, fmtBeg);
176  size_t segEnd = x.find_first_of(s_nameFmtSegEnd, fmtBeg);
177  DIAG_Assert(segBeg == fmtBeg && segEnd != string::npos,
178  DIAG_UnexpectedInput << "'" << x << "'");
179  segBeg++;
180  string segStr = x.substr(segBeg, segEnd - segBeg);
181 
182  switch (i_seg) {
183  case 1: namePfx(segStr); break;
184  case 2: nameBase(segStr); break;
185  case 3: nameSfx(segStr); break;
186  case 4: type(stringToADescTy(segStr)); break;
187  case 5: dbId((uint)StrUtil::toLong(segStr)); break;
188  case 6: dbNumMetrics((uint)StrUtil::toLong(segStr)); break;
189  default: DIAG_Die(DIAG_UnexpectedInput);
190  }
191 
192  fmtBeg = segEnd + 1;
193  }
194  }
195  else {
196  nameBase(x);
197  }
198 }
199 
200 
201 std::string
203 {
204  string nm = name();
205  if (0) {
206  nm += " {dbId: " + StrUtil::toStr(dbId())
207  + ", dbNumMetrics: " + StrUtil::toStr(dbNumMetrics()) + "}";
208  }
209  return nm;
210 
211  //std::ostringstream os;
212  //dump(os);
213  //return os.str();
214 }
215 
216 
217 std::ostream&
218 ADesc::dumpMe(std::ostream& os) const
219 {
220  os << toString();
221  return os;
222 }
223 
224 
225 void
227 {
228  dump(std::cerr);
229  std::cerr.flush();
230 }
231 
232 //***************************************************************************
233 
234 
237 {
238  switch (ty) {
242  default:
244  }
245 }
246 
247 
250 {
251  switch (ty) {
255  default:
257  }
258 }
259 
260 
261 
262 //***************************************************************************
263 // SampledDesc
264 //***************************************************************************
265 
266 std::string
268 {
269  string units = isUnitsEvents() ? " [events]" : " [samples]";
270  string xtra = " {" + description() + ":" + StrUtil::toStr(period()) + " ev/smpl}";
271  string str = ADesc::toString() + units + xtra;
272  return str;
273 }
274 
275 
276 std::string
278 {
279  switch (computedType()) {
280  case ComputedTy_NULL:
281  return "raw";
282 
283  default:
284  case ComputedTy_NonFinal:
286  break;
287 
288  case ComputedTy_Final:
289  DIAG_Assert(type() != TyNULL, "");
290  return "final";
291  }
293 }
294 
295 
296 std::ostream&
297 SampledDesc::dumpMe(std::ostream& os) const
298 {
299  os << toString();
300  return os;
301 }
302 
303 
304 //***************************************************************************
305 // DerivedDesc
306 //***************************************************************************
307 
308 std::string
310 {
311  string exprStr = (m_expr) ? m_expr->toString() : "";
312  string str = ADesc::toString() + " {" + exprStr + "}";
313  return str;
314 }
315 
316 
317 std::string
319 {
320  switch (computedType()) {
321  default:
322  case ComputedTy_NULL:
324  break;
325 
326  case ComputedTy_NonFinal:
327  return "derived-incr";
328 
329  case ComputedTy_Final:
330  return "derived";
331  }
333 }
334 
335 
336 std::ostream&
337 DerivedDesc::dumpMe(std::ostream& os) const
338 {
339  os << toString();
340  return os;
341 }
342 
343 
344 //***************************************************************************
345 // DerivedIncrDesc
346 //***************************************************************************
347 
348 std::string
350 {
351  string exprStr = (m_expr) ? m_expr->toString() : "";
352  string str = ADesc::toString() + " {" + exprStr + "}";
353  return str;
354 }
355 
356 
357 std::string
359 {
360  switch (computedType()) {
361  default:
362  case ComputedTy_NULL:
364  break;
365 
366  case ComputedTy_NonFinal:
367  return "derived-incr";
368 
369  case ComputedTy_Final:
370  return "derived";
371  }
373 }
374 
375 
376 std::ostream&
377 DerivedIncrDesc::dumpMe(std::ostream& os) const
378 {
379  os << toString();
380  return os;
381 }
382 
383 
384 //***************************************************************************
385 
386 } // namespace Metric
387 } // namespace Prof
388 
const std::string & nameSfx() const
static ADescTy fromHPCRunMetricValTy(MetricFlags_ValTy_t ty)
static MetricFlags_ValTy_t toHPCRunMetricValTy(ADescTy ty)
string toStr(const int x, int base)
Definition: StrUtil.cpp:243
static const char * ADescTyToXMLString(ADescTy type)
virtual std::string toString() const
void nameFromString(const std::string &x)
const char * DIAG_Unimplemented
static ADescTy stringToADescTy(const std::string &x)
long toLong(const char *str, unsigned *endidx)
Definition: StrUtil.cpp:165
std::string name() const
static const std::string s_nameExcl
std::string nameToFmt() const
static const char s_nameFmtSegBeg
static const char s_nameFmtSegEnd
virtual std::string toString() const
const std::string & nameBase() const
unsigned int uint
Definition: uint.h:124
ComputedTy computedType() const
virtual std::string toString() const
uint dbNumMetrics() const
virtual std::string toString() const
ADescTy type() const
std::ostream & dump(std::ostream &os=std::cerr) const
MetricFlags_ValTy_t
Definition: hpcrun-fmt.h:239
std::string m_nameBase
virtual std::ostream & dumpMe(std::ostream &os=std::cerr) const
const char * DIAG_UnexpectedInput
virtual std::ostream & dumpMe(std::ostream &os=std::cerr) const
virtual std::string toValueTyStringXML() const
virtual std::ostream & dumpMe(std::ostream &os=std::cerr) const
virtual std::string toValueTyStringXML() const
static const std::string s_nameFmtTag
virtual std::ostream & dumpMe(std::ostream &os=std::cerr) const
const std::string & namePfx() const
virtual std::string toValueTyStringXML() const
const std::string & description() const
static const std::string s_nameIncl
static const std::string s_nameNULL
#define DIAG_Die(...)
Definition: diagnostics.h:267
static const std::string & ADescTyToString(ADescTy type)
static long period
Definition: itimer.c:194