forked from factor/factor
/
sampling_profiler.cpp
62 lines (50 loc) · 1.3 KB
/
sampling_profiler.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
#include "master.hpp"
namespace factor
{
void factor_vm::record_sample()
{
cell recorded_sample_count;
cell recorded_gc_sample_count;
recorded_sample_count = safepoint_sample_count;
recorded_gc_sample_count = safepoint_gc_sample_count;
if (recorded_sample_count == 0 && recorded_gc_sample_count == 0)
return;
/* Another sample signal could be raised while we record these counts */
FACTOR_ATOMIC_SUB(&safepoint_sample_count, recorded_sample_count);
FACTOR_ATOMIC_SUB(&safepoint_gc_sample_count, recorded_gc_sample_count);
samples.push_back(profiling_sample(
recorded_sample_count,
recorded_gc_sample_count,
ctx,
capture_callstack(ctx)
));
}
void factor_vm::set_sampling_profiler(bool sampling_p)
{
if (sampling_p == sampling_profiler_p)
return;
if (sampling_p)
start_sampling_profiler();
else
end_sampling_profiler();
}
void factor_vm::start_sampling_profiler()
{
safepoint_sample_count = 0;
safepoint_gc_sample_count = 0;
samples.clear();
samples.reserve(10*FACTOR_PROFILE_SAMPLES_PER_SECOND);
sampling_profiler_p = true;
start_sampling_profiler_timer();
}
void factor_vm::end_sampling_profiler()
{
end_sampling_profiler_timer();
record_sample();
sampling_profiler_p = false;
}
void factor_vm::primitive_sampling_profiler()
{
set_sampling_profiler(to_boolean(ctx->pop()));
}
}