[0d0e60]: libpp / arrange_profiles.h Maximize Restore History

Download this file

arrange_profiles.h    226 lines (187 with data), 6.1 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
/**
* @file arrange_profiles.h
* Classify and process a list of candidate sample files
* into merged sets and classes.
*
* @remark Copyright 2003 OProfile authors
* @remark Read the file COPYING
*
* @author John Levon
*/
#ifndef ARRANGE_PROFILES_H
#define ARRANGE_PROFILES_H
#include <string>
#include <list>
#include <vector>
#include <iosfwd>
#include "image_errors.h"
/**
* store merging options options used to classify profiles
*/
struct merge_option {
bool cpu;
bool lib;
bool tid;
bool tgid;
bool unitmask;
};
/**
* This describes which parameters are set for each
* equivalence class.
*/
struct profile_template {
std::string event;
std::string count;
std::string unitmask;
std::string tgid;
std::string tid;
std::string cpu;
};
/**
* A samples filename + its associated callgraph sample filename.
*/
struct profile_sample_files {
/**
* This member can be empty since it is possible to get callgraph
* w/o any samples to the binary. e.g an application which defer all
* works to shared library but if arrange_profiles receive a sample
* file list filtered from cg file sample_filename can't be empty
*/
std::string sample_filename;
/**
* List of callgraph sample filename. If the {dep} part of
* cg_filename != {cg} part it's a cross binary samples file.
*/
std::list<std::string> cg_files;
};
/**
* A number of profiles files that are all dependent on
* the same main (application) profile, for the same
* dependent image.
*/
struct profile_dep_set {
/// which dependent image is this set for
std::string lib_image;
/// the actual sample files optionnaly including callgraph sample files
std::list<profile_sample_files> files;
};
/**
* A number of profile files all for the same binary with the same
* profile specification (after merging). Includes the set of dependent
* profile files, if any.
*
* For example, we could have image == "/bin/bash", where files
* contains all profiles against /bin/bash, and deps contains
* the sample file list for /lib/libc.so, /lib/ld.so etc.
*/
struct profile_set {
std::string image;
/// the actual sample files for the main image and the asociated
/// callgraph files
std::list<profile_sample_files> files;
/// all profile files dependent on the main image
std::list<profile_dep_set> deps;
};
/**
* A class collection of profiles. This is an equivalence class and
* will correspond to columnar output of opreport.
*/
struct profile_class {
std::list<profile_set> profiles;
/// human-readable column name
std::string name;
/// human-readable long name
std::string longname;
/// merging matches against this
profile_template ptemplate;
};
struct profile_classes {
/**
* This is only set if we're not classifying on event/count
* anyway - if we're classifying on event/count, then we'll
* already output the details of each class's event/count.
*
* It's only used when classifying by CPU, tgid etc. so the
* user can still see what perfctr event was used.
*/
std::string event;
/// CPU info
std::string cpuinfo;
/// the actual classes
std::vector<profile_class> v;
};
std::ostream & operator<<(std::ostream &, profile_sample_files const &);
std::ostream & operator<<(std::ostream &, profile_dep_set const &);
std::ostream & operator<<(std::ostream &, profile_set const &);
std::ostream & operator<<(std::ostream &, profile_template const &);
std::ostream & operator<<(std::ostream &, profile_class const &);
std::ostream & operator<<(std::ostream &, profile_classes const &);
/**
* Take a list of sample filenames, and process them into a set of
* classes containing profile_sets. Merging is done at this stage
* as well as attaching dependent profiles to the main image.
*
* The classes correspond to the columns you'll get in opreport:
* this can be a number of events, or different CPUs, etc.
*/
profile_classes const
arrange_profiles(std::list<std::string> const & files,
merge_option const & merge_by);
/**
* A set of sample files where the image binary to open
* are all the same.
*/
struct image_set {
/// this is main app image, *not* necessarily
/// the one we need to open
std::string app_image;
/// the sample files
std::list<profile_sample_files> files;
};
typedef std::list<image_set> image_group_set;
/**
* All sample files where the binary image to open is
* the same.
*
* This is the "inverse" to some degree of profile_set.
* For example, here we might have image = "/lib/libc.so",
* with groups being the profile classifications
* tgid:404, tgid:301, etc.
*
* Within each group there's a number of image_sets.
* All the sample files listed within the image_sets
* are still for /lib/libc.so, but they may have
* different app_image values, e.g. /bin/bash.
* We need to keep track of the app_image values to
* make opreport give the right info in the "app"
* column.
*/
struct inverted_profile {
inverted_profile() : error(image_ok) {}
/// the image to open
std::string image;
/// an error found in reading the image
mutable image_error error;
/// all sample files with data for the above image
std::vector<image_group_set> groups;
};
class extra_images;
/**
* Invert the profile set. For opreport -l, opannotate etc.,
* processing the profile_classes directly is slow, because
* we end up opening BFDs multiple times (for each class,
* dependent images etc.). This function returns an inverted
* set of sample files, where the primary sort is on the binary
* image to open.
*
* Thus each element in the returned list is for exactly one
* binary file that we're going to bfd_openr(). Attached to that
* is the actual sample files we need to process for that binary
* file. In order to get the output right, these have to be
* marked with the profile class they're from (hence the groups
* vector), and the app image that owned the sample file, if
* applicable (hence image_set).
*/
std::list<inverted_profile> const
invert_profiles(profile_classes const & classes, extra_images const & extra);
#endif /* !ARRANGE_PROFILES_H */