improve result logging
This commit is contained in:
parent
02d19fce2a
commit
0ba41d5aea
3 changed files with 73 additions and 10 deletions
|
@ -12,9 +12,11 @@ async function main() {
|
||||||
.pipeThrough(new TextLineStream());
|
.pipeThrough(new TextLineStream());
|
||||||
|
|
||||||
const stats = new Tracker();
|
const stats = new Tracker();
|
||||||
|
stats.update([0, "total", Number(Temporal.Now.instant().epochNanoseconds)]);
|
||||||
try {
|
try {
|
||||||
for await (const line of lines) stats.update(JSON.parse(line) as Msg);
|
for await (const line of lines) stats.update(JSON.parse(line) as Msg);
|
||||||
} catch (_) { /* STDOUT closed */ }
|
} catch (_) { /* STDOUT closed */ }
|
||||||
|
stats.update([1, "total", Number(Temporal.Now.instant().epochNanoseconds)]);
|
||||||
|
|
||||||
stats.log();
|
stats.log();
|
||||||
}
|
}
|
||||||
|
@ -41,7 +43,8 @@ class Tracker {
|
||||||
}
|
}
|
||||||
|
|
||||||
log() {
|
log() {
|
||||||
for (const section of this.register.values()) section.log();
|
const total = this.register.get("total")?.average();
|
||||||
|
for (const section of this.register.values()) section.log(total);
|
||||||
Deno.exit(0);
|
Deno.exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -69,11 +72,21 @@ class SectionTracker {
|
||||||
this.runs.push(duration);
|
this.runs.push(duration);
|
||||||
}
|
}
|
||||||
|
|
||||||
log() {
|
log(total_average: number | undefined) {
|
||||||
const count = this.runs.length;
|
const count = this.runs.length;
|
||||||
const avg = this.average() / 1_000;
|
const avg = this.average();
|
||||||
const line = \`\${this.name} :\\t\${count} runs, \${avg} µs avg\`;
|
const cumul = count * this.average();
|
||||||
console.log(line);
|
const fraciton = Math.floor((total_average ? cumul / total_average : 0) * 100);
|
||||||
|
const show_total = total_average !== undefined && this.name !== "total";
|
||||||
|
const columns = [
|
||||||
|
this.name,
|
||||||
|
\`\${count} runs\`,
|
||||||
|
\`\${to_human(avg)} avg\`,
|
||||||
|
\`\${to_human(cumul)} cumul\`,
|
||||||
|
...(show_total ? [\`\${fraciton} %\`] : []),
|
||||||
|
];
|
||||||
|
const line = columns.map((e) => e.padStart(18));
|
||||||
|
console.log(...line);
|
||||||
}
|
}
|
||||||
|
|
||||||
average() {
|
average() {
|
||||||
|
@ -82,5 +95,23 @@ class SectionTracker {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function to_human(duration_ns: number) {
|
||||||
|
const units = [
|
||||||
|
[3_600_000_000_000, "h"],
|
||||||
|
[60_000_000_000, "min"],
|
||||||
|
[1_000_000_000, "s"],
|
||||||
|
[1_000_000, "ms"],
|
||||||
|
[1_000, "µs"],
|
||||||
|
[1, "ns"],
|
||||||
|
] as const;
|
||||||
|
for (const [fac, name] of units) {
|
||||||
|
if ((duration_ns / fac) < 1.) continue;
|
||||||
|
const mapped_duration = duration_ns / fac;
|
||||||
|
const [integral, decimal] = mapped_duration.toString().split(".");
|
||||||
|
const formatted = \`\${integral}.\${decimal.slice(0, 3).padEnd(3, "0")}\`;
|
||||||
|
return \`\${formatted} \${name}\`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (import.meta.main) await main();
|
if (import.meta.main) await main();
|
||||||
`;
|
`;
|
41
src/child.ts
41
src/child.ts
|
@ -12,9 +12,11 @@ async function main() {
|
||||||
.pipeThrough(new TextLineStream());
|
.pipeThrough(new TextLineStream());
|
||||||
|
|
||||||
const stats = new Tracker();
|
const stats = new Tracker();
|
||||||
|
stats.update([0, "total", Number(Temporal.Now.instant().epochNanoseconds)]);
|
||||||
try {
|
try {
|
||||||
for await (const line of lines) stats.update(JSON.parse(line) as Msg);
|
for await (const line of lines) stats.update(JSON.parse(line) as Msg);
|
||||||
} catch (_) { /* STDOUT closed */ }
|
} catch (_) { /* STDOUT closed */ }
|
||||||
|
stats.update([1, "total", Number(Temporal.Now.instant().epochNanoseconds)]);
|
||||||
|
|
||||||
stats.log();
|
stats.log();
|
||||||
}
|
}
|
||||||
|
@ -41,7 +43,8 @@ class Tracker {
|
||||||
}
|
}
|
||||||
|
|
||||||
log() {
|
log() {
|
||||||
for (const section of this.register.values()) section.log();
|
const total = this.register.get("total")?.average();
|
||||||
|
for (const section of this.register.values()) section.log(total);
|
||||||
Deno.exit(0);
|
Deno.exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -69,11 +72,21 @@ class SectionTracker {
|
||||||
this.runs.push(duration);
|
this.runs.push(duration);
|
||||||
}
|
}
|
||||||
|
|
||||||
log() {
|
log(total_average: number | undefined) {
|
||||||
const count = this.runs.length;
|
const count = this.runs.length;
|
||||||
const avg = this.average() / 1_000;
|
const avg = this.average();
|
||||||
const line = `${this.name} :\t${count} runs, ${avg} µs avg`;
|
const cumul = count * this.average();
|
||||||
console.log(line);
|
const fraciton = Math.floor((total_average ? cumul / total_average : 0) * 100);
|
||||||
|
const show_total = total_average !== undefined && this.name !== "total";
|
||||||
|
const columns = [
|
||||||
|
this.name,
|
||||||
|
`${count} runs`,
|
||||||
|
`${to_human(avg)} avg`,
|
||||||
|
`${to_human(cumul)} cumul`,
|
||||||
|
...(show_total ? [`${fraciton} %`] : []),
|
||||||
|
];
|
||||||
|
const line = columns.map((e) => e.padStart(18));
|
||||||
|
console.log(...line);
|
||||||
}
|
}
|
||||||
|
|
||||||
average() {
|
average() {
|
||||||
|
@ -82,4 +95,22 @@ class SectionTracker {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function to_human(duration_ns: number) {
|
||||||
|
const units = [
|
||||||
|
[3_600_000_000_000, "h"],
|
||||||
|
[60_000_000_000, "min"],
|
||||||
|
[1_000_000_000, "s"],
|
||||||
|
[1_000_000, "ms"],
|
||||||
|
[1_000, "µs"],
|
||||||
|
[1, "ns"],
|
||||||
|
] as const;
|
||||||
|
for (const [fac, name] of units) {
|
||||||
|
if ((duration_ns / fac) < 1.) continue;
|
||||||
|
const mapped_duration = duration_ns / fac;
|
||||||
|
const [integral, decimal] = mapped_duration.toString().split(".");
|
||||||
|
const formatted = `${integral}.${decimal.slice(0, 3).padEnd(3, "0")}`;
|
||||||
|
return `${formatted} ${name}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (import.meta.main) await main();
|
if (import.meta.main) await main();
|
||||||
|
|
|
@ -38,6 +38,7 @@ export class Observer {
|
||||||
"run",
|
"run",
|
||||||
`--allow-read=${socket_path}`,
|
`--allow-read=${socket_path}`,
|
||||||
`--allow-write=${socket_path}`,
|
`--allow-write=${socket_path}`,
|
||||||
|
"--unstable-temporal",
|
||||||
"-",
|
"-",
|
||||||
socket_path,
|
socket_path,
|
||||||
];
|
];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue