about summary refs log tree commit diff stats
path: root/020run.cc
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-08-14 18:30:46 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-08-14 18:30:46 -0700
commite0551d78f10b9405f30d3074f3644c4de075d317 (patch)
treeb1a6fb4659d48e0971829ef021ecfbba1e37139c /020run.cc
parentc6520d9694d3cee265833b9e857f5f693645caba (diff)
downloadmu-e0551d78f10b9405f30d3074f3644c4de075d317.tar.gz
1995 - simple profile of instruction spend
The slowness of the environment -- even for code spanning just a couple
hundred lines -- is the biggest priority right now.
Diffstat (limited to '020run.cc')
-rw-r--r--020run.cc11
1 files changed, 11 insertions, 0 deletions
diff --git a/020run.cc b/020run.cc
index e9d8c2a8..1c63c564 100644
--- a/020run.cc
+++ b/020run.cc
@@ -44,6 +44,7 @@ struct routine {
 
 :(before "End Globals")
 routine* Current_routine = NULL;
+map<string, long long int> Instructions_running;
 
 :(code)
 void run(recipe_ordinal r) {
@@ -57,6 +58,7 @@ void run_current_routine()
   while (!Current_routine->completed())  // later layers will modify condition
   {
     // Running One Instruction
+    Instructions_running[current_recipe_name()]++;
     if (current_instruction().is_label) { ++current_step_index(); continue; }
     trace(Initial_callstack_depth+Callstack_depth, "run") << current_instruction().to_string() << end();
     if (Memory[0] != 0) {
@@ -154,6 +156,15 @@ if (!Run_tests) {
 }
 
 :(code)
+void dump_profile() {
+  for (map<string, long long int>::iterator p = Instructions_running.begin(); p != Instructions_running.end(); ++p) {
+    cerr << p->first << ": " << p->second << '\n';
+  }
+}
+:(before "End One-time Setup")
+atexit(dump_profile);
+
+:(code)
 void cleanup_main() {
   if (!Trace_file.empty() && Trace_stream) {
     ofstream fout(Trace_file.c_str());