Skip to content

Commit a937289

Browse files
authored
Merge pull request #64 from MoseleyBioinformaticsLab/granular
Adds the process_id field to the sub tracker log
2 parents 61dbd99 + 6329bad commit a937289

File tree

5 files changed

+31
-29
lines changed

5 files changed

+31
-29
lines changed

src/gpu_tracker/_helper_classes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ class _SubTrackerLog:
142142
class CodeBlockPosition(enum.Enum):
143143
START = 'START'
144144
STOP = 'STOP'
145+
process_id: int
145146
code_block_name: str
146147
position: CodeBlockPosition
147148
timestamp: float

src/gpu_tracker/sub_tracker.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,15 @@ def __init__(
3131
file_path = os.path.abspath(caller_frame.filename)
3232
code_block_attribute = caller_frame.lineno if code_block_attribute is None else code_block_attribute
3333
self.code_block_name = f'{file_path}:{code_block_attribute}'
34+
self.process_id = os.getpid()
3435
if sub_tracking_file is None:
35-
sub_tracking_file = f'{os.getpid()}.csv'
36+
sub_tracking_file = f'{self.process_id}.csv'
3637
self.sub_tracking_file = sub_tracking_file
3738
self._sub_tracking_file = _Writer.create(self.sub_tracking_file)
3839

3940
def _log(self, code_block_position: _SubTrackerLog.CodeBlockPosition):
4041
sub_tracker_log = _SubTrackerLog(
41-
code_block_name=self.code_block_name, position=code_block_position.value, timestamp=time.time())
42+
process_id=self.process_id, code_block_name=self.code_block_name, position=code_block_position.value, timestamp=time.time())
4243
self._sub_tracking_file.write_row(sub_tracker_log)
4344

4445
def __enter__(self):
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
position,timestamp
2-
START,12
3-
STOP,13
1+
position,process_id,timestamp
2+
START,1234,12
3+
STOP,1234,13

tests/data/decorated-function.csv

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
position,timestamp
2-
START,0
3-
STOP,1
4-
START,2
5-
STOP,3
6-
START,4
7-
STOP,5
8-
START,6
9-
STOP,7
10-
START,8
11-
STOP,9
12-
START,10
13-
STOP,11
1+
position,process_id,timestamp
2+
START,1234,0
3+
STOP,1234,1
4+
START,1234,2
5+
STOP,1234,3
6+
START,1234,4
7+
STOP,1234,5
8+
START,1234,6
9+
STOP,1234,7
10+
START,1234,8
11+
STOP,1234,9
12+
START,1234,10
13+
STOP,1234,11

tests/data/sub-tracker.csv

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
position,timestamp
2-
START,0
3-
STOP,1
4-
START,2
5-
STOP,3
6-
START,4
7-
STOP,5
8-
START,6
9-
STOP,7
10-
START,8
11-
STOP,9
1+
position,process_id,timestamp
2+
START,1234,0
3+
STOP,1234,1
4+
START,1234,2
5+
STOP,1234,3
6+
START,1234,4
7+
STOP,1234,5
8+
START,1234,6
9+
STOP,1234,7
10+
START,1234,8
11+
STOP,1234,9

0 commit comments

Comments
 (0)