HPCToolkit
Args.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 using std::cerr;
64 using std::endl;
65 
66 #include <string>
67 using std::string;
68 
69 //*************************** User Include Files ****************************
70 
71 #include <include/hpctoolkit-config.h>
72 #include <include/gcc-attr.h>
73 
74 #include "Args.hpp"
75 
76 #include <lib/analysis/Util.hpp>
77 
79 #include <lib/support/Trace.hpp>
80 #include <lib/support/StrUtil.hpp>
81 
82 //*************************** Forward Declarations **************************
83 
84 #define ARG_Throw(streamArgs) DIAG_ThrowX(Args::Exception, streamArgs)
85 
86 // Cf. DIAG_Die.
87 #define ARG_ERROR(streamArgs) \
88  { std::ostringstream WeIrDnAmE; \
89  WeIrDnAmE << streamArgs /*<< std::ends*/; \
90  printError(std::cerr, WeIrDnAmE.str()); \
91  exit(1); }
92 
93 //***************************************************************************
94 
95 static const char* version_info = HPCTOOLKIT_VERSION_STRING;
96 
97 static const char* usage_summary =
98 "profile-file [profile-file]*\n";
99 
100 static const char* usage_details =
101  "hpcproftt generates textual dumps of call path profiles\n"
102  "recorded by hpcrun. The profile list may contain one or\n"
103  "more call path profiles.\n"
104  "\n"
105  "Options:\n"
106  " -V, --version Print version information.\n"
107  " -h, --help Print this help.\n";
108 
109 #define CLP CmdLineParser
110 #define CLP_SEPARATOR "!!!"
111 
112 // Note: Changing the option name requires changing the name in Parse()
114  // General
115  { 'V', "version", CLP::ARG_NONE, CLP::DUPOPT_CLOB, NULL,
116  NULL },
117  { 'h', "help", CLP::ARG_NONE, CLP::DUPOPT_CLOB, NULL,
118  NULL },
119  CmdLineParser_OptArgDesc_NULL_MACRO // SGI's compiler requires this version
120 };
121 
122 #undef CLP
123 
124 //***************************************************************************
125 // Args
126 //***************************************************************************
127 
128 Args::Args()
129 {
130  Ctor();
131 }
132 
133 
134 Args::Args(int argc, const char* const argv[])
135 {
136  Ctor();
137  parse(argc, argv);
138 }
139 
140 
141 void
142 Args::Ctor()
143 {
144  obj_metricsAsPercents = true;
145  obj_showSourceCode = false;
146  obj_procThreshold = 1;
147 
149 
150 
151  // Analysis::Args
154 
155  out_db_experiment = "";
156  db_dir = "";
157  db_copySrcFiles = false;
158 
159  out_txt = "-";
161  txt_srcAnnotation = false;
162 }
163 
164 
165 Args::~Args()
166 {
167 }
168 
169 
170 void
171 Args::printVersion(std::ostream& os) const
172 {
173  os << getCmd() << ": " << version_info << endl;
174 }
175 
176 
177 void
178 Args::printUsage(std::ostream& os) const
179 {
180  os << "Usage: \n"
181  << " " << getCmd() << " " << usage_summary << endl
182  << usage_details << endl;
183 }
184 
185 
186 void
187 Args::printError(std::ostream& os, const char* msg) /*const*/
188 {
189  os << getCmd() << ": " << msg << endl
190  << "Try '" << getCmd() << " --help' for more information." << endl;
191 }
192 
193 void
194 Args::printError(std::ostream& os, const std::string& msg) /*const*/
195 {
196  printError(os, msg.c_str());
197 }
198 
199 
200 const std::string&
201 Args::getCmd() /*const*/
202 {
203  // avoid error messages with: .../bin/hpcproftt-bin
204  static string cmd = "hpcproftt";
205  return cmd; // parser.getCmd();
206 }
207 
208 
209 void
210 Args::parse(int argc, const char* const argv[])
211 {
212  try {
213  // -------------------------------------------------------
214  // Parse the command line
215  // -------------------------------------------------------
216  parser.parse(optArgs, argc, argv);
217 
218  // -------------------------------------------------------
219  // Sift through results, checking for semantic errors
220  // -------------------------------------------------------
221 
222  // Special options that should be checked first
223  if (parser.isOpt("help")) {
224  printUsage(std::cerr);
225  exit(1);
226  }
227  if (parser.isOpt("version")) {
228  printVersion(std::cerr);
229  exit(1);
230  }
231 
232  // FIXME: sanity check that options correspond to mode
233 
234  // Check for required arguments
235  uint numArgs = parser.getNumArgs();
236  if ( !(numArgs >= 1) ) {
237  ARG_ERROR("Incorrect number of arguments!");
238  }
239 
240  profileFiles.resize(numArgs);
241  for (uint i = 0; i < numArgs; ++i) {
242  profileFiles[i] = parser.getArg(i);
243  }
244  }
245  catch (const CmdLineParser::ParseError& x) {
246  ARG_ERROR(x.what());
247  }
248  catch (const CmdLineParser::Exception& x) {
249  DIAG_EMsg(x.message());
250  exit(1);
251  }
252  catch (const Args::Exception& x) {
253  ARG_ERROR(x.what());
254  }
255 }
256 
257 
258 // Cf. lib/analysis/ArgsHPCProf::parseArg_metric()
259 void
260 Args::parseArg_metric(Args* args, const string& value, const char* errTag)
261 {
262  if (value == "thread") {
263  if (args) {
266  }
267  }
268  else if (value == "sum") {
269  if (args) {
274  }
275  }
276  else if (value == "stats") {
277  if (args) {
282  }
283  }
284  else {
285  ARG_Throw(errTag << ": Unexpected value received: '" << value << "'");
286  }
287 }
288 
289 
290 void
291 Args::dump(std::ostream& os) const
292 {
293  os << "Args.cmd= " << getCmd() << endl;
295 }
296 
Definition: Args.hpp:79
static void parseArg_metric(Args *args, const std::string &opts, const char *errTag)
Definition: Args.cpp:260
~Args()
Definition: Args.cpp:173
bool isOpt(const char swShort) const
std::string db_dir
Definition: Args.hpp:199
void printUsage(std::ostream &os) const
Definition: Args.cpp:186
uint prof_metrics
Definition: Args.hpp:176
#define DIAG_EMsg(...)
Definition: diagnostics.h:251
virtual const std::string & what() const
Definition: Exception.hpp:126
bool txt_srcAnnotation
Definition: Args.hpp:233
#define ARG_ERROR(streamArgs)
Definition: Args.cpp:87
static void MetricFlg_clear(uint &flags, MetricFlg x)
Definition: Args.hpp:162
uint64_t obj_procThreshold
Definition: Args.hpp:140
void Ctor()
Definition: Args.cpp:162
bool profflat_computeFinalMetricValues
Definition: Args.hpp:182
void parse(const OptArgDesc *optArgDescs, int argc, const char *const argv[])
CmdLineParser parser
Definition: Args.hpp:120
bool obj_showSourceCode
Definition: Args.hpp:143
static const char * version_info
Definition: Args.cpp:95
unsigned int getNumArgs() const
void printVersion(std::ostream &os) const
Definition: Args.cpp:179
void parse(int argc, const char *const argv[])
Definition: Args.cpp:208
std::string out_db_experiment
Definition: Args.hpp:196
static const char * usage_summary
Definition: Args.cpp:97
virtual void dump(std::ostream &os=std::cerr) const
Definition: Args.cpp:144
static const char * usage_details
Definition: Args.cpp:100
#define ARG_Throw(streamArgs)
Definition: Args.cpp:84
virtual std::string message() const
Definition: Exception.hpp:134
exit
Definition: names.cpp:1
unsigned int uint
Definition: uint.h:124
std::string out_txt
Definition: Args.hpp:213
Args()
Definition: Args.cpp:150
#define CmdLineParser_OptArgDesc_NULL_MACRO
std::vector< std::string > profileFiles
Definition: Args.hpp:138
void printError(std::ostream &os, const char *msg) const
Definition: Args.cpp:194
void Diagnostics_SetDiagnosticFilterLevel(int lvl)
Definition: diagnostics.cpp:80
static CmdLineParser::OptArgDesc optArgs[]
Definition: Args.hpp:119
const std::string & getArg(unsigned int i) const
#define NULL
Definition: ElfHelper.cpp:85
bool db_copySrcFiles
Definition: Args.hpp:200
const std::string & getCmd() const
Definition: Args.hpp:102
bool obj_metricsAsPercents
Definition: Args.hpp:142
int txt_summary
Definition: Args.hpp:231
void dump(std::ostream &os=std::cerr) const
Definition: Args.cpp:296
static void MetricFlg_set(uint &flags, MetricFlg x)
Definition: Args.hpp:158