HPCToolkit
Metric-IDBExpr.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_Metric_IDBExpr_hpp
61 #define prof_Prof_Metric_IDBExpr_hpp
62 
63 //************************* System Include Files ****************************
64 
65 #include <iostream>
66 
67 #include <string>
68 
69 //*************************** User Include Files ****************************
70 
71 #include <include/gcc-attr.h>
72 #include <include/uint.h>
73 
75 #include <lib/support/StrUtil.hpp>
76 
77 
78 //*************************** Forward Declarations **************************
79 
80 
81 //***************************************************************************
82 
83 namespace Prof {
84 
85 namespace Metric {
86 
87 //***************************************************************************
88 //
89 // IDBExpr
90 //
91 // Interface/Mixin to represent the Experiment database's formulas for
92 // computing the Flat and Callers view given derived CCT metrics.
93 //
94 //***************************************************************************
95 
96 class IDBExpr {
97 public:
98  // --------------------------------------------------------
99  // Create/Destroy
100  // --------------------------------------------------------
102  { }
103 
104  virtual ~IDBExpr()
105  { }
106 
107  IDBExpr&
109  { return *this; }
110 
111 
112  // --------------------------------------------------------
113  // Formulas to compute Flat and Callers view
114  // --------------------------------------------------------
115 
116  // initialize: [Flat|Callers]-accum is initialized from CCT-accum
117 
118  // combineString1: [Flat|Callers]-accum x cct-accum -> [Flat|Callers]-accum
119  virtual std::string
120  combineString1() const = 0;
121 
122  // combineString2: [Flat|Callers]-accum x cct-accum -> [Flat|Callers]-accum
123  virtual std::string
124  combineString2() const = 0;
125 
126  // finalizeString: accumulator-list -> output
127  virtual std::string
128  finalizeString() const = 0;
129 
130 
131  // --------------------------------------------------------
132  // Commonly used standard deviation formulas
133  // --------------------------------------------------------
134 
135  std::string
137  {
138  std::string a = accumStr(0);
139  std::string z = "min(" + a + ", " + a + ")";
140  return z;
141  }
142 
143  std::string
145  { return accumStr(0); }
146 
147 
148  std::string
150  {
151  std::string a = accumStr(0);
152  std::string z = "max(" + a + ", " + a + ")";
153  return z;
154  }
155 
156  std::string
158  { return accumStr(0); }
159 
160 
161  std::string
163  {
164  std::string a1 = accumStr(0);
165  std::string z1 = "sum(" + a1 + ", " + a1 + ")"; // running sum
166  return z1;
167  }
168 
169  std::string
171  {
172  std::string a2 = accumStr(1);
173  std::string z2 = "sum(" + a2 + ", " + a2 + ")"; // running sum of squares
174  return z2;
175  }
176 
177 
178  std::string
180  {
181  std::string a = accumStr(0);
182  std::string z = "sum(" + a + ", " + a + ")";
183  return z;
184  }
185 
186  std::string
188  { return accumStr(0); }
189 
190 
191  std::string
193  {
194  std::string a = accumStr(0);
195  std::string z = "sum(" + a + ", " + a + ")";
196  return z;
197  }
198 
199  std::string
201  {
202  // Laks hack: for callers view and flat view, it would be
203  // more accurate if we divide the sum with the aggregate
204  // since the num of callers view and flat view will be
205  // accumulated
206  std::string n = numSrcStr();
207  std::string a = accumStr(0);
208  std::string z = a + " / " + n;
209  return z;
210  }
211 
212 
213  std::string
214  finalizeStringStdDev(std::string* meanRet = NULL) const
215  {
216  std::string n = numSrcStr();
217  std::string a1 = accumStr(0); // running sum
218  std::string a2 = accumStr(1); // running sum of squares
219 
220  std::string mean = a1 + " / " + n;
221  std::string z1 = "pow(" + mean + ", 2)"; // (mean)^2
222  std::string z2 = "(" + a2 + " / " + n + ")"; // (sum of squares)/n
223  std::string sdev = "sqrt(" + z2 + " - " + z1 + ")";
224 
225  if (meanRet) {
226  *meanRet = mean;
227  }
228  return sdev;
229  }
230 
231 
232  std::string
234  {
235  std::string mean;
236  std::string sdev = finalizeStringStdDev(&mean);
237  std::string z = sdev + " / (" + mean + ")";
238  return z;
239  }
240 
241 
242  std::string
244  {
245  std::string mean;
246  std::string sdev = finalizeStringStdDev(&mean);
247  std::string z = sdev + "* 100 / (" + mean + ")";
248  return z;
249  }
250 
251 
252  std::string
254  {
255  std::string a = accumStr(0);
256  // laks: avoid accumulation of NumSrc for callers view and flat view
257  // std::string z = "sum(" + a + ", " + a + ")"; // a + numSrcFix()
258  return a; // originally: z;
259  }
260 
261  std::string
263  { return accumStr(0); }
264 
265 
266  // --------------------------------------------------------
267  // Primitives for building formulas
268  // --------------------------------------------------------
269 
270  virtual uint
271  accumId(int) const = 0;
272 
273  std::string
274  accumStr(int i) const
275  { return "$"+ StrUtil::toStr(accumId(i)); }
276 
277 
278  // --------------------------------------------------------
279  // Primitives for building formulas
280  // --------------------------------------------------------
281 
282  virtual uint
283  numAccum() const = 0;
284 
285 
286  // --------------------------------------------------------
287  // Primitives for building formulas
288  // --------------------------------------------------------
289 
290  virtual bool
291  hasNumSrcVar() const = 0;
292 
293  std::string
294  numSrcStr() const
295  { return (hasNumSrcVar()) ? numSrcVarStr() : numSrcFxdStr(); }
296 
297 
298  virtual uint
299  numSrcFxd() const = 0;
300 
301  std::string
302  numSrcFxdStr() const
303  { return StrUtil::toStr(numSrcFxd()); }
304 
305 
306  virtual uint
307  numSrcVarId() const = 0;
308 
309  std::string
310  numSrcVarStr() const
311  { return "$" + StrUtil::toStr(numSrcVarId()); }
312 
313 
314  // --------------------------------------------------------
315  //
316  // --------------------------------------------------------
317 
318  virtual std::string
319  toString() const;
320 
321 
322  virtual std::ostream&
323  dump(std::ostream& os = std::cout) const
324  { return os; }
325 
326  void
327  ddump() const;
328 
329 protected:
330  enum {maxAccums = 2};
331 private:
332 };
333 
334 //***************************************************************************
335 
336 } // namespace Metric
337 
338 } // namespace Prof
339 
340 
341 #endif /* prof_Prof_Metric_IDBExpr_hpp */
std::string combineString2StdDev() const
virtual uint numSrcVarId() const =0
std::string finalizeStringStdDev(std::string *meanRet=NULL) const
std::string finalizeStringSum() const
std::string combineString1NumSource() const
std::string finalizeStringCoefVar() const
string toStr(const int x, int base)
Definition: StrUtil.cpp:243
IDBExpr & operator=(const IDBExpr &GCC_ATTR_UNUSED x)
std::string finalizeStringNumSource() const
virtual uint numAccum() const =0
virtual std::string combineString1() const =0
virtual std::string toString() const
virtual bool hasNumSrcVar() const =0
std::string finalizeStringRStdDev() const
virtual uint numSrcFxd() const =0
unsigned int uint
Definition: uint.h:124
std::string combineString1Max() const
std::string finalizeStringMean() const
std::string numSrcStr() const
std::string combineString1Min() const
virtual std::string finalizeString() const =0
std::string combineString1Mean() const
std::string numSrcFxdStr() const
std::string finalizeStringMin() const
#define NULL
Definition: ElfHelper.cpp:85
virtual std::ostream & dump(std::ostream &os=std::cout) const
std::string finalizeStringMax() const
std::string combineString1Sum() const
std::string combineString1StdDev() const
#define GCC_ATTR_UNUSED
Definition: gcc-attr.h:80
<!-- ********************************************************************--> 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
std::string numSrcVarStr() const
virtual std::string combineString2() const =0
virtual uint accumId(int) const =0
std::string accumStr(int i) const