Skip to content

Commit 22e859e

Browse files
authored
[Bug] Robust code for profiler server (#1221)
* robust code for profiler * robust code
1 parent de6bac4 commit 22e859e

File tree

3 files changed

+125
-28
lines changed

3 files changed

+125
-28
lines changed

visualdl/component/profiler/profiler_data.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ def get_views(self):
131131
return views
132132

133133
def get_device_infos(self):
134+
if not self.overview_parser:
135+
return
134136
if not self.overview_parser.has_device:
135137
device_type = 'CPU'
136138
return {
@@ -219,6 +221,8 @@ def get_model_perspective(self, time_unit):
219221
'''
220222
Get total cpu and gpu statistics for model perspective of each profiler step.
221223
'''
224+
if not self.overview_parser:
225+
return
222226
data = OrderedDict()
223227
data['column_name'] = [
224228
"name", "calls", "total_time", "avg_time", "max_time", "min_time",
@@ -281,6 +285,8 @@ def get_model_perspective(self, time_unit):
281285
return data
282286

283287
def get_model_perspective_perstep(self, device_type, time_unit):
288+
if not self.overview_parser:
289+
return
284290
try:
285291
data = OrderedDict()
286292
data['order'] = []
@@ -329,6 +335,8 @@ def get_model_perspective_perstep(self, device_type, time_unit):
329335
return new_data
330336

331337
def get_event_type_perspective(self, device_type, time_unit):
338+
if not self.overview_parser:
339+
return
332340
data = OrderedDict()
333341
data['order'] = []
334342
if device_type == 'cpu':
@@ -416,6 +424,8 @@ def get_event_type_perspective(self, device_type, time_unit):
416424
return data
417425

418426
def get_event_type_model_perspective(self, time_unit): # noqa: C901
427+
if not self.overview_parser:
428+
return
419429
data = OrderedDict()
420430
data['order'] = []
421431
data['phase_type'] = []
@@ -470,6 +480,8 @@ def get_event_type_model_perspective(self, time_unit): # noqa: C901
470480
return newdata
471481

472482
def get_userdefined_perspective(self, time_unit):
483+
if not self.overview_parser:
484+
return
473485
data = OrderedDict()
474486
if self.overview_parser.has_device:
475487
data['column_name'] = [
@@ -542,6 +554,8 @@ def get_userdefined_perspective(self, time_unit):
542554
return data
543555

544556
def get_operator_pie(self, topk, time_unit='ms'):
557+
if not self.operator_parser:
558+
return
545559
data = OrderedDict()
546560
data['column_name'] = [
547561
"name", "calls", "total_time", "avg_time", "max_time", "min_time",
@@ -611,6 +625,8 @@ def get_operator_pie(self, topk, time_unit='ms'):
611625

612626
def get_operator_pie_expand( # noqa: C901
613627
self, topk, device_type, time_unit):
628+
if not self.operator_parser:
629+
return
614630
data = OrderedDict()
615631
data['order'] = []
616632
data['phase_type'] = []
@@ -713,6 +729,9 @@ def get_operator_table( # noqa: C901 Todo: Optimize code
713729
group_by='op_name',
714730
search_name=None,
715731
time_unit='ms'):
732+
if not self.operator_parser:
733+
return
734+
716735
def get_children_data(event):
717736
datas = []
718737
for innerop_name, item in event.operator_inners.items():
@@ -1359,6 +1378,8 @@ def get_children_data(event):
13591378
return data
13601379

13611380
def get_kernel_pie(self, topk, time_unit='ms'):
1381+
if not self.kernel_parser:
1382+
return
13621383
data = OrderedDict()
13631384
data['column_name'] = [
13641385
"name", "calls", "total_time", "avg_time", "max_time", "min_time",
@@ -1405,6 +1426,8 @@ def get_kernel_pie(self, topk, time_unit='ms'):
14051426
return data
14061427

14071428
def get_kernel_table(self, group_by='', search_name=None, time_unit='ms'):
1429+
if not self.kernel_parser:
1430+
return
14081431
data = OrderedDict()
14091432
data['events'] = []
14101433
total_gpu_time = 0
@@ -1561,6 +1584,8 @@ def get_kernel_table(self, group_by='', search_name=None, time_unit='ms'):
15611584
return data
15621585

15631586
def get_kernel_tc_pie(self, topk, time_unit='ms'):
1587+
if not self.kernel_parser:
1588+
return
15641589
data = OrderedDict()
15651590
data['column_name'] = ["name", "calls", "ratio"]
15661591

@@ -1602,9 +1627,13 @@ def get_kernel_tc_pie(self, topk, time_unit='ms'):
16021627
return data
16031628

16041629
def get_trace_data(self):
1630+
if not self.trace_parser:
1631+
return
16051632
return self.trace_parser.content
16061633

16071634
def get_memory_devices(self):
1635+
if not self.memory_parser:
1636+
return
16081637
data = []
16091638
for device in self.memory_curve.keys():
16101639
data.append({
@@ -1620,6 +1649,8 @@ def get_memory_devices(self):
16201649
return data
16211650

16221651
def get_memory_curve(self, device_type, time_unit='ms'):
1652+
if not self.memory_parser:
1653+
return
16231654
curves = self.memory_curve[device_type]
16241655
data = {}
16251656
data['name'] = {
@@ -1647,6 +1678,8 @@ def get_memory_events(self,
16471678
max_size=float('inf'),
16481679
search_name=None,
16491680
time_unit='ms'):
1681+
if not self.memory_parser:
1682+
return
16501683
data = {}
16511684
data['column_name'] = [
16521685
'MemoryAddr', 'MemoryType', 'AllocatedEvent', 'AllocatedTimestamp',
@@ -1705,6 +1738,8 @@ def filter_func(item):
17051738
return data
17061739

17071740
def get_op_memory_events(self, device_type, search_name=None):
1741+
if not self.memory_parser:
1742+
return
17081743
data = {}
17091744
data['column_name'] = [
17101745
'EventName', 'MemoryType', 'AllocationCount', 'FreeCount',

0 commit comments

Comments
 (0)