forked from dotandev/hintents
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample_flamegraph.html
More file actions
362 lines (324 loc) · 11.4 KB
/
sample_flamegraph.html
File metadata and controls
362 lines (324 loc) · 11.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Interactive Flamegraph - Sample</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
background: #f5f5f5;
padding: 20px;
}
@media (prefers-color-scheme: dark) {
body { background: #1e1e2e; color: #cdd6f4; }
}
.container {
max-width: 1400px;
margin: 0 auto;
background: white;
border-radius: 8px;
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
overflow: hidden;
}
@media (prefers-color-scheme: dark) {
.container { background: #181825; box-shadow: 0 2px 8px rgba(0,0,0,0.3); }
}
.toolbar {
padding: 15px 20px;
border-bottom: 1px solid #e0e0e0;
display: flex;
gap: 10px;
align-items: center;
flex-wrap: wrap;
}
@media (prefers-color-scheme: dark) {
.toolbar { border-bottom-color: #313244; }
}
.toolbar button {
padding: 8px 16px;
border: 1px solid #ccc;
background: white;
border-radius: 4px;
cursor: pointer;
font-size: 14px;
transition: all 0.2s;
}
.toolbar button:hover {
background: #f0f0f0;
border-color: #999;
}
@media (prefers-color-scheme: dark) {
.toolbar button {
background: #313244;
border-color: #45475a;
color: #cdd6f4;
}
.toolbar button:hover {
background: #45475a;
border-color: #585b70;
}
}
.toolbar input {
padding: 8px 12px;
border: 1px solid #ccc;
border-radius: 4px;
font-size: 14px;
flex: 1;
min-width: 200px;
max-width: 400px;
}
@media (prefers-color-scheme: dark) {
.toolbar input {
background: #313244;
border-color: #45475a;
color: #cdd6f4;
}
}
.svg-container {
padding: 20px;
overflow: auto;
position: relative;
}
svg {
display: block;
margin: 0 auto;
cursor: default;
}
.tooltip {
position: fixed;
background: rgba(0, 0, 0, 0.9);
color: white;
padding: 8px 12px;
border-radius: 4px;
font-size: 12px;
pointer-events: none;
z-index: 1000;
display: none;
max-width: 400px;
word-wrap: break-word;
}
@media (prefers-color-scheme: dark) {
.tooltip { background: rgba(30, 30, 46, 0.95); border: 1px solid #45475a; }
}
.info {
padding: 10px 20px;
font-size: 13px;
color: #666;
border-top: 1px solid #e0e0e0;
}
@media (prefers-color-scheme: dark) {
.info { color: #a6adc8; border-top-color: #313244; }
}
</style>
</head>
<body>
<div class="container">
<div class="toolbar">
<button id="resetBtn">Reset Zoom</button>
<input type="text" id="searchInput" placeholder="Search frames (e.g., function name)...">
<button id="searchBtn">Search</button>
<button id="clearBtn">Clear</button>
</div>
<div class="svg-container">
<svg xmlns="http://www.w3.org/2000/svg" width="1200" height="400" viewBox="0 0 1200 400">
<style type="text/css">
/* Dark mode support for flamegraph SVGs */
@media (prefers-color-scheme: dark) {
/* Invert the background from white to a dark surface */
svg { background-color: #1e1e2e; }
/* Main text (function names, labels) */
text { fill: #cdd6f4 !important; }
/* Title and subtitle */
text.title { fill: #cdd6f4 !important; }
/* Details / info bar at the bottom */
rect.background { fill: #1e1e2e !important; }
/* Slightly desaturate the flame rectangles for better contrast on dark bg */
rect[fill] {
opacity: 0.92;
}
/* Search match highlight */
rect[fill="rgb(230,0,230)"] {
fill: rgb(200,80,200) !important;
}
}
</style>
<text x="600" y="30" text-anchor="middle" font-size="20" font-weight="bold">Sample Flamegraph - Soroban Resource Consumption</text>
<!-- Main function -->
<g>
<title>main() - 100% (1000ms)</title>
<rect x="0" y="60" width="1200" height="40" fill="rgb(230, 159, 0)" stroke="white"/>
<text x="600" y="85" text-anchor="middle" font-size="14">main() - 100%</text>
</g>
<!-- Contract invocation -->
<g>
<title>invoke_contract() - 80% (800ms)</title>
<rect x="0" y="110" width="960" height="40" fill="rgb(86, 180, 233)" stroke="white"/>
<text x="480" y="135" text-anchor="middle" font-size="14">invoke_contract() - 80%</text>
</g>
<!-- Token transfer -->
<g>
<title>token_transfer() - 40% (400ms)</title>
<rect x="0" y="160" width="480" height="40" fill="rgb(0, 158, 115)" stroke="white"/>
<text x="240" y="185" text-anchor="middle" font-size="14">token_transfer() - 40%</text>
</g>
<!-- Balance check -->
<g>
<title>check_balance() - 20% (200ms)</title>
<rect x="0" y="210" width="240" height="40" fill="rgb(240, 228, 66)" stroke="white"/>
<text x="120" y="235" text-anchor="middle" font-size="14">check_balance() - 20%</text>
</g>
<!-- Storage read -->
<g>
<title>storage_read() - 10% (100ms)</title>
<rect x="0" y="260" width="120" height="40" fill="rgb(213, 94, 0)" stroke="white"/>
<text x="60" y="285" text-anchor="middle" font-size="12">storage_read()</text>
</g>
<!-- Deserialize -->
<g>
<title>deserialize() - 10% (100ms)</title>
<rect x="120" y="260" width="120" height="40" fill="rgb(204, 121, 167)" stroke="white"/>
<text x="180" y="285" text-anchor="middle" font-size="12">deserialize()</text>
</g>
<!-- Update balance -->
<g>
<title>update_balance() - 20% (200ms)</title>
<rect x="240" y="210" width="240" height="40" fill="rgb(0, 114, 178)" stroke="white"/>
<text x="360" y="235" text-anchor="middle" font-size="14">update_balance() - 20%</text>
</g>
<!-- Event emission -->
<g>
<title>emit_event() - 40% (400ms)</title>
<rect x="480" y="160" width="480" height="40" fill="rgb(230, 159, 0)" stroke="white"/>
<text x="720" y="185" text-anchor="middle" font-size="14">emit_event() - 40%</text>
</g>
<!-- Logging -->
<g>
<title>log_debug() - 20% (200ms)</title>
<rect x="960" y="110" width="240" height="40" fill="rgb(86, 180, 233)" stroke="white"/>
<text x="1080" y="135" text-anchor="middle" font-size="14">log_debug() - 20%</text>
</g>
</svg>
</div>
<div class="info">
<strong>Interactions:</strong> Hover for details • Click to zoom • Search to highlight
</div>
</div>
<div class="tooltip" id="tooltip"></div>
<script>
(function() {
'use strict';
const svg = document.querySelector('svg');
const tooltip = document.getElementById('tooltip');
const resetBtn = document.getElementById('resetBtn');
const searchInput = document.getElementById('searchInput');
const searchBtn = document.getElementById('searchBtn');
const clearBtn = document.getElementById('clearBtn');
let zoomStack = [];
let originalViewBox = null;
// Initialize
if (svg) {
originalViewBox = svg.getAttribute('viewBox') || '0 0 ' + svg.getAttribute('width') + ' ' + svg.getAttribute('height');
setupInteractivity();
}
function setupInteractivity() {
// Hover tooltips
svg.addEventListener('mouseover', handleMouseOver);
svg.addEventListener('mouseout', handleMouseOut);
svg.addEventListener('mousemove', handleMouseMove);
// Click to zoom
svg.addEventListener('click', handleClick);
// Toolbar actions
resetBtn.addEventListener('click', resetZoom);
searchBtn.addEventListener('click', performSearch);
clearBtn.addEventListener('click', clearSearch);
searchInput.addEventListener('keypress', (e) => {
if (e.key === 'Enter') performSearch();
});
}
function handleMouseOver(e) {
const target = e.target;
if (target.tagName === 'rect' || target.tagName === 'g') {
const g = target.tagName === 'g' ? target : target.parentElement;
const title = g.querySelector('title');
if (title) {
tooltip.textContent = title.textContent;
tooltip.style.display = 'block';
}
}
}
function handleMouseOut(e) {
tooltip.style.display = 'none';
}
function handleMouseMove(e) {
if (tooltip.style.display === 'block') {
tooltip.style.left = (e.clientX + 10) + 'px';
tooltip.style.top = (e.clientY + 10) + 'px';
}
}
function handleClick(e) {
const target = e.target;
if (target.tagName !== 'rect') return;
const g = target.parentElement;
const rect = target;
// Get bounding box
const x = parseFloat(rect.getAttribute('x') || 0);
const y = parseFloat(rect.getAttribute('y') || 0);
const width = parseFloat(rect.getAttribute('width') || 0);
const height = parseFloat(rect.getAttribute('height') || 0);
if (width > 0 && height > 0) {
// Save current viewBox to stack
zoomStack.push(svg.getAttribute('viewBox'));
// Calculate new viewBox with some padding
const padding = width * 0.1;
const newX = Math.max(0, x - padding);
const newY = Math.max(0, y - padding);
const newWidth = width + (padding * 2);
const newHeight = height * 10; // Show more vertical context
svg.setAttribute('viewBox', newX + ' ' + newY + ' ' + newWidth + ' ' + newHeight);
}
}
function resetZoom() {
if (originalViewBox) {
svg.setAttribute('viewBox', originalViewBox);
zoomStack = [];
}
}
function performSearch() {
const query = searchInput.value.trim().toLowerCase();
if (!query) return;
clearSearch();
const allGroups = svg.querySelectorAll('g');
let matchCount = 0;
allGroups.forEach(g => {
const title = g.querySelector('title');
const rect = g.querySelector('rect');
if (title && rect && title.textContent.toLowerCase().includes(query)) {
// Highlight matching frames
const originalFill = rect.getAttribute('fill');
rect.setAttribute('data-original-fill', originalFill);
rect.setAttribute('fill', 'rgb(230, 100, 230)');
rect.setAttribute('data-highlighted', 'true');
matchCount++;
}
});
if (matchCount === 0) {
alert('No matches found for: ' + query);
}
}
function clearSearch() {
const highlighted = svg.querySelectorAll('rect[data-highlighted="true"]');
highlighted.forEach(rect => {
const originalFill = rect.getAttribute('data-original-fill');
if (originalFill) {
rect.setAttribute('fill', originalFill);
}
rect.removeAttribute('data-original-fill');
rect.removeAttribute('data-highlighted');
});
}
})();
</script>
</body>
</html>