HPCToolkit
Flat-SrcCorrelation.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 #ifndef Analysis_Flat_SrcCorrelation_hpp
48 #define Analysis_Flat_SrcCorrelation_hpp
49 
50 //************************ System Include Files ******************************
51 
52 #include <iostream>
53 #include <list> // STL
54 #include <vector> // STL
55 #include <string>
56 
57 //************************* User Include Files *******************************
58 
59 #include <include/uint.h>
60 
61 #include "Args.hpp"
62 #include "TextUtil.hpp"
63 
66 
68 #include <lib/prof/Metric-Mgr.hpp>
69 #include <lib/prof/Struct-Tree.hpp>
70 
71 #include <lib/binutils/LM.hpp>
72 
73 #include <lib/support/Unique.hpp>
74 
75 //************************ Forward Declarations ******************************
76 
77 //****************************************************************************
78 
79 namespace Analysis {
80 
81 namespace Flat {
82 
83 
84 class Driver : public Unique { // not copyable
85 public:
86  Driver(const Analysis::Args& args,
87  Prof::Metric::Mgr& mMgr, Prof::Struct::Tree& structure);
88  ~Driver();
89 
90  // -------------------------------------------------------
91  //
92  // -------------------------------------------------------
93  int
94  run();
95 
96  // -------------------------------------------------------
97  //
98  // -------------------------------------------------------
99  // Test the specified path against each of the paths in the
100  // database. Replace with the pair of the first matching path.
101  std::string
102  replacePath(const char* path);
103 
104  std::string
105  replacePath(const std::string& path)
106  { return replacePath(path.c_str()); }
107 
108  // -------------------------------------------------------
109  //
110  // -------------------------------------------------------
111  void
112  write_experiment(std::ostream &os) const;
113 
114  void
115  write_csv(std::ostream &os) const;
116 
117  void
118  write_txt(std::ostream &os) const;
119 
120  void
121  write_config(std::ostream &os = std::cout) const;
122 
123  // -------------------------------------------------------
124  //
125  // -------------------------------------------------------
126  std::string
127  toString() const;
128 
129  void
130  dump() const;
131 
132 public:
133  typedef std::map<string, bool> StringToBoolMap;
134 
135  typedef std::pair<Prof::Flat::ProfileData*,
137  typedef std::vector<ProfToMetricsTuple> ProfToMetricsTupleVec;
138 
139 private:
140  void
142 
143  void
145  Prof::Struct::Tree& structure);
146 
147 
148  // -------------------------------------------------------
149 
150  void
152 
153  void
154  computeRawBatchJob_LM(const string& lmname, const string& lmname_orig,
155  Prof::Struct::Tree& structure,
156  ProfToMetricsTupleVec& profToMetricsVec,
157  bool useStruct);
158 
159  void
161  const Prof::Flat::EventData& profevent,
162  VMA lm_load_addr,
163  Prof::Struct::Tree& structure,
164  Prof::Struct::LM* lmStrct,
165  /*const*/ BinUtil::LM* lm,
166  bool useStruct);
167 
168  bool
169  getNextRawBatch(ProfToMetricsTupleVec& batchJob,
170  Prof::Metric::Mgr::StringToADescVecMap::const_iterator& it,
171  const Prof::Metric::Mgr::StringToADescVecMap::const_iterator& it_end);
172 
173  void
174  clearRawBatch(ProfToMetricsTupleVec& batchJob);
175 
176  bool
177  hasStructure(const string& lmname, Prof::Struct::Tree& structure,
178  StringToBoolMap& hasStructureTbl);
179 
180  // -------------------------------------------------------
181 
182  void
184 
185  // [mBegId, mEndId)
186  void
188  const Prof::Metric::AExpr** mExprVec,
189  uint mBegId, uint mEndId);
190 
191  // -------------------------------------------------------
192 
193  Prof::Flat::ProfileData*
194  readProf(const string& fnm);
195 
196  void
197  readProf(Prof::Flat::ProfileData* prof);
198 
199  BinUtil::LM*
200  openLM(const string& fnm);
201 
202  // -------------------------------------------------------
203 
204  void
205  write_txt_secSummary(std::ostream& os,
207  const std::string& title,
208  const Prof::Struct::ANodeFilter* filter) const;
209 
210  void
211  write_txt_annotateFile(std::ostream& os,
213  const Prof::Struct::File* fileStrct) const;
214 
215  void
216  write_txt_hdr(std::ostream& os, const std::string& hdr) const;
217 
218 
219 private:
221 
224 
226 };
227 
228 
229 //****************************************************************************
230 
232  : public DocHandlerArgs {
233 public:
235  : DocHandlerArgs(NULL), m_driver(driver)
236  { }
237 
238  virtual
240  { }
241 
242  // Would be better to use realpath() and RealPathMgr
243  string
244  replacePath(const char* oldpath) const
245  { return m_driver->replacePath(oldpath); }
246 
247  string
248  replacePath(const std::string& oldpath) const
249  { return m_driver->replacePath(oldpath); }
250 
251 private:
253 };
254 
255 //****************************************************************************
256 
257 } // namespace Flat
258 
259 } // namespace Analysis
260 
261 //****************************************************************************
262 
263 #endif // Analysis_Flat_SrcCorrelation_hpp
void write_txt(std::ostream &os) const
void write_txt_hdr(std::ostream &os, const std::string &hdr) const
std::string replacePath(const char *path)
static struct perf_mem_metric metric
Definition: pmu_x86.c:114
std::vector< ProfToMetricsTuple > ProfToMetricsTupleVec
Prof::Flat::ProfileData * readProf(const string &fnm)
bfd_vma VMA
Definition: ISATypes.hpp:79
void write_txt_secSummary(std::ostream &os, Analysis::TextUtil::ColumnFormatter &colFmt, const std::string &title, const Prof::Struct::ANodeFilter *filter) const
Prof::Metric::Mgr & m_mMgr
void computeRawMetrics(Prof::Metric::Mgr &mMgr, Prof::Struct::Tree &structure)
void write_experiment(std::ostream &os) const
void computeRawBatchJob_LM(const string &lmname, const string &lmname_orig, Prof::Struct::Tree &structure, ProfToMetricsTupleVec &profToMetricsVec, bool useStruct)
std::vector< ADesc * > ADescVec
void write_csv(std::ostream &os) const
std::string replacePath(const std::string &path)
BinUtil::LM * openLM(const string &fnm)
void correlateMetricsWithStructure(Prof::Metric::Mgr &mMgr, Prof::Struct::Tree &structure)
bool hasStructure(const string &lmname, Prof::Struct::Tree &structure, StringToBoolMap &hasStructureTbl)
bool getNextRawBatch(ProfToMetricsTupleVec &batchJob, Prof::Metric::Mgr::StringToADescVecMap::const_iterator &it, const Prof::Metric::Mgr::StringToADescVecMap::const_iterator &it_end)
const Analysis::Args & m_args
unsigned int uint
Definition: uint.h:124
void computeDerivedBatch(Prof::Struct::Tree &structure, const Prof::Metric::AExpr **mExprVec, uint mBegId, uint mEndId)
Prof::Struct::Tree & m_structure
std::pair< Prof::Flat::ProfileData *, Prof::Metric::ADescVec * > ProfToMetricsTuple
void write_txt_annotateFile(std::ostream &os, Analysis::TextUtil::ColumnFormatter &colFmt, const Prof::Struct::File *fileStrct) const
std::map< string, bool > StringToBoolMap
string replacePath(const std::string &oldpath) const
void populateStructure(Prof::Struct::Tree &structure)
void correlateRaw(Prof::Metric::ADesc *metric, const Prof::Flat::EventData &profevent, VMA lm_load_addr, Prof::Struct::Tree &structure, Prof::Struct::LM *lmStrct, BinUtil::LM *lm, bool useStruct)
string replacePath(const char *oldpath) const
#define NULL
Definition: ElfHelper.cpp:85
void write_config(std::ostream &os=std::cout) const
void computeDerivedMetrics(Prof::Metric::Mgr &mMgr, Prof::Struct::Tree &structure)
Driver(const Analysis::Args &args, Prof::Metric::Mgr &mMgr, Prof::Struct::Tree &structure)
void clearRawBatch(ProfToMetricsTupleVec &batchJob)
std::string toString() const