Skip to content

Commit

Permalink
style updates
Browse files Browse the repository at this point in the history
  • Loading branch information
movsesyanae committed Oct 14, 2024
1 parent b959fee commit 1fd2bc9
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions pipit/readers/core_reader.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from abc import ABC, abstractmethod
from typing import List, Dict

import pandas
Expand All @@ -8,15 +7,16 @@

class CoreTraceReader:
"""
Helper Object to read traces from different sources and convert them into a common format
Helper Object to read traces from different sources and convert them into a common
format
"""

def __init__(self, start: int = 0, stride: int = 1):
"""
Should be called by each process to create an empty trace per process in the reader. Creates the following
data structures to represent an empty trace:
- events: Dict[int, Dict[int, List[Dict]]]
- stacks: Dict[int, Dict[int, List[int]]]
Should be called by each process to create an empty trace per process in the
reader. Creates the following data structures to represent an empty trace:
- events: Dict[int, Dict[int, List[Dict]]]
- stacks: Dict[int, Dict[int, List[int]]]
"""
# keep stride for how much unique id should be incremented
self.stride = stride
Expand All @@ -34,7 +34,8 @@ def __init__(self, start: int = 0, stride: int = 1):

def add_event(self, event: Dict) -> None:
"""
Should be called to add each event to the trace. Will update the event lists and stacks accordingly.
Should be called to add each event to the trace. Will update the event lists and
stacks accordingly.
"""
# get process number -- if not present, set to 0
if "Process" in event:
Expand Down Expand Up @@ -66,12 +67,14 @@ def add_event(self, event: Dict) -> None:
self.stacks[process][thread] = []
stack: List[int] = self.stacks[process][thread]

# if the event is an enter event, add the event to the stack and update the parent-child relationships
# if the event is an enter event, add the event to the stack and update the
# parent-child relationships
if event["Event Type"] == "Enter":
self.__update_parent_child_relationships(event, stack, event_list, False)
elif event["Event Type"] == "Instant":
self.__update_parent_child_relationships(event, stack, event_list, True)
# if the event is a leave event, update the matching event and pop from the stack
# if the event is a leave event, update the matching event and pop from the
# stack
elif event["Event Type"] == "Leave":
self.__update_match_event(event, stack, event_list)

Expand Down Expand Up @@ -103,9 +106,12 @@ def finalize(self):
)
return trace_df

def __update_parent_child_relationships(self, event: Dict, stack: List[int], event_list: List[Dict],is_instant: bool) -> None:
def __update_parent_child_relationships(
self, event: Dict, stack: List[int], event_list: List[Dict], is_instant: bool
) -> None:
"""
This method can be thought of the update upon an "Enter" event. It adds to the stack and CCT
This method can be thought of the update upon an "Enter" event. It adds to the
stack and CCT
"""
if len(stack) == 0:
# root event
Expand All @@ -118,10 +124,13 @@ def __update_parent_child_relationships(self, event: Dict, stack: List[int], eve
if not is_instant:
stack.append(len(event_list))

def __update_match_event(self, leave_event: Dict, stack: List[int], event_list: List[Dict]) -> None:
def __update_match_event(
self, leave_event: Dict, stack: List[int], event_list: List[Dict]
) -> None:
"""
This method can be thought of the update upon a "Leave" event. It pops from the stack and updates the event list.
We should look into using this function to add artificial "Leave" events for unmatched "Enter" events
This method can be thought of the update upon a "Leave" event. It pops from the
stack and updates the event list. We should look into using this function to add
artificial "Leave" events for unmatched "Enter" events
"""

while len(stack) > 0:
Expand All @@ -146,6 +155,7 @@ def __get_unique_id(self) -> int:
self.unique_id += self.stride
return self.unique_id


def concat_trace_data(data_list):
"""
Concatenates the data from multiple trace readers into a single trace reader
Expand Down

0 comments on commit 1fd2bc9

Please sign in to comment.