From 01766fb4b67c2ec7e90706cbb1f48febfeeb12a1 Mon Sep 17 00:00:00 2001
From: Matthieu Schaller <schaller@strw.leidenuniv.nl>
Date: Fri, 6 Dec 2019 14:28:42 +0100
Subject: [PATCH] Add HTML anchors to the different sections of the task plot
 webpage.

---
 tools/task_plots/analyse_tasks.py            | 22 ++++++++++++++++++++
 tools/task_plots/analyse_threadpool_tasks.py | 20 ++++++++++++++++++
 tools/task_plots/process_plot_tasks          |  2 +-
 tools/task_plots/process_plot_tasks_MPI      |  2 +-
 tools/task_plots/process_plot_threadpool     |  2 +-
 5 files changed, 45 insertions(+), 3 deletions(-)

diff --git a/tools/task_plots/analyse_tasks.py b/tools/task_plots/analyse_tasks.py
index 8ba0c6ee53..c093d18c2d 100755
--- a/tools/task_plots/analyse_tasks.py
+++ b/tools/task_plots/analyse_tasks.py
@@ -57,9 +57,17 @@ parser.add_argument(
     default="all",
     action="store",
 )
+parser.add_argument(
+    "--html",
+    dest="html",
+    help="Use html titles and anchors in the output (default: False)",
+    default=False,
+    action="store_true",
+)
 
 args = parser.parse_args()
 infile = args.input
+with_html = args.html
 
 #  Tasks and subtypes. Indexed as in tasks.h.
 TASKTYPES = [
@@ -301,6 +309,8 @@ for rank in ranks:
                     sidtimes[my_sid] = []
                 sidtimes[my_sid].append(dt)
 
+        if with_html:
+            print('<div id="thread{}"></div>'.format(i))
         print("# Thread : ", i)
         for key in sorted(tasktimes.keys()):
             taskmin = min(tasktimes[key])
@@ -319,6 +329,8 @@ for rank in ranks:
             )
         print()
 
+    if with_html:
+        print('<div id="all"></div>')
     print("# All threads : ")
     for key in sorted(alltasktimes.keys()):
         taskmin = min(alltasktimes[key])
@@ -338,6 +350,8 @@ for rank in ranks:
     print()
 
     # For pairs, show stuff sorted by SID
