6 profiling_sample::profiling_sample(factor_vm *vm,
11 sample_count(sample_count),
12 gc_sample_count(gc_sample_count),
15 vm->record_callstack_sample(&callstack_begin, &callstack_end);
18 void factor_vm::record_sample()
20 cell recorded_sample_count;
21 cell recorded_gc_sample_count;
23 recorded_sample_count = safepoint_sample_count;
24 recorded_gc_sample_count = safepoint_gc_sample_count;
25 if (recorded_sample_count == 0 && recorded_gc_sample_count == 0)
28 /* Another sample signal could be raised while we record these counts */
29 FACTOR_ATOMIC_SUB(&safepoint_sample_count, recorded_sample_count);
30 FACTOR_ATOMIC_SUB(&safepoint_gc_sample_count, recorded_gc_sample_count);
32 samples.push_back(profiling_sample(
34 recorded_sample_count,
35 recorded_gc_sample_count,
40 void factor_vm::record_callstack_sample(cell *begin, cell *end)
42 *begin = sample_callstacks.size();
43 stack_frame *frame = ctx->bottom_frame();
45 while (frame >= ctx->callstack_top) {
46 sample_callstacks.push_back(frame_code(frame));
47 frame = frame_successor(frame);
50 *end = sample_callstacks.size();
53 void factor_vm::set_sampling_profiler(bool sampling_p)
55 if (sampling_p == sampling_profiler_p)
59 start_sampling_profiler();
61 end_sampling_profiler();
64 void factor_vm::start_sampling_profiler()
66 safepoint_sample_count = 0;
67 safepoint_gc_sample_count = 0;
69 samples.reserve(10*FACTOR_PROFILE_SAMPLES_PER_SECOND);
70 sample_callstacks.reserve(100*FACTOR_PROFILE_SAMPLES_PER_SECOND);
71 sampling_profiler_p = true;
72 start_sampling_profiler_timer();
75 void factor_vm::end_sampling_profiler()
77 end_sampling_profiler_timer();
79 sampling_profiler_p = false;
82 void factor_vm::primitive_sampling_profiler()
84 set_sampling_profiler(to_boolean(ctx->pop()));