Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/gpu_tracker/_helper_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/gpu_tracker/sub_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
6 changes: 3 additions & 3 deletions tests/data/decorated-function-other-file.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
position,timestamp
START,12
STOP,13
position,process_id,timestamp
START,1234,12
STOP,1234,13
26 changes: 13 additions & 13 deletions tests/data/decorated-function.csv
Original file line number Diff line number Diff line change
@@ -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
22 changes: 11 additions & 11 deletions tests/data/sub-tracker.csv
Original file line number Diff line number Diff line change
@@ -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
Loading