VM: trying to simplify record_sample and the profiling_sample constructor

char-rename
Björn Lindqvist 2016-08-14 03:12:36 +02:00
parent f0834e7b36
commit 2f6f69eb5b
3 changed files with 18 additions and 19 deletions

View File

@ -25,22 +25,20 @@ void profiling_sample_count::clear() volatile {
atomic::fence(); atomic::fence();
} }
profiling_sample::profiling_sample(factor_vm* vm, bool prolog_p, profiling_sample::profiling_sample(profiling_sample_count const& counts, cell thread,
profiling_sample_count const& counts, cell callstack_begin, cell callstack_end)
cell thread) : counts(counts), thread(thread),
: counts(counts), thread(thread) { callstack_begin(callstack_begin),
vm->record_callstack_sample(&callstack_begin, &callstack_end, prolog_p); callstack_end(callstack_end) { }
}
void factor_vm::record_sample(bool prolog_p) { void factor_vm::record_sample(bool prolog_p) {
profiling_sample_count counts = safepoint.sample_counts.record_counts(); profiling_sample_count counts = safepoint.sample_counts.record_counts();
if (!counts.empty()) if (counts.empty()) {
samples.push_back(profiling_sample(this, prolog_p, counts, return;
special_objects[OBJ_CURRENT_THREAD]));
} }
/* Appends the callstack, which is just a sequence of quotation or
void factor_vm::record_callstack_sample(cell* begin, cell* end, bool prolog_p) { word references, to sample_callstacks. */
*begin = sample_callstacks.size(); cell begin = sample_callstacks.size();
bool skip_p = prolog_p; bool skip_p = prolog_p;
auto recorder = [&](cell frame_top, cell size, code_block* owner, cell addr) { auto recorder = [&](cell frame_top, cell size, code_block* owner, cell addr) {
@ -50,10 +48,12 @@ void factor_vm::record_callstack_sample(cell* begin, cell* end, bool prolog_p) {
sample_callstacks.push_back(owner->owner); sample_callstacks.push_back(owner->owner);
}; };
iterate_callstack(ctx, recorder); iterate_callstack(ctx, recorder);
cell end = sample_callstacks.size();
std::reverse(sample_callstacks.begin() + begin, sample_callstacks.end());
*end = sample_callstacks.size(); /* Add the sample. */
cell thread = special_objects[OBJ_CURRENT_THREAD];
std::reverse(sample_callstacks.begin() + *begin, sample_callstacks.end()); samples.push_back(profiling_sample(counts, thread, begin, end));
} }
void factor_vm::set_sampling_profiler(fixnum rate) { void factor_vm::set_sampling_profiler(fixnum rate) {

View File

@ -47,8 +47,8 @@ struct profiling_sample {
code_block entries in the vm sample_callstacks array. */ code_block entries in the vm sample_callstacks array. */
cell callstack_begin, callstack_end; cell callstack_begin, callstack_end;
profiling_sample(factor_vm* vm, bool prolog_p, profiling_sample(profiling_sample_count const& counts, cell thread,
profiling_sample_count const& counts, cell thread); cell callstack_begin, cell callstack_end);
}; };
} }

View File

@ -188,7 +188,6 @@ struct factor_vm {
/* sampling_profiler */ /* sampling_profiler */
void record_sample(bool prolog_p); void record_sample(bool prolog_p);
void record_callstack_sample(cell* begin, cell* end, bool prolog_p);
void start_sampling_profiler(fixnum rate); void start_sampling_profiler(fixnum rate);
void end_sampling_profiler(); void end_sampling_profiler();
void set_sampling_profiler(fixnum rate); void set_sampling_profiler(fixnum rate);