]> gitweb.factorcode.org Git - factor.git/blobdiff - vm/sampling_profiler.cpp
audio.engine.test: cleanup using
[factor.git] / vm / sampling_profiler.cpp
index 962cdc4f56f6260232592b413078c1aeaa85f4b3..0388feaf070e78d46ee9d08f1400385caa756a3b 100644 (file)
@@ -36,11 +36,11 @@ void factor_vm::growarr_add(array *growarr_, cell elt_) {
   set_array_nth(growarr.untagged(), 0, tag_fixnum(count + 1));
 }
 
-profiling_sample_count profiling_sample_count::record_counts() volatile {
+profiling_sample profiling_sample::record_counts() volatile {
   atomic::fence();
-  profiling_sample_count returned(sample_count, gc_sample_count,
-                                  jit_sample_count, foreign_sample_count,
-                                  foreign_thread_sample_count);
+  profiling_sample returned(sample_count, gc_sample_count,
+                            jit_sample_count, foreign_sample_count,
+                            foreign_thread_sample_count);
   atomic::fetch_subtract(&sample_count, returned.sample_count);
   atomic::fetch_subtract(&gc_sample_count, returned.gc_sample_count);
   atomic::fetch_subtract(&jit_sample_count, returned.jit_sample_count);
@@ -50,7 +50,7 @@ profiling_sample_count profiling_sample_count::record_counts() volatile {
   return returned;
 }
 
-void profiling_sample_count::clear() volatile {
+void profiling_sample::clear_counts() volatile {
   sample_count = 0;
   gc_sample_count = 0;
   jit_sample_count = 0;
@@ -59,16 +59,10 @@ void profiling_sample_count::clear() volatile {
   atomic::fence();
 }
 
-profiling_sample::profiling_sample(profiling_sample_count const& counts, cell thread,
-                                   cell callstack_begin, cell callstack_end)
-    : counts(counts), thread(thread),
-      callstack_begin(callstack_begin),
-      callstack_end(callstack_end) { }
-
-// Allocates memory (sample_callstacks2->add)
+// Allocates memory
 void factor_vm::record_sample(bool prolog_p) {
-  profiling_sample_count counts = sample_counts.record_counts();
-  if (counts.empty()) {
+  profiling_sample result = current_sample.record_counts();
+  if (result.empty()) {
     return;
   }
   // Appends the callstack, which is just a sequence of quotation or
@@ -79,6 +73,9 @@ void factor_vm::record_sample(bool prolog_p) {
 
   bool skip_p = prolog_p;
   auto recorder = [&](cell frame_top, cell size, code_block* owner, cell addr) {
+    (void)frame_top;
+    (void)size;
+    (void)addr;
     if (skip_p)
       skip_p = false;
     else {
@@ -89,22 +86,26 @@ void factor_vm::record_sample(bool prolog_p) {
   cell end = growarr_capacity(callstacks.untagged());
 
   // Add the sample.
-  cell thread = special_objects[OBJ_CURRENT_THREAD];
-  samples.push_back(profiling_sample(counts, thread, begin, end));
+  result.thread = special_objects[OBJ_CURRENT_THREAD];
+  result.callstack_begin = begin;
+  result.callstack_end = end;
+  samples.push_back(result);
 }
 
-void factor_vm::set_sampling_profiler(fixnum rate) {
-  bool running_p = (atomic::load(&sampling_profiler_p) != 0);
+// Allocates memory
+void factor_vm::set_profiling(fixnum rate) {
+  bool running_p = atomic::load(&sampling_profiler_p);
   if (rate > 0 && !running_p)
     start_sampling_profiler(rate);
   else if (rate == 0 && running_p)
     end_sampling_profiler();
 }
 
+// Allocates memory
 void factor_vm::start_sampling_profiler(fixnum rate) {
   special_objects[OBJ_SAMPLE_CALLSTACKS] = tag<array>(allot_growarr());
   samples_per_second = rate;
-  sample_counts.clear();
+  current_sample.clear_counts();
   // Release the memory consumed by collecting samples.
   samples.clear();
   samples.shrink_to_fit();
@@ -119,8 +120,9 @@ void factor_vm::end_sampling_profiler() {
   record_sample(false);
 }
 
-void factor_vm::primitive_sampling_profiler() {
-  set_sampling_profiler(to_fixnum(ctx->pop()));
+// Allocates memory
+void factor_vm::primitive_set_profiling() {
+  set_profiling(to_fixnum(ctx->pop()));
 }
 
 // Allocates memory
@@ -141,15 +143,15 @@ void factor_vm::primitive_get_samples() {
     data_root<array> sample(allot_array(7, false_object), this);
 
     set_array_nth(sample.untagged(), 0,
-                  tag_fixnum(from_iter->counts.sample_count));
+                  tag_fixnum(from_iter->sample_count));
     set_array_nth(sample.untagged(), 1,
-                  tag_fixnum(from_iter->counts.gc_sample_count));
+                  tag_fixnum(from_iter->gc_sample_count));
     set_array_nth(sample.untagged(), 2,
-                  tag_fixnum(from_iter->counts.jit_sample_count));
+                  tag_fixnum(from_iter->jit_sample_count));
     set_array_nth(sample.untagged(), 3,
-                  tag_fixnum(from_iter->counts.foreign_sample_count));
+                  tag_fixnum(from_iter->foreign_sample_count));
     set_array_nth(sample.untagged(), 4,
-                  tag_fixnum(from_iter->counts.foreign_thread_sample_count));
+                  tag_fixnum(from_iter->foreign_thread_sample_count));
 
     set_array_nth(sample.untagged(), 5, from_iter->thread);