Skip to content

Commit

Permalink
Limit number of demangler invocations in autograd profiler
Browse files Browse the repository at this point in the history
  • Loading branch information
apaszke authored and soumith committed Oct 3, 2017
1 parent 312e0ce commit 6fbbb1b
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion torch/autograd/profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,9 @@ def __repr__(self):
self.cpu_time_str, self.cuda_time_str, self.key)


################################################################################
# Utilities

def demangle(name):
"""Demangle a C++ identifier using c++filt"""
try:
Expand All @@ -253,6 +256,12 @@ def demangle(name):
return name


class StringTable(defaultdict):
def __missing__(self, key):
self[key] = demangle(key)
return self[key]


################################################################################
# CPU checkpoints

Expand All @@ -264,6 +273,7 @@ def parse_cpu_trace(thread_records):
start_time = None
functions = []
function_stack = []
string_table = StringTable()
for r in itertools.chain(*thread_records):
record = Record(*r)
if record.name == '__start_profile':
Expand All @@ -272,7 +282,7 @@ def parse_cpu_trace(thread_records):
continue
elif record.kind == 'push':
function_stack.append(FunctionEvent(
id=next_id, name=demangle(record.name), start=record.timestamp, end=record.timestamp))
id=next_id, name=string_table[record.name], start=record.timestamp, end=record.timestamp))
next_id += 1
elif record.kind == 'pop':
function_stack[-1].end = record.timestamp
Expand Down

0 comments on commit 6fbbb1b

Please sign in to comment.