Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

[0d0e60]: pp / opreport_options.cpp Maximize Restore History

Download this file

opreport_options.cpp    216 lines (178 with data), 5.5 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
/**
* @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 "cverb.h"
using namespace std;
profile_classes classes;
namespace options {
demangle_type demangle = dmt_normal;
bool symbols;
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;
}
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(demangle_option, "demangle", '\0',
"demangle GNU C++ symbol names (default normal)",
"none|normal|smart"),
popt::option(outfile, "output-file", 'o',
"output to the given filename", "file"),
// PP:5
popt::option(options::symbols, "symbols", 'l',
"list all symbols"),
popt::option(options::debug_info, "debug-info", 'g',
"add source file and line number to output"),
popt::option(options::details, "details", 'd',
"output detailed samples for each symbol"),
popt::option(options::exclude_dependent, "exclude-dependent", 'x',
"exclude libs, kernel, and module samples for applications"),
popt::option(sort, "sort", 's',
"sort by", "sample,image,app-name,symbol,debug,vma"),
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(mergespec, "merge", 'm',
"comma separated list", "cpu,lib,tid,tgid,unitmask,all"),
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", 'c',
"percentage field show accumulated count"),
popt::option(options::reverse_sort, "reverse-sort", 'r',
"use reverse sort"),
popt::option(options::global_percent, "global-percent", '\0',
"percentage are not relative to symbol count or image "
"count but total sample count"),
};
// FIXME: separate file if reused
void handle_sort_option()
{
if (sort.empty()) {
// PP:5.14 sort default to sample
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);
}
}
// FIXME: separate file if reused
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()
{
using namespace options;
bool do_exit = false;
if (!symbols) {
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) {
cerr << "--global-percent is meaningless "
<< "with --symbols and without --details" << endl;
do_exit = true;
}
if (do_exit)
exit(EXIT_FAILURE);
}
} // namespace anon
void handle_options(vector<string> const & non_options)
{
using namespace options;
if (details) {
symbols = true;
show_address = true;
}
handle_sort_option();
merge_by = handle_merge_option(mergespec, true, exclude_dependent);
handle_output_file();
demangle = handle_demangle_option(demangle_option);
check_options();
symbol_filter = string_filter(include_symbols, exclude_symbols);
profile_spec const spec =
profile_spec::create(non_options, extra_found_images);
list<string> sample_files = spec.generate_file_list(exclude_dependent, true);
cverb << "Matched sample files: " << sample_files.size() << endl;
copy(sample_files.begin(), sample_files.end(),
ostream_iterator<string>(cverb, "\n"));
classes = arrange_profiles(sample_files, merge_by);
cverb << "profile_classes:\n" << classes << endl;
if (classes.v.empty()) {
cerr << "error: no sample files found: profile specification "
"too strict ?" << endl;
exit(EXIT_FAILURE);
}
}