-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
423 lines (368 loc) · 12.6 KB
/
index.html
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
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
<!DOCTYPE html>
<html>
<head>
<title>HeapView</title>
<style>
body {
display: grid;
grid-template-columns: 220px 1fr;
grid-template-rows: auto auto 1fr auto;
grid-template-areas:
"header header"
"tabs tabs"
"sidebar content"
"footer footer";
height: 100vh;
margin: 0;
font-family: Arial, sans-serif;
}
header {
grid-area: header;
background-color: black;
color: white;
padding: 10px;
text-align: center;
}
footer {
grid-area: footer;
background-color: black;
color: white;
padding: 10px;
text-align: center;
}
#tabs {
grid-area: tabs;
padding: 10px;
display: flex;
justify-content: center;
align-items: center;
}
.tab-button:not(:last-child) {
margin-right: 5px;
}
.tab-button {
background-color: #88ff00;
color: black;
font-weight: 600;
border: none;
padding: 5px 10px;
cursor: pointer;
margin-right: 10px;
}
.tab-button:hover {
background-color: #72b801;
}
#sidebar {
grid-area: sidebar;
background-color: #f0f0f0;
padding: 10px;
}
#content {
grid-area: content;
padding: 10px;
overflow-x: auto;
max-width: 100%;
}
#graphContainer {
max-width: 100%;
margin: 0 auto;
}
.record-type {
cursor: pointer;
padding: 8px;
font-weight: bold;
border-bottom: 1px solid #ccc;
transition: background-color 0.3s;
}
.record-type:hover {
background-color: #ddd;
}
.record-type:last-child {
border-bottom: none;
}
.row {
border: 1px solid #ccc;
margin: 5px 0;
padding: 10px;
background-color: #fff;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
transition: transform 0.2s, box-shadow 0.2s;
}
.row:hover {
/* transform: scale(1.01); */
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}
.row .pointer-info {
margin-left: 20px;
padding-left: 10px;
border-left: 1px solid #ccc;
}
.pointer-info p {
margin: 0;
}
button {
background-color: #007BFF;
color: white;
border: none;
padding: 5px 10px;
cursor: pointer;
}
button:hover {
background-color: #0056b3;
}
#graphControls {
display: flex;
align-items: center;
margin-left: 10px;
}
#searchInput {
margin-left: 20px;
padding: 5px;
border: 1px solid #ccc;
border-radius: 4px;
}
#resetZoom {
padding: 5px 10px;
background-color: #007BFF;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}
#resetZoom:hover {
background-color: #0056b3;
}
.highlight {
background-color: yellow;
}
a {
color: #007BFF;
}
</style>
</head>
<body>
<header>
<h1>HeapView</h1>
<p>a heap dump viewer for Go heap dumps</p>
</header>
<div id="sidebar">
{{range .RecordTypes}}
<div class="record-type" data-type="{{.RecordType}}">
{{.RecordTypeStr}}
</div>
{{end}}
</div>
<div id="tabs">
<button id="recordsTab" class="tab-button">Records</button>
<button id="graphTab" class="tab-button">Graph</button>
<input type="text" id="searchInput" placeholder="Search...">
<div id="graphControls" style="display: none;">
<button id="resetZoom">Reset Zoom</button>
</div>
</div>
<div id="content">
<!-- Records view -->
<div id="recordsView">
{{range .Records}}
<div class="row {{.RecordType}}">
{{.Repr}}
{{if .HasPointers}}
<button onclick="toggleRow('{{.RowID}}')">Toggle</button>
<div id="{{.RowID}}" class="pointer-info" style="display: none;">
{{range .Pointers}}
<p>Pointer({{.Index}}) at address 0x{{.Address}} (incoming = 0x{{.Incoming}}, outgoing = 0x{{.Outgoing}})</p>
{{end}}
</div>
{{end}}
</div>
{{end}}
</div>
<!-- Graph view (initially hidden) -->
<div id="graphView" style="display: none;">
<div id="graphContainer">
<!-- The graph will be rendered here using D3.js -->
</div>
</div>
</div>
<footer>
<p>Source code: <a href="https://github.com/burntcarrot/heapview">https://github.com/burntcarrot/heapview</a></p>
</footer>
<script src="https://d3js.org/d3.v7.min.js"></script>
<script>
function toggleRow(rowId) {
var row = document.getElementById(rowId);
var pointerInfo = document.getElementById(rowId).querySelector(".pointer-info");
if (row.style.display === "none") {
row.style.display = "block";
pointerInfo.style.display = "block";
} else {
row.style.display = "none";
pointerInfo.style.display = "none";
}
}
var recordTypeElements = document.getElementsByClassName("record-type");
for (var i = 0; i < recordTypeElements.length; i++) {
recordTypeElements[i].addEventListener("click", function() {
var selectedType = this.getAttribute("data-type");
var rows = document.getElementsByClassName("row");
for (var j = 0; j < rows.length; j++) {
var row = rows[j];
var recordType = row.classList[1];
if (recordType === selectedType) {
row.style.display = "block";
} else {
row.style.display = "none";
}
}
});
}
function renderGraph(graphData) {
const data = JSON.parse(graphData);
const margin = { top: 20, right: 20, bottom: 20, left: 20 };
const width = window.innerWidth - margin.left - margin.right;
const height = window.innerHeight - margin.top - margin.bottom - 200;
d3.select("#graphContainer").selectAll("*").remove();
const svg = d3.select("#graphContainer")
.append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom);
const g = svg.append("g")
.attr("transform", `translate(${margin.left},${margin.top})`);
const zoom = d3.zoom()
.scaleExtent([0.1, 10])
.on("zoom", (event) => {
g.attr("transform", event.transform);
});
svg.call(zoom);
const simulation = d3.forceSimulation(data.nodes)
.force("link", d3.forceLink(data.links).id(d => d.id).distance(30))
.force("charge", d3.forceManyBody().strength(-300))
.force("center", d3.forceCenter(width / 2, height / 2))
.force("collide", d3.forceCollide().radius(30))
.force("x", d3.forceX(width / 2).strength(0.1))
.force("y", d3.forceY(height / 2).strength(0.1));
const link = g.append("g")
.attr("class", "links")
.selectAll("line")
.data(data.links)
.enter().append("line")
.attr("stroke", "#999")
.attr("stroke-opacity", 0.6)
.attr("stroke-width", 1);
const node = g.append("g")
.attr("class", "nodes")
.selectAll("g")
.data(data.nodes)
.enter().append("g")
.call(d3.drag()
.on("start", dragstarted)
.on("drag", dragged)
.on("end", dragended));
node.append("circle")
.attr("r", 8)
.attr("fill", "#69b3a2");
node.append("text")
.text(d => d.label)
.attr("x", 10)
.attr("y", 3)
.style("font-size", "8px");
simulation
.nodes(data.nodes)
.on("tick", ticked);
simulation.force("link")
.links(data.links);
function ticked() {
link
.attr("x1", d => d.source.x)
.attr("y1", d => d.source.y)
.attr("x2", d => d.target.x)
.attr("y2", d => d.target.y);
node
.attr("transform", d => `translate(${d.x},${d.y})`);
}
function dragstarted(event, d) {
if (!event.active) simulation.alphaTarget(0.3).restart();
d.fx = d.x;
d.fy = d.y;
}
function dragged(event, d) {
d.fx = event.x;
d.fy = event.y;
}
function dragended(event, d) {
if (!event.active) simulation.alphaTarget(0);
d.fx = null;
d.fy = null;
}
// Search and color nodes
const searchInput = document.getElementById("searchInput");
searchInput.addEventListener("input", function() {
const searchTerm = this.value.toLowerCase();
node.each(function(d) {
const isMatch = d.label.toLowerCase().includes(searchTerm);
d3.select(this).select("circle")
.attr("fill", isMatch ? "#ff0000" : "#69b3a2")
.attr("r", isMatch ? 12 : 8);
if (isMatch && searchTerm !== "") {
const transform = d3.zoomTransform(svg.node());
const scale = transform.k;
const x = -d.x * scale + width / 2;
const y = -d.y * scale + height / 2;
svg.transition().duration(750).call(
zoom.transform,
d3.zoomIdentity.translate(x, y).scale(scale)
);
}
});
});
// Reset zoom
const resetZoomButton = document.getElementById("resetZoom");
resetZoomButton.addEventListener("click", function() {
svg.transition().duration(750).call(
zoom.transform,
d3.zoomIdentity
);
});
}
// Search and highlight records
function searchRecords() {
const searchTerm = document.getElementById("searchInput").value.toLowerCase();
const rows = document.querySelectorAll("#recordsView .row");
rows.forEach(row => {
const text = row.textContent.toLowerCase();
if (text.includes(searchTerm)) {
row.style.display = "block";
highlightText(row, searchTerm);
} else {
row.style.display = "none";
}
});
}
function highlightText(element, searchTerm) {
const regex = new RegExp(searchTerm, 'gi');
element.innerHTML = element.textContent.replace(regex, match => `<span class="highlight">${match}</span>`);
}
document.getElementById("searchInput").addEventListener("input", function() {
if (document.getElementById("recordsView").style.display !== "none") {
searchRecords();
}
});
document.getElementById("graphTab").addEventListener("click", function() {
document.getElementById("recordsView").style.display = "none";
document.getElementById("graphView").style.display = "block";
document.getElementById("graphControls").style.display = "flex";
document.getElementById("searchInput").placeholder = "Search nodes...";
var graphDataString = '{{ .GraphData }}';
renderGraph(graphDataString);
});
document.getElementById("recordsTab").addEventListener("click", function() {
document.getElementById("recordsView").style.display = "block";
document.getElementById("graphView").style.display = "none";
document.getElementById("graphControls").style.display = "none";
document.getElementById("searchInput").placeholder = "Search records...";
searchRecords();
});
searchRecords();
</script>
</body>
</html>