-
Notifications
You must be signed in to change notification settings - Fork 347
/
Copy pathmetrics.ts
77 lines (69 loc) · 2.26 KB
/
metrics.ts
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
/*
* metrics.ts
*
* Copyright (C) 2020-2023 Posit Software, PBC
*/
import { inputTargetIndexCacheMetrics } from "../../project/project-index.ts";
type FileReadRecord = {
path: string;
stack: string;
};
let fileReads: FileReadRecord[] | undefined = undefined;
export function captureFileReads() {
fileReads = [];
const originalReadTextFileSync = Deno.readTextFileSync;
Deno.readTextFileSync = function (path: string | URL) {
try {
throw new Error("File read");
} catch (e) {
const stack = e.stack!.split("\n").slice(2);
fileReads!.push({ path: String(path), stack });
}
return originalReadTextFileSync(path);
};
}
export function quartoPerformanceMetrics() {
return {
inputTargetIndexCache: inputTargetIndexCacheMetrics,
fileReads,
};
}
export function reportPeformanceMetrics() {
console.log("---");
console.log("Performance metrics");
console.log("Quarto:");
console.log(JSON.stringify(quartoPerformanceMetrics(), null, 2));
console.log();
// denoMetrics is some kind of fancy object that doesn't respond
// to a bunch of the normal methods. So we have to do this
// the JSON-round-trip way.
console.log("Deno:");
const denoMetrics = JSON.parse(JSON.stringify(Deno.metrics() as any));
denoMetrics.ops = Object.fromEntries(
Object.entries(denoMetrics.ops).map(
([key, opMetrics]: any) => {
for (const key of Object.keys(opMetrics)) {
if (opMetrics[key] === 0) {
delete opMetrics[key];
}
}
return [key, opMetrics];
},
).filter(([_key, opMetrics]: any) => Object.keys(opMetrics).length > 0)
.map(([key, opMetrics]: any) => {
if (
(opMetrics.opsDispatched === opMetrics.opsDispatchedSync &&
opMetrics.opsDispatched === opMetrics.opsCompleted &&
opMetrics.opsDispatched === opMetrics.opsCompletedSync) ||
(opMetrics.opsDispatched === opMetrics.opsDispatchedAsync &&
opMetrics.opsDispatched === opMetrics.opsCompleted &&
opMetrics.opsDispatched === opMetrics.opsCompletedAsync)
) {
return [key, opMetrics.opsDispatched];
} else {
return [key, opMetrics];
}
}),
);
console.log(JSON.stringify(denoMetrics, null, 2));
}