[6893b5]: pp / opreport_options.cpp  Maximize  Restore  History

Download this file

346 lines (286 with data), 8.9 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
/**
* @file opreport_options.cpp
* Options for opreport tool
*
* @remark Copyright 2003 OProfile authors
* @remark Read the file COPYING
*
* @author John Levon
* @author Philippe Elie
*/
#include <vector>
#include <list>
#include <iostream>
#include <algorithm>
#include <iterator>
#include <fstream>
#include "profile_spec.h"
#include "arrange_profiles.h"
#include "opreport_options.h"
#include "popt_options.h"
#include "string_filter.h"
#include "file_manip.h"
#include "xml_output.h"
#include "xml_utils.h"
#include "cverb.h"
#include "op_exception.h"
using namespace std;
profile_classes classes;
profile_classes classes2;
namespace options {
demangle_type demangle = dmt_normal;
bool symbols;
bool callgraph;
bool debug_info;
bool details;
bool exclude_dependent;
string_filter symbol_filter;
sort_options sort_by;
merge_option merge_by;
bool show_header = true;
bool long_filenames;
bool show_address;
bool accumulated;
bool reverse_sort;
bool global_percent;
bool xml;
string xml_options;
}
namespace {
string outfile;
vector<string> mergespec;
vector<string> sort;
vector<string> exclude_symbols;
vector<string> include_symbols;
string demangle_option = "normal";
popt::option options_array[] = {
popt::option(options::callgraph, "callgraph", 'c',
"show call graph"),
popt::option(options::details, "details", 'd',
"output detailed samples for each symbol"),
popt::option(options::symbols, "symbols", 'l',
"list all symbols"),
popt::option(outfile, "output-file", 'o',
"output to the given filename", "file"),
popt::option(sort, "sort", 's',
"sort by", "sample,image,app-name,symbol,debug,vma"),
popt::option(options::reverse_sort, "reverse-sort", 'r',
"use reverse sort"),
popt::option(mergespec, "merge", 'm',
"comma separated list", "cpu,lib,tid,tgid,unitmask,all"),
popt::option(options::exclude_dependent, "exclude-dependent", 'x',
"exclude libs, kernel, and module samples for applications"),
popt::option(exclude_symbols, "exclude-symbols", 'e',
"exclude these comma separated symbols", "symbols"),
popt::option(include_symbols, "include-symbols", 'i',
"include these comma separated symbols", "symbols"),
popt::option(options::threshold_opt, "threshold", 't',
"minimum percentage needed to produce output",
"percent"),
popt::option(demangle_option, "demangle", 'D',
"demangle GNU C++ symbol names (default normal)",
"none|normal|smart"),
// PP:5
popt::option(options::debug_info, "debug-info", 'g',
"add source file and line number to output"),
popt::option(options::show_header, "no-header", 'n',
"remove all headers from output"),
popt::option(options::show_address, "show-address", 'w',
"show VMA address of each symbol"),
popt::option(options::long_filenames, "long-filenames", 'f',
"show the full path of filenames"),
popt::option(options::accumulated, "accumulated", 'a',
"percentage field show accumulated count"),
popt::option(options::global_percent, "global-percent", '%',
"percentage are not relative to symbol count or image "
"count but total sample count"),
popt::option(options::xml, "xml", 'X',
"XML output"),
};
void handle_sort_option()
{
if (options::xml && !sort.empty()) {
cerr << "warning: sort options ignored because they "
<< "are incompatible with --xml" << endl;
// don't allow any other sorting, except the default below,
// to mess up symbol traversal for XML
sort.clear();
}
if (sort.empty() || options::xml) {
// PP:5.14 sort default to sample
if (options::xml) {
// implicitly sort by app-name,image so that in the
// symbol traversal all library module symbols are
// grouped together with their application
sort.push_back("app-name");
sort.push_back("image");
} else
sort.push_back("sample");
}
vector<string>::const_iterator cit = sort.begin();
vector<string>::const_iterator end = sort.end();
for (; cit != end; ++cit)
options::sort_by.add_sort_option(*cit);
}
void handle_output_file()
{
if (outfile.empty())
return;
static ofstream os(outfile.c_str());
if (!os) {
cerr << "Couldn't open \"" << outfile
<< "\" for writing." << endl;
exit(EXIT_FAILURE);
}
cout.rdbuf(os.rdbuf());
}
/// Check incompatible or meaningless options.
void check_options(bool diff)
{
using namespace options;
bool do_exit = false;
if (callgraph) {
symbols = true;
if (details) {
cerr << "--callgraph is incompatible with --details" << endl;
do_exit = true;
}
if (diff) {
cerr << "differential profiles are incompatible with --callgraph" << endl;
do_exit = true;
}
}
if (xml) {
if (accumulated) {
cerr << "--accumulated is incompatible with --xml" << endl;
do_exit = true;
}
if (global_percent) {
cerr << "--global_percent is incompatible with --xml" << endl;
do_exit = true;
}
}
if (details && diff) {
cerr << "differential profiles are incompatible with --details" << endl;
do_exit = true;
}
if (!symbols) {
if (diff) {
cerr << "different profiles are meaningless "
"without --symbols" << endl;
do_exit = true;
}
if (show_address) {
cerr << "--show-address is meaningless "
"without --symbols" << endl;
do_exit = true;
}
if (debug_info || accumulated) {
cerr << "--debug-info and --accumulated are "
<< "meaningless without --symbols" << endl;
do_exit = true;
}
if (!exclude_symbols.empty() || !include_symbols.empty()) {
cerr << "--exclude-symbols and --include-symbols are "
<< "meaningless without --symbols" << endl;
do_exit = true;
}
if (find(sort_by.options.begin(), sort_by.options.end(),
sort_options::vma) != sort_by.options.end()) {
cerr << "--sort=vma is "
<< "meaningless without --symbols" << endl;
do_exit = true;
}
}
if (global_percent && symbols && !(details || callgraph)) {
cerr << "--global-percent is meaningless with --symbols "
"and without --details or --callgraph" << endl;
do_exit = true;
}
if (do_exit)
exit(EXIT_FAILURE);
}
/// process a spec into classes
void process_spec(profile_classes & classes, list<string> const & spec)
{
using namespace options;
copy(spec.begin(), spec.end(),
ostream_iterator<string>(cverb << vsfile, " "));
cverb << vsfile << "\n\n";
profile_spec const pspec =
profile_spec::create(spec, options::image_path,
options::root_path);
list<string> sample_files;
again:
try {
sample_files = pspec.generate_file_list(exclude_dependent,
!options::callgraph);
} catch (op_no_samples_exception e) {
if (try_another_session_dir())
goto again;
else
throw op_fatal_error(e.what());
}
cverb << vsfile << "Archive: " << pspec.get_archive_path() << endl;
cverb << vsfile << "Matched sample files: " << sample_files.size()
<< endl;
copy(sample_files.begin(), sample_files.end(),
ostream_iterator<string>(cverb << vsfile, "\n"));
classes = arrange_profiles(sample_files, merge_by,
pspec.extra_found_images);
cverb << vsfile << "profile_classes:\n" << classes << endl;
if (classes.v.empty()) {
cerr << "error: no sample files found: profile specification "
"too strict ?" << endl;
exit(EXIT_FAILURE);
}
}
} // namespace anon
void handle_options(options::spec const & spec)
{
using namespace options;
if (details) {
symbols = true;
show_address = true;
}
if (options::xml) {
if (spec.common.size() != 0)
xml_utils::add_option(SESSION, spec.common);
if (debug_info)
xml_utils::add_option(DEBUG_INFO, true);
if (details)
xml_utils::add_option(DETAILS, true);
if (!image_path.empty())
xml_utils::add_option(IMAGE_PATH, image_path);
if (!mergespec.empty())
xml_utils::add_option(MERGE, mergespec);
if (exclude_dependent)
xml_utils::add_option(EXCLUDE_DEPENDENT, true);
if (!exclude_symbols.empty())
xml_utils::add_option(EXCLUDE_SYMBOLS, exclude_symbols);
if (!include_symbols.empty())
xml_utils::add_option(INCLUDE_SYMBOLS, include_symbols);
}
handle_sort_option();
merge_by = handle_merge_option(mergespec, true, exclude_dependent);
handle_output_file();
demangle = handle_demangle_option(demangle_option);
check_options(spec.first.size());
symbol_filter = string_filter(include_symbols, exclude_symbols);
if (!spec.first.size()) {
process_spec(classes, spec.common);
} else {
if (options::xml) {
cerr << "differential profiles are incompatible with --xml" << endl;
exit(EXIT_FAILURE);
}
cverb << vsfile << "profile spec 1:" << endl;
process_spec(classes, spec.first);
cverb << vsfile << "profile spec 2:" << endl;
process_spec(classes2, spec.second);
if (!classes.matches(classes2)) {
cerr << "profile classes are incompatible" << endl;
exit(EXIT_FAILURE);
}
}
}