From c7c44601965c5001c06595f9fa10179c9433c65d Mon Sep 17 00:00:00 2001 From: Jose Gracia Date: Wed, 7 Feb 2024 11:31:30 +0100 Subject: [PATCH] Log command line in output files --- monitoring/db/scripts/get_detailed_power.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/monitoring/db/scripts/get_detailed_power.py b/monitoring/db/scripts/get_detailed_power.py index f06dd47..491ccba 100755 --- a/monitoring/db/scripts/get_detailed_power.py +++ b/monitoring/db/scripts/get_detailed_power.py @@ -70,7 +70,7 @@ class Power: return power - def to_file(self, jobid): + def to_file(self, jobid, header=""): """Dumps power data to file. Returns filename is succesfull and None if unsucessfull.""" fname = self.filename(jobid) if os.path.exists(fname): @@ -79,7 +79,7 @@ class Power: try: with open(fname, "w+") as f: - f.write(self.header()) + f.write(header + self.header()) f.write(self.body()) except IOError: print("Error: could not write to file ", fname) @@ -205,6 +205,7 @@ class App: self.db = MonitoringDB(self.config.verbose) def run_all(self): + header = f"# {config.datetime}: {config.cmd}\n#\n" for jobid in self.config.jobid: try: power = Power.from_db(self.db, jobid, self.config.interval) @@ -212,14 +213,17 @@ class App: print('No data found for job ID "{}"'.format(jobid)) continue - fn = power.to_file(jobid) + fn = power.to_file(jobid, header) if fn: print('Created file {fn}'.format(fn=fn)) if __name__ == "__main__": import sys + from datetime import datetime config = parse_arguments(sys.argv[1:]) + config.cmd = " ".join(sys.argv) + config.datetime = f"{datetime.now()}" main = App(config) main.run_all()