Oregami
Repositories/oxedyne/fe2o3

oxedyne/fe2o3/fe2o3_austenite/tools/bench/cpuprof_check.mjs

2.9 KiB, 1 run

created by r1870400018:66226, which is this file's identity for as long as the history lasts, whatever it is later renamed to

download · who wrote it · its history

1#!/usr/bin/env node
2// Checks cpuprof_rank.mjs on a profile built by hand, whose every figure is known: the demangling of
3// legacy Rust symbols, a sample lasting until the next sample, the nearest Austenite frame taking the time
4// of the allocator frames beneath it, and an inclusive time counted once whatever the recursion.
5import { demangle, rank } from './cpuprof_rank.mjs';
6
7let failed = 0;
8let checks = 0;
9function check(name, got, want) {
10 checks++;
11 const g = JSON.stringify(got);
12 const w = JSON.stringify(want);
13 if (g !== w) {
14 failed++;
15 console.log(`FAIL ${name}: got ${g}, want ${w}`);
16 }
17}
18
19const H = 'h0123456789abcdef';
20const sym = (...parts) => `_ZN${parts.map((p) => p.length + p).join('')}${17}${H}E`;
21check('plain path', demangle(sym('oxedyne_fe2o3_austenite', 'flow', 'par', 'layout_par')),
22 'oxedyne_fe2o3_austenite::flow::par::layout_par');
23check('trait impl', demangle(`_ZN67_$LT$alloc..vec..Vec$LT$T$C$A$GT$$u20$as$u20$core..clone..Clone$GT$5clone17${H}E`),
24 '<alloc::vec::Vec<T,A> as core::clone::Clone>::clone');
25check('not a symbol', demangle('compileProject'), 'compileProject');
26check('already demangled', demangle(`oxedyne_fe2o3_austenite::flow::par::layout_with::${H}`),
27 'oxedyne_fe2o3_austenite::flow::par::layout_with');
28
29const frame = (id, functionName, children = [], url = 'wasm://wasm/x') => ({ id, callFrame: { functionName, url }, children });
30const A = (m, f) => sym('oxedyne_fe2o3_austenite', m, f);
31// root(1) > austenite flow::par (2) > alloc::vec::push (3) and > austenite flow::par recursion (4) > memcpy-like core::ptr (5);
32// root > austenite eval::eval (6).
33const profile = {
34 startTime: 0, endTime: 100000,
35 nodes: [
36 frame(1, '(root)', [2, 6], ''),
37 frame(2, A('flow', 'par'), [3, 4]),
38 frame(3, sym('alloc', 'vec', 'push')),
39 frame(4, A('flow', 'par'), [5]),
40 frame(5, sym('core', 'ptr', 'copy')),
41 frame(6, A('eval', 'eval')),
42 ],
43 // Samples at 0, 10, 30, 60 and 100 ms: nodes 3, 5, 5, 6, 3. Each lasts until the next, the last not at all,
44 // so they last 10, 20, 30, 40 and 0 ms; read as the delta before each they would last 0, 10, 20, 30, 40.
45 samples: [3, 5, 5, 6, 3],
46 timeDeltas: [0, 10000, 20000, 30000, 40000],
47};
48const r = rank(profile, { top: 5, incl: ['flow::par', 'eval::eval'], callers: ['core::ptr::copy'] });
49check('busy', r.total_ms, 100);
50const by = (rows) => Object.fromEntries(rows.map((x) => [x.name, x.ms]).sort((a, b) => a[0].localeCompare(b[0])));
51check('self by crate', by(r.by_crate), { alloc: 10, core: 50, oxedyne_fe2o3_austenite: 40 });
52check('asked by', by(r.asked_by), { 'austenite::eval::eval': 40, 'austenite::flow::par': 60 });
53check('inclusive counts once', by(r.inclusive), { 'eval::eval': 40, 'flow::par': 60 });
54// Node 5 (core::ptr::copy, 50 ms) is called by node 4 (flow::par), whose own name does not match.
55check('callers', by(r.callers[0].rows), { 'oxedyne_fe2o3_austenite::flow::par': 50 });
56console.log(`cpuprof_check: ${checks} checks, ${failed} failed`);
57process.exit(failed ? 1 : 0);