| 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()) |