runmap 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,41 @@
1
+ name: Publish to PyPI
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - "v*"
7
+
8
+ jobs:
9
+ build:
10
+ runs-on: ubuntu-latest
11
+ steps:
12
+ - uses: actions/checkout@v4
13
+
14
+ - uses: actions/setup-python@v5
15
+ with:
16
+ python-version: "3.12"
17
+
18
+ - name: Install build tools
19
+ run: pip install build
20
+
21
+ - name: Build package
22
+ run: python -m build
23
+
24
+ - uses: actions/upload-artifact@v4
25
+ with:
26
+ name: dist
27
+ path: dist/
28
+
29
+ publish:
30
+ needs: build
31
+ runs-on: ubuntu-latest
32
+ environment: pypi
33
+ permissions:
34
+ id-token: write
35
+ steps:
36
+ - uses: actions/download-artifact@v4
37
+ with:
38
+ name: dist
39
+ path: dist/
40
+
41
+ - uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,11 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ *$py.class
4
+ *.egg-info/
5
+ dist/
6
+ build/
7
+ *.egg
8
+ .pytest_cache/
9
+ .venv/
10
+ venv/
11
+ *.whl
@@ -0,0 +1,160 @@
1
+ # Project Instructions
2
+
3
+ General rules for code, markdown, and documentation written by AI in this project.
4
+
5
+ ---
6
+
7
+ ## Code
8
+
9
+ ### Comments
10
+
11
+ - Use single-line comments only, unless a comment is 2-3+ lines — then use a docstring/block comment
12
+ - Write comments only when the code is not obvious to someone with basic knowledge of the language
13
+ - If a block needs explaining — explain it briefly; don't over-describe
14
+
15
+ ### Naming & style
16
+
17
+ - No self-praising names — no `Advanced`, `Ultimate`, `Professional`, `Expert`, `Smart`, `Intelligent`, etc. in class, function, variable, or constant names
18
+ - No "Modern", "intuitive", "polished", "seamless" in package names, descriptions, or identifiers unless there's a specific reason (e.g. marketing)
19
+ - Use abbreviations and short words where it reads naturally
20
+ - Use standard libraries, well-known packages, tools, and frameworks — don't reinvent the wheel unless there's no other way
21
+
22
+ ### General
23
+
24
+ - No unused imports, dependencies, or dead code
25
+ - No overly technical terms when simpler ones work
26
+ - Code should be readable to other developers without a tour; middle-level language features are fine when appropriate
27
+ - Don't write explanations about what code does outside code blocks
28
+
29
+ ---
30
+
31
+ ## Markdown files
32
+
33
+ Follow standard markdown linting rules (markdownlint):
34
+
35
+ - Headings increment by one level at a time (MD001)
36
+ - Consistent heading style (MD003)
37
+ - Consistent unordered list style (MD004, MD007)
38
+ - No trailing spaces (MD009), no hard tabs (MD010)
39
+ - No multiple consecutive blank lines (MD012)
40
+ - No reversed link syntax (MD011), no bare URLs (MD034), no empty links (MD042)
41
+ - Fenced code blocks surrounded by blank lines (MD031) and have a language specified (MD040)
42
+ - Lists surrounded by blank lines (MD032)
43
+ - No inline HTML (MD033) unless necessary
44
+ - Single top-level heading per file (MD025)
45
+ - No trailing punctuation in headings (MD026)
46
+ - Images must have alt text (MD045)
47
+ - Files end with a single newline (MD047)
48
+ - Tables surrounded by blank lines (MD058), consistent pipe style (MD055), correct column count (MD056)
49
+ - Proper capitalization of proper names (MD044)
50
+
51
+ The file must be readable and make sense to humans, not just pass a linter.
52
+
53
+ ---
54
+
55
+ ## README and documentation
56
+
57
+ ### Main rule
58
+
59
+ Don't praise the project, code, or yourself. Describe what it does and how to use it.
60
+
61
+ ### Tone
62
+
63
+ - Natural, conversational — like explaining to a developer, not writing a spec
64
+ - Short sentences, no walls of text
65
+ - No emojis, no excessive exclamation marks
66
+ - No "just" or "simply" before instructions
67
+ - No redundant phrases like "This project is built with..."
68
+
69
+ ### Avoid these words and phrases
70
+
71
+ `Modern`, `intuitive`, `polished`, `seamless`, `instant`, `robust`, `scalable`, `high performance`,
72
+ `lightweight` (unless in a general factual context like "LuminFM is a fast, lightweight file manager"),
73
+ `easy to use`, `user-friendly`, `powerful features`, `out of the box`, `state of the art`,
74
+ `cutting edge`, `industry standard`, `next-generation`, `best-in-class`, `world-class`,
75
+ `game-changer`, `revolutionary`, `innovative`, `versatile`, `flexible`, `customizable`,
76
+ `seamless experience`, `that makes your workflow easier`, `that enhances productivity`,
77
+ `that simplifies complex tasks`, `that redefines excellence` — and similar marketing copy
78
+
79
+ ### Structure
80
+
81
+ 1. Title with badges (release, license, versions, platforms, latest commit, etc.)
82
+ 2. One-sentence tagline
83
+ 3. One paragraph: what it is and why you'd use it
84
+ 4. `## Getting Started` — download link and setup commands
85
+ 5. `## Features` — main features in plain language (see below)
86
+ 6. `## Requirements` — if needed; link to requirements file if one exists
87
+ 7. `## License` — link to LICENSE file
88
+
89
+ Don't add project structure, implementation details, or contribution guidelines unless asked. If developer info is needed, add it separately under `## Build` or `## Contributing`.
90
+
91
+ ### Headings
92
+
93
+ - Use `##` for main sections
94
+ - Avoid `###` unless a critical subsection is needed
95
+ - Keep total heading count low (5–7)
96
+
97
+ ### Features section
98
+
99
+ Write features as a short list with this pattern:
100
+
101
+ ```markdown
102
+ ## Features
103
+
104
+ - Feature name: Short description of what it does.
105
+ ```
106
+
107
+ Don't state obvious things (e.g. "You can open files" in a file manager). Write only features that
108
+ are notable or non-obvious. Keep descriptions short — don't explain why a feature is good, just
109
+ what it does.
110
+
111
+ Bad:
112
+
113
+ ```markdown
114
+ - Tabbed browsing: Work with multiple folders at once without opening new windows
115
+ - Themes: Light and dark modes that persist across sessions
116
+ ```
117
+
118
+ Good:
119
+
120
+ ```markdown
121
+ - Tabbed browsing: Work with multiple folders at once
122
+ - Themes: Light and dark themes support
123
+ ```
124
+
125
+ ### Code blocks
126
+
127
+ - Always specify the language
128
+ - Keep examples short and runnable
129
+ - Show only what's necessary
130
+
131
+ ### Links
132
+
133
+ Use `[Release Downloads](url)` format. You can link to releases, the LICENSE file, a website if
134
+ there is one, etc.
135
+
136
+ ---
137
+
138
+ ## Typography
139
+
140
+ Use standard keyboard characters where possible. Avoid special Unicode symbols unless there's
141
+ no alternative.
142
+
143
+ | Instead of | Use |
144
+ |------------|-----|
145
+ | `—` (em dash) | `-` (preffered) or `--` |
146
+ | `–` (en dash) | `-` |
147
+ | `«»` or `""` (curly/guillemet quotes) | `"` |
148
+ | `''` (curly single quotes) | `'` |
149
+ | `→`, `←`, `↑`, `↓` (arrows) | `->`, `<-`, `^`, or plain words |
150
+ | `…` (ellipsis) | `...` |
151
+ | `×` (multiplication sign) | `x` |
152
+ | `•` (bullet) | `-` in markdown lists |
153
+
154
+ This applies to code, markdown, docs, and comments. Exception: if a symbol is part of an
155
+ actual string value, a UI label, or has semantic meaning in context — use whatever is correct.
156
+
157
+ ## Dots
158
+
159
+ - Do not add periods at the end of docstrings or comments unless required by the language, tooling, or style guide used by the project
160
+ - In this project, comments and docstrings are typically written without trailing periods
runmap-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 NazarHK
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
runmap-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,68 @@
1
+ Metadata-Version: 2.4
2
+ Name: runmap
3
+ Version: 0.1.0
4
+ Summary: Python call tree profiler for the terminal
5
+ Project-URL: Homepage, https://github.com/nazarhktwitch/runmap
6
+ Project-URL: Repository, https://github.com/nazarhktwitch/runmap
7
+ Project-URL: Issues, https://github.com/nazarhktwitch/runmap/issues
8
+ Author: Nazar Burlai
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Keywords: call-tree,cli,performance,profiler,tracing
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Environment :: Console
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Topic :: Software Development :: Debuggers
22
+ Classifier: Topic :: Software Development :: Testing
23
+ Classifier: Typing :: Typed
24
+ Requires-Python: >=3.10
25
+ Requires-Dist: rich>=13.0
26
+ Provides-Extra: dev
27
+ Requires-Dist: pytest; extra == 'dev'
28
+ Requires-Dist: pytest-cov; extra == 'dev'
29
+ Description-Content-Type: text/markdown
30
+
31
+ # runmap
32
+
33
+ Visualize Python function call trees with timing in the terminal
34
+
35
+ Run any script through runmap and see a tree of every function call, how long
36
+ each took, and where the hot spots are
37
+
38
+ ## Getting Started
39
+
40
+ ```bash
41
+ pip install runmap
42
+ ```
43
+
44
+ ```bash
45
+ python -m runmap script.py
46
+ python -m runmap script.py --min-ms 5 --depth 3
47
+ python -m runmap script.py --out run.trace
48
+ python -m runmap diff before.trace after.trace
49
+ ```
50
+
51
+ ## Features
52
+
53
+ - Call tree view: shows the full function call hierarchy with per-node timing.
54
+ - Time bars: proportional block bars next to each node for quick visual scanning.
55
+ - Hot markers: flags functions whose self time exceeds 20% of total runtime.
56
+ - Depth and threshold filters: `--depth` and `--min-ms` trim noise from large trees.
57
+ - Trace files: `--out` saves a `.trace` JSON file for later comparison.
58
+ - Diff mode: `runmap diff A.trace B.trace` shows a delta table (faster/slower/new).
59
+ - Sampling mode: `--sample` uses signal-based 100 Hz sampling instead of `sys.settrace` (Unix only).
60
+
61
+ ## Requirements
62
+
63
+ - Python 3.10+
64
+ - [rich](https://github.com/Textualize/rich) >= 13.0
65
+
66
+ ## License
67
+
68
+ [MIT](LICENSE)
runmap-0.1.0/README.md ADDED
@@ -0,0 +1,38 @@
1
+ # runmap
2
+
3
+ Visualize Python function call trees with timing in the terminal
4
+
5
+ Run any script through runmap and see a tree of every function call, how long
6
+ each took, and where the hot spots are
7
+
8
+ ## Getting Started
9
+
10
+ ```bash
11
+ pip install runmap
12
+ ```
13
+
14
+ ```bash
15
+ python -m runmap script.py
16
+ python -m runmap script.py --min-ms 5 --depth 3
17
+ python -m runmap script.py --out run.trace
18
+ python -m runmap diff before.trace after.trace
19
+ ```
20
+
21
+ ## Features
22
+
23
+ - Call tree view: shows the full function call hierarchy with per-node timing.
24
+ - Time bars: proportional block bars next to each node for quick visual scanning.
25
+ - Hot markers: flags functions whose self time exceeds 20% of total runtime.
26
+ - Depth and threshold filters: `--depth` and `--min-ms` trim noise from large trees.
27
+ - Trace files: `--out` saves a `.trace` JSON file for later comparison.
28
+ - Diff mode: `runmap diff A.trace B.trace` shows a delta table (faster/slower/new).
29
+ - Sampling mode: `--sample` uses signal-based 100 Hz sampling instead of `sys.settrace` (Unix only).
30
+
31
+ ## Requirements
32
+
33
+ - Python 3.10+
34
+ - [rich](https://github.com/Textualize/rich) >= 13.0
35
+
36
+ ## License
37
+
38
+ [MIT](LICENSE)
@@ -0,0 +1,24 @@
1
+ import time
2
+
3
+ def load_data():
4
+ time.sleep(0.01)
5
+ return list(range(100))
6
+
7
+ def validate(data):
8
+ time.sleep(0.003)
9
+ return [x for x in data if x % 2 == 0]
10
+
11
+ def process(data):
12
+ time.sleep(0.005)
13
+ return [x * 2 for x in data]
14
+
15
+ def save(data):
16
+ time.sleep(0.004)
17
+
18
+ def main():
19
+ data = load_data()
20
+ clean = validate(data)
21
+ result = process(clean)
22
+ save(result)
23
+
24
+ main()
@@ -0,0 +1,44 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "runmap"
7
+ version = "0.1.0"
8
+ description = "Python call tree profiler for the terminal"
9
+ requires-python = ">=3.10"
10
+ dependencies = ["rich>=13.0"]
11
+ readme = "README.md"
12
+ license = "MIT"
13
+ keywords = ["profiler", "call-tree", "tracing", "performance", "cli"]
14
+ authors = [
15
+ { name = "Nazar Burlai" },
16
+ ]
17
+ classifiers = [
18
+ "Development Status :: 4 - Beta",
19
+ "Environment :: Console",
20
+ "Intended Audience :: Developers",
21
+ "License :: OSI Approved :: MIT License",
22
+ "Programming Language :: Python :: 3",
23
+ "Programming Language :: Python :: 3.10",
24
+ "Programming Language :: Python :: 3.11",
25
+ "Programming Language :: Python :: 3.12",
26
+ "Programming Language :: Python :: 3.13",
27
+ "Topic :: Software Development :: Debuggers",
28
+ "Topic :: Software Development :: Testing",
29
+ "Typing :: Typed",
30
+ ]
31
+
32
+ [project.urls]
33
+ Homepage = "https://github.com/nazarhktwitch/runmap"
34
+ Repository = "https://github.com/nazarhktwitch/runmap"
35
+ Issues = "https://github.com/nazarhktwitch/runmap/issues"
36
+
37
+ [project.scripts]
38
+ runmap = "runmap.__main__:main"
39
+
40
+ [project.optional-dependencies]
41
+ dev = ["pytest", "pytest-cov"]
42
+
43
+ [tool.pytest.ini_options]
44
+ testpaths = ["tests"]
@@ -0,0 +1 @@
1
+ __version__ = "0.1.0"
@@ -0,0 +1,145 @@
1
+ from __future__ import annotations
2
+
3
+ import argparse
4
+ import runpy
5
+ import sys
6
+ import traceback as tb
7
+ from pathlib import Path
8
+
9
+ from runmap import __version__
10
+ from runmap import exporter, diff as diff_mod
11
+ from runmap.tracer import Tracer
12
+ from runmap.tree import build
13
+ from runmap.renderer import render
14
+
15
+
16
+ def _run_script(script: str, args: list[str]) -> None:
17
+ """Execute target script in its own namespace, replacing sys.argv"""
18
+ script_path = Path(script).resolve()
19
+ if not script_path.exists():
20
+ sys.exit(f"runmap: file not found: {script}")
21
+
22
+ sys.argv = [str(script_path)] + args
23
+ sys.path.insert(0, str(script_path.parent))
24
+ runpy.run_path(str(script_path), run_name="__main__")
25
+
26
+
27
+ def _build_run_parser() -> argparse.ArgumentParser:
28
+ p = argparse.ArgumentParser(
29
+ prog="runmap",
30
+ description="Visualize Python function call trees with timing",
31
+ )
32
+ p.add_argument("--version", action="version", version=f"runmap {__version__}")
33
+ p.add_argument("--no-color", action="store_true", help="Disable rich styling")
34
+ p.add_argument("--depth", type=int, default=None, metavar="INT",
35
+ help="Max tree depth (default: unlimited)")
36
+ p.add_argument("--min-ms", type=float, default=0.0, metavar="MS",
37
+ help="Hide nodes below this threshold in ms (default: 0)")
38
+ p.add_argument("--sample", action="store_true",
39
+ help="Use signal-based sampler instead of sys.settrace (Unix only)")
40
+ p.add_argument("--out", default=None, metavar="FILE",
41
+ help="Save .trace JSON to file")
42
+ p.add_argument("script", help="Path to script to profile")
43
+ p.add_argument("script_args", nargs=argparse.REMAINDER,
44
+ help="Arguments passed to the script")
45
+ return p
46
+
47
+
48
+ def _build_diff_parser() -> argparse.ArgumentParser:
49
+ p = argparse.ArgumentParser(
50
+ prog="runmap diff",
51
+ description="Compare two .trace files",
52
+ )
53
+ p.add_argument("a", metavar="A.trace")
54
+ p.add_argument("b", metavar="B.trace")
55
+ p.add_argument("--min-delta-ms", type=float, default=0.0, metavar="MS",
56
+ help="Hide entries with |delta| below this value (default: 0)")
57
+ p.add_argument("--no-color", action="store_true", help="Disable rich styling")
58
+ return p
59
+
60
+
61
+ def _cmd_run(args: argparse.Namespace) -> None:
62
+ if args.sample:
63
+ if sys.platform == "win32":
64
+ sys.exit(
65
+ "runmap: --sample is not available on Windows. "
66
+ "signal.setitimer is Unix-only. Use the default tracer mode."
67
+ )
68
+ from runmap.sampler import Sampler
69
+ sampler = Sampler()
70
+ sampler.start()
71
+ exc_info = None
72
+ try:
73
+ _run_script(args.script, args.script_args)
74
+ except SystemExit:
75
+ raise
76
+ except Exception:
77
+ exc_info = sys.exc_info()
78
+ finally:
79
+ sampler.stop()
80
+ records = sampler.to_records()
81
+ else:
82
+ tracer = Tracer()
83
+ tracer.start()
84
+ exc_info = None
85
+ try:
86
+ _run_script(args.script, args.script_args)
87
+ except SystemExit:
88
+ raise
89
+ except Exception:
90
+ exc_info = sys.exc_info()
91
+ finally:
92
+ tracer.stop()
93
+ records = tracer.records
94
+
95
+ root = build(records)
96
+ render(
97
+ root,
98
+ depth_limit=args.depth,
99
+ min_ms=args.min_ms,
100
+ no_color=args.no_color,
101
+ )
102
+
103
+ if args.out:
104
+ exporter.save(records, args.out)
105
+
106
+ if exc_info is not None:
107
+ # Re-raise with original traceback after showing the partial tree
108
+ raise exc_info[1].with_traceback(exc_info[2])
109
+
110
+
111
+ def _cmd_diff(args: argparse.Namespace) -> None:
112
+ old_records = exporter.load(args.a)
113
+ new_records = exporter.load(args.b)
114
+ results = diff_mod.compare(old_records, new_records)
115
+ diff_mod.render_diff(results, min_delta_ms=args.min_delta_ms, no_color=args.no_color)
116
+
117
+
118
+ def main() -> None:
119
+ # Ensure stdout uses UTF-8 regardless of the system codepage (e.g. CP1251 on Windows)
120
+ if hasattr(sys.stdout, "reconfigure"):
121
+ sys.stdout.reconfigure(encoding="utf-8", errors="replace")
122
+
123
+ argv = sys.argv[1:]
124
+
125
+ # Detect diff subcommand before handing to argparse so that a script path
126
+ # like "example.py" is never mistaken for an invalid subcommand choice
127
+ if argv and argv[0] == "diff":
128
+ parser = _build_diff_parser()
129
+ args = parser.parse_args(argv[1:])
130
+ _cmd_diff(args)
131
+ return
132
+
133
+ # Handle --version / --help with no script given
134
+ if not argv or argv == ["--version"]:
135
+ parser = _build_run_parser()
136
+ parser.parse_args(argv) # prints version or help and exits
137
+ return
138
+
139
+ parser = _build_run_parser()
140
+ args = parser.parse_args(argv)
141
+ _cmd_run(args)
142
+
143
+
144
+ if __name__ == "__main__":
145
+ main()
@@ -0,0 +1,84 @@
1
+ from __future__ import annotations
2
+
3
+ import math
4
+
5
+ from rich.console import Console
6
+ from rich.table import Table
7
+
8
+ from runmap.models import DiffResult, TraceRecord
9
+
10
+
11
+ def _aggregate(records: list[TraceRecord]) -> dict[str, float]:
12
+ """Sum total_ms per qualname"""
13
+ totals: dict[str, float] = {}
14
+ for r in records:
15
+ ms = (r.end_time - r.start_time) * 1000
16
+ totals[r.qualname] = totals.get(r.qualname, 0.0) + ms
17
+ return totals
18
+
19
+
20
+ def compare(old_records: list[TraceRecord], new_records: list[TraceRecord]) -> list[DiffResult]:
21
+ old = _aggregate(old_records)
22
+ new = _aggregate(new_records)
23
+
24
+ all_names = set(old) | set(new)
25
+ results: list[DiffResult] = []
26
+
27
+ for name in all_names:
28
+ old_ms = old.get(name, 0.0)
29
+ new_ms = new.get(name, 0.0)
30
+ delta_ms = new_ms - old_ms
31
+ if old_ms == 0:
32
+ delta_pct = math.inf if new_ms > 0 else 0.0
33
+ else:
34
+ delta_pct = (delta_ms / old_ms) * 100
35
+
36
+ results.append(DiffResult(
37
+ node_name=name,
38
+ old_ms=old_ms,
39
+ new_ms=new_ms,
40
+ delta_ms=delta_ms,
41
+ delta_pct=delta_pct,
42
+ ))
43
+
44
+ # Sort by abs delta descending
45
+ results.sort(key=lambda r: abs(r.delta_ms), reverse=True)
46
+ return results
47
+
48
+
49
+ def render_diff(
50
+ results: list[DiffResult],
51
+ min_delta_ms: float = 0.0,
52
+ no_color: bool = False,
53
+ ) -> None:
54
+ console = Console(highlight=False, no_color=no_color, legacy_windows=False)
55
+
56
+ filtered = [r for r in results if abs(r.delta_ms) >= min_delta_ms]
57
+ if not filtered:
58
+ console.print("[dim]No differences above threshold.[/dim]")
59
+ return
60
+
61
+ table = Table(show_header=True, header_style="bold")
62
+ table.add_column("Function", style="", no_wrap=True)
63
+ table.add_column("Old (ms)", justify="right")
64
+ table.add_column("New (ms)", justify="right")
65
+ table.add_column("Delta (ms)", justify="right")
66
+
67
+ for r in filtered:
68
+ pct = r.delta_pct
69
+ old_str = f"{r.old_ms:.1f}" if r.old_ms else "-"
70
+ new_str = f"{r.new_ms:.1f}" if r.new_ms else "-"
71
+
72
+ if math.isinf(pct) or abs(pct) < 5:
73
+ delta_str = f"{r.delta_ms:+.1f}"
74
+ style = "dim"
75
+ elif r.delta_ms < 0:
76
+ delta_str = f"{r.delta_ms:+.1f} ({pct:+.1f}%)"
77
+ style = "green"
78
+ else:
79
+ delta_str = f"{r.delta_ms:+.1f} ({pct:+.1f}%)"
80
+ style = "red"
81
+
82
+ table.add_row(r.node_name, old_str, new_str, f"[{style}]{delta_str}[/{style}]")
83
+
84
+ console.print(table)
@@ -0,0 +1,44 @@
1
+ from __future__ import annotations
2
+
3
+ import json
4
+ from pathlib import Path
5
+
6
+ from runmap.models import TraceRecord
7
+
8
+
9
+ def save(records: list[TraceRecord], path: str | Path) -> None:
10
+ data = [
11
+ {
12
+ "qualname": r.qualname,
13
+ "filename": r.filename,
14
+ "lineno": r.lineno,
15
+ "start_time": r.start_time,
16
+ "end_time": r.end_time,
17
+ "depth": r.depth,
18
+ "parent_name": r.parent_name,
19
+ }
20
+ for r in records
21
+ ]
22
+ Path(path).write_text(json.dumps(data, indent=2), encoding="utf-8")
23
+
24
+
25
+ def load(path: str | Path) -> list[TraceRecord]:
26
+ p = Path(path)
27
+ if not p.exists():
28
+ raise FileNotFoundError(
29
+ f"Trace file not found: {p}\n"
30
+ "Generate one with: python -m runmap script.py --out output.trace"
31
+ )
32
+ data = json.loads(p.read_text(encoding="utf-8"))
33
+ return [
34
+ TraceRecord(
35
+ qualname=d["qualname"],
36
+ filename=d["filename"],
37
+ lineno=d["lineno"],
38
+ start_time=d["start_time"],
39
+ end_time=d["end_time"],
40
+ depth=d["depth"],
41
+ parent_name=d["parent_name"],
42
+ )
43
+ for d in data
44
+ ]