From bb6eccbb969e75efac4e59c2053532e01c58312e Mon Sep 17 00:00:00 2001
From: Georges Da Costa <dacosta@irit.fr>
Date: Wed, 9 Apr 2025 12:56:31 +0200
Subject: [PATCH] Cleans moj plugins and do not install moj if already in the
 path

---
 expetator/monitors/mojitos.py | 37 ++++++++++++++++++++---------------
 1 file changed, 21 insertions(+), 16 deletions(-)

diff --git a/expetator/monitors/mojitos.py b/expetator/monitors/mojitos.py
index f5f8a36..083ccec 100644
--- a/expetator/monitors/mojitos.py
+++ b/expetator/monitors/mojitos.py
@@ -1,5 +1,6 @@
 import os
 import stat
+import shutil
 
 def read_int(filename):
     """Read integer from file filename"""
@@ -69,24 +70,28 @@ class Mojitos:
             #               '/usr/share/doc/libpowercap-dev',
             #               '/usr/share/doc/libpowercap0']]:
             #     executor.hosts('apt install -y libpowercap0 libpowercap-dev powercap-utils', root=True)
-        if not os.path.exists('/tmp/mojitos'):
-            executor.local('cd /tmp; git clone https://gitlab.irit.fr/sepia-pub/mojitos.git')
-        else:
-            executor.local('cd /tmp/mojitos; git pull')
-        executor.local('cd /tmp/mojitos; ./configure.sh; make')
-        executor.local('cp /tmp/mojitos/bin/mojitos /tmp/bin/')
-        if True or self.rapl or self.perf:
-            executor.hosts('sudo-g5k modprobe msr', root=True)
-            if read_int('/proc/sys/kernel/perf_event_paranoid') != 0:
-                executor.hosts("sh -c 'echo 0 >/proc/sys/kernel/perf_event_paranoid'", root=True)
-            mode = os.stat('/sys/class/powercap/intel-rapl/intel-rapl:0/constraint_0_max_power_uw')
-            if not mode.st_mode & stat.S_IWUSR:
-                executor.hosts("chmod a+rw /sys/class/powercap/intel-rapl/*/*", root=True)
-                executor.hosts("chmod a+rw /sys/class/powercap/intel-rapl/*/*/*", root=True)
 
+        binary = shutil.which('mojitos')
+        if binary is None:
+            if not os.path.exists('/tmp/mojitos'):
+                executor.local('cd /tmp; git clone https://gitlab.irit.fr/sepia-pub/mojitos.git')
+            else:
+                executor.local('cd /tmp/mojitos; git pull')
+            executor.local('cd /tmp/mojitos; ./configure.sh; make')
+            executor.local('cp /tmp/mojitos/bin/mojitos /tmp/bin/')
+            if self.rapl or self.perf:
+                executor.hosts('modprobe msr', root=True)
+                if read_int('/proc/sys/kernel/perf_event_paranoid') != 0:
+                    executor.hosts("sh -c 'echo 0 >/proc/sys/kernel/perf_event_paranoid'", root=True)
+                mode = os.stat('/sys/class/powercap/intel-rapl/intel-rapl:0/constraint_0_max_power_uw')
+                if not mode.st_mode & stat.S_IWUSR:
+                    executor.hosts("chmod a+r /sys/class/powercap/intel-rapl/*/*", root=True)
+                    executor.hosts("chmod a+r /sys/class/powercap/intel-rapl/*/*/*", root=True)
+            binary = '/tmp/bin/mojitos'
+        
         self.executor = executor
-
-        self.cmdline = '/tmp/bin/mojitos -t 0 -f %s' % self.frequency
+        
+        self.cmdline = f'{binary} -t 0 -f {self.frequency}'
         if self.perf:
             self.cmdline += ' -p ' + ','.join(self.names & perf_names)
         if self.network:
-- 
GitLab