+    if with_html:
+        print('<div id="sid"></div>')
     print("# By SID (all threads): ")
     print(
         "# {0:<17s}: {1:>7s} {2:>9s} {3:>9s} {4:>9s} {5:>9s} {6:>9s}".format(
@@ -375,6 +389,8 @@ for rank in ranks:
     #  Dead times.
     print("# Times not in tasks (deadtimes)")
     print("# ------------------------------")
+    if with_html:
+        print('<div id="before"></div>')
     print("# Time before first task:")
     print("# no.    : {0:>9s} {1:>9s}".format("value", "percent"))
     predeadtimes = []
@@ -410,6 +426,8 @@ for rank in ranks:
     )
     print()
 
+    if with_html:
+        print('<div id="after"></div>')
     print("# Time after last task:")
     print("# no.    : {0:>9s} {1:>9s}".format("value", "percent"))
     postdeadtimes = []
@@ -446,6 +464,8 @@ for rank in ranks:
     print()
 
     #  Time in engine, i.e. from first to last tasks.
+    if with_html:
+        print('<div id="between"></div>')
     print("# Time between tasks (engine deadtime):")
     print(
         "# no.    : {0:>9s} {1:>9s} {2:>9s} {3:>9s} {4:>9s} {5:>9s}".format(
@@ -503,6 +523,8 @@ for rank in ranks:
     print()
 
     #  All times in step.
+    if with_html:
+        print('<div id="dead"></div>')
     print("# All deadtimes:")
     print(
         "# no.    : {0:>9s} {1:>9s} {2:>9s} {3:>9s} {4:>9s} {5:>9s}".format(
diff --git a/tools/task_plots/analyse_threadpool_tasks.py b/tools/task_plots/analyse_threadpool_tasks.py
index af8d88dc1d..425f6bb62e 100755
--- a/tools/task_plots/analyse_threadpool_tasks.py
+++ b/tools/task_plots/analyse_threadpool_tasks.py
@@ -49,9 +49,17 @@ parser.add_argument(
     default=False,
     action="store_true",
 )
+parser.add_argument(
+    "--html",
+    dest="html",
+    help="Use html titles and anchors in the output (default: False)",
+    default=False,
+    action="store_true",
+)
 
 args = parser.parse_args()
 infile = args.input
+with_html = args.html
 
 #  Read header. First two lines.
 with open(infile) as infid:
@@ -145,6 +153,8 @@ for i in threadids:
             alltasktimes[key] = []
         alltasktimes[key].append(dt)
 
+    if with_html:
+        print('<div id="thread{}"></div>'.format(i))
     print("# Thread : ", i)
     for key in sorted(tasktimes.keys()):
         taskmin = min(tasktimes[key])
@@ -163,6 +173,8 @@ for i in threadids:
         )
     print()
 
+if with_html:
+    print('<div id="all"></div>')
 print("# All threads : ")
 for key in sorted(alltasktimes.keys()):
     taskmin = min(alltasktimes[key])
@@ -184,6 +196,8 @@ print()
 #  Dead times.
 print("# Times not in tasks (deadtimes)")
 print("# ------------------------------")
+if with_html:
+    print('<div id="before"></div>')
 print("# Time before first task:")
 print("# no.    : {0:>9s} {1:>9s}".format("value", "percent"))
 predeadtimes = []
@@ -216,6 +230,8 @@ print(
 )
 print()
 
+if with_html:
+    print('<div id="after"></div>')
 print("# Time after last task:")
 print("# no.    : {0:>9s} {1:>9s}".format("value", "percent"))
 postdeadtimes = []
@@ -249,6 +265,8 @@ print(
 print()
 
 #  Time in threadpool, i.e. from first to last tasks.
+if with_html:
+    print('<div id="between"></div>')
 print("# Time between tasks (threadpool deadtime):")
 print(
     "# no.    : {0:>9s} {1:>9s} {2:>9s} {3:>9s} {4:>9s} {5:>9s}".format(
@@ -303,6 +321,8 @@ print(
 print()
 
 #  All times in step.
+if with_html:
+    print('<div id="dead"></div>')
 print("# All deadtimes:")
 print(
     "# no.    : {0:>9s} {1:>9s} {2:>9s} {3:>9s} {4:>9s} {5:>9s}".format(
diff --git a/tools/task_plots/process_plot_tasks b/tools/task_plots/process_plot_tasks
index 4df04ab46b..df841d9c53 100755
--- a/tools/task_plots/process_plot_tasks
+++ b/tools/task_plots/process_plot_tasks
@@ -60,7 +60,7 @@ done
 #  And process them,
 echo "Processing thread info files..."
 echo $list | xargs -P $NPROCS -n 3 /bin/bash -c "${SCRIPTHOME}/plot_tasks.py --expand 1 --limit $TIMERANGE --width 16 --height 4 \$0 \$2 "
-echo $list | xargs -P $NPROCS -n 3 /bin/bash -c "${SCRIPTHOME}/analyse_tasks.py \$0 > \$2.stats"
+echo $list | xargs -P $NPROCS -n 3 /bin/bash -c "${SCRIPTHOME}/analyse_tasks.py --html \$0 > \$2.stats"
 
 echo "Writing output index.html file"
 #  Construct document - serial.
diff --git a/tools/task_plots/process_plot_tasks_MPI b/tools/task_plots/process_plot_tasks_MPI
index 736aad05b9..031051ae54 100755
--- a/tools/task_plots/process_plot_tasks_MPI
+++ b/tools/task_plots/process_plot_tasks_MPI
@@ -66,7 +66,7 @@ nrank=$(($nrank-1))
 echo "Processing thread info files..."
 echo $list | xargs -P $NPROCS -n 3 /bin/bash -c "${SCRIPTHOME}/plot_tasks.py --expand 1 --limit $TIMERANGE \$0 \$2 "
 for i in $(seq 0 $nrank); do
-    echo $list | xargs -P $NPROCS -n 3 /bin/bash -c "${SCRIPTHOME}/analyse_tasks.py -r $i \$0 > \$2${i}.stats"
+    echo $list | xargs -P $NPROCS -n 3 /bin/bash -c "${SCRIPTHOME}/analyse_tasks.py -r $i --html \$0 > \$2${i}.stats"
 done
 
 echo "Writing output index.html file"
diff --git a/tools/task_plots/process_plot_threadpool b/tools/task_plots/process_plot_threadpool
index 0076ec1c4e..b1238b3668 100755
--- a/tools/task_plots/process_plot_threadpool
+++ b/tools/task_plots/process_plot_threadpool
@@ -65,7 +65,7 @@ done
 #  And process them,
 echo "Processing threadpool info files..."
 echo $list | xargs -P $NPROCS -n 3 /bin/bash -c "${SCRIPTHOME}/plot_threadpool.py --expand 1 --limit $TIMERANGE --width 16 --height 4 \$0 \$2 "
-echo $list | xargs -P $NPROCS -n 3 /bin/bash -c "${SCRIPTHOME}/analyse_threadpool_tasks.py \$0 > \$2.stats"
+echo $list | xargs -P $NPROCS -n 3 /bin/bash -c "${SCRIPTHOME}/analyse_threadpool_tasks.py \$0 --html > \$2.stats"
 
 echo "Writing output threadpool-index.html file"
 #  Construct document - serial.
-- 
GitLab