MCPcopy Create free account
hub / github.com/pytorch/executorch / transform_events

Function transform_events

examples/arm/visualize.py:80–115  ·  view source on GitHub ↗

Annotate the 'queue' table in-place with duration based on trace events.

(
    objects: Iterable[Dict[str, Any]], queue_df: pd.DataFrame, sub_ops: set
)

Source from the content-addressed store, hash-verified

78
79
80def transform_events(
81 objects: Iterable[Dict[str, Any]], queue_df: pd.DataFrame, sub_ops: set
82) -> None:
83 """
84 Annotate the 'queue' table in-place with duration based on trace events.
85 """
86 queue_df_len = len(queue_df)
87 offsets = queue_df["offset"].astype(int)
88
89 start_ts, cmd_index, chain_len = 0, 0, 1
90
91 def is_end_of_command(qread_offset: int, end_idx: int) -> bool:
92 if end_idx >= queue_df_len:
93 return qread_offset > offsets[cmd_index]
94 return qread_offset == offsets[end_idx]
95
96 for event in (e for e in objects if e.get("tid") == "qread"):
97 if cmd_index >= queue_df_len:
98 break
99
100 qread_offset = 4 * int(event["args"]["qread"])
101
102 while (cmd_index + chain_len <= queue_df_len - 1) and queue_df.iloc[
103 cmd_index + chain_len
104 ]["scheduled_id"] in sub_ops:
105 chain_len += 1
106
107 end_idx = cmd_index + chain_len
108 if is_end_of_command(qread_offset, end_idx):
109 end_ts = int(event["ts"]) - 1
110 queue_df.loc[cmd_index, ["duration"]] = [
111 end_ts - start_ts,
112 ]
113 start_ts = end_ts
114 cmd_index = end_idx
115 chain_len = 1
116
117
118Agg = Union[str, Callable[[pd.Series], Any]]

Callers 1

build_overlay_dataFunction · 0.85

Calls 2

is_end_of_commandFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected