9
9
from collections import OrderedDict
10
10
from enum import Enum
11
11
12
- from typing import Dict , List , Tuple
12
+ from typing import Dict , List , Optional , Tuple
13
13
14
- from prettytable import PrettyTable
14
+ from prettytable import PrettyTable # type: ignore[import-not-found]
15
15
16
16
# This version number should match the one defined in profiler.h
17
17
ET_PROF_VER = 0x00000001
@@ -89,8 +89,7 @@ class ProfileEvent:
89
89
duration : List [float ]
90
90
chain_idx : int = - 1
91
91
instruction_idx : int = - 1
92
- # pyre-ignore[8]: Incompatible attribute type
93
- stacktrace : str = None
92
+ stacktrace : Optional [str ] = None
94
93
95
94
96
95
@dataclasses .dataclass
@@ -134,8 +133,8 @@ def parse_prof_blocks(
134
133
135
134
# Iterate through all the profiling blocks data that have been grouped by name.
136
135
for name , data_list in prof_blocks .items ():
137
- prof_data_list = []
138
- mem_prof_data_list = []
136
+ prof_data_list : List [ ProfileEvent ] = []
137
+ mem_prof_data_list : List [ MemAllocation ] = []
139
138
# Each entry in data_list is a tuple in which the first entry is profiling data
140
139
# and the second entry is memory allocation data, also each entry in data_list
141
140
# represents one iteration of a code block.
@@ -168,13 +167,13 @@ def parse_prof_blocks(
168
167
169
168
# Group all the memory allocation events based on the allocator they were
170
169
# allocated from.
171
- alloc_sum_dict = OrderedDict ()
170
+ alloc_sum_dict : OrderedDict [ int , int ] = OrderedDict ()
172
171
for alloc in mem_prof_data_list :
173
172
alloc_sum_dict [alloc .allocator_id ] = (
174
173
alloc_sum_dict .get (alloc .allocator_id , 0 ) + alloc .allocation_size
175
174
)
176
175
177
- mem_prof_sum_list = []
176
+ mem_prof_sum_list : List [ MemEvent ] = []
178
177
for allocator_id , allocation_size in alloc_sum_dict .items ():
179
178
mem_prof_sum_list .append (
180
179
MemEvent (allocator_dict [allocator_id ], allocation_size )
@@ -243,7 +242,9 @@ def deserialize_profile_results(
243
242
prof_allocator_struct_size = struct .calcsize (ALLOCATOR_STRUCT_FMT )
244
243
prof_allocation_struct_size = struct .calcsize (ALLOCATION_STRUCT_FMT )
245
244
prof_result_struct_size = struct .calcsize (PROF_RESULT_STRUCT_FMT )
246
- prof_blocks = OrderedDict ()
245
+ prof_blocks : OrderedDict [
246
+ str , List [Tuple [List [ProfileData ], List [MemAllocation ]]]
247
+ ] = OrderedDict ()
247
248
allocator_dict = {}
248
249
base_offset = 0
249
250
@@ -375,19 +376,19 @@ def profile_aggregate_framework_tax(
375
376
prof_framework_tax = OrderedDict ()
376
377
377
378
for name , prof_data_list in prof_data .items ():
378
- execute_max = []
379
- kernel_and_delegate_sum = []
379
+ execute_max : List [ int ] = []
380
+ kernel_and_delegate_sum : List [ int ] = []
380
381
381
382
for d in prof_data_list :
382
383
if "Method::execute" in d .name :
383
- execute_max = max (execute_max , d .duration )
384
+ execute_max = max (execute_max , d .duration ) # type: ignore[arg-type]
384
385
385
386
if "native_call" in d .name or "delegate_execute" in d .name :
386
387
for idx in range (len (d .duration )):
387
388
if idx < len (kernel_and_delegate_sum ):
388
- kernel_and_delegate_sum [idx ] += d .duration [idx ]
389
+ kernel_and_delegate_sum [idx ] += d .duration [idx ] # type: ignore[call-overload]
389
390
else :
390
- kernel_and_delegate_sum .append (d .duration [idx ])
391
+ kernel_and_delegate_sum .append (d .duration [idx ]) # type: ignore[arg-type]
391
392
392
393
if len (execute_max ) == 0 or len (kernel_and_delegate_sum ) == 0 :
393
394
continue
@@ -408,10 +409,9 @@ def profile_aggregate_framework_tax(
408
409
409
410
def profile_framework_tax_table (
410
411
prof_framework_tax_data : Dict [str , ProfileEventFrameworkTax ]
411
- ):
412
- tables = []
412
+ ) -> List [ PrettyTable ] :
413
+ tables : List [ PrettyTable ] = []
413
414
for name , prof_data_list in prof_framework_tax_data .items ():
414
- tables = []
415
415
table_agg = PrettyTable ()
416
416
table_agg .title = name + " framework tax calculations"
417
417
0 commit comments