forked from factor/factor
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
vm: groundwork for sampling profiler
Set up the state necessary to collect samples. We still need to add GC support for walking the sample set, and the compiler needs to register GC roots before safepoints as well. We also need primitives to expose the data to Factor for reporting.
- Loading branch information
Showing
11 changed files
with
186 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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())); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
namespace factor | ||
{ | ||
|
||
#define FACTOR_PROFILE_SAMPLES_PER_SECOND 1000 | ||
|
||
struct profiling_sample | ||
{ | ||
// Number of samples taken before the safepoint that recorded the sample | ||
cell sample_count; | ||
// Number of samples taken during GC | ||
cell gc_sample_count; | ||
// Active context during sample | ||
context *ctx; | ||
// The callstack at safepoint time | ||
cell callstack; | ||
|
||
profiling_sample(cell sample_count, | ||
cell gc_sample_count, | ||
context *ctx, | ||
cell callstack) | ||
: | ||
sample_count(sample_count), | ||
gc_sample_count(gc_sample_count), | ||
ctx(ctx), | ||
callstack(callstack) | ||
{ | ||
} | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters