profiling-explorer 1.0.0__py3-none-any.whl
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.
- profiling_explorer/__init__.py +0 -0
- profiling_explorer/__main__.py +6 -0
- profiling_explorer/main.py +56 -0
- profiling_explorer/management/__init__.py +0 -0
- profiling_explorer/management/commands/__init__.py +0 -0
- profiling_explorer/management/commands/runserver.py +28 -0
- profiling_explorer/py.typed +0 -0
- profiling_explorer/settings.py +37 -0
- profiling_explorer/static/script.js +84 -0
- profiling_explorer/static/styles.css +281 -0
- profiling_explorer/templates/_row.html +9 -0
- profiling_explorer/templates/base.html +27 -0
- profiling_explorer/templates/callers_callees.html +30 -0
- profiling_explorer/templates/index.html +23 -0
- profiling_explorer/templatetags/__init__.py +0 -0
- profiling_explorer/templatetags/profiling_explorer_tags.py +24 -0
- profiling_explorer/urls.py +14 -0
- profiling_explorer/views.py +330 -0
- profiling_explorer-1.0.0.dist-info/METADATA +150 -0
- profiling_explorer-1.0.0.dist-info/RECORD +24 -0
- profiling_explorer-1.0.0.dist-info/WHEEL +5 -0
- profiling_explorer-1.0.0.dist-info/entry_points.txt +2 -0
- profiling_explorer-1.0.0.dist-info/licenses/LICENSE +21 -0
- profiling_explorer-1.0.0.dist-info/top_level.txt +1 -0
|
File without changes
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
import os
|
|
5
|
+
import pstats
|
|
6
|
+
import sys
|
|
7
|
+
from collections.abc import Sequence
|
|
8
|
+
|
|
9
|
+
import django
|
|
10
|
+
from django.core.management import call_command
|
|
11
|
+
|
|
12
|
+
from profiling_explorer import settings, views
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def main(argv: Sequence[str] | None = None) -> int:
|
|
16
|
+
if argv is None:
|
|
17
|
+
argv = sys.argv[1:]
|
|
18
|
+
|
|
19
|
+
parser = argparse.ArgumentParser(prog="profiling-explorer", allow_abbrev=False)
|
|
20
|
+
parser.suggest_on_error = True # type: ignore[attr-defined]
|
|
21
|
+
parser.add_argument(
|
|
22
|
+
"filename",
|
|
23
|
+
metavar="FILE",
|
|
24
|
+
help="The pstats data file to explore.",
|
|
25
|
+
)
|
|
26
|
+
parser.add_argument(
|
|
27
|
+
"--port",
|
|
28
|
+
type=int,
|
|
29
|
+
default=8099,
|
|
30
|
+
metavar="PORT",
|
|
31
|
+
help="Port for the local web server (default: 8099).",
|
|
32
|
+
)
|
|
33
|
+
parser.add_argument(
|
|
34
|
+
"--dev",
|
|
35
|
+
action="store_true",
|
|
36
|
+
default=False,
|
|
37
|
+
help="Run in development mode (enables server reload and debug mode).",
|
|
38
|
+
)
|
|
39
|
+
args = parser.parse_args(argv)
|
|
40
|
+
|
|
41
|
+
settings.DEBUG = args.dev # type: ignore[attr-defined]
|
|
42
|
+
|
|
43
|
+
views.profile = views.build_profile(pstats.Stats(args.filename), args.filename)
|
|
44
|
+
|
|
45
|
+
os.environ["DJANGO_SETTINGS_MODULE"] = "profiling_explorer.settings"
|
|
46
|
+
|
|
47
|
+
django.setup()
|
|
48
|
+
|
|
49
|
+
call_command(
|
|
50
|
+
"runserver",
|
|
51
|
+
f"127.0.0.1:{args.port}",
|
|
52
|
+
"--nothreading",
|
|
53
|
+
*(() if args.dev else ("--noreload",)),
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
return 0
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import logging
|
|
4
|
+
import webbrowser
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
from django.core.management.commands.runserver import Command as RunserverCommand
|
|
8
|
+
from django.utils.log import RequireDebugTrue
|
|
9
|
+
|
|
10
|
+
logger = logging.getLogger("django.server")
|
|
11
|
+
logger.filters.append(RequireDebugTrue())
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class Command(RunserverCommand):
|
|
15
|
+
addr: str
|
|
16
|
+
|
|
17
|
+
def handle(self, *args: Any, **options: Any) -> None:
|
|
18
|
+
self.use_reloader = options["use_reloader"]
|
|
19
|
+
super().handle(*args, **options)
|
|
20
|
+
|
|
21
|
+
def on_bind(self, server_port: int) -> None:
|
|
22
|
+
self.stdout.write(
|
|
23
|
+
f"profiling-explorer running at http://{self.addr}:{server_port}/\n"
|
|
24
|
+
"Press CTRL+C to quit."
|
|
25
|
+
)
|
|
26
|
+
if not self.use_reloader:
|
|
27
|
+
print("Opening in web browser…")
|
|
28
|
+
webbrowser.open(f"http://{self.addr}:{server_port}")
|
|
File without changes
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
|
|
5
|
+
# Hide development server warning
|
|
6
|
+
# https://docs.djangoproject.com/en/stable/ref/django-admin/#envvar-DJANGO_RUNSERVER_HIDE_WARNING
|
|
7
|
+
os.environ["DJANGO_RUNSERVER_HIDE_WARNING"] = "true"
|
|
8
|
+
|
|
9
|
+
# Disable host header validation
|
|
10
|
+
ALLOWED_HOSTS = ["*"]
|
|
11
|
+
|
|
12
|
+
INSTALLED_APPS = [
|
|
13
|
+
"profiling_explorer",
|
|
14
|
+
"django.contrib.humanize",
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
MIDDLEWARE = [
|
|
18
|
+
"django.middleware.common.CommonMiddleware",
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
ROOT_URLCONF = "profiling_explorer.urls"
|
|
22
|
+
|
|
23
|
+
SECRET_KEY = "we-dont-use-any-secret-features-so-whatever"
|
|
24
|
+
|
|
25
|
+
TEMPLATES = [
|
|
26
|
+
{
|
|
27
|
+
"BACKEND": "django.template.backends.django.DjangoTemplates",
|
|
28
|
+
"DIRS": [],
|
|
29
|
+
"APP_DIRS": True,
|
|
30
|
+
"OPTIONS": {
|
|
31
|
+
"builtins": [
|
|
32
|
+
"profiling_explorer.templatetags.profiling_explorer_tags",
|
|
33
|
+
"django.contrib.humanize.templatetags.humanize",
|
|
34
|
+
],
|
|
35
|
+
},
|
|
36
|
+
}
|
|
37
|
+
]
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
async function fetchDoc(url, options) {
|
|
2
|
+
const response = await fetch(url, options);
|
|
3
|
+
const html = await response.text();
|
|
4
|
+
return new DOMParser().parseFromString(html, 'text/html');
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
// Filter box
|
|
8
|
+
const searchInput = document.getElementById('pe-search');
|
|
9
|
+
let searchTimeout = null;
|
|
10
|
+
let searchAbort = null;
|
|
11
|
+
|
|
12
|
+
searchInput.addEventListener('input', () => {
|
|
13
|
+
clearTimeout(searchTimeout);
|
|
14
|
+
searchTimeout = setTimeout(async () => {
|
|
15
|
+
const q = searchInput.value.trim();
|
|
16
|
+
const url = new URL(window.location.href);
|
|
17
|
+
if (q) {
|
|
18
|
+
url.searchParams.set('q', q);
|
|
19
|
+
} else {
|
|
20
|
+
url.searchParams.delete('q');
|
|
21
|
+
}
|
|
22
|
+
history.replaceState(null, '', url);
|
|
23
|
+
|
|
24
|
+
searchAbort?.abort();
|
|
25
|
+
searchAbort = new AbortController();
|
|
26
|
+
try {
|
|
27
|
+
const doc = await fetchDoc(url, { signal: searchAbort.signal });
|
|
28
|
+
document.querySelector('main').replaceWith(doc.querySelector('main'));
|
|
29
|
+
} catch (e) {
|
|
30
|
+
if (e.name !== 'AbortError') throw e;
|
|
31
|
+
}
|
|
32
|
+
}, 300);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
// Copy buttons
|
|
36
|
+
document.addEventListener('click', (e) => {
|
|
37
|
+
const btn = e.target.closest('button.copy-btn');
|
|
38
|
+
if (!btn) return;
|
|
39
|
+
|
|
40
|
+
const text = btn.dataset.copy;
|
|
41
|
+
navigator.clipboard.writeText(text).then(() => {
|
|
42
|
+
btn.classList.add('copied');
|
|
43
|
+
setTimeout(() => btn.classList.remove('copied'), 1500);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
// Pagination
|
|
49
|
+
class PePaginationMarker extends HTMLElement {
|
|
50
|
+
connectedCallback() {
|
|
51
|
+
this._observer = new IntersectionObserver(
|
|
52
|
+
(entries) => {
|
|
53
|
+
if (entries[0].isIntersecting) {
|
|
54
|
+
this._observer.disconnect();
|
|
55
|
+
this._load();
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
{ root: document.querySelector('main'), rootMargin: '200px' }
|
|
59
|
+
);
|
|
60
|
+
this._observer.observe(this);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
disconnectedCallback() {
|
|
64
|
+
this._observer?.disconnect();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async _load() {
|
|
68
|
+
const doc = await fetchDoc(this.dataset.url);
|
|
69
|
+
|
|
70
|
+
const tbody = document.querySelector('tbody');
|
|
71
|
+
for (const row of doc.querySelectorAll('tbody tr')) {
|
|
72
|
+
tbody.appendChild(document.adoptNode(row));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const nextMarker = doc.querySelector('pe-pagination-marker');
|
|
76
|
+
if (nextMarker) {
|
|
77
|
+
this.replaceWith(document.adoptNode(nextMarker));
|
|
78
|
+
} else {
|
|
79
|
+
this.remove();
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
customElements.define('pe-pagination-marker', PePaginationMarker);
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
:root {
|
|
2
|
+
--bg: #ffffff;
|
|
3
|
+
--surface: #f6f8fa;
|
|
4
|
+
--text: #1a1a1a;
|
|
5
|
+
--text-dim: #57606a;
|
|
6
|
+
--funcname: #7c3aed;
|
|
7
|
+
--border: #d0d7de;
|
|
8
|
+
--stripe: rgba(0, 0, 0, .03);
|
|
9
|
+
--row-hover: rgba(0, 0, 0, .06);
|
|
10
|
+
--nav-bg: #ffffff;
|
|
11
|
+
--nav-text: #1a1a1a;
|
|
12
|
+
--nav-dim: rgba(0, 0, 0, .4);
|
|
13
|
+
--nav-border: var(--border);
|
|
14
|
+
|
|
15
|
+
font-family: system-ui, sans-serif;
|
|
16
|
+
color-scheme: light dark;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
@media (prefers-color-scheme: dark) {
|
|
20
|
+
:root {
|
|
21
|
+
--bg: #0d1117;
|
|
22
|
+
--surface: #161b22;
|
|
23
|
+
--text: #e6edf3;
|
|
24
|
+
--text-dim: #8b949e;
|
|
25
|
+
--funcname: #c084fc;
|
|
26
|
+
--border: #30363d;
|
|
27
|
+
--stripe: rgba(255, 255, 255, .03);
|
|
28
|
+
--row-hover: rgba(255, 255, 255, .06);
|
|
29
|
+
--nav-bg: #161b22;
|
|
30
|
+
--nav-text: #e6edf3;
|
|
31
|
+
--nav-dim: rgba(230, 237, 243, .45);
|
|
32
|
+
--nav-border: rgba(230, 237, 243, .08);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
*, *::before, *::after {
|
|
37
|
+
box-sizing: border-box;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
body {
|
|
41
|
+
margin: 0;
|
|
42
|
+
background: var(--bg);
|
|
43
|
+
color: var(--text);
|
|
44
|
+
display: flex;
|
|
45
|
+
flex-direction: column;
|
|
46
|
+
height: 100dvh;
|
|
47
|
+
overflow: hidden;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
nav.primary {
|
|
51
|
+
background: var(--nav-bg);
|
|
52
|
+
color: var(--nav-text);
|
|
53
|
+
flex-shrink: 0;
|
|
54
|
+
display: flex;
|
|
55
|
+
align-items: baseline;
|
|
56
|
+
gap: 0 1rem;
|
|
57
|
+
padding: 0.6rem 1.5rem 0 1.5rem;
|
|
58
|
+
border-bottom: 1px solid var(--nav-border);
|
|
59
|
+
|
|
60
|
+
& h1 {
|
|
61
|
+
margin: 0;
|
|
62
|
+
font-size: 1.1rem;
|
|
63
|
+
font-weight: 600;
|
|
64
|
+
letter-spacing: -.01em;
|
|
65
|
+
white-space: nowrap;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
& h2 {
|
|
69
|
+
margin: 0;
|
|
70
|
+
font-size: 1.1rem;
|
|
71
|
+
font-weight: 400;
|
|
72
|
+
overflow: hidden;
|
|
73
|
+
text-overflow: ellipsis;
|
|
74
|
+
white-space: nowrap;
|
|
75
|
+
min-width: 0;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
& p {
|
|
79
|
+
margin: 0;
|
|
80
|
+
font-size: 0.9rem;
|
|
81
|
+
white-space: nowrap;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
& input[type=search] {
|
|
85
|
+
margin-inline-start: auto;
|
|
86
|
+
margin-block-end: 0.3rem;
|
|
87
|
+
padding: 0.25rem 0.55rem;
|
|
88
|
+
border: 1px solid var(--border);
|
|
89
|
+
background: var(--bg);
|
|
90
|
+
color: var(--text);
|
|
91
|
+
font-size: 0.875rem;
|
|
92
|
+
width: 20rem;
|
|
93
|
+
|
|
94
|
+
&::placeholder {
|
|
95
|
+
color: var(--text-dim);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
&:focus {
|
|
99
|
+
outline: 2px solid var(--funcname);
|
|
100
|
+
outline-offset: -1px;
|
|
101
|
+
border-color: transparent;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
nav.secondary {
|
|
107
|
+
display: flex;
|
|
108
|
+
align-items: baseline;
|
|
109
|
+
gap: 1rem;
|
|
110
|
+
padding: 0.6rem 1.5rem;
|
|
111
|
+
border-bottom: 1px solid var(--border);
|
|
112
|
+
background: var(--surface);
|
|
113
|
+
|
|
114
|
+
& h3 {
|
|
115
|
+
margin: 0;
|
|
116
|
+
font-size: 1rem;
|
|
117
|
+
font-weight: 600;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
a.back-link {
|
|
121
|
+
color: var(--text-dim);
|
|
122
|
+
|
|
123
|
+
&:hover {
|
|
124
|
+
color: var(--text);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
main {
|
|
131
|
+
overflow: auto;
|
|
132
|
+
flex: 1;
|
|
133
|
+
min-height: 0;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
table {
|
|
137
|
+
border-collapse: collapse;
|
|
138
|
+
white-space: nowrap;
|
|
139
|
+
width: 100%;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
thead tr {
|
|
143
|
+
background: var(--surface);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
th {
|
|
147
|
+
position: sticky;
|
|
148
|
+
top: 0;
|
|
149
|
+
background: var(--surface);
|
|
150
|
+
z-index: 1;
|
|
151
|
+
padding: 0.45rem 0.9rem;
|
|
152
|
+
text-align: right;
|
|
153
|
+
font-weight: 600;
|
|
154
|
+
letter-spacing: .05em;
|
|
155
|
+
color: var(--text-dim);
|
|
156
|
+
border-bottom: 2px solid var(--border);
|
|
157
|
+
width: 1%;
|
|
158
|
+
|
|
159
|
+
&.filename {
|
|
160
|
+
width: auto;
|
|
161
|
+
text-align: left;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
& a {
|
|
165
|
+
text-decoration: none;
|
|
166
|
+
color: inherit;
|
|
167
|
+
|
|
168
|
+
&:hover {
|
|
169
|
+
color: var(--text);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
pe-sort-indicator {
|
|
175
|
+
margin-left: 0.3em;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
td {
|
|
179
|
+
padding: 0.28rem 0.9rem;
|
|
180
|
+
text-align: right;
|
|
181
|
+
font-family: ui-monospace, 'Cascadia Code', 'Source Code Pro', Menlo, Consolas, 'DejaVu Sans Mono', monospace;
|
|
182
|
+
border-bottom: 1px solid var(--border);
|
|
183
|
+
font-variant-numeric: tabular-nums;
|
|
184
|
+
width: 1%;
|
|
185
|
+
|
|
186
|
+
&.filename {
|
|
187
|
+
width: auto;
|
|
188
|
+
text-align: left;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
tr.focal & {
|
|
192
|
+
background: color-mix(in srgb, var(--funcname) 10%, var(--surface));
|
|
193
|
+
border-bottom: 2px solid var(--border);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
pe-funcname {
|
|
198
|
+
color: var(--funcname);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
button.copy-btn {
|
|
202
|
+
display: inline-flex;
|
|
203
|
+
align-items: center;
|
|
204
|
+
background: none;
|
|
205
|
+
border: none;
|
|
206
|
+
padding: 0;
|
|
207
|
+
margin-right: 0.35em;
|
|
208
|
+
cursor: pointer;
|
|
209
|
+
color: var(--text-dim);
|
|
210
|
+
opacity: 0;
|
|
211
|
+
vertical-align: middle;
|
|
212
|
+
transition: color 0.1s, opacity 0.1s;
|
|
213
|
+
|
|
214
|
+
&:hover {
|
|
215
|
+
color: var(--text);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
tr:hover & {
|
|
219
|
+
opacity: 1;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
tr:hover &:disabled {
|
|
223
|
+
opacity: 0;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
&.copied {
|
|
227
|
+
color: #22c55e;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
tbody tr:nth-child(even) {
|
|
232
|
+
background: var(--stripe);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
tbody tr:hover {
|
|
236
|
+
background: var(--row-hover);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
a.callexs {
|
|
240
|
+
color: var(--text-dim);
|
|
241
|
+
text-decoration: none;
|
|
242
|
+
|
|
243
|
+
&:hover {
|
|
244
|
+
color: var(--text);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
pe-pagination-marker {
|
|
249
|
+
display: block;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/* [[[cog
|
|
253
|
+
import cog, math
|
|
254
|
+
cog.outl(".pct-0 { color: var(--text); }")
|
|
255
|
+
for b in range(1, 20):
|
|
256
|
+
v = round((b / 20) ** 0.75 * 100)
|
|
257
|
+
cog.outl(f".pct-{b:<2} {{ color: color-mix(in srgb, red {v}%, var(--text)); }}")
|
|
258
|
+
cog.outl(".pct-20 { color: red; }")
|
|
259
|
+
]]] */
|
|
260
|
+
.pct-0 { color: var(--text); }
|
|
261
|
+
.pct-1 { color: color-mix(in srgb, red 11%, var(--text)); }
|
|
262
|
+
.pct-2 { color: color-mix(in srgb, red 18%, var(--text)); }
|
|
263
|
+
.pct-3 { color: color-mix(in srgb, red 24%, var(--text)); }
|
|
264
|
+
.pct-4 { color: color-mix(in srgb, red 30%, var(--text)); }
|
|
265
|
+
.pct-5 { color: color-mix(in srgb, red 35%, var(--text)); }
|
|
266
|
+
.pct-6 { color: color-mix(in srgb, red 41%, var(--text)); }
|
|
267
|
+
.pct-7 { color: color-mix(in srgb, red 46%, var(--text)); }
|
|
268
|
+
.pct-8 { color: color-mix(in srgb, red 50%, var(--text)); }
|
|
269
|
+
.pct-9 { color: color-mix(in srgb, red 55%, var(--text)); }
|
|
270
|
+
.pct-10 { color: color-mix(in srgb, red 59%, var(--text)); }
|
|
271
|
+
.pct-11 { color: color-mix(in srgb, red 64%, var(--text)); }
|
|
272
|
+
.pct-12 { color: color-mix(in srgb, red 68%, var(--text)); }
|
|
273
|
+
.pct-13 { color: color-mix(in srgb, red 72%, var(--text)); }
|
|
274
|
+
.pct-14 { color: color-mix(in srgb, red 77%, var(--text)); }
|
|
275
|
+
.pct-15 { color: color-mix(in srgb, red 81%, var(--text)); }
|
|
276
|
+
.pct-16 { color: color-mix(in srgb, red 85%, var(--text)); }
|
|
277
|
+
.pct-17 { color: color-mix(in srgb, red 89%, var(--text)); }
|
|
278
|
+
.pct-18 { color: color-mix(in srgb, red 92%, var(--text)); }
|
|
279
|
+
.pct-19 { color: color-mix(in srgb, red 96%, var(--text)); }
|
|
280
|
+
.pct-20 { color: red; }
|
|
281
|
+
/* [[[end]]] */
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
{% load humanize profiling_explorer_tags %}
|
|
2
|
+
<tr{% if focal %} class=focal{% endif %}>
|
|
3
|
+
<td>{{ stats.calls|intcomma }}
|
|
4
|
+
<td class="{{ stats.calls_pct|pct_class }}">{{ stats.calls_pct|pct }}
|
|
5
|
+
<td>{% if stats.internal_ms != None %}{{ stats.internal_ms|intcomma }}{% endif %}
|
|
6
|
+
<td>{{ stats.cumulative_ms|intcomma }}
|
|
7
|
+
<td class="{{ stats.cumulative_ms_pct|pct_class }}">{{ stats.cumulative_ms_pct|pct }}
|
|
8
|
+
<td class=filename title="{{ row.full_filename }}"><button {% if not row.full_filename %}disabled{% endif %} class=copy-btn data-copy="{{ row.full_filename }}:{{ row.lineno }}" aria-label="Copy"><svg aria-hidden="true" width="18" height="18"><use href="#icon-copy"></use></svg></button>{% if row.filename %}{{ row.filename }}:{{ row.lineno }} {% endif %}<pe-funcname>{{ row.funcname }}</pe-funcname>
|
|
9
|
+
<td>{% if row.id %}<a class=callexs href="/callers/{{ row.id }}/"><svg aria-hidden="true" width="18" height="18"><use href="#icon-tree" transform="rotate(180 9 9)"></use></svg> callers</a> <a class=callexs href="/callees/{{ row.id }}/"><svg aria-hidden="true" width="18" height="18"><use href="#icon-tree"></use></svg> callees</a>{% endif %}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{% load humanize profiling_explorer_tags %}
|
|
2
|
+
<!DOCTYPE html>
|
|
3
|
+
<html lang=en>
|
|
4
|
+
<head>
|
|
5
|
+
<title>profiling-explorer</title>
|
|
6
|
+
<link rel=stylesheet href=/styles.css>
|
|
7
|
+
<script src=/script.js type=module></script>
|
|
8
|
+
</head>
|
|
9
|
+
<body>
|
|
10
|
+
<svg hidden width=0 height=0>
|
|
11
|
+
<symbol id="icon-copy" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2">
|
|
12
|
+
<path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path>
|
|
13
|
+
<rect width="13" height="13" x="9" y="9" rx="2"></rect>
|
|
14
|
+
</symbol>
|
|
15
|
+
<symbol id="icon-tree" viewBox="0 0 24 24" fill="none" stroke="none">
|
|
16
|
+
<path fill="currentColor" d="M19.5 23a3.5 3.5 0 0 1-1-6.855V14a1 1 0 0 0-1-1h-11a1 1 0 0 0-1 1v2.145A3.502 3.502 0 0 1 4.5 23a3.5 3.5 0 0 1-1-6.855V14a3 3 0 0 1 3-3H11V7.855A3.502 3.502 0 0 1 12 1a3.5 3.5 0 0 1 1 6.855V11h4.5a3 3 0 0 1 3 3v2.145a3.502 3.502 0 0 1-1 6.855"></path>
|
|
17
|
+
</symbol>
|
|
18
|
+
</svg>
|
|
19
|
+
<nav class=primary>
|
|
20
|
+
<h1>🗺️ profiling-explorer</h1>
|
|
21
|
+
<h2>{{ profile.filename }}</h2>
|
|
22
|
+
<p>{{ profile.total_calls|intcomma }} calls · {{ profile.total_time_ms|intcomma }} ms</p>
|
|
23
|
+
<input type=search id=pe-search placeholder="Filter by filename or function…" autocomplete=off autofocus value="{{ q }}">
|
|
24
|
+
</nav>
|
|
25
|
+
{% block main %}{% endblock %}
|
|
26
|
+
</body>
|
|
27
|
+
</html>
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{% extends "base.html" %}
|
|
2
|
+
{% load humanize profiling_explorer_tags %}
|
|
3
|
+
{% block main %}
|
|
4
|
+
<main>
|
|
5
|
+
<nav class=secondary>
|
|
6
|
+
<a href=/ class=back-link>← back</a>
|
|
7
|
+
<h3>{% if heading == "Callers" %}<svg aria-hidden="true" width="18" height="18"><use href="#icon-tree" transform="rotate(180 9 9)"></use></svg>{% else %}<svg aria-hidden="true" width="18" height="18"><use href="#icon-tree"></use></svg>{% endif %}
|
|
8
|
+
{{ heading }} of {{ focal_row.filename }}:{{ focal_row.lineno }} <pe-funcname>{{ focal_row.funcname }}</pe-funcname></h3>
|
|
9
|
+
</nav>
|
|
10
|
+
<table>
|
|
11
|
+
<thead>
|
|
12
|
+
<tr>
|
|
13
|
+
<th>calls
|
|
14
|
+
<th>%
|
|
15
|
+
<th>internal ms
|
|
16
|
+
<th>cumulative ms <pe-sort-indicator>↓</pe-sort-indicator>
|
|
17
|
+
<th>%
|
|
18
|
+
<th class=filename>filename:lineno function
|
|
19
|
+
<th>
|
|
20
|
+
</thead>
|
|
21
|
+
<tbody>
|
|
22
|
+
{% include "_row.html" with row=focal_row stats=focal_row focal=True only %}
|
|
23
|
+
{% for row, edge in rows_with_edges %}
|
|
24
|
+
{% include "_row.html" with row=row stats=edge focal=False only %}
|
|
25
|
+
{% endfor %}
|
|
26
|
+
</tbody>
|
|
27
|
+
</table>
|
|
28
|
+
{% if next_url %}<pe-pagination-marker data-url="{{ next_url }}"></pe-pagination-marker>{% endif %}
|
|
29
|
+
</main>
|
|
30
|
+
{% endblock %}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{% extends "base.html" %}
|
|
2
|
+
{% load humanize profiling_explorer_tags %}
|
|
3
|
+
{% block main %}
|
|
4
|
+
<main>
|
|
5
|
+
<table>
|
|
6
|
+
<thead>
|
|
7
|
+
<tr>
|
|
8
|
+
{% for col in columns %}
|
|
9
|
+
<th><a href="{% querystring sort=col.next_sort %}">{{ col.label }} <pe-sort-indicator>{{ col.indicator }}</pe-sort-indicator></a>
|
|
10
|
+
{% if col.key == "calls" or col.key == "cumulative_ms" %}<th>%
|
|
11
|
+
{% endif %}{% endfor %}
|
|
12
|
+
<th class=filename>filename:lineno function
|
|
13
|
+
<th>
|
|
14
|
+
</thead>
|
|
15
|
+
<tbody>
|
|
16
|
+
{% for row in rows %}
|
|
17
|
+
{% include "_row.html" with row=row stats=row focal=False only %}
|
|
18
|
+
{% endfor %}
|
|
19
|
+
</tbody>
|
|
20
|
+
</table>
|
|
21
|
+
{% if next_url %}<pe-pagination-marker data-url="{{ next_url }}"></pe-pagination-marker>{% endif %}
|
|
22
|
+
</main>
|
|
23
|
+
{% endblock %}
|
|
File without changes
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import math
|
|
4
|
+
|
|
5
|
+
from django.template import Library
|
|
6
|
+
|
|
7
|
+
register = Library()
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@register.filter
|
|
11
|
+
def sub(value: int, arg: int) -> int:
|
|
12
|
+
return value - arg
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@register.filter
|
|
16
|
+
def pct(value: float) -> str:
|
|
17
|
+
return f"{value:.1f}%"
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@register.filter
|
|
21
|
+
def pct_class(value: float) -> str:
|
|
22
|
+
if value < 0.05:
|
|
23
|
+
return "pct-0"
|
|
24
|
+
return f"pct-{min(20, math.ceil(value / 5))}"
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from django.urls import path
|
|
4
|
+
|
|
5
|
+
from . import views
|
|
6
|
+
|
|
7
|
+
urlpatterns = [
|
|
8
|
+
path("", views.index, name="index"),
|
|
9
|
+
path("callers/<str:row_id>/", views.callers_view, name="callers"),
|
|
10
|
+
path("callees/<str:row_id>/", views.callees_view, name="callees"),
|
|
11
|
+
path("favicon.ico", views.favicon),
|
|
12
|
+
path("styles.css", views.file, {"filename": "styles.css"}),
|
|
13
|
+
path("script.js", views.file, {"filename": "script.js"}),
|
|
14
|
+
]
|
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import hashlib
|
|
4
|
+
import os
|
|
5
|
+
import pstats
|
|
6
|
+
import re
|
|
7
|
+
from dataclasses import dataclass
|
|
8
|
+
from importlib.resources import files as resource_files
|
|
9
|
+
from typing import Any
|
|
10
|
+
from urllib.parse import urlencode
|
|
11
|
+
|
|
12
|
+
from django.http import FileResponse, Http404, HttpRequest, HttpResponse
|
|
13
|
+
from django.shortcuts import render
|
|
14
|
+
from django.views.decorators.http import require_GET
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@dataclass(slots=True)
|
|
18
|
+
class RowStats:
|
|
19
|
+
calls: int
|
|
20
|
+
calls_pct: float
|
|
21
|
+
internal_ms: int | None
|
|
22
|
+
cumulative_ms: int
|
|
23
|
+
cumulative_ms_pct: float
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
@dataclass(slots=True)
|
|
27
|
+
class EdgeStats(RowStats):
|
|
28
|
+
pass
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
@dataclass(slots=True)
|
|
32
|
+
class Row(RowStats):
|
|
33
|
+
id: str
|
|
34
|
+
filename: str
|
|
35
|
+
full_filename: str
|
|
36
|
+
lineno: int
|
|
37
|
+
funcname: str
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
@dataclass(slots=True)
|
|
41
|
+
class Profile:
|
|
42
|
+
filename: str
|
|
43
|
+
total_calls: int
|
|
44
|
+
total_time_ms: int
|
|
45
|
+
rows: list[Row]
|
|
46
|
+
rows_by_id: dict[str, Row]
|
|
47
|
+
callers_map: dict[str, dict[str, EdgeStats]]
|
|
48
|
+
callees_map: dict[str, dict[str, EdgeStats]]
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
# Populated by main()
|
|
52
|
+
profile: Profile = None # type: ignore[assignment]
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
_STRIP_PREFIX_RE = re.compile(
|
|
56
|
+
r"""
|
|
57
|
+
^
|
|
58
|
+
.*
|
|
59
|
+
(?:
|
|
60
|
+
# virtualenv packages
|
|
61
|
+
/site-packages/
|
|
62
|
+
|
|
|
63
|
+
# standard library
|
|
64
|
+
lib/python3\.\d+/
|
|
65
|
+
)
|
|
66
|
+
""",
|
|
67
|
+
re.VERBOSE,
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def _shorten_filename(filename: str) -> str:
|
|
72
|
+
match = _STRIP_PREFIX_RE.match(filename)
|
|
73
|
+
if match:
|
|
74
|
+
return filename[match.end() :]
|
|
75
|
+
return os.path.relpath(filename)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def _row_id(full_filename: str, lineno: int, funcname: str) -> str:
|
|
79
|
+
return hashlib.sha256(f"{full_filename}:{lineno}:{funcname}".encode()).hexdigest()[
|
|
80
|
+
:12
|
|
81
|
+
]
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def _row_id_from_pstats_key(key: tuple[str, int, str]) -> str:
|
|
85
|
+
filename, lineno, funcname = key
|
|
86
|
+
full_filename = "" if filename == "~" else filename
|
|
87
|
+
return _row_id(full_filename, lineno, funcname)
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def build_profile(s: pstats.Stats, path: str) -> Profile:
|
|
91
|
+
s.sort_stats("cumulative")
|
|
92
|
+
total_calls: int = s.total_calls # type: ignore[attr-defined]
|
|
93
|
+
total_time_ms = round(s.total_tt * 1000) # type: ignore[attr-defined]
|
|
94
|
+
rows = []
|
|
95
|
+
rows_by_id = {}
|
|
96
|
+
for key in s.fcn_list: # type: ignore[attr-defined]
|
|
97
|
+
filename, lineno, funcname = key
|
|
98
|
+
_, calls, tottime, cumtime, _ = s.stats[key] # type: ignore[attr-defined]
|
|
99
|
+
if filename == "~":
|
|
100
|
+
if funcname.startswith("<") and funcname.endswith(">"):
|
|
101
|
+
funcname = f"{{{funcname[1:-1]}}}"
|
|
102
|
+
short_filename = ""
|
|
103
|
+
full_filename = ""
|
|
104
|
+
else:
|
|
105
|
+
short_filename = _shorten_filename(filename)
|
|
106
|
+
full_filename = filename
|
|
107
|
+
row_id = _row_id(full_filename, lineno, funcname)
|
|
108
|
+
cumulative_ms = round(cumtime * 1_000)
|
|
109
|
+
row = Row(
|
|
110
|
+
id=row_id,
|
|
111
|
+
calls=calls,
|
|
112
|
+
calls_pct=min(100.0, calls / total_calls * 100) if total_calls else 0.0,
|
|
113
|
+
internal_ms=round(tottime * 1_000),
|
|
114
|
+
cumulative_ms=cumulative_ms,
|
|
115
|
+
cumulative_ms_pct=min(100.0, cumulative_ms / total_time_ms * 100)
|
|
116
|
+
if total_time_ms
|
|
117
|
+
else 0.0,
|
|
118
|
+
filename=short_filename,
|
|
119
|
+
full_filename=full_filename,
|
|
120
|
+
lineno=lineno,
|
|
121
|
+
funcname=funcname,
|
|
122
|
+
)
|
|
123
|
+
rows.append(row)
|
|
124
|
+
rows_by_id[row_id] = row
|
|
125
|
+
|
|
126
|
+
def make_edge(enc: int, etc: float) -> EdgeStats:
|
|
127
|
+
cumulative_ms = round(etc * 1_000)
|
|
128
|
+
return EdgeStats(
|
|
129
|
+
calls=enc,
|
|
130
|
+
calls_pct=min(100.0, enc / total_calls * 100) if total_calls else 0.0,
|
|
131
|
+
internal_ms=None,
|
|
132
|
+
cumulative_ms=cumulative_ms,
|
|
133
|
+
cumulative_ms_pct=(
|
|
134
|
+
min(100.0, cumulative_ms / total_time_ms * 100)
|
|
135
|
+
if total_time_ms
|
|
136
|
+
else 0.0
|
|
137
|
+
),
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
callers_map: dict[str, dict[str, EdgeStats]] = {}
|
|
141
|
+
callees_map: dict[str, dict[str, EdgeStats]] = {}
|
|
142
|
+
for (filename, lineno, funcname), (*_, callers) in s.stats.items(): # type: ignore[attr-defined]
|
|
143
|
+
full_filename = "" if filename == "~" else filename
|
|
144
|
+
callee_id = _row_id(full_filename, lineno, funcname)
|
|
145
|
+
for caller_key, (enc, _, __, etc) in callers.items():
|
|
146
|
+
caller_id = _row_id_from_pstats_key(caller_key)
|
|
147
|
+
edge = make_edge(enc, etc)
|
|
148
|
+
callers_map.setdefault(callee_id, {})[caller_id] = edge
|
|
149
|
+
callees_map.setdefault(caller_id, {})[callee_id] = edge
|
|
150
|
+
|
|
151
|
+
return Profile(
|
|
152
|
+
filename=path,
|
|
153
|
+
total_calls=total_calls,
|
|
154
|
+
total_time_ms=total_time_ms,
|
|
155
|
+
rows=rows,
|
|
156
|
+
rows_by_id=rows_by_id,
|
|
157
|
+
callers_map=callers_map,
|
|
158
|
+
callees_map=callees_map,
|
|
159
|
+
)
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
def _build_edge_rows(
|
|
163
|
+
edges: dict[str, EdgeStats],
|
|
164
|
+
) -> list[tuple[Row, EdgeStats]]:
|
|
165
|
+
result = [
|
|
166
|
+
(row, edge)
|
|
167
|
+
for row_id, edge in edges.items()
|
|
168
|
+
if (row := profile.rows_by_id.get(row_id)) is not None
|
|
169
|
+
]
|
|
170
|
+
result.sort(key=lambda pair: pair[1].cumulative_ms, reverse=True)
|
|
171
|
+
return result
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
PAGE_SIZE = 200
|
|
175
|
+
|
|
176
|
+
_VALID_SORT_COLS = {"calls", "internal_ms", "cumulative_ms"}
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
def _render_table(
|
|
180
|
+
request: HttpRequest,
|
|
181
|
+
rows: list[Row],
|
|
182
|
+
template: str,
|
|
183
|
+
extra_context: dict[str, Any],
|
|
184
|
+
edge_stats: dict[str, EdgeStats] | None = None,
|
|
185
|
+
) -> HttpResponse:
|
|
186
|
+
sort_param = request.GET.get("sort", "-cumulative_ms")
|
|
187
|
+
sort_desc = not sort_param.startswith("+")
|
|
188
|
+
sort_col = sort_param.lstrip("+-")
|
|
189
|
+
if sort_col not in _VALID_SORT_COLS:
|
|
190
|
+
sort_col = "cumulative_ms"
|
|
191
|
+
sort_desc = True
|
|
192
|
+
sort_param = "-cumulative_ms"
|
|
193
|
+
|
|
194
|
+
q = request.GET.get("q", "").strip()
|
|
195
|
+
filtered_rows = rows
|
|
196
|
+
if q:
|
|
197
|
+
filtered_rows = [r for r in rows if q in r.filename or q in r.funcname]
|
|
198
|
+
|
|
199
|
+
if edge_stats is None:
|
|
200
|
+
sorted_rows = sorted(
|
|
201
|
+
filtered_rows,
|
|
202
|
+
key=lambda r: (getattr(r, sort_col), r.filename, r.lineno, r.funcname),
|
|
203
|
+
reverse=sort_desc,
|
|
204
|
+
)
|
|
205
|
+
else:
|
|
206
|
+
sorted_rows = sorted(
|
|
207
|
+
filtered_rows,
|
|
208
|
+
key=lambda r: edge_stats[r.id].cumulative_ms,
|
|
209
|
+
reverse=True,
|
|
210
|
+
)
|
|
211
|
+
|
|
212
|
+
offset = int(request.GET.get("offset", 0))
|
|
213
|
+
page_rows = sorted_rows[offset : offset + PAGE_SIZE]
|
|
214
|
+
|
|
215
|
+
next_url = None
|
|
216
|
+
next_offset = offset + PAGE_SIZE
|
|
217
|
+
if next_offset < len(sorted_rows):
|
|
218
|
+
params: dict[str, str | int] = {"sort": sort_param, "offset": next_offset}
|
|
219
|
+
if q:
|
|
220
|
+
params["q"] = q
|
|
221
|
+
next_url = request.path + "?" + urlencode(params)
|
|
222
|
+
|
|
223
|
+
def col_config(key: str, label: str) -> dict[str, str]:
|
|
224
|
+
config = {"key": key, "label": label}
|
|
225
|
+
if sort_col == key:
|
|
226
|
+
config["indicator"] = "↓" if sort_desc else "↑"
|
|
227
|
+
config["next_sort"] = f"+{key}" if sort_desc else f"-{key}"
|
|
228
|
+
else:
|
|
229
|
+
config["indicator"] = ""
|
|
230
|
+
config["next_sort"] = f"-{key}"
|
|
231
|
+
return config
|
|
232
|
+
|
|
233
|
+
context = {
|
|
234
|
+
"profile": profile,
|
|
235
|
+
"rows": page_rows,
|
|
236
|
+
"next_url": next_url,
|
|
237
|
+
"q": q,
|
|
238
|
+
"columns": [
|
|
239
|
+
col_config("calls", "calls"),
|
|
240
|
+
col_config("internal_ms", "internal ms"),
|
|
241
|
+
col_config("cumulative_ms", "cumulative ms"),
|
|
242
|
+
],
|
|
243
|
+
**extra_context,
|
|
244
|
+
}
|
|
245
|
+
if edge_stats is not None:
|
|
246
|
+
context["rows_with_edges"] = [(r, edge_stats[r.id]) for r in page_rows]
|
|
247
|
+
|
|
248
|
+
return render(request, template, context)
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
def index(request: HttpRequest) -> HttpResponse:
|
|
252
|
+
return _render_table(request, profile.rows, "index.html", {})
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
def _callers_callees_view(
|
|
256
|
+
request: HttpRequest,
|
|
257
|
+
focal_row: Row,
|
|
258
|
+
edges: dict[str, EdgeStats],
|
|
259
|
+
opposite_url: str,
|
|
260
|
+
heading: str,
|
|
261
|
+
opposite_label: str,
|
|
262
|
+
) -> HttpResponse:
|
|
263
|
+
rows_with_edges = _build_edge_rows(edges)
|
|
264
|
+
rows = [r for r, _ in rows_with_edges]
|
|
265
|
+
edge_stats: dict[str, EdgeStats] = {r.id: e for r, e in rows_with_edges}
|
|
266
|
+
|
|
267
|
+
return _render_table(
|
|
268
|
+
request,
|
|
269
|
+
rows,
|
|
270
|
+
"callers_callees.html",
|
|
271
|
+
{
|
|
272
|
+
"focal_row": focal_row,
|
|
273
|
+
"heading": heading,
|
|
274
|
+
"opposite_label": opposite_label,
|
|
275
|
+
"opposite_url": opposite_url,
|
|
276
|
+
},
|
|
277
|
+
edge_stats=edge_stats,
|
|
278
|
+
)
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
@require_GET
|
|
282
|
+
def callers_view(request: HttpRequest, row_id: str) -> HttpResponse:
|
|
283
|
+
focal_row = profile.rows_by_id.get(row_id)
|
|
284
|
+
if focal_row is None:
|
|
285
|
+
raise Http404()
|
|
286
|
+
return _callers_callees_view(
|
|
287
|
+
request,
|
|
288
|
+
focal_row,
|
|
289
|
+
profile.callers_map.get(row_id, {}),
|
|
290
|
+
opposite_url=f"/callees/{row_id}/",
|
|
291
|
+
heading="Callers",
|
|
292
|
+
opposite_label="view callees →",
|
|
293
|
+
)
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
@require_GET
|
|
297
|
+
def callees_view(request: HttpRequest, row_id: str) -> HttpResponse:
|
|
298
|
+
focal_row = profile.rows_by_id.get(row_id)
|
|
299
|
+
if focal_row is None:
|
|
300
|
+
raise Http404()
|
|
301
|
+
return _callers_callees_view(
|
|
302
|
+
request,
|
|
303
|
+
focal_row,
|
|
304
|
+
profile.callees_map.get(row_id, {}),
|
|
305
|
+
opposite_url=f"/callers/{row_id}/",
|
|
306
|
+
heading="Callees",
|
|
307
|
+
opposite_label="← view callers",
|
|
308
|
+
)
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
@require_GET
|
|
312
|
+
def file(request: HttpRequest, *, filename: str) -> FileResponse:
|
|
313
|
+
return FileResponse(
|
|
314
|
+
resource_files("profiling_explorer")
|
|
315
|
+
.joinpath("static")
|
|
316
|
+
.joinpath(filename)
|
|
317
|
+
.open("rb"),
|
|
318
|
+
)
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
@require_GET
|
|
322
|
+
def favicon(request: HttpRequest) -> HttpResponse:
|
|
323
|
+
return HttpResponse(
|
|
324
|
+
(
|
|
325
|
+
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">'
|
|
326
|
+
+ '<text y=".9em" font-size="90">🗺️</text>'
|
|
327
|
+
+ "</svg>"
|
|
328
|
+
),
|
|
329
|
+
content_type="image/svg+xml",
|
|
330
|
+
)
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: profiling-explorer
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Table-based exploration tool for Python profiling data (pstats files).
|
|
5
|
+
Author-email: Adam Johnson <me@adamj.eu>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Changelog, https://github.com/adamchainz/profiling-explorer/blob/main/CHANGELOG.rst
|
|
8
|
+
Project-URL: Funding, https://adamj.eu/books/
|
|
9
|
+
Project-URL: Repository, https://github.com/adamchainz/profiling-explorer
|
|
10
|
+
Keywords: profiler,profiling,pstats
|
|
11
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Natural Language :: English
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
21
|
+
Classifier: Typing :: Typed
|
|
22
|
+
Requires-Python: >=3.10
|
|
23
|
+
Description-Content-Type: text/x-rst
|
|
24
|
+
License-File: LICENSE
|
|
25
|
+
Requires-Dist: django>=5.2
|
|
26
|
+
Dynamic: license-file
|
|
27
|
+
|
|
28
|
+
==================
|
|
29
|
+
profiling-explorer
|
|
30
|
+
==================
|
|
31
|
+
|
|
32
|
+
.. image:: https://img.shields.io/github/actions/workflow/status/adamchainz/profiling-explorer/main.yml.svg?branch=main&style=for-the-badge
|
|
33
|
+
:target: https://github.com/adamchainz/profiling-explorer/actions?workflow=CI
|
|
34
|
+
|
|
35
|
+
.. image:: https://img.shields.io/badge/Coverage-70%25-success?style=for-the-badge
|
|
36
|
+
:target: https://github.com/adamchainz/profiling-explorer/actions?workflow=CI
|
|
37
|
+
|
|
38
|
+
.. image:: https://img.shields.io/pypi/v/profiling-explorer.svg?style=for-the-badge
|
|
39
|
+
:target: https://pypi.org/project/profiling-explorer/
|
|
40
|
+
|
|
41
|
+
.. image:: https://img.shields.io/badge/code%20style-black-000000.svg?style=for-the-badge
|
|
42
|
+
:target: https://github.com/psf/black
|
|
43
|
+
|
|
44
|
+
.. image:: https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white&style=for-the-badge
|
|
45
|
+
:target: https://github.com/pre-commit/pre-commit
|
|
46
|
+
:alt: pre-commit
|
|
47
|
+
|
|
48
|
+
----
|
|
49
|
+
|
|
50
|
+
Table-based exploration tool for Python profiling data (pstats files).
|
|
51
|
+
|
|
52
|
+
.. Generated with:
|
|
53
|
+
.. uvx --with django python -m cProfile -o django_utils_html.pstats -m django.utils.html
|
|
54
|
+
.. uvr profiling-explorer django_utils_html.pstats
|
|
55
|
+
.. …then in another tab:
|
|
56
|
+
.. uvx shot-scraper --width 1280 --height 720 --retina --wait 1000 http://127.0.0.1:8099/ -o screenshot.png
|
|
57
|
+
|
|
58
|
+
.. figure:: https://raw.githubusercontent.com/adamchainz/profiling-explorer/screenshot/screenshot.png
|
|
59
|
+
:alt: profiling-explorer screenshot
|
|
60
|
+
|
|
61
|
+
----
|
|
62
|
+
|
|
63
|
+
**Get better at command line Git** with my book `Boost Your Git DX <https://adamchainz.gumroad.com/l/bygdx>`__.
|
|
64
|
+
|
|
65
|
+
----
|
|
66
|
+
|
|
67
|
+
Requirements
|
|
68
|
+
------------
|
|
69
|
+
|
|
70
|
+
Python 3.10 to 3.14 supported.
|
|
71
|
+
|
|
72
|
+
Installation
|
|
73
|
+
------------
|
|
74
|
+
|
|
75
|
+
1. Install with **pip**:
|
|
76
|
+
|
|
77
|
+
.. code-block:: sh
|
|
78
|
+
|
|
79
|
+
python -m pip install profiling-explorer
|
|
80
|
+
|
|
81
|
+
Usage
|
|
82
|
+
-----
|
|
83
|
+
|
|
84
|
+
``profiling-explorer`` reads |pstats|__ files as generated by Python’s profilers: |profiling.tracing|__ (called ``cProfile`` on Python < 3.15) and |profiling.sampling|__ (new in Python 3.15).
|
|
85
|
+
To use it, first generate a profile file, for example by running your program under cProfile:
|
|
86
|
+
|
|
87
|
+
.. |pstats| replace:: ``pstats``
|
|
88
|
+
__ https://docs.python.org/3.15/library/pstats.html
|
|
89
|
+
|
|
90
|
+
.. |profiling.tracing| replace:: ``profiling.tracing``
|
|
91
|
+
__ https://docs.python.org/3.15/library/profiling.tracing.html
|
|
92
|
+
|
|
93
|
+
.. |profiling.sampling| replace:: ``profiling.sampling``
|
|
94
|
+
__ https://docs.python.org/3.15/library/profiling.sampling.html
|
|
95
|
+
|
|
96
|
+
.. code-block:: console
|
|
97
|
+
|
|
98
|
+
$ python -m cProfile -o example.pstats example.py
|
|
99
|
+
|
|
100
|
+
(Also runnable as ``python -m profiling.tracing`` instead on Python 3.15+.)
|
|
101
|
+
|
|
102
|
+
Then run ``profiling-explorer`` with the generated file:
|
|
103
|
+
|
|
104
|
+
.. code-block:: console
|
|
105
|
+
|
|
106
|
+
$ profiling-explorer example.pstats
|
|
107
|
+
|
|
108
|
+
The report will open in your web browser, and you can explore the profile data with the interactive interface.
|
|
109
|
+
Features:
|
|
110
|
+
|
|
111
|
+
* Click the **calls**, **internal ms**, or **cumulative ms** column headers to sort by that column.
|
|
112
|
+
* Use the search box to filter by filename or function name.
|
|
113
|
+
* Hover by a filename + line number pair to reveal the copy button, which copies the location to your clipboard for faster opening.
|
|
114
|
+
* Click the **callers** or **callees** links on the right of a row to see the callers or callees of that function.
|
|
115
|
+
|
|
116
|
+
Full help:
|
|
117
|
+
|
|
118
|
+
.. [[[cog
|
|
119
|
+
.. import cog
|
|
120
|
+
.. import subprocess
|
|
121
|
+
.. import sys
|
|
122
|
+
.. result = subprocess.run(
|
|
123
|
+
.. [sys.executable, "-m", "profiling_explorer", "--help"],
|
|
124
|
+
.. capture_output=True,
|
|
125
|
+
.. text=True,
|
|
126
|
+
.. )
|
|
127
|
+
.. cog.outl("")
|
|
128
|
+
.. cog.outl(".. code-block:: console")
|
|
129
|
+
.. cog.outl("")
|
|
130
|
+
.. for line in result.stdout.splitlines():
|
|
131
|
+
.. if line.strip() == "":
|
|
132
|
+
.. cog.outl("")
|
|
133
|
+
.. else:
|
|
134
|
+
.. cog.outl(" " + line.rstrip())
|
|
135
|
+
.. cog.outl("")
|
|
136
|
+
.. ]]]
|
|
137
|
+
|
|
138
|
+
.. code-block:: console
|
|
139
|
+
|
|
140
|
+
usage: profiling-explorer [-h] [--port PORT] [--dev] FILE
|
|
141
|
+
|
|
142
|
+
positional arguments:
|
|
143
|
+
FILE The pstats data file to explore.
|
|
144
|
+
|
|
145
|
+
options:
|
|
146
|
+
-h, --help show this help message and exit
|
|
147
|
+
--port PORT Port for the local web server (default: 8099).
|
|
148
|
+
--dev Run in development mode (enables server reload and debug mode).
|
|
149
|
+
|
|
150
|
+
.. [[[end]]]
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
profiling_explorer/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
profiling_explorer/__main__.py,sha256=4vXOGIOJCdezrLY-gKNANezVLN4Ln8j5bAe_KgZdXM0,154
|
|
3
|
+
profiling_explorer/main.py,sha256=_ZuNCxKVnVVd8_2Z6-KD6Kvw9OHR_gAiikHXvTWfs8s,1410
|
|
4
|
+
profiling_explorer/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
+
profiling_explorer/settings.py,sha256=B1NmTGW5BqnTclh8Bn-RzfA-F4Gub4n5TdTfBhTwwVk,894
|
|
6
|
+
profiling_explorer/urls.py,sha256=Mseb3NNwq7NgI0d6S0KnjpwmpKRdFI6QeCcJg37XKaw,454
|
|
7
|
+
profiling_explorer/views.py,sha256=9WOYnsS1JRfoHmZxnFA0YOVAI4emPN5EmaLiIdtH3rc,9484
|
|
8
|
+
profiling_explorer/management/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
9
|
+
profiling_explorer/management/commands/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
10
|
+
profiling_explorer/management/commands/runserver.py,sha256=vE5k0G25gOkWjVwgnRnUowk3PtapcU-waitWK0ieSXs,859
|
|
11
|
+
profiling_explorer/static/script.js,sha256=l9g5jZj8Tqkzc6TDQXzLGbu2HE63L59I7cZhrPwQhAc,2243
|
|
12
|
+
profiling_explorer/static/styles.css,sha256=0Py97dRhvQqWcYvX9iLz1cwL5jAIk_St0d1mRXnGrtk,5690
|
|
13
|
+
profiling_explorer/templates/_row.html,sha256=87uzUagddMDSJG7GzFIOKkqDfDkGxYg7Viv2gZMmCb0,1150
|
|
14
|
+
profiling_explorer/templates/base.html,sha256=lt1dYznpuFd0jsdU14roWnpgf5btPRLw87f6NRqJY78,1368
|
|
15
|
+
profiling_explorer/templates/callers_callees.html,sha256=T6qPTbOrSYMi_OmyJtAoeGxzsKfBzTotb_vero3WBb0,1180
|
|
16
|
+
profiling_explorer/templates/index.html,sha256=yUdf7QO9erPdbBrWva_DvC2l5y3bUQjdqmH9SEn77FA,759
|
|
17
|
+
profiling_explorer/templatetags/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
18
|
+
profiling_explorer/templatetags/profiling_explorer_tags.py,sha256=9L3p2yIkdpGiLO_w87HsgjRpgpnA3k3fUjaw7lrYFIA,412
|
|
19
|
+
profiling_explorer-1.0.0.dist-info/licenses/LICENSE,sha256=blVuFA7Qdp2_CcTyGXLxA4CsHsAjAquxVc4O6ODqye4,1069
|
|
20
|
+
profiling_explorer-1.0.0.dist-info/METADATA,sha256=nLWYtNZPnd_1e9rJFYTY7ZMVMFLnUPOjCiCs11scBq4,5149
|
|
21
|
+
profiling_explorer-1.0.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
22
|
+
profiling_explorer-1.0.0.dist-info/entry_points.txt,sha256=ZfJniu4afaqvx6Gv2hNrWLZcPx8amxp-E-eMY4oUxHs,68
|
|
23
|
+
profiling_explorer-1.0.0.dist-info/top_level.txt,sha256=rcEyxu8VPgrOsvq9fNVwwX5FP4-s8l67lurknkqiZgc,19
|
|
24
|
+
profiling_explorer-1.0.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Adam Johnson
|
|
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.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
profiling_explorer
|