HPCToolkit
Metric-IData.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/gcc-attr.h>
72 #include <include/uint.h>
73 
74 #include "Metric-IData.hpp"
75 #include "Metric-Mgr.hpp" // for Prof::Metric::Mgr
76 
77 #include <lib/xml/xml.hpp>
78 
81 
82 //*************************** Forward Declarations **************************
83 
84 
85 //***************************************************************************
86 
87 namespace Prof {
88 namespace Metric {
89 
90 
91 //***************************************************************************
92 // IData
93 //***************************************************************************
94 
95 std::string
96 IData::toStringMetrics(int oFlags, const char* pfx) const
97 {
98  std::ostringstream os;
99  dumpMetrics(os, oFlags, pfx);
100  return os.str();
101 }
102 
103 
104 std::ostream&
105 IData::writeMetricsXML(std::ostream& os,
106  const Mgr *metricMgr,
107  uint mBegId, uint mEndId,
108  int GCC_ATTR_UNUSED oFlags, const char* pfx) const
109 {
110  bool wasMetricWritten = false;
111 
112  if (mBegId == IData::npos) {
113  mBegId = 0;
114  }
115  mEndId = std::min(numMetrics(), mEndId);
116 
117  for (uint i = mBegId; i < mEndId; i++) {
118  if (hasMetric(i)) {
119  hpcrun_metricVal_t val = m_metrics[i];
120  std::string mval;
121 
122  // specific case for address-base type:
123  // use the integer format to print to the xml to make it easy the xml parser
124  // to parse the number.
125 
126  uint desc_id = i-mBegId;
127  const Metric::ADesc* adesc = metricMgr->metric(desc_id);
128  const Metric::SampledDesc* mdesc = dynamic_cast<const Metric::SampledDesc*>(adesc);
129  if (mdesc->flags().fields.valFmt == MetricFlags_ValFmt_Address) {
130  mval = xml::MakeAttrNum(val.i);
131  } else{
132  mval = xml::MakeAttrNum(val.r);
133  }
134 
135  os << ((!wasMetricWritten) ? pfx : "");
136  os << "<M " << "n" << xml::MakeAttrNum(i)
137  << " v" << mval << "/>";
138  wasMetricWritten = true;
139  }
140  }
141 
142  return os;
143 }
144 
145 
146 std::ostream&
147 IData::dumpMetrics(std::ostream& os, int GCC_ATTR_UNUSED oFlags,
148  const char* GCC_ATTR_UNUSED pfx) const
149 {
150  return os;
151 }
152 
153 
154 void
156 {
157  dumpMetrics();
158 }
159 
160 
161 //***************************************************************************
162 
163 } // namespace Metric
164 } // namespace Prof
165 
MetricFlags_ValFmt_t valFmt
Definition: hpcrun-fmt.h:263
uint numMetrics() const
unsigned int uint
Definition: uint.h:124
hpcrun_metricFlags_fields fields
Definition: hpcrun-fmt.h:276
bool hasMetric(size_t mId) const
std::string MakeAttrNum(int x)
Definition: xml.hpp:228
Metric::ADesc * metric(uint i)
Definition: Metric-Mgr.hpp:131
std::string toStringMetrics(int oFlags=0, const char *pfx="") const
hpcrun_metricFlags_t flags() const
#define GCC_ATTR_UNUSED
Definition: gcc-attr.h:80
std::ostream & writeMetricsXML(std::ostream &os, const Mgr *metricMgr, uint mBegId=Metric::IData::npos, uint mEndId=Metric::IData::npos, int oFlags=0, const char *pfx="") const
std::ostream & dumpMetrics(std::ostream &os=std::cerr, int oFlags=0, const char *pfx="") const
void ddumpMetrics() const
static const uint npos