From 2a9c96e01f99bb57d9ce859123624adf00a81078 Mon Sep 17 00:00:00 2001
From: Matthieu Schaller <schaller@strw.leidenuniv.nl>
Date: Wed, 18 Mar 2020 11:24:14 +0100
Subject: [PATCH] Time the task dumping operations and add them to the analysis
 script when running with --task-dumps

---
 src/task.c               | 18 ++++++++++++++++++
 tools/analyse_runtime.py |  3 +++
 2 files changed, 21 insertions(+)

diff --git a/src/task.c b/src/task.c
index 30f6a96219..4930d28a9e 100644
--- a/src/task.c
+++ b/src/task.c
@@ -915,6 +915,8 @@ void task_dump_all(struct engine *e, int step) {
 
 #ifdef SWIFT_DEBUG_TASKS
 
+  const ticks tic = getticks();
+
   /* Need this to convert ticks to seconds. */
   const unsigned long long cpufreq = clocks_get_cpufreq();
 
@@ -1008,6 +1010,10 @@ void task_dump_all(struct engine *e, int step) {
   }
   fclose(file_thread);
 #endif  // WITH_MPI
+
+  if (e->verbose)
+    message("took %.3f %s.", clocks_from_ticks(getticks() - tic),
+            clocks_getunit());
 #endif  // SWIFT_DEBUG_TASKS
 }
 
@@ -1036,6 +1042,8 @@ void task_dump_all(struct engine *e, int step) {
 void task_dump_stats(const char *dumpfile, struct engine *e, int header,
                      int allranks) {
 
+  const ticks function_tic = getticks();
+
   /* Need arrays for sum, min and max across all types and subtypes. */
   double sum[task_type_count][task_subtype_count];
   double tsum[task_type_count][task_subtype_count];
@@ -1171,6 +1179,10 @@ void task_dump_stats(const char *dumpfile, struct engine *e, int header,
 #ifdef WITH_MPI
   }
 #endif
+
+  if (e->verbose)
+    message("took %.3f %s.", clocks_from_ticks(getticks() - function_tic),
+            clocks_getunit());
 }
 
 /**
@@ -1188,6 +1200,8 @@ void task_dump_stats(const char *dumpfile, struct engine *e, int header,
  */
 void task_dump_active(struct engine *e) {
 
+  const ticks tic = getticks();
+
   /* Need this to convert ticks to seconds. */
   unsigned long long cpufreq = clocks_get_cpufreq();
   char dumpfile[35];
@@ -1234,4 +1248,8 @@ void task_dump_active(struct engine *e) {
     count++;
   }
   fclose(file_thread);
+
+  if (e->verbose)
+    message("took %.3f %s.", clocks_from_ticks(getticks() - tic),
+            clocks_getunit());
 }
diff --git a/tools/analyse_runtime.py b/tools/analyse_runtime.py
index bdb09679e6..cfa7b97707 100755
--- a/tools/analyse_runtime.py
+++ b/tools/analyse_runtime.py
@@ -97,6 +97,9 @@ labels = [
     ["engine_print_task_counts:", 0],
     ["engine_drift_top_multipoles:", 0],
     ["Communicating rebuild flag", 0],
+    ["task_dump_all", 0],
+    ["task_dump_stats", 0],
+    ["task_dump_active", 0],
     ["engine_split:", 0],
     ["space_init", 0],
     ["engine_init", 0],
-- 
GitLab