From a938e4a3d24fd60b8eeda7790dad5670407191c6 Mon Sep 17 00:00:00 2001 From: erikhuck Date: Fri, 4 Apr 2025 18:46:26 -0400 Subject: [PATCH] Adds the process_id field to the sub tracker log --- src/gpu_tracker/_helper_classes.py | 1 + src/gpu_tracker/sub_tracker.py | 5 ++-- tests/data/decorated-function-other-file.csv | 6 ++--- tests/data/decorated-function.csv | 26 ++++++++++---------- tests/data/sub-tracker.csv | 22 ++++++++--------- 5 files changed, 31 insertions(+), 29 deletions(-) diff --git a/src/gpu_tracker/_helper_classes.py b/src/gpu_tracker/_helper_classes.py index 0517cf0..3739dec 100644 --- a/src/gpu_tracker/_helper_classes.py +++ b/src/gpu_tracker/_helper_classes.py @@ -142,6 +142,7 @@ class _SubTrackerLog: class CodeBlockPosition(enum.Enum): START = 'START' STOP = 'STOP' + process_id: int code_block_name: str position: CodeBlockPosition timestamp: float diff --git a/src/gpu_tracker/sub_tracker.py b/src/gpu_tracker/sub_tracker.py index 5709095..6f3bc1b 100644 --- a/src/gpu_tracker/sub_tracker.py +++ b/src/gpu_tracker/sub_tracker.py @@ -31,14 +31,15 @@ def __init__( file_path = os.path.abspath(caller_frame.filename) code_block_attribute = caller_frame.lineno if code_block_attribute is None else code_block_attribute self.code_block_name = f'{file_path}:{code_block_attribute}' + self.process_id = os.getpid() if sub_tracking_file is None: - sub_tracking_file = f'{os.getpid()}.csv' + sub_tracking_file = f'{self.process_id}.csv' self.sub_tracking_file = sub_tracking_file self._sub_tracking_file = _Writer.create(self.sub_tracking_file) def _log(self, code_block_position: _SubTrackerLog.CodeBlockPosition): sub_tracker_log = _SubTrackerLog( - code_block_name=self.code_block_name, position=code_block_position.value, timestamp=time.time()) + process_id=self.process_id, code_block_name=self.code_block_name, position=code_block_position.value, timestamp=time.time()) self._sub_tracking_file.write_row(sub_tracker_log) def __enter__(self): diff --git a/tests/data/decorated-function-other-file.csv b/tests/data/decorated-function-other-file.csv index 925682e..ee8c85a 100644 --- a/tests/data/decorated-function-other-file.csv +++ b/tests/data/decorated-function-other-file.csv @@ -1,3 +1,3 @@ -position,timestamp -START,12 -STOP,13 +position,process_id,timestamp +START,1234,12 +STOP,1234,13 diff --git a/tests/data/decorated-function.csv b/tests/data/decorated-function.csv index d7ae905..46958f9 100644 --- a/tests/data/decorated-function.csv +++ b/tests/data/decorated-function.csv @@ -1,13 +1,13 @@ -position,timestamp -START,0 -STOP,1 -START,2 -STOP,3 -START,4 -STOP,5 -START,6 -STOP,7 -START,8 -STOP,9 -START,10 -STOP,11 +position,process_id,timestamp +START,1234,0 +STOP,1234,1 +START,1234,2 +STOP,1234,3 +START,1234,4 +STOP,1234,5 +START,1234,6 +STOP,1234,7 +START,1234,8 +STOP,1234,9 +START,1234,10 +STOP,1234,11 diff --git a/tests/data/sub-tracker.csv b/tests/data/sub-tracker.csv index 23b1c72..1f134bf 100644 --- a/tests/data/sub-tracker.csv +++ b/tests/data/sub-tracker.csv @@ -1,11 +1,11 @@ -position,timestamp -START,0 -STOP,1 -START,2 -STOP,3 -START,4 -STOP,5 -START,6 -STOP,7 -START,8 -STOP,9 +position,process_id,timestamp +START,1234,0 +STOP,1234,1 +START,1234,2 +STOP,1234,3 +START,1234,4 +STOP,1234,5 +START,1234,6 +STOP,1234,7 +START,1234,8 +STOP,1234,9