]> gitweb.factorcode.org Git - factor.git/commitdiff
VM: trying to simplify record_sample and the profiling_sample constructor
authorBjörn Lindqvist <bjourne@gmail.com>
Sun, 14 Aug 2016 01:12:36 +0000 (03:12 +0200)
committerBjörn Lindqvist <bjourne@gmail.com>
Mon, 15 Aug 2016 13:16:41 +0000 (15:16 +0200)
vm/sampling_profiler.cpp
vm/sampling_profiler.hpp
vm/vm.hpp

index 581539405956d1717de8876f8abf1da15a3d99f9..5a848fb8619cf6772b051f4d40167c9b1dcb4fdc 100644 (file)
@@ -25,22 +25,20 @@ void profiling_sample_count::clear() volatile {
   atomic::fence();
 }
 
-profiling_sample::profiling_sample(factor_vm* vm, bool prolog_p,
-                                   profiling_sample_count const& counts,
-                                   cell thread)
-    : counts(counts), thread(thread) {
-  vm->record_callstack_sample(&callstack_begin, &callstack_end, prolog_p);
-}
+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) { }
 
 void factor_vm::record_sample(bool prolog_p) {
   profiling_sample_count counts = safepoint.sample_counts.record_counts();
-  if (!counts.empty())
-    samples.push_back(profiling_sample(this, prolog_p, counts,
-                                       special_objects[OBJ_CURRENT_THREAD]));
-}
-
-void factor_vm::record_callstack_sample(cell* begin, cell* end, bool prolog_p) {
-  *begin = sample_callstacks.size();
+  if (counts.empty()) {
+    return;
+  }
+  /* Appends the callstack, which is just a sequence of quotation or
+     word references, to sample_callstacks. */
+  cell begin = sample_callstacks.size();
 
   bool skip_p = prolog_p;
   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);
   };
   iterate_callstack(ctx, recorder);
+  cell end = sample_callstacks.size();
+  std::reverse(sample_callstacks.begin() + begin, sample_callstacks.end());
 
-  *end = sample_callstacks.size();
-
-  std::reverse(sample_callstacks.begin() + *begin, sample_callstacks.end());
+  /* Add the sample. */
+  cell thread = special_objects[OBJ_CURRENT_THREAD];
+  samples.push_back(profiling_sample(counts, thread, begin, end));
 }
 
 void factor_vm::set_sampling_profiler(fixnum rate) {
index 6def041b1ca4f40d4faa4f424d74badc09d1c97d..e6a68356f8a97323da91b9744150d2f08f7781c4 100644 (file)
@@ -47,8 +47,8 @@ struct profiling_sample {
      code_block entries in the vm sample_callstacks array. */
   cell callstack_begin, callstack_end;
 
-  profiling_sample(factor_vm* vm, bool prolog_p,
-                   profiling_sample_count const& counts, cell thread);
+  profiling_sample(profiling_sample_count const& counts, cell thread,
+                   cell callstack_begin, cell callstack_end);
 };
 
 }
index 50757252b873d1059ebe4e13282aa21b0d2496fe..43fd9e1d1bb237435613b1b9ae1b5d12cf5cb3be 100644 (file)
--- a/vm/vm.hpp
+++ b/vm/vm.hpp
@@ -188,7 +188,6 @@ struct factor_vm {
 
   /* sampling_profiler */
   void record_sample(bool prolog_p);
-  void record_callstack_sample(cell* begin, cell* end, bool prolog_p);
   void start_sampling_profiler(fixnum rate);
   void end_sampling_profiler();
   void set_sampling_profiler(fixnum rate);