From babafcb3c06f49e6b32f10771a53a8b6c325275e Mon Sep 17 00:00:00 2001
From: Arnaud Watlet <arnaud.watlet@umons.ac.be>
Date: Fri, 16 Jun 2023 17:55:46 +0200
Subject: [PATCH] Adds log parser and exec_log plotting capability

---
 ohmpi/plots.py |  9 ++++++---
 ohmpi/utils.py | 11 ++++++++---
 2 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/ohmpi/plots.py b/ohmpi/plots.py
index a4b03ac7..170ea01a 100644
--- a/ohmpi/plots.py
+++ b/ohmpi/plots.py
@@ -4,10 +4,13 @@ from utils import parse_log
 from datetime import datetime
 import matplotlib
 
-def plot_exec_log(exec_log,names=None):
-    time, process_id, tag, msg = parse_log(exec_log)
+def plot_exec_log(exec_log,names=None,last_session=True):
+    time, process_id, tag, msg, session = parse_log(exec_log)
+    print(session)
+    if last_session:
+        time, process_id, tag, msg = time[session==max(session)], process_id[session==max(session)], tag[session==max(session)], msg[session==max(session)]
     events = msg[tag == 'EVENT']
-
+    print(time)
     category, name, state, time = np.empty(events.shape[0]).astype(str), np.empty(events.shape[0]).astype(str), \
         np.empty(events.shape[0]).astype(str), np.empty(events.shape[0]).astype(str)
 
diff --git a/ohmpi/utils.py b/ohmpi/utils.py
index 8645e7ad..2a5e5274 100644
--- a/ohmpi/utils.py
+++ b/ohmpi/utils.py
@@ -64,8 +64,9 @@ def change_config(config_file, verbose=True):
 def parse_log(log):
     msg_started = False
     msg_tmp = ''
+    s = 0
     with open(log, "r") as file:
-        time, process_id, msg, tag = [], [], [], []
+        time, process_id, msg, tag, session = [], [], [], [], []
         for i,line in enumerate(file):
             if len(line.split(" | ")) > 1:
                 time.append(line.split(" | ")[0])
@@ -80,9 +81,13 @@ def parse_log(log):
                     msg[-1] = msg[-1] + msg_tmp
                     msg_tmp = ''
                     msg_started = False
+            if tag[i] == 'INFO':
+                if 'NEW SESSION' in msg[i]:
+                    s+=1
+            session.append(s)
     time = np.array(time)
     process_id = np.array(process_id)
     tag = np.array(tag)
     msg = np.array(msg)
-
-    return time, process_id, tag, msg
\ No newline at end of file
+    session = np.array(session)
+    return time, process_id, tag, msg, session
\ No newline at end of file
-- 
GitLab