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 
64 #include <string>
65 using std::string;
66 
67 #include <limits.h> /* for 'PATH_MAX' */
68 
69 #include <unistd.h> /* for getcwd() */
70 
71 //*************************** User Include Files ****************************
72 
73 #include "Args.hpp"
74 
76 #include <lib/support/FileUtil.hpp>
77 #include <lib/support/realpath.h>
78 
79 
80 //*************************** Forward Declarations **************************
81 
82 //***************************************************************************
83 // Args
84 //***************************************************************************
85 
86 namespace Analysis {
87 
88 
90 {
91  Ctor();
92 }
93 
94 
95 void
97 {
98  // -------------------------------------------------------
99  // Correlation arguments
100  // -------------------------------------------------------
101 
102  doNormalizeTy = true;
103 
105 
107 
108  // -------------------------------------------------------
109  // Output arguments
110  // -------------------------------------------------------
111 
113  out_db_csv = "";
115  db_copySrcFiles = true;
116  out_db_config = "";
117  db_makeMetricDB = true;
118  db_addStructId = false;
119 
122  txt_srcAnnotation = false;
123 
124  // laks: disable redundancy elimination by default
125  remove_redundancy = false;
126 }
127 
128 
130 {
131 }
132 
133 
134 string
136 {
137  std::ostringstream os;
138  dump(os);
139  return os.str();
140 }
141 
142 
143 void
144 Args::dump(std::ostream& os) const
145 {
146  os << "db_dir= " << db_dir << std::endl;
147  os << "out_db_experiment= " << out_db_experiment << std::endl;
148  os << "out_db_csv= " << out_db_csv << std::endl;
149  os << "out_txt= " << out_txt << std::endl;
150 }
151 
152 
153 void
154 Args::ddump() const
155 {
156  dump(std::cerr);
157 }
158 
159 
160 } // namespace Analysis
161 
162 
163 //***************************************************************************
164 
165 namespace Analysis {
166 
167 
168 void
170 {
171  char cwd[PATH_MAX+1];
172  getcwd(cwd, PATH_MAX);
173 
174  for (PathTupleVec::iterator it = searchPathTpls.begin();
175  it != searchPathTpls.end(); /* */) {
176  string& x = it->first; // current path
177  PathTupleVec::iterator x_it = it;
178 
179  ++it; // advance iterator
180 
181  if (chdir(x.c_str()) == 0) {
182  char norm_x[PATH_MAX+1];
183  getcwd(norm_x, PATH_MAX);
184  x = norm_x; // replace x with norm_x
185  }
186  else {
187  DIAG_Msg(1, "Discarding search path: " << x);
188  searchPathTpls.erase(x_it);
189  }
190  chdir(cwd);
191  }
192 
193  if (searchPathTpls.size() > 0) {
194  DIAG_Msg(2, "search paths:");
195  for (uint i = 0; i < searchPathTpls.size(); ++i) {
196  DIAG_Msg(2, " " << searchPathTpls[i].first);
197  }
198  }
199 }
200 
201 
202 void
204 {
205  // prepare output directory (N.B.: chooses a unique name!)
206  string dir = db_dir; // make copy
207  std::pair<string, bool> ret =
208  FileUtil::mkdirUnique(dir); // N.B.: exits on failure...
209  db_dir = RealPath(ret.first.c_str());
210 }
211 
212 
213 std::string
215 {
216  string path = ".";
217  for (uint i = 0; i < searchPathTpls.size(); ++i) {
218  path += string(":") + searchPathTpls[i].first;
219  }
220  return path;
221 }
222 
223 
224 } // namespace Analysis
225 
226 
227 //***************************************************************************
228 
229 
void makeDatabaseDir()
Definition: Args.cpp:203
#define Analysis_DB_DIR_nm
Definition: Args.hpp:192
PathTupleVec searchPathTpls
Definition: Args.hpp:125
std::string db_dir
Definition: Args.hpp:199
uint prof_metrics
Definition: Args.hpp:176
bool remove_redundancy
Definition: Args.hpp:241
void Ctor()
Definition: Args.cpp:96
bool txt_srcAnnotation
Definition: Args.hpp:233
bool profflat_computeFinalMetricValues
Definition: Args.hpp:182
virtual std::string toString() const
Definition: Args.cpp:135
bool db_addStructId
Definition: Args.hpp:205
std::string out_db_experiment
Definition: Args.hpp:196
virtual void dump(std::ostream &os=std::cerr) const
Definition: Args.cpp:144
unsigned int uint
Definition: uint.h:124
bool db_makeMetricDB
Definition: Args.hpp:204
std::string out_txt
Definition: Args.hpp:213
void ddump() const
Definition: Args.cpp:154
std::string searchPathStr() const
Definition: Args.cpp:214
std::string out_db_config
Definition: Args.hpp:202
#define Analysis_OUT_DB_EXPERIMENT
Definition: Args.hpp:188
std::pair< string, bool > mkdirUnique(const char *dirnm)
Definition: FileUtil.cpp:364
#define DIAG_Msg(level,...)
Definition: diagnostics.h:241
const char * RealPath(const char *nm)
Definition: realpath.c:69
#define Analysis_OUT_TXT
Definition: Args.hpp:211
void normalizeSearchPaths()
Definition: Args.cpp:169
bool db_copySrcFiles
Definition: Args.hpp:200
int txt_summary
Definition: Args.hpp:231
virtual ~Args()
Definition: Args.cpp:129
#define Analysis_DB_DIR_pfx
Definition: Args.hpp:191
bool doNormalizeTy
Definition: Args.hpp:140
std::string out_db_csv
Definition: Args.hpp:197