Skip to content

Commit

Permalink
Cleanup data parsing code
Browse files Browse the repository at this point in the history
  • Loading branch information
solidpixel committed Jan 7, 2025
1 parent 81cb3cb commit a328625
Show file tree
Hide file tree
Showing 9 changed files with 490 additions and 325 deletions.
4 changes: 4 additions & 0 deletions .mypy.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
[mypy]
exclude = lglpy/timeline/protos/.*\.py
ignore_missing_imports = True
disable_error_code = annotation-unchecked

[mypy-lglpy.timeline.data.raw_trace]
disable_error_code = attr-defined

[mypy-google.*]
ignore_missing_imports = True
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ ignore-patterns=^\.#
# manipulated during runtime and thus existing member attributes cannot be
# deduced by static analysis). It supports qualified module names, as well as
# Unix pattern matching.
ignored-modules=cairo
ignored-modules=cairo,protos

# Python code to execute, usually for sys.path manipulation such as
# pygtk.require().
Expand Down
2 changes: 1 addition & 1 deletion lglpy/comms/service_gpu_timeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def handle_render_pass(self, msg: Any) -> None:

# If this is a continuation then merge records
if last_render_pass and (last_render_pass['tid'] == msg['tid']):
# Don't accumulate if tagID is flagged as ambiguous
# Don't accumulate if tag_id is flagged as ambiguous
if last_render_pass['drawCallCount'] != -1:
last_render_pass['drawCallCount'] += msg['drawCallCount']

Expand Down
85 changes: 16 additions & 69 deletions lglpy/timeline/data/processed_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,76 +21,23 @@
# SOFTWARE.
# -----------------------------------------------------------------------------
'''
TODO
This module implements the processed trace that stores the formatted workloads
that merge data from the Perfetto data and GPU Timeline layer data into a
single combined representation.
'''
import enum

import lglpy.timeline.data.raw_trace as raw


class GPUStreamID(enum.Enum):
'''
Symbolic mapping of known GPU scheduling stream IDs.
'''
COMPUTE = 0
NONFRAGMENT = 1
FRAGMENT = 2
BINNING = 3
MAIN = 4
TRANSFER = 5

@classmethod
def get_ui_name(self, streamID) -> str:
'''
Get presentable name for a stream.
'''
HUMAN_NAMES = {
self.COMPUTE: 'Compute',
self.NONFRAGMENT: 'Non-fragment',
self.FRAGMENT: 'Fragment',
self.BINNING: 'Binning',
self.MAIN: 'Main',
self.TRANSFER: 'Transfer'
}

return HUMAN_NAMES[streamID]


class GPUStageID(enum.Enum):
'''
Symbolic mapping of known GPU workload stage IDs.
'''
COMPUTE = 0
ADVANCED_GEOMETRY = 1
VERTEX = 2
FRAGMENT = 3
BINNING = 4
MAIN = 5
IMAGE_TRANSFER = 6
BUFFER_TRANSFER = 7

@classmethod
def get_ui_name(self, streamID) -> str:
'''
Get presentable name for a stream.
'''
HUMAN_NAMES = {
self.COMPUTE: 'Compute',
self.ADVANCED_GEOMETRY: 'Advanced geometry',
self.VERTEX: 'Vertex',
self.FRAGMENT: 'Fragment',
self.BINNING: 'Binning',
self.MAIN: 'Main',
self.IMAGE_TRANSFER: 'Image transfer',
self.BUFFER_TRANSFER: 'Buffer transfer'
}

return HUMAN_NAMES[streamID]


class GPUWorkload:
'''
Base class for workloads in a trace.
Attributes:
tag_id: The unique tag ID assigned by the layer.
start_time: The event start time in nanoseconds.
duration: The event duration in nanoseconds.
stream:
'''

def __init__(self, event, metadata):
Expand Down Expand Up @@ -180,13 +127,13 @@ def get_long_label(self):
lines.append(self.label_stack[-1])

if self.draw_call_count < 0:
drawStr = 'Unknown draws'
draw_str = 'Unknown draws'
elif self.draw_call_count == 1:
drawStr = '1 draw'
draw_str = '1 draw'
else:
drawStr = f'{self.draw_call_count} draws'
draw_str = f'{self.draw_call_count} draws'

line = f'{self.workload_x}x{self.workload_y} ({drawStr})'
line = f'{self.workload_x}x{self.workload_y} ({draw_str})'
lines.append(line)

line = self.get_attachment_long_label()
Expand Down Expand Up @@ -216,9 +163,9 @@ def __init__(self, event, metadata):
super().__init__(event, metadata)

# We must have metadata so no need to check
self.workload_x = metadata.xGroups
self.workload_y = metadata.yGroups
self.workload_z = metadata.zGroups
self.workload_x = metadata.groups_x
self.workload_y = metadata.groups_y
self.workload_z = metadata.groups_z

def get_long_label(self):
lines = []
Expand Down
Loading

0 comments on commit a328625

Please sign in to comment.