-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBundleStatsMain.cc
72 lines (56 loc) · 2.03 KB
/
BundleStatsMain.cc
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
#include <cassert>
#include <iostream>
#include <map>
#include "MemoryTrace.hh"
#define EXIT_INVALID_ARGUMENTS 1
#define EXIT_INVALID_TRACE 2
namespace {
struct BundleStats {
int num_components { 1 }; // the number of contiguous chunks
uint64_t address_delta; // the difference between the highest and the lowest address
};
// Required to use the struct as a map key
bool operator<(const BundleStats& lhs, const BundleStats& rhs) {
return lhs.num_components < rhs.num_components ||
(lhs.num_components == rhs.num_components &&
lhs.address_delta < rhs.address_delta);
}
} // namespace
int main(int argc, char* argv[]) {
if (argc < 2) {
std::cout << "Usage: bundle-stats TRACE-FILE\n";
std::exit(EXIT_INVALID_ARGUMENTS);
}
const std::string trace_fname { argv[1] };
TraceFileType encoding;
try {
encoding = MemoryTraceTools::guess_file_type(trace_fname);
} catch (const std::invalid_argument& e) {
std::exit(EXIT_INVALID_TRACE);
}
MemoryTrace trace { trace_fname, encoding };
std::map<BundleStats, uint64_t> bundles;
const auto requests = trace.getRequests();
for (size_t i = 0; i < requests.size(); i++) {
const auto& bundle_start = requests[i];
if (!bundle_start.is_bundle() || bundle_start.bundle_kind == 7) continue;
assert(bundle_start.is_bundle_start() &&
"First request in a bundle not a bundle start");
BundleStats this_bundle;
do {
i++;
this_bundle.num_components++;
} while (!requests[i].is_bundle_end());
const auto& bundle_end = requests[i];
const auto range_start = std::min(bundle_start.address, bundle_end.address);
const auto range_end = std::max(bundle_start.address, bundle_end.address);
this_bundle.address_delta =
range_end - range_start + bundle_end.size;
bundles[this_bundle]++;
}
std::cout << "components,delta,count\n";
for (const auto& [bundle, count] : bundles)
std::cout << bundle.num_components << ',' << bundle.address_delta << ',' << count
<< '\n';
return 0;
}