HPCToolkit
main.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 #include <fstream>
64 
65 #include <string>
66 using std::string;
67 
68 #include <vector>
69 
70 //*************************** User Include Files ****************************
71 
72 #include <include/gcc-attr.h>
73 
74 #include "Args.hpp"
75 
77 #include <lib/analysis/Util.hpp>
78 
81 
82 
83 //*************************** Forward Declarations ***************************
84 
85 static int
86 realmain(int argc, char* const* argv);
87 
88 static void
90  const Analysis::Args& args,
92 
93 
94 //****************************************************************************
95 
96 void
98 (
99  int error_code
100 )
101 {
102  exit(error_code);
103 }
104 
105 
106 int
107 main(int argc, char* const* argv)
108 {
109  int ret;
110 
111  try {
112  ret = realmain(argc, argv);
113  }
114  catch (const Diagnostics::Exception& x) {
115  DIAG_EMsg(x.message());
116  exit(1);
117  }
118  catch (const std::bad_alloc& x) {
119  DIAG_EMsg("[std::bad_alloc] " << x.what());
120  exit(1);
121  }
122  catch (const std::exception& x) {
123  DIAG_EMsg("[std::exception] " << x.what());
124  exit(1);
125  }
126  catch (...) {
127  DIAG_EMsg("Unknown exception encountered!");
128  exit(2);
129  }
130 
131  return ret;
132 }
133 
134 
135 static int
136 realmain(int argc, char* const* argv)
137 {
138  Args args;
139  args.parse(argc, argv);
140 
142 
145 
146  // ------------------------------------------------------------
147  // 0. Special checks
148  // ------------------------------------------------------------
149 
150  if (nArgs.paths->size() == 0) {
151  std::cerr << "ERROR: command line directories"
152  " contain no .hpcrun files; no database generated\n";
153  exit(-1);
154  }
155 
156  if (nArgs.paths->size() == 1 && !args.hpcprof_isMetricArg) {
158  }
159 
161  && nArgs.paths->size() > 16
162  && !args.hpcprof_forceMetrics) {
163  DIAG_Throw("You have requested thread-level metrics for " << nArgs.paths->size() << " profile files. Because this may result in an unusable database, to continue you must use the --force-metric option.");
164  }
165 
166  // ------------------------------------------------------------
167  // 1a. Create canonical CCT // Normalize trace files
168  // ------------------------------------------------------------
169 
171  Analysis::Util::UIntVec* groupMap =
172  (nArgs.groupMax > 1) ? nArgs.groupMap : NULL;
173 
174  uint rFlags = 0;
177  }
179 
181  Analysis::CallPath::read(*nArgs.paths, groupMap, mergeTy, rFlags, mrgFlags);
182 
184 
185 
186  // -------------------------------------------------------
187  // 0. Make empty Experiment database (ensure file system works)
188  // -------------------------------------------------------
189 
190  args.makeDatabaseDir();
191 
192  // ------------------------------------------------------------
193  // 1b. Add static structure to canonical CCT
194  // ------------------------------------------------------------
195 
196  Prof::Struct::Tree* structure = new Prof::Struct::Tree("");
197  if (!args.structureFiles.empty()) {
198  Analysis::CallPath::readStructure(structure, args);
199  }
200  prof->structure(structure);
201 
202  bool printProgress = true;
203 
205  args.doNormalizeTy,
206  printProgress);
207 
208  // -------------------------------------------------------
209  // 2a. Create summary metrics for canonical CCT
210  // -------------------------------------------------------
211 
213  makeMetrics(*prof, args, nArgs);
214  }
215 
216  // -------------------------------------------------------
217  // 2b. Prune and normalize canonical CCT
218  // -------------------------------------------------------
219 
222  }
223 
225 
227  // Apply after all CCT pruning/normalization is completed.
228  //TODO: Analysis::CallPath::applySummaryMetricAgents(*prof, args.agent);
229  }
230 
231  prof->cct()->makeDensePreorderIds();
232 
233  // -------------------------------------------------------
234  // 2c. Create thread-level metric DB
235  // -------------------------------------------------------
236  // Currently we use --metric=thread as a proxy for the metric database
237 
238  // ------------------------------------------------------------
239  // 3. Generate Experiment database
240  // INVARIANT: database dir already exists
241  // ------------------------------------------------------------
242 
244 
245  if (args.title.empty()) {
246  args.title = prof->name();
247  }
248 
249  if (!args.db_makeMetricDB) {
250  prof->metricMgr()->zeroDBInfo();
251  }
252 
254 
255 
256  // -------------------------------------------------------
257  // Cleanup
258  // -------------------------------------------------------
259  nArgs.destroy();
260 
261  delete prof;
262 
263  return 0;
264 }
265 
266 
267 //****************************************************************************
268 
269 static void
271  const Analysis::Args& args,
273 {
274  Prof::Metric::Mgr& mMgr = *prof.metricMgr();
275 
276  Prof::CCT::ANode* cctRoot = prof.cct()->root();
277 
278  // -------------------------------------------------------
279  // create derived metrics
280  // -------------------------------------------------------
281  uint numSrc = mMgr.size();
282  uint mSrcBeg = 0, mSrcEnd = numSrc; // [ )
283 
284  uint mDrvdBeg = 0, mDrvdEnd = 0; // [ )
285 
286  bool needAllStats =
289  bool needMultiOccurance =
291 
292  mDrvdBeg = mMgr.makeSummaryMetrics(needAllStats, needMultiOccurance,
293  mSrcBeg, mSrcEnd);
294  if (mDrvdBeg != Prof::Metric::Mgr::npos) {
295  mDrvdEnd = mMgr.size();
296  }
297 
299  for (uint mId = mSrcBeg; mId < mSrcEnd; ++mId) {
300  Prof::Metric::ADesc* m = mMgr.metric(mId);
301  m->isVisible(false);
302  }
303  }
304 
305  // -------------------------------------------------------
306  // aggregate sampled metrics (in batch)
307  // -------------------------------------------------------
308 
309  VMAIntervalSet ivalsetIncl;
310  VMAIntervalSet ivalsetExcl;
311 
312  for (uint mId = mSrcBeg; mId < mSrcEnd; ++mId) {
313  Prof::Metric::ADesc* m = mMgr.metric(mId);
314  if (m->type() == Prof::Metric::ADesc::TyIncl) {
315  ivalsetIncl.insert(VMAInterval(mId, mId + 1)); // [ )
316  }
317  else if (m->type() == Prof::Metric::ADesc::TyExcl) {
318  ivalsetExcl.insert(VMAInterval(mId, mId + 1)); // [ )
319  }
321  }
322 
323  cctRoot->aggregateMetricsIncl(ivalsetIncl);
324  cctRoot->aggregateMetricsExcl(ivalsetExcl);
325 
326 
327  // -------------------------------------------------------
328  // compute derived metrics
329  // -------------------------------------------------------
330  cctRoot->computeMetrics(mMgr, mDrvdBeg, mDrvdEnd, /*doFinal*/false);
331 
332  for (uint i = mDrvdBeg; i < mDrvdEnd; ++i) {
333  Prof::Metric::ADesc* m = mMgr.metric(i);
335  }
336 }
Definition: Args.hpp:79
void makeDatabaseDir()
Definition: Args.cpp:203
void prof_abort(int error_code)
Definition: main.cpp:98
void aggregateMetricsIncl(uint mBegId, uint mEndId)
Definition: CCT-Tree.cpp:458
void readStructure(Prof::Struct::Tree *structure, const Analysis::Args &args)
Definition: CallPath.cpp:210
NormalizeProfileArgs_t normalizeProfileArgs(const StringVec &inPaths)
Definition: Util.cpp:179
void normalize(Prof::CallPath::Profile &prof, string agent, bool doNormalizeTy)
bool isVisible() const
uint prof_metrics
Definition: Args.hpp:176
#define DIAG_EMsg(...)
Definition: diagnostics.h:251
bool remove_redundancy
Definition: Args.hpp:241
std::vector< std::string > structureFiles
Definition: Args.hpp:128
ANode * root() const
Definition: CCT-Tree.hpp:160
static bool MetricFlg_isSum(uint flags)
Definition: Args.hpp:170
void overlayStaticStructureMain(Prof::CallPath::Profile &prof, string agent, bool doNormalizeTy, bool printProgress)
Definition: CallPath.cpp:347
void pruneStructTree(Prof::CallPath::Profile &prof)
Definition: CallPath.cpp:839
bool hpcprof_forceMetrics
Definition: Args.hpp:97
void zeroDBInfo() const
Definition: Metric-Mgr.cpp:721
std::vector< uint > UIntVec
Definition: Util.hpp:109
static RealPathMgr & singleton()
std::string searchPathStr
Definition: Args.hpp:119
void makeDatabase(Prof::CallPath::Profile &prof, const Analysis::Args &args)
Definition: CallPath.cpp:1106
void computeMetrics(const Metric::Mgr &mMgr, uint mBegId, uint mEndId, bool doFinal)
Definition: CCT-Tree.cpp:605
void parse(int argc, const char *const argv[])
Definition: Args.cpp:208
static bool MetricFlg_isSet(uint flags, MetricFlg x)
Definition: Args.hpp:154
uint size() const
Definition: Metric-Mgr.hpp:153
uint makeSummaryMetrics(bool needAllStats, bool needMultiOccurance, uint srcBegId=Mgr::npos, uint srcEndId=Mgr::npos)
Definition: Metric-Mgr.cpp:135
virtual std::string message() const
Definition: Exception.hpp:134
exit
Definition: names.cpp:1
unsigned int uint
Definition: uint.h:124
static void makeMetrics(Prof::CallPath::Profile &prof, const Analysis::Args &args, const Analysis::Util::NormalizeProfileArgs_t &nArgs)
ComputedTy computedType() const
static const uint npos
Definition: Metric-Mgr.hpp:202
bool db_makeMetricDB
Definition: Args.hpp:204
int main(int argc, char *argv[])
Definition: main.cpp:125
std::pair< iterator, bool > insert(const VMA beg, const VMA end)
std::vector< std::string > profileFiles
Definition: Args.hpp:138
ADescTy type() const
const std::string & searchPaths() const
const Metric::Mgr * metricMgr() const
void disable_redundancy(bool flag)
Prof::Struct::Tree * structure() const
void aggregateMetricsExcl(uint mBegId, uint mEndId)
Definition: CCT-Tree.cpp:505
std::string agent
Definition: Args.hpp:114
bool hpcprof_isMetricArg
Definition: Args.hpp:96
static bool MetricFlg_isThread(uint flags)
Definition: Args.hpp:166
void pruneBySummaryMetrics(Prof::CallPath::Profile &prof, uint8_t *prunedNodes)
Definition: CallPath.cpp:805
uint makeDensePreorderIds()
Definition: CCT-Tree.cpp:232
#define NULL
Definition: ElfHelper.cpp:85
std::string title
Definition: Args.hpp:121
Prof::CallPath::Profile * read(const Util::StringVec &profileFiles, const Util::UIntVec *groupMap, int mergeTy, uint rFlags, uint mrgFlags)
Definition: CallPath.cpp:142
Metric::ADesc * metric(uint i)
Definition: Metric-Mgr.hpp:131
#define GCC_ATTR_UNUSED
Definition: gcc-attr.h:80
static int realmain(int argc, char *const *argv)
Definition: main.cpp:136
const std::string & name() const
bool doNormalizeTy
Definition: Args.hpp:140
CCT::Tree * cct() const