MCPcopy Create free account
hub / github.com/pytorch/pytorch / dump_string

Method dump_string

torch/jit/_script.py:1647–1675  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1645 self.profile.disable()
1646
1647 def dump_string(self) -> str:
1648 outputs: List[str] = []
1649 for source_stats in self.profile._dump_stats():
1650 source_ref = source_stats.source()
1651 source_lines = source_ref.text().splitlines()
1652 dedent = min([len(line) - len(line.lstrip(" ")) for line in source_lines])
1653 source_lines = [line[dedent:] for line in source_lines]
1654
1655 start_line = source_ref.starting_lineno()
1656 end_line = start_line + len(source_lines)
1657 source_range = range(start_line, end_line)
1658 lineno = _ScriptProfileColumn("Line #")
1659 hits = _ScriptProfileColumn("Hits")
1660 time_ns = _ScriptProfileColumn("Time (ns)")
1661 line_contents = _ScriptProfileColumn("Line Contents", 0, 1)
1662 stats = source_stats.line_map()
1663 for line in source_range:
1664 lineno.add_row(line, line)
1665 line_contents.add_row(line, source_lines[line - start_line])
1666 stat = stats.get(line)
1667 if stat is not None:
1668 hits.add_row(line, stat.count())
1669 time_ns.add_row(line, stat.duration_ns())
1670
1671 table = _ScriptProfileTable(
1672 [lineno, hits, time_ns, line_contents], list(source_range)
1673 )
1674 outputs.append(table.dump_string())
1675 return "\n\n".join(outputs)
1676
1677 def dump(self):
1678 print(self.dump_string())

Callers 6

dumpMethod · 0.95
test_basicMethod · 0.45
test_scriptMethod · 0.45
test_multiMethod · 0.45
fnMethod · 0.45
test_emptyMethod · 0.45

Calls 12

_ScriptProfileTableClass · 0.85
listFunction · 0.85
lstripMethod · 0.80
minFunction · 0.50
rangeFunction · 0.50
sourceMethod · 0.45
add_rowMethod · 0.45
getMethod · 0.45
countMethod · 0.45
appendMethod · 0.45
joinMethod · 0.45

Tested by 5

test_basicMethod · 0.36
test_scriptMethod · 0.36
test_multiMethod · 0.36
fnMethod · 0.36
test_emptyMethod · 0.36