-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathprof.cpp
71 lines (57 loc) · 1.31 KB
/
prof.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#if !defined(__EMSCRIPTEN__)
#include <iostream>
#include <cstdio>
#include <numeric>
#include <SDL2/SDL.h>
#include <fstream>
#include <vector>
#include <algorithm>
#include <thread>
#include <mutex>
#include <chrono>
#endif
#include "types.hpp"
#include "cpu.hpp"
namespace PROF {
u32 hits[ sizeof(MMU::flash)>>1 ];
const u32 hitCount = sizeof(hits)/sizeof(hits[0]);
bool dumpOnExit = true;
bool hitCaller;
#if !defined(__EMSCRIPTEN__)
struct Sample{
u32 addr;
u32 count;
};
static void dump() {
std::cout << "Preparing samples..." << std::endl;
u32 maxCount = 0;
std::vector<Sample> samples;
for( u32 i=0; i<hitCount; ++i ){
if( !hits[i] )
continue;
if( hits[i] > maxCount )
maxCount = hits[i];
samples.push_back(Sample{ i<<1, hits[i] });
}
std::sort(
samples.begin(),
samples.end(),
[]( const Sample &l, const Sample &r ) -> bool {
return r.count < l.count;
});
std::ofstream out("hotspots.log");
for( u32 i=0, max = std::min<u32>(samples.size(), 128); i<max; ++i ){
out << std::hex << samples[i].addr << " " << samples[i].count << std::endl;
}
}
#endif
void init( bool _hitCaller ){
#if !defined(__EMSCRIPTEN__)
hitCaller = _hitCaller;
atexit([](){
if( dumpOnExit )
dump();
});
#endif
}
}