-
Notifications
You must be signed in to change notification settings - Fork 186
Expand file tree
/
Copy pathpage.vue
More file actions
580 lines (528 loc) · 16.9 KB
/
Copy pathpage.vue
File metadata and controls
580 lines (528 loc) · 16.9 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
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
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
<script setup lang="tsx">
import {h, ref, Ref, computed} from "vue";
import {getUrlParams, changeUrl} from "../../utils/navigation";
import {postMsgpack} from "../../utils/requests";
import {SELF_PROFILE_DATA_URL} from "../../urls";
import {openTraceInPerfetto} from "../../perfetto";
import {
Selector,
SelfProfileResponse,
createTitleData,
createDownloadLinksData,
createTableData,
createArtifactData,
DeltaData,
} from "./utils";
const loading = ref(true);
const data: Ref<SelfProfileResponse | null> = ref(null);
const selector: Ref<Selector | null> = ref(null);
const showIncr = ref(true);
const showDelta = ref(true);
type SortDirection = "asc" | "desc";
// Client-side sorting state
const currentSortColumn = ref<string>("timeSeconds");
const currentSortDirection = ref<SortDirection>("desc");
// Computed properties for UI data
const titleData = computed(() => createTitleData(selector.value));
const downloadLinksData = computed(() =>
createDownloadLinksData(selector.value)
);
const unsortedTableData = computed(() => createTableData(data.value));
const tableData = computed(() => {
const rows = unsortedTableData.value;
if (rows.length === 0) return rows;
// Separate totals row from data rows
const totalsRow = rows.find((row) => row.isTotal);
const dataRows = rows.filter((row) => !row.isTotal);
// Sort data rows based on current sort column and direction
const sortedDataRows = dataRows.sort((a, b) => {
let aValue: string | number;
let bValue: string | number;
let aSecondary: number | undefined;
let bSecondary: number | undefined;
// Map column name to data property
switch (currentSortColumn.value) {
case "label": // Query/Function
aValue = a.label;
bValue = b.label;
break;
case "timeSeconds": // Time (s)
aValue = a.timeSeconds;
bValue = b.timeSeconds;
// Use percentage change as secondary sort for equal absolute values
aSecondary =
a.timeDelta !== null ? Math.abs(a.timeDelta.percentage) : 0;
bSecondary =
b.timeDelta !== null ? Math.abs(b.timeDelta.percentage) : 0;
break;
case "executions": // Executions
aValue = a.executions;
bValue = b.executions;
// Use percentage change as secondary sort for equal absolute values
aSecondary =
a.executionsDelta !== null
? Math.abs(a.executionsDelta.percentage)
: 0;
bSecondary =
b.executionsDelta !== null
? Math.abs(b.executionsDelta.percentage)
: 0;
break;
case "incrementalLoading": // Incremental loading (s)
aValue = a.incrementalLoading;
bValue = b.incrementalLoading;
// Use percentage change as secondary sort for equal absolute values
aSecondary =
a.incrementalLoadingDelta !== null
? Math.abs(a.incrementalLoadingDelta.percentage)
: 0;
bSecondary =
b.incrementalLoadingDelta !== null
? Math.abs(b.incrementalLoadingDelta.percentage)
: 0;
break;
case "timePercent": // Time (%)
aValue = a.timePercent.value;
bValue = b.timePercent.value;
break;
case "timeDelta": // Time delta
aValue = a.timeDelta !== null ? a.timeDelta.delta : -Infinity;
bValue = b.timeDelta !== null ? b.timeDelta.delta : -Infinity;
// Use percentage as secondary sort for equal delta values
aSecondary =
a.timeDelta !== null ? Math.abs(a.timeDelta.percentage) : 0;
bSecondary =
b.timeDelta !== null ? Math.abs(b.timeDelta.percentage) : 0;
break;
case "executionsDelta": // Executions delta
aValue =
a.executionsDelta !== null ? a.executionsDelta.delta : -Infinity;
bValue =
b.executionsDelta !== null ? b.executionsDelta.delta : -Infinity;
// Use percentage as secondary sort for equal delta values
aSecondary =
a.executionsDelta !== null
? Math.abs(a.executionsDelta.percentage)
: 0;
bSecondary =
b.executionsDelta !== null
? Math.abs(b.executionsDelta.percentage)
: 0;
break;
case "incrementalLoadingDelta": // Incremental loading delta
aValue =
a.incrementalLoadingDelta !== null
? a.incrementalLoadingDelta.delta
: -Infinity;
bValue =
b.incrementalLoadingDelta !== null
? b.incrementalLoadingDelta.delta
: -Infinity;
// Use percentage as secondary sort for equal delta values
aSecondary =
a.incrementalLoadingDelta !== null
? Math.abs(a.incrementalLoadingDelta.percentage)
: 0;
bSecondary =
b.incrementalLoadingDelta !== null
? Math.abs(b.incrementalLoadingDelta.percentage)
: 0;
break;
default:
aValue = a.label;
bValue = b.label;
}
// Handle string vs number comparison
let comparison: number;
if (typeof aValue === "string" && typeof bValue === "string") {
comparison = aValue.localeCompare(bValue);
} else {
comparison = (aValue as number) - (bValue as number);
// If primary values are equal and we have secondary sort criteria, use percentage change
if (
comparison === 0 &&
aSecondary !== undefined &&
bSecondary !== undefined
) {
comparison = bSecondary - aSecondary; // Higher percentage change comes first
}
}
return currentSortDirection.value === "asc" ? comparison : -comparison;
});
// Return totals row first, then sorted data rows
return totalsRow ? [totalsRow, ...sortedDataRows] : sortedDataRows;
});
const artifactData = computed(() => createArtifactData(data.value));
function handlePerfettoClick(link: string, title: string) {
openTraceInPerfetto(link, title);
}
function loadSortFromUrl(urlParams: Dict<string>) {
const sort = urlParams["sort"] ?? "-timeSeconds"; // Default to descending timeSeconds
// Handle sort format: either "columnName" for asc or "-columnName" for desc
if (sort.startsWith("-")) {
currentSortColumn.value = sort.substring(1);
currentSortDirection.value = "desc";
} else {
currentSortColumn.value = sort;
currentSortDirection.value = "asc";
}
}
function storeSortToUrl() {
const params = getUrlParams();
const sortValue =
currentSortDirection.value === "desc"
? `-${currentSortColumn.value}`
: currentSortColumn.value;
params["sort"] = sortValue;
changeUrl(params);
}
async function loadData() {
const params = getUrlParams();
const {commit, base_commit, benchmark, scenario} = params;
// Load sort state from URL
loadSortFromUrl(params);
const currentSelector: Selector = {
commit,
base_commit: base_commit ?? null,
benchmark,
scenario,
};
selector.value = currentSelector;
const response = await postMsgpack<SelfProfileResponse>(
SELF_PROFILE_DATA_URL,
currentSelector
);
data.value = response;
populateUIData(response, currentSelector);
loading.value = false;
}
function populateUIData(responseData: SelfProfileResponse, state: Selector) {
showDelta.value =
responseData.base_profile_delta !== undefined &&
responseData.base_profile_delta !== null;
showIncr.value = state.scenario.includes("incr-");
}
function changeSortParameters(
columnName: string,
defaultDirection: SortDirection
) {
// Toggle direction if clicking the same column, otherwise use default direction
if (currentSortColumn.value === columnName) {
currentSortDirection.value =
currentSortDirection.value === "asc" ? "desc" : "asc";
} else {
currentSortColumn.value = columnName;
currentSortDirection.value = defaultDirection;
}
// Update URL with new sort state
storeSortToUrl();
}
function getHeaderClass(columnName: string): string {
if (columnName === currentSortColumn.value) {
if (currentSortDirection.value === "asc") {
return "header-sort-asc";
} else {
return "header-sort-desc";
}
}
return "header-sort";
}
function DeltaComponent({delta}: {delta: DeltaData | null}) {
if (delta === null) {
return <span>-</span>;
}
let {from, percentage, isIntegral} = delta;
const to = from + delta.delta;
let classes: string;
if (percentage > 1) {
classes = "positive";
} else if (percentage < -1) {
classes = "negative";
} else {
classes = "neutral";
}
if (Math.abs(delta.delta) <= 0.05) {
classes = "neutral";
}
let text: string;
if (isIntegral) {
text = delta.delta.toString();
} else {
text = delta.delta.toFixed(3);
}
if (percentage != Infinity && percentage != -Infinity) {
text += `(${percentage.toFixed(1)}%)`.padStart(10, " ");
} else {
text += `-`.padStart(10, " ");
}
const title = `${from.toFixed(3)} to ${to.toFixed(3)} ≈ ${delta.delta.toFixed(
3
)}`;
return (
<span class={classes} title={title}>
{text}
</span>
);
}
loadData();
</script>
<template>
<div>
<div v-if="loading">
<p>Loading...</p>
</div>
<div v-else id="content">
<h3 id="title">
{{ titleData.text }}
<template v-if="selector?.base_commit">
<br />diff vs base {{ selector.base_commit.substring(0, 10) }},
<a :href="titleData.baseHref">query info for just base commit</a>
<br />
<a :href="titleData.selfHref">query info for just this commit</a>
</template>
</h3>
<div id="raw-urls">
<template v-if="downloadLinksData.baseLinks">
Download/view
<a :href="downloadLinksData.baseLinks.raw">raw</a>,
<a :href="downloadLinksData.baseLinks.flamegraph">flamegraph</a>,
<a :href="downloadLinksData.baseLinks.crox">crox</a>,
<a :href="downloadLinksData.baseLinks.codegen">codegen-schedule</a>
(<a
href="#"
@click.prevent="
handlePerfettoClick(
downloadLinksData.baseLinks.perfetto.link,
downloadLinksData.baseLinks.perfetto.traceTitle
)
"
>Perfetto</a
>,
<a :href="downloadLinksData.baseLinks.firefox">Firefox profiler</a>)
results for {{ selector?.base_commit?.substring(0, 10) }} (base
commit)
<br />
</template>
Download/view
<a :href="downloadLinksData.newLinks.raw">raw</a>,
<a :href="downloadLinksData.newLinks.flamegraph">flamegraph</a>,
<a :href="downloadLinksData.newLinks.crox">crox</a>,
<a :href="downloadLinksData.newLinks.codegen">codegen-schedule</a>
(<a
href="#"
@click.prevent="
handlePerfettoClick(
downloadLinksData.newLinks.perfetto.link,
downloadLinksData.newLinks.perfetto.traceTitle
)
"
>Perfetto</a
>, <a :href="downloadLinksData.newLinks.firefox">Firefox profiler</a>)
results for {{ selector?.commit?.substring(0, 10) }} (new commit)
<template v-if="downloadLinksData.diffLink">
<br />
Diff: <a :href="downloadLinksData.diffLink">codegen-schedule</a>
</template>
<template v-if="downloadLinksData.localCommands.base">
<br />
Local profile (base):
<code>{{ downloadLinksData.localCommands.base }}</code>
</template>
<br />
Local profile (new):
<code>{{ downloadLinksData.localCommands.new }}</code>
<template v-if="downloadLinksData.localCommands.diff">
<br />
Local profile (diff):
<code>{{ downloadLinksData.localCommands.diff }}</code>
</template>
</div>
<h4>Artifact Size</h4>
<table id="artifact-table">
<thead>
<tr>
<th>Artifact</th>
<th>Size</th>
<th>Size delta</th>
</tr>
</thead>
<tbody id="artifact-body">
<tr v-for="artifact in artifactData" :key="artifact.name">
<td style="text-align: center">{{ artifact.name }}</td>
<td>{{ artifact.size }}</td>
<td>{{ artifact.sizeDelta }}</td>
</tr>
</tbody>
</table>
<p>
'Instructions (%)' is the percentage of instructions executed on this
query (we do not use wall-time as we want to account for parallelism).
</p>
<p>
<b
>Note: self-profile measurements have been
<a href="https://github.com/rust-lang/rustc-perf/pull/1984"
>recently switched</a
>
from wall-time to HW counters (instruction count). If comparing with
an older artifact, the timings might not be directly comparable.</b
>
</p>
<p>Executions do not include cached executions.</p>
<table>
<thead>
<tr id="table-header">
<th :class="getHeaderClass('label')">
<a href="#" @click.prevent="changeSortParameters('label', 'asc')"
>Query/Function</a
>
</th>
<th :class="getHeaderClass('timePercent')">
<a
href="#"
@click.prevent="changeSortParameters('timePercent', 'desc')"
>Instructions (%)</a
>
</th>
<th :class="getHeaderClass('timeSeconds')">
<a
href="#"
@click.prevent="changeSortParameters('timeSeconds', 'desc')"
>Instructions</a
>
</th>
<th v-if="showDelta" :class="getHeaderClass('timeDelta')">
<a
href="#"
@click.prevent="changeSortParameters('timeDelta', 'desc')"
>Instructions delta</a
>
</th>
<th :class="getHeaderClass('executions')">
<a
href="#"
@click.prevent="changeSortParameters('executions', 'desc')"
>Executions</a
>
</th>
<th v-if="showDelta" :class="getHeaderClass('executionsDelta')">
<a
href="#"
@click.prevent="changeSortParameters('executionsDelta', 'desc')"
>Executions delta</a
>
</th>
<th
v-if="showIncr"
:class="getHeaderClass('incrementalLoading')"
title="Incremental loading instructions"
>
<a
href="#"
@click.prevent="
changeSortParameters('incrementalLoading', 'desc')
"
>Incremental loading (icounts)</a
>
</th>
<th
v-if="showIncr && showDelta"
:class="getHeaderClass('incrementalLoadingDelta')"
>
<a
href="#"
@click.prevent="
changeSortParameters('incrementalLoadingDelta', 'desc')
"
>Incremental loading delta</a
>
</th>
</tr>
</thead>
<tbody id="primary-table">
<tr
v-for="(row, index) in tableData"
:key="index"
:class="{'total-row': row.isTotal}"
>
<td>{{ row.label }}</td>
<td :title="row.timePercent.title">
{{ row.timePercent.formatted }}
</td>
<td>{{ row.timeSeconds.toFixed(3) }}</td>
<td v-if="showDelta">
<DeltaComponent :delta="row.timeDelta" />
</td>
<td>{{ row.executions }}</td>
<td v-if="showDelta">
<DeltaComponent :delta="row.executionsDelta" />
</td>
<td v-if="showIncr">{{ row.incrementalLoading.toFixed(3) }}</td>
<td v-if="showDelta && showIncr">
<DeltaComponent :delta="row.incrementalLoadingDelta" />
</td>
</tr>
</tbody>
</table>
</div>
</div>
</template>
<style lang="scss" scoped>
table {
border-collapse: collapse;
}
thead th {
padding-left: 1em;
}
.positive {
color: red;
font-weight: bold;
}
.negative {
color: green;
font-weight: bold;
}
.neutral {
color: #666;
}
.total-row {
font-weight: bold;
background-color: #eee !important;
border-top: 1px solid black;
border-bottom: 1px solid black;
}
#primary-table td,
#primary-table th {
padding-left: 1.5em;
white-space: pre;
}
#primary-table tr:nth-child(2n + 1) {
background-color: #f9f9f9;
}
#primary-table tr:nth-child(1) {
background-color: #eee;
font-weight: bold;
border-top: 1px solid black;
border-bottom: 1px solid black;
}
.header-sort::after {
content: "⇕";
}
.header-sort-desc::after {
content: "▼";
}
.header-sort-asc::after {
content: "▲";
}
code {
background-color: #eee;
border-radius: 3px;
user-select: all;
}
#artifact-table th {
text-align: center;
}
#artifact-table td {
padding: 0 0 0 20px;
}
</style>