Skip to content

Commit

Permalink
expose trace line count and byte count
Browse files Browse the repository at this point in the history
  • Loading branch information
ArkaneMoose committed Apr 8, 2024
1 parent 3bf7991 commit fe1cb7d
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions backend/lightningsim/trace_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ class ReadTraceResult:
channel_depths: Dict[Stream, int]
axi_latencies: Dict[AXIInterface, int]
is_ap_ctrl_chain: bool
line_count: int
byte_count: int


async def read_trace(reader: StreamReader, solution: Solution):
Expand All @@ -83,6 +85,8 @@ async def read_trace(reader: StreamReader, solution: Solution):
axi_interfaces: List[AXIInterface] = []
axi_latencies: Dict[AXIInterface, int] = {}
is_ap_ctrl_chain = False
line_count = 0
byte_count = 0

# TraceEntry caches to save memory
trace_bb_cache: Dict[Tuple[str, int], TraceEntry] = {}
Expand All @@ -93,6 +97,8 @@ async def read_trace(reader: StreamReader, solution: Solution):
axi_writeresp_cache: Dict[AXIInterface, TraceEntry] = {}

async for line in reader:
line_count += 1
byte_count += len(line)
type, *metadata_list = line.decode(errors="replace").strip().split("\t")

if type == "spec_channel":
Expand Down Expand Up @@ -174,6 +180,8 @@ async def read_trace(reader: StreamReader, solution: Solution):
channel_depths=channel_depths,
axi_latencies=axi_latencies,
is_ap_ctrl_chain=is_ap_ctrl_chain,
line_count=line_count,
byte_count=byte_count,
)


Expand All @@ -184,6 +192,8 @@ class UnresolvedTrace:
channel_depths: Dict[Stream, int]
axi_latencies: Dict[AXIInterface, int]
is_ap_ctrl_chain: bool
line_count: int
byte_count: int

def __iter__(self):
return iter(self.trace)
Expand All @@ -208,6 +218,8 @@ async def await_trace_functions(read_trace_result: ReadTraceResult):
channel_depths=read_trace_result.channel_depths,
axi_latencies=read_trace_result.axi_latencies,
is_ap_ctrl_chain=read_trace_result.is_ap_ctrl_chain,
line_count=read_trace_result.line_count,
byte_count=read_trace_result.byte_count,
)


Expand Down Expand Up @@ -267,6 +279,8 @@ class ResolvedTrace:
axi_latencies: Dict[AXIInterface, int]
is_ap_ctrl_chain: bool
num_stall_events: int
line_count: int
byte_count: int

def __iter__(self):
return iter(self.trace)
Expand Down Expand Up @@ -457,4 +471,6 @@ def do_sync_work_batch(deadline=SYNC_WORK_BATCH_DURATION):
axi_latencies=trace.axi_latencies,
is_ap_ctrl_chain=trace.is_ap_ctrl_chain,
num_stall_events=num_stall_events,
line_count=trace.line_count,
byte_count=trace.byte_count,
)

0 comments on commit fe1cb7d

Please sign in to comment.