@@ -153,12 +153,16 @@ class Event:
153
153
154
154
@staticmethod
155
155
def _gen_from_profile_events (
156
- signature : ProfileEventSignature , events : List [ProfileEvent ]
156
+ signature : ProfileEventSignature ,
157
+ events : List [ProfileEvent ],
158
+ scale_factor : int = 1 ,
157
159
) -> "Event" :
158
160
"""
159
161
Given a ProfileEventSignature and a list of ProfileEvents with that signature,
160
162
return an Event object matching the ProfileEventSignature, with perf_data
161
163
populated from the list of ProfileEvents
164
+
165
+ An optional inverse scale factor can be provided to adjust the event timestamps
162
166
"""
163
167
if signature .delegate_id is not None : # 0 is a valid value
164
168
delegate_debug_identifier = signature .delegate_id
@@ -170,7 +174,10 @@ def _gen_from_profile_events(
170
174
name = signature .name if not is_delegated_op else str (delegate_debug_identifier )
171
175
172
176
perf_data = PerfData (
173
- [float (event .end_time - event .start_time ) / 1000 for event in events ]
177
+ [
178
+ float (event .end_time - event .start_time ) / scale_factor
179
+ for event in events
180
+ ]
174
181
)
175
182
176
183
return Event (
@@ -247,10 +254,15 @@ def to_dataframe(self) -> pd.DataFrame:
247
254
return df
248
255
249
256
@staticmethod
250
- def _gen_from_etdump (etdump : ETDumpFlatCC ) -> List ["EventBlock" ]:
257
+ def _gen_from_etdump (
258
+ etdump : ETDumpFlatCC , scale_factor : int = 1
259
+ ) -> List ["EventBlock" ]:
251
260
"""
252
261
Given an etdump, generate a list of EventBlocks corresponding to the
253
- contents
262
+ contents.
263
+
264
+ An optional (inverse) scale factor can be provided to adjust the
265
+ etdump timestamps associated with each EventBlocks
254
266
"""
255
267
256
268
# Group all the RunData by the set of profile events
@@ -286,7 +298,7 @@ def _gen_from_etdump(etdump: ETDumpFlatCC) -> List["EventBlock"]:
286
298
EventBlock (
287
299
name = str (index ),
288
300
events = [
289
- Event ._gen_from_profile_events (signature , event )
301
+ Event ._gen_from_profile_events (signature , event , scale_factor )
290
302
for signature , event in profile_events .items ()
291
303
],
292
304
)
@@ -360,16 +372,25 @@ class Inspector:
360
372
"""
361
373
362
374
def __init__ (
363
- self , etdump_path : Optional [str ] = None , etrecord_path : Optional [str ] = None
375
+ self ,
376
+ etdump_path : Optional [str ] = None ,
377
+ etrecord_path : Optional [str ] = None ,
378
+ etdump_scale : int = 1000 ,
364
379
) -> None :
365
380
"""
366
381
Create an inspector instance from the provided ETDump/ETRecord
382
+
383
+ Args:
384
+ etdump_path: Path to the ETDump file.
385
+ etrecord_path: Path to the ETRecord file.
386
+ etdump_scale: Inverse Scale Factor used to cast the timestamps in ETDump
387
+ defaults to milli (1000ms = 1s).
367
388
"""
368
389
369
390
# TODO: etrecord_path can be optional, so need to support the case when it is not present
370
391
self ._etrecord = gen_etrecord_object (etrecord_path = etrecord_path )
371
392
etdump = gen_etdump_object (etdump_path = etdump_path )
372
- self .event_blocks = EventBlock ._gen_from_etdump (etdump )
393
+ self .event_blocks = EventBlock ._gen_from_etdump (etdump , etdump_scale )
373
394
374
395
self ._op_graph_dict : Mapping [
375
396
str , OperatorGraphWithStats
0 commit comments