-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpginfo.cpp
53 lines (45 loc) · 1.59 KB
/
pginfo.cpp
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
#include "Profile.h"
#include <fstream>
#include <iostream>
#include <cerrno>
#include <cstdlib>
#include <cstring>
int main(int argc, char** argv)
{
if (argc < 3)
{
std::cout << "Usage: " << program_invocation_short_name << " {flat|callgraph} filename.pgdata\n";
exit(EXIT_SUCCESS);
}
ProfileMode mode;
if (strcmp(argv[1], "flat") == 0)
mode = ProfileMode::Flat;
else if (strcmp(argv[1], "callgraph") == 0)
mode = ProfileMode::CallGraph;
else
{
std::cerr << "Invalid mode '" << argv[1] <<"'\n";
exit(EXIT_FAILURE);
}
std::fstream input(argv[2], std::ios_base::in);
if (!input)
{
std::cerr << "Error reading input file " << argv[1] << '\n';
exit(EXIT_FAILURE);
}
Profile profile;
profile.load(input, mode);
input.close();
size_t entryCount = 0;
for (const auto& memoryObject: profile.memoryObjects())
entryCount += memoryObject.second.entries().size();
std::cout << "memory objects: " << profile.memoryObjects().size() << "\nentries: " << entryCount
<< "\n\nmmap events: " << profile.mmapEventCount() << "\ngood sample events: " << profile.goodSamplesCount()
<< "\nnon-user sample events: " << profile.nonUserSamples()
<< "\nunmapped sample events: " << profile.unmappedSamples() << "\ntotal sample events: "
<< profile.goodSamplesCount() + profile.nonUserSamples() + profile.unmappedSamples() << "\ntotal events: "
<< profile.goodSamplesCount() + profile.goodSamplesCount() + profile.nonUserSamples() +
profile.unmappedSamples()
<< '\n';
return 0;
}