@flanksource/clicky-ui 0.3.85 → 0.3.87
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components.cjs +0 -1
- package/dist/components.d.ts +1 -1
- package/dist/components.d.ts.map +1 -1
- package/dist/components.js +2 -2
- package/dist/data/ProgressBars.cjs +157 -101
- package/dist/data/ProgressBars.cjs.map +1 -1
- package/dist/data/ProgressBars.d.ts +1 -1
- package/dist/data/ProgressBars.d.ts.map +1 -1
- package/dist/data/ProgressBars.js +157 -101
- package/dist/data/ProgressBars.js.map +1 -1
- package/dist/data/ai/PromptCatalog/PromptCatalogTable.cjs +1 -0
- package/dist/data/ai/PromptCatalog/PromptCatalogTable.cjs.map +1 -1
- package/dist/data/ai/PromptCatalog/PromptCatalogTable.d.ts.map +1 -1
- package/dist/data/ai/PromptCatalog/PromptCatalogTable.js +1 -0
- package/dist/data/ai/PromptCatalog/PromptCatalogTable.js.map +1 -1
- package/dist/data/traces/ProcessResourceMetrics.cjs +99 -0
- package/dist/data/traces/ProcessResourceMetrics.cjs.map +1 -0
- package/dist/data/traces/ProcessResourceMetrics.d.ts +10 -0
- package/dist/data/traces/ProcessResourceMetrics.d.ts.map +1 -0
- package/dist/data/traces/ProcessResourceMetrics.js +99 -0
- package/dist/data/traces/ProcessResourceMetrics.js.map +1 -0
- package/dist/data/traces/ProcessTraceDetail.cjs +85 -108
- package/dist/data/traces/ProcessTraceDetail.cjs.map +1 -1
- package/dist/data/traces/ProcessTraceDetail.d.ts +7 -1
- package/dist/data/traces/ProcessTraceDetail.d.ts.map +1 -1
- package/dist/data/traces/ProcessTraceDetail.js +88 -111
- package/dist/data/traces/ProcessTraceDetail.js.map +1 -1
- package/dist/data/traces/ProcessUsageBars.cjs +37 -41
- package/dist/data/traces/ProcessUsageBars.cjs.map +1 -1
- package/dist/data/traces/ProcessUsageBars.d.ts.map +1 -1
- package/dist/data/traces/ProcessUsageBars.js +37 -41
- package/dist/data/traces/ProcessUsageBars.js.map +1 -1
- package/dist/data/traces/process-tree.cjs +35 -0
- package/dist/data/traces/process-tree.cjs.map +1 -1
- package/dist/data/traces/process-tree.d.ts +15 -0
- package/dist/data/traces/process-tree.d.ts.map +1 -1
- package/dist/data/traces/process-tree.js +35 -1
- package/dist/data/traces/process-tree.js.map +1 -1
- package/dist/data/version-info.cjs +3 -3
- package/dist/data/version-info.js +3 -3
- package/dist/expressions/playground/ExpressionPlayground.cjs +207 -156
- package/dist/expressions/playground/ExpressionPlayground.cjs.map +1 -1
- package/dist/expressions/playground/ExpressionPlayground.d.ts +1 -6
- package/dist/expressions/playground/ExpressionPlayground.d.ts.map +1 -1
- package/dist/expressions/playground/ExpressionPlayground.js +207 -156
- package/dist/expressions/playground/ExpressionPlayground.js.map +1 -1
- package/dist/expressions/playground/useEvaluator.cjs +56 -42
- package/dist/expressions/playground/useEvaluator.cjs.map +1 -1
- package/dist/expressions/playground/useEvaluator.d.ts +0 -2
- package/dist/expressions/playground/useEvaluator.d.ts.map +1 -1
- package/dist/expressions/playground/useEvaluator.js +56 -42
- package/dist/expressions/playground/useEvaluator.js.map +1 -1
- package/dist/expressions/playground/useSampleRuns.cjs +22 -18
- package/dist/expressions/playground/useSampleRuns.cjs.map +1 -1
- package/dist/expressions/playground/useSampleRuns.d.ts +2 -3
- package/dist/expressions/playground/useSampleRuns.d.ts.map +1 -1
- package/dist/expressions/playground/useSampleRuns.js +22 -18
- package/dist/expressions/playground/useSampleRuns.js.map +1 -1
- package/dist/hooks/use-latest.cjs +14 -0
- package/dist/hooks/use-latest.cjs.map +1 -0
- package/dist/hooks/use-latest.d.ts +3 -0
- package/dist/hooks/use-latest.d.ts.map +1 -0
- package/dist/hooks/use-latest.js +14 -0
- package/dist/hooks/use-latest.js.map +1 -0
- package/dist/index.cjs +0 -1
- package/dist/index.js +2 -2
- package/dist/overlay/ConfirmDialog.cjs +12 -37
- package/dist/overlay/ConfirmDialog.cjs.map +1 -1
- package/dist/overlay/ConfirmDialog.d.ts +3 -17
- package/dist/overlay/ConfirmDialog.d.ts.map +1 -1
- package/dist/overlay/ConfirmDialog.js +12 -37
- package/dist/overlay/ConfirmDialog.js.map +1 -1
- package/dist/overlay/useConfirm.cjs +1 -16
- package/dist/overlay/useConfirm.cjs.map +1 -1
- package/dist/overlay/useConfirm.d.ts +1 -9
- package/dist/overlay/useConfirm.d.ts.map +1 -1
- package/dist/overlay/useConfirm.js +3 -17
- package/dist/overlay/useConfirm.js.map +1 -1
- package/dist/runtime/barrels.json +1574 -1576
- package/dist/runtime/importmap.json +2184 -2183
- package/package.json +1 -1
- package/dist/overlay/confirmMemory.cjs +0 -58
- package/dist/overlay/confirmMemory.cjs.map +0 -1
- package/dist/overlay/confirmMemory.d.ts +0 -8
- package/dist/overlay/confirmMemory.d.ts.map +0 -1
- package/dist/overlay/confirmMemory.js +0 -54
- package/dist/overlay/confirmMemory.js.map +0 -1
|
@@ -1,50 +1,46 @@
|
|
|
1
|
+
const require_UiChip = require("../../icons/components/UiChip.cjs");
|
|
2
|
+
const require_UiMemoryStick = require("../../icons/components/UiMemoryStick.cjs");
|
|
1
3
|
const require_format = require("../../lib/format.cjs");
|
|
2
|
-
const
|
|
4
|
+
const require_ProgressBars = require("../ProgressBars.cjs");
|
|
3
5
|
const require_process_tree = require("./process-tree.cjs");
|
|
4
6
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
5
7
|
// src/data/traces/ProcessUsageBars.tsx
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_ProgressBar.ProgressBar, {
|
|
22
|
-
label,
|
|
23
|
-
total: 100,
|
|
24
|
-
height: "h-1",
|
|
25
|
-
segments: [{
|
|
26
|
-
count: Math.max(0, Math.min(100, percent)),
|
|
27
|
-
color: "bg-primary",
|
|
28
|
-
label: value
|
|
29
|
-
}]
|
|
30
|
-
})]
|
|
31
|
-
});
|
|
32
|
-
}
|
|
8
|
+
var GiB = 1024 ** 3;
|
|
9
|
+
/** One bar per core (100% CPU), captioned as a CPU %. */
|
|
10
|
+
var CPU_UNIT = {
|
|
11
|
+
perBar: 100,
|
|
12
|
+
label: "",
|
|
13
|
+
barLabel: "core",
|
|
14
|
+
format: (cores) => require_process_tree.formatCpuPercent(cores * 100)
|
|
15
|
+
};
|
|
16
|
+
/** One bar per GB of RSS, captioned in the readable byte size. */
|
|
17
|
+
var RSS_UNIT = {
|
|
18
|
+
perBar: GiB,
|
|
19
|
+
label: "",
|
|
20
|
+
barLabel: "GB",
|
|
21
|
+
format: (gb) => require_format.formatBytes(gb * GiB)
|
|
22
|
+
};
|
|
33
23
|
function ProcessUsageBars({ row, memoryPercent }) {
|
|
34
24
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
35
|
-
className: "flex shrink-0 gap-3",
|
|
36
|
-
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
25
|
+
className: "flex shrink-0 items-center gap-3",
|
|
26
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_ProgressBars.ProgressBars, {
|
|
27
|
+
variant: "cell",
|
|
28
|
+
orientation: "vertical",
|
|
29
|
+
showLabel: false,
|
|
30
|
+
icon: require_UiChip.UiChip,
|
|
31
|
+
unit: CPU_UNIT,
|
|
32
|
+
title: `CPU for pid ${row.pid}`,
|
|
33
|
+
usage: row.cpuPercent ?? void 0,
|
|
34
|
+
hoverFooter: `Peak ${require_process_tree.formatCpuPercent(row.peakCpuPercent)} · one bar per core`
|
|
35
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_ProgressBars.ProgressBars, {
|
|
36
|
+
variant: "cell",
|
|
37
|
+
orientation: "vertical",
|
|
38
|
+
showLabel: false,
|
|
39
|
+
icon: require_UiMemoryStick.UiMemoryStick,
|
|
40
|
+
unit: RSS_UNIT,
|
|
41
|
+
title: `RAM for pid ${row.pid}`,
|
|
42
|
+
usage: row.rssBytes,
|
|
43
|
+
hoverFooter: `Peak ${require_format.formatBytes(row.peakRssBytes)}${memoryPercent === void 0 ? "" : ` · ${memoryPercent.toFixed(1)}% of host RAM`} · one bar per GB`
|
|
48
44
|
})]
|
|
49
45
|
});
|
|
50
46
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProcessUsageBars.cjs","names":["
|
|
1
|
+
{"version":3,"file":"ProcessUsageBars.cjs","names":["formatCpuPercent","formatBytes","ProgressBars","UiChip","UiMemoryStick"],"sources":["../../../src/data/traces/ProcessUsageBars.tsx"],"sourcesContent":["import { UiChip, UiMemoryStick } from \"../../icons\";\nimport { formatBytes } from \"../../lib/format\";\nimport { ProgressBars, type ProgressBarsUnit } from \"../ProgressBars\";\nimport { formatCpuPercent } from \"./process-tree\";\nimport type { ProcessNodeRow } from \"./types\";\n\nconst GiB = 1024 ** 3;\n\n/** One bar per core (100% CPU), captioned as a CPU %. */\nconst CPU_UNIT: ProgressBarsUnit = { perBar: 100, label: \"\", barLabel: \"core\", format: (cores) => formatCpuPercent(cores * 100) };\n\n/** One bar per GB of RSS, captioned in the readable byte size. */\nconst RSS_UNIT: ProgressBarsUnit = { perBar: GiB, label: \"\", barLabel: \"GB\", format: (gb) => formatBytes(gb * GiB) };\n\nexport function ProcessUsageBars({ row, memoryPercent }: { row: ProcessNodeRow; memoryPercent: number | undefined }) {\n return <div className=\"flex shrink-0 items-center gap-3\">\n <ProgressBars variant=\"cell\" orientation=\"vertical\" showLabel={false} icon={UiChip} unit={CPU_UNIT}\n title={`CPU for pid ${row.pid}`} usage={row.cpuPercent ?? undefined}\n hoverFooter={`Peak ${formatCpuPercent(row.peakCpuPercent)} · one bar per core`} />\n <ProgressBars variant=\"cell\" orientation=\"vertical\" showLabel={false} icon={UiMemoryStick} unit={RSS_UNIT}\n title={`RAM for pid ${row.pid}`} usage={row.rssBytes}\n hoverFooter={`Peak ${formatBytes(row.peakRssBytes)}${memoryPercent === undefined ? \"\" : ` · ${memoryPercent.toFixed(1)}% of host RAM`} · one bar per GB`} />\n </div>;\n}\n"],"mappings":";;;;;;;AAMA,IAAM,MAAM,QAAQ;;AAGpB,IAAM,WAA6B;CAAE,QAAQ;CAAK,OAAO;CAAI,UAAU;CAAQ,SAAS,UAAUA,qBAAAA,iBAAiB,QAAQ,GAAG;AAAE;;AAGhI,IAAM,WAA6B;CAAE,QAAQ;CAAK,OAAO;CAAI,UAAU;CAAM,SAAS,OAAOC,eAAAA,YAAY,KAAK,GAAG;AAAE;AAEnH,SAAgB,iBAAiB,EAAE,KAAK,iBAA6E;CACnH,OAAO,iBAAA,GAAA,kBAAA,KAAA,CAAC,OAAD;EAAK,WAAU;EAAf,UAAA,CACL,iBAAA,GAAA,kBAAA,IAAA,CAACC,qBAAAA,cAAD;GAAc,SAAQ;GAAO,aAAY;GAAW,WAAW;GAAO,MAAMC,eAAAA;GAAQ,MAAM;GACxF,OAAO,eAAe,IAAI;GAAO,OAAO,IAAI,cAAc,KAAA;GAC1D,aAAa,QAAQH,qBAAAA,iBAAiB,IAAI,cAAc,EAAE;EAAuB,CAAA,GACnF,iBAAA,GAAA,kBAAA,IAAA,CAACE,qBAAAA,cAAD;GAAc,SAAQ;GAAO,aAAY;GAAW,WAAW;GAAO,MAAME,sBAAAA;GAAe,MAAM;GAC/F,OAAO,eAAe,IAAI;GAAO,OAAO,IAAI;GAC5C,aAAa,QAAQH,eAAAA,YAAY,IAAI,YAAY,IAAI,kBAAkB,KAAA,IAAY,KAAK,MAAM,cAAc,QAAQ,CAAC,EAAE,eAAe;EAAqB,CAAA,CAC1J;;AACP"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProcessUsageBars.d.ts","sourceRoot":"","sources":["../../../src/data/traces/ProcessUsageBars.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ProcessUsageBars.d.ts","sourceRoot":"","sources":["../../../src/data/traces/ProcessUsageBars.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAU9C,wBAAgB,gBAAgB,CAAC,EAAE,GAAG,EAAE,aAAa,EAAE,EAAE;IAAE,GAAG,EAAE,cAAc,CAAC;IAAC,aAAa,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,+BASlH"}
|
|
@@ -1,50 +1,46 @@
|
|
|
1
|
+
import { UiChip } from "../../icons/components/UiChip.js";
|
|
2
|
+
import { UiMemoryStick } from "../../icons/components/UiMemoryStick.js";
|
|
1
3
|
import { formatBytes } from "../../lib/format.js";
|
|
2
|
-
import {
|
|
4
|
+
import { ProgressBars } from "../ProgressBars.js";
|
|
3
5
|
import { formatCpuPercent } from "./process-tree.js";
|
|
4
6
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
7
|
// src/data/traces/ProcessUsageBars.tsx
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}) : /* @__PURE__ */ jsx(ProgressBar, {
|
|
22
|
-
label,
|
|
23
|
-
total: 100,
|
|
24
|
-
height: "h-1",
|
|
25
|
-
segments: [{
|
|
26
|
-
count: Math.max(0, Math.min(100, percent)),
|
|
27
|
-
color: "bg-primary",
|
|
28
|
-
label: value
|
|
29
|
-
}]
|
|
30
|
-
})]
|
|
31
|
-
});
|
|
32
|
-
}
|
|
8
|
+
var GiB = 1024 ** 3;
|
|
9
|
+
/** One bar per core (100% CPU), captioned as a CPU %. */
|
|
10
|
+
var CPU_UNIT = {
|
|
11
|
+
perBar: 100,
|
|
12
|
+
label: "",
|
|
13
|
+
barLabel: "core",
|
|
14
|
+
format: (cores) => formatCpuPercent(cores * 100)
|
|
15
|
+
};
|
|
16
|
+
/** One bar per GB of RSS, captioned in the readable byte size. */
|
|
17
|
+
var RSS_UNIT = {
|
|
18
|
+
perBar: GiB,
|
|
19
|
+
label: "",
|
|
20
|
+
barLabel: "GB",
|
|
21
|
+
format: (gb) => formatBytes(gb * GiB)
|
|
22
|
+
};
|
|
33
23
|
function ProcessUsageBars({ row, memoryPercent }) {
|
|
34
24
|
return /* @__PURE__ */ jsxs("div", {
|
|
35
|
-
className: "flex shrink-0 gap-3",
|
|
36
|
-
children: [/* @__PURE__ */ jsx(
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
25
|
+
className: "flex shrink-0 items-center gap-3",
|
|
26
|
+
children: [/* @__PURE__ */ jsx(ProgressBars, {
|
|
27
|
+
variant: "cell",
|
|
28
|
+
orientation: "vertical",
|
|
29
|
+
showLabel: false,
|
|
30
|
+
icon: UiChip,
|
|
31
|
+
unit: CPU_UNIT,
|
|
32
|
+
title: `CPU for pid ${row.pid}`,
|
|
33
|
+
usage: row.cpuPercent ?? void 0,
|
|
34
|
+
hoverFooter: `Peak ${formatCpuPercent(row.peakCpuPercent)} · one bar per core`
|
|
35
|
+
}), /* @__PURE__ */ jsx(ProgressBars, {
|
|
36
|
+
variant: "cell",
|
|
37
|
+
orientation: "vertical",
|
|
38
|
+
showLabel: false,
|
|
39
|
+
icon: UiMemoryStick,
|
|
40
|
+
unit: RSS_UNIT,
|
|
41
|
+
title: `RAM for pid ${row.pid}`,
|
|
42
|
+
usage: row.rssBytes,
|
|
43
|
+
hoverFooter: `Peak ${formatBytes(row.peakRssBytes)}${memoryPercent === void 0 ? "" : ` · ${memoryPercent.toFixed(1)}% of host RAM`} · one bar per GB`
|
|
48
44
|
})]
|
|
49
45
|
});
|
|
50
46
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProcessUsageBars.js","names":[],"sources":["../../../src/data/traces/ProcessUsageBars.tsx"],"sourcesContent":["import { formatBytes } from \"../../lib/format\";\nimport {
|
|
1
|
+
{"version":3,"file":"ProcessUsageBars.js","names":[],"sources":["../../../src/data/traces/ProcessUsageBars.tsx"],"sourcesContent":["import { UiChip, UiMemoryStick } from \"../../icons\";\nimport { formatBytes } from \"../../lib/format\";\nimport { ProgressBars, type ProgressBarsUnit } from \"../ProgressBars\";\nimport { formatCpuPercent } from \"./process-tree\";\nimport type { ProcessNodeRow } from \"./types\";\n\nconst GiB = 1024 ** 3;\n\n/** One bar per core (100% CPU), captioned as a CPU %. */\nconst CPU_UNIT: ProgressBarsUnit = { perBar: 100, label: \"\", barLabel: \"core\", format: (cores) => formatCpuPercent(cores * 100) };\n\n/** One bar per GB of RSS, captioned in the readable byte size. */\nconst RSS_UNIT: ProgressBarsUnit = { perBar: GiB, label: \"\", barLabel: \"GB\", format: (gb) => formatBytes(gb * GiB) };\n\nexport function ProcessUsageBars({ row, memoryPercent }: { row: ProcessNodeRow; memoryPercent: number | undefined }) {\n return <div className=\"flex shrink-0 items-center gap-3\">\n <ProgressBars variant=\"cell\" orientation=\"vertical\" showLabel={false} icon={UiChip} unit={CPU_UNIT}\n title={`CPU for pid ${row.pid}`} usage={row.cpuPercent ?? undefined}\n hoverFooter={`Peak ${formatCpuPercent(row.peakCpuPercent)} · one bar per core`} />\n <ProgressBars variant=\"cell\" orientation=\"vertical\" showLabel={false} icon={UiMemoryStick} unit={RSS_UNIT}\n title={`RAM for pid ${row.pid}`} usage={row.rssBytes}\n hoverFooter={`Peak ${formatBytes(row.peakRssBytes)}${memoryPercent === undefined ? \"\" : ` · ${memoryPercent.toFixed(1)}% of host RAM`} · one bar per GB`} />\n </div>;\n}\n"],"mappings":";;;;;;;AAMA,IAAM,MAAM,QAAQ;;AAGpB,IAAM,WAA6B;CAAE,QAAQ;CAAK,OAAO;CAAI,UAAU;CAAQ,SAAS,UAAU,iBAAiB,QAAQ,GAAG;AAAE;;AAGhI,IAAM,WAA6B;CAAE,QAAQ;CAAK,OAAO;CAAI,UAAU;CAAM,SAAS,OAAO,YAAY,KAAK,GAAG;AAAE;AAEnH,SAAgB,iBAAiB,EAAE,KAAK,iBAA6E;CACnH,OAAO,qBAAC,OAAD;EAAK,WAAU;EAAf,UAAA,CACL,oBAAC,cAAD;GAAc,SAAQ;GAAO,aAAY;GAAW,WAAW;GAAO,MAAM;GAAQ,MAAM;GACxF,OAAO,eAAe,IAAI;GAAO,OAAO,IAAI,cAAc,KAAA;GAC1D,aAAa,QAAQ,iBAAiB,IAAI,cAAc,EAAE;EAAuB,CAAA,GACnF,oBAAC,cAAD;GAAc,SAAQ;GAAO,aAAY;GAAW,WAAW;GAAO,MAAM;GAAe,MAAM;GAC/F,OAAO,eAAe,IAAI;GAAO,OAAO,IAAI;GAC5C,aAAa,QAAQ,YAAY,IAAI,YAAY,IAAI,kBAAkB,KAAA,IAAY,KAAK,MAAM,cAAc,QAAQ,CAAC,EAAE,eAAe;EAAqB,CAAA,CAC1J;;AACP"}
|
|
@@ -90,6 +90,40 @@ function processSeries(samples, key) {
|
|
|
90
90
|
rss: own.map((sample) => sample.rssBytes)
|
|
91
91
|
};
|
|
92
92
|
}
|
|
93
|
+
/**
|
|
94
|
+
* The combined CPU % and RSS bytes of a process and all its descendants at
|
|
95
|
+
* each sampling tick (one tick is one sampling round across every process), in
|
|
96
|
+
* tick order, so the peak of a series is the most the subtree used at once. A
|
|
97
|
+
* tick's CPU sums the known readings and is left out when none is known.
|
|
98
|
+
* The latest tick retains its CPU and RSS totals even when CPU is unknown.
|
|
99
|
+
*/
|
|
100
|
+
function subtreeSeries(rows, samples, key) {
|
|
101
|
+
const keys = /* @__PURE__ */ new Set([key]);
|
|
102
|
+
for (let grew = true; grew;) {
|
|
103
|
+
grew = false;
|
|
104
|
+
for (const row of rows) if (row.parentKey && keys.has(row.parentKey) && !keys.has(row.key)) {
|
|
105
|
+
keys.add(row.key);
|
|
106
|
+
grew = true;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
const ticks = /* @__PURE__ */ new Map();
|
|
110
|
+
for (const sample of samples) {
|
|
111
|
+
if (!keys.has(sample.key)) continue;
|
|
112
|
+
const total = ticks.get(sample.tick) ?? {
|
|
113
|
+
cpu: null,
|
|
114
|
+
rss: 0
|
|
115
|
+
};
|
|
116
|
+
total.rss += sample.rssBytes;
|
|
117
|
+
if (sample.cpuPercent != null) total.cpu = (total.cpu ?? 0) + sample.cpuPercent;
|
|
118
|
+
ticks.set(sample.tick, total);
|
|
119
|
+
}
|
|
120
|
+
const ordered = [...ticks].sort(([a], [b]) => a - b).map(([, total]) => total);
|
|
121
|
+
return {
|
|
122
|
+
cpu: ordered.flatMap((total) => total.cpu === null ? [] : [total.cpu]),
|
|
123
|
+
rss: ordered.map((total) => total.rss),
|
|
124
|
+
latest: ordered.at(-1)
|
|
125
|
+
};
|
|
126
|
+
}
|
|
93
127
|
/** SVG polyline points for `values` in a `width` x `height` box, zero at the bottom and the maximum at the top. */
|
|
94
128
|
function sparklinePoints(values, width, height) {
|
|
95
129
|
if (values.length < 2) return void 0;
|
|
@@ -110,5 +144,6 @@ exports.processLifetimeMs = processLifetimeMs;
|
|
|
110
144
|
exports.processSeries = processSeries;
|
|
111
145
|
exports.pruneExitedProcesses = pruneExitedProcesses;
|
|
112
146
|
exports.sparklinePoints = sparklinePoints;
|
|
147
|
+
exports.subtreeSeries = subtreeSeries;
|
|
113
148
|
|
|
114
149
|
//# sourceMappingURL=process-tree.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"process-tree.cjs","names":[],"sources":["../../../src/data/traces/process-tree.ts"],"sourcesContent":["import type { ProcessNodeRow, ProcessSampleRow } from \"./types\";\n\nexport type ProcessTreeNode = {\n row: ProcessNodeRow;\n children: ProcessTreeNode[];\n /** The process has exited: by its status, or because an exit time was recorded. */\n exited: boolean;\n};\n\nconst byStart = (a: ProcessTreeNode, b: ProcessTreeNode) =>\n Date.parse(a.row.startedAt) - Date.parse(b.row.startedAt) || a.row.pid - b.row.pid;\n\n/**\n * Builds the forest a `process_tree` stream describes: each row under its\n * `parentKey`. A row whose parent was never recorded (the capture began below\n * it) becomes a root. The stream holds each process once, so a repeated key or a\n * parent cycle is a corrupt capture and throws.\n */\nexport function buildProcessForest(rows: ProcessNodeRow[]): ProcessTreeNode[] {\n const nodes = new Map<string, ProcessTreeNode>();\n for (const row of rows) {\n if (nodes.has(row.key)) throw new Error(`process tree key \"${row.key}\" appears twice`);\n nodes.set(row.key, { row, children: [], exited: isProcessExited(row) });\n }\n\n const roots: ProcessTreeNode[] = [];\n for (const node of nodes.values()) {\n const parent = node.row.parentKey ? nodes.get(node.row.parentKey) : undefined;\n (parent ? parent.children : roots).push(node);\n }\n\n roots.sort((a, b) => Number(Boolean(b.row.isRoot)) - Number(Boolean(a.row.isRoot)) || byStart(a, b));\n const reached = flattenForest(roots);\n if (reached.length !== nodes.size) {\n const lost = [...nodes.keys()].filter((key) => !reached.some((node) => node.row.key === key));\n throw new Error(`process tree has a parent cycle among keys ${lost.map((key) => `\"${key}\"`).join(\", \")}`);\n }\n for (const node of nodes.values()) node.children.sort(byStart);\n return roots;\n}\n\n/**\n * Drops exited processes from a forest, keeping an exited process only while it\n * still has a live descendant to hang off. Returns new nodes; the input is not\n * modified.\n */\nexport function pruneExitedProcesses(roots: ProcessTreeNode[]): ProcessTreeNode[] {\n return roots.flatMap((node) => {\n const children = pruneExitedProcesses(node.children);\n return node.exited && children.length === 0 ? [] : [{ ...node, children }];\n });\n}\n\n/** How long the process lived: to its exit, else to the last time it was seen. */\nexport function processLifetimeMs(row: ProcessNodeRow): number {\n return Date.parse(row.exitedAt ?? row.lastSeenAt) - Date.parse(row.startedAt);\n}\n\n/** A trace timestamp as local `YYYY-MM-DD HH:MM:SS`; text that is not a date is returned unchanged. */\nexport function formatProcessTimestamp(iso: string): string {\n const date = new Date(iso);\n if (Number.isNaN(date.getTime())) return iso;\n const pad = (n: number) => String(n).padStart(2, \"0\");\n return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}`;\n}\n\n/** The process has exited: by its status, or because an exit time was recorded. */\nexport function isProcessExited(row: ProcessNodeRow): boolean {\n return row.status === \"exited\" || Boolean(row.exitedAt);\n}\n\n/** The forest depth-first, parents before children. */\nexport function flattenForest(roots: ProcessTreeNode[]): ProcessTreeNode[] {\n const flat: ProcessTreeNode[] = [];\n const visit = (node: ProcessTreeNode) => {\n flat.push(node);\n node.children.forEach(visit);\n };\n roots.forEach(visit);\n return flat;\n}\n\n/** A CPU % for display, \"—\" while it is still unknown. */\nexport function formatCpuPercent(value: number | null | undefined): string {\n return value == null ? \"—\" : `${value.toFixed(1)}%`;\n}\n\nfunction knownCpu(samples: ProcessSampleRow[]): number[] {\n return samples.flatMap((sample) => (sample.cpuPercent == null ? [] : [sample.cpuPercent]));\n}\n\n/** Each process's known CPU % over its samples, in tick order. */\nexport function cpuSeriesByKey(samples: ProcessSampleRow[]): Map<string, number[]> {\n const byKey = new Map<string, ProcessSampleRow[]>();\n for (const sample of samples) byKey.set(sample.key, [...(byKey.get(sample.key) ?? []), sample]);\n return new Map([...byKey].map(([key, list]) => [key, knownCpu(list.sort((a, b) => a.tick - b.tick))]));\n}\n\n/** One process's known CPU % and RSS bytes over its samples, in tick order. */\nexport function processSeries(samples: ProcessSampleRow[], key: string): { cpu: number[]; rss: number[] } {\n const own = samples.filter((sample) => sample.key === key).sort((a, b) => a.tick - b.tick);\n return { cpu: knownCpu(own), rss: own.map((sample) => sample.rssBytes) };\n}\n\n/** SVG polyline points for `values` in a `width` x `height` box, zero at the bottom and the maximum at the top. */\nexport function sparklinePoints(values: number[], width: number, height: number): string | undefined {\n if (values.length < 2) return undefined;\n const max = Math.max(...values);\n return values\n .map((value, index) => {\n const x = (index / (values.length - 1)) * width;\n const y = max === 0 ? height : height - (value / max) * height;\n return `${x.toFixed(1)},${y.toFixed(1)}`;\n })\n .join(\" \");\n}\n"],"mappings":";AASA,IAAM,WAAW,GAAoB,MACnC,KAAK,MAAM,EAAE,IAAI,SAAS,IAAI,KAAK,MAAM,EAAE,IAAI,SAAS,KAAK,EAAE,IAAI,MAAM,EAAE,IAAI;;;;;;;AAQjF,SAAgB,mBAAmB,MAA2C;CAC5E,MAAM,wBAAQ,IAAI,IAA6B;CAC/C,KAAK,MAAM,OAAO,MAAM;EACtB,IAAI,MAAM,IAAI,IAAI,GAAG,GAAG,MAAM,IAAI,MAAM,qBAAqB,IAAI,IAAI,gBAAgB;EACrF,MAAM,IAAI,IAAI,KAAK;GAAE;GAAK,UAAU,CAAC;GAAG,QAAQ,gBAAgB,GAAG;EAAE,CAAC;CACxE;CAEA,MAAM,QAA2B,CAAC;CAClC,KAAK,MAAM,QAAQ,MAAM,OAAO,GAAG;EACjC,MAAM,SAAS,KAAK,IAAI,YAAY,MAAM,IAAI,KAAK,IAAI,SAAS,IAAI,KAAA;EACpE,CAAC,SAAS,OAAO,WAAW,MAAA,CAAO,KAAK,IAAI;CAC9C;CAEA,MAAM,MAAM,GAAG,MAAM,OAAO,QAAQ,EAAE,IAAI,MAAM,CAAC,IAAI,OAAO,QAAQ,EAAE,IAAI,MAAM,CAAC,KAAK,QAAQ,GAAG,CAAC,CAAC;CACnG,MAAM,UAAU,cAAc,KAAK;CACnC,IAAI,QAAQ,WAAW,MAAM,MAAM;EACjC,MAAM,OAAO,CAAC,GAAG,MAAM,KAAK,CAAC,CAAC,CAAC,QAAQ,QAAQ,CAAC,QAAQ,MAAM,SAAS,KAAK,IAA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src/data/traces/process-tree.ts"],"sourcesContent":["import type { ProcessNodeRow, ProcessSampleRow } from \"./types\";\n\nexport type ProcessTreeNode = {\n row: ProcessNodeRow;\n children: ProcessTreeNode[];\n /** The process has exited: by its status, or because an exit time was recorded. */\n exited: boolean;\n};\n\nconst byStart = (a: ProcessTreeNode, b: ProcessTreeNode) =>\n Date.parse(a.row.startedAt) - Date.parse(b.row.startedAt) || a.row.pid - b.row.pid;\n\n/**\n * Builds the forest a `process_tree` stream describes: each row under its\n * `parentKey`. A row whose parent was never recorded (the capture began below\n * it) becomes a root. The stream holds each process once, so a repeated key or a\n * parent cycle is a corrupt capture and throws.\n */\nexport function buildProcessForest(rows: ProcessNodeRow[]): ProcessTreeNode[] {\n const nodes = new Map<string, ProcessTreeNode>();\n for (const row of rows) {\n if (nodes.has(row.key)) throw new Error(`process tree key \"${row.key}\" appears twice`);\n nodes.set(row.key, { row, children: [], exited: isProcessExited(row) });\n }\n\n const roots: ProcessTreeNode[] = [];\n for (const node of nodes.values()) {\n const parent = node.row.parentKey ? nodes.get(node.row.parentKey) : undefined;\n (parent ? parent.children : roots).push(node);\n }\n\n roots.sort((a, b) => Number(Boolean(b.row.isRoot)) - Number(Boolean(a.row.isRoot)) || byStart(a, b));\n const reached = flattenForest(roots);\n if (reached.length !== nodes.size) {\n const lost = [...nodes.keys()].filter((key) => !reached.some((node) => node.row.key === key));\n throw new Error(`process tree has a parent cycle among keys ${lost.map((key) => `\"${key}\"`).join(\", \")}`);\n }\n for (const node of nodes.values()) node.children.sort(byStart);\n return roots;\n}\n\n/**\n * Drops exited processes from a forest, keeping an exited process only while it\n * still has a live descendant to hang off. Returns new nodes; the input is not\n * modified.\n */\nexport function pruneExitedProcesses(roots: ProcessTreeNode[]): ProcessTreeNode[] {\n return roots.flatMap((node) => {\n const children = pruneExitedProcesses(node.children);\n return node.exited && children.length === 0 ? [] : [{ ...node, children }];\n });\n}\n\n/** How long the process lived: to its exit, else to the last time it was seen. */\nexport function processLifetimeMs(row: ProcessNodeRow): number {\n return Date.parse(row.exitedAt ?? row.lastSeenAt) - Date.parse(row.startedAt);\n}\n\n/** A trace timestamp as local `YYYY-MM-DD HH:MM:SS`; text that is not a date is returned unchanged. */\nexport function formatProcessTimestamp(iso: string): string {\n const date = new Date(iso);\n if (Number.isNaN(date.getTime())) return iso;\n const pad = (n: number) => String(n).padStart(2, \"0\");\n return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}`;\n}\n\n/** The process has exited: by its status, or because an exit time was recorded. */\nexport function isProcessExited(row: ProcessNodeRow): boolean {\n return row.status === \"exited\" || Boolean(row.exitedAt);\n}\n\n/** The forest depth-first, parents before children. */\nexport function flattenForest(roots: ProcessTreeNode[]): ProcessTreeNode[] {\n const flat: ProcessTreeNode[] = [];\n const visit = (node: ProcessTreeNode) => {\n flat.push(node);\n node.children.forEach(visit);\n };\n roots.forEach(visit);\n return flat;\n}\n\n/** A CPU % for display, \"—\" while it is still unknown. */\nexport function formatCpuPercent(value: number | null | undefined): string {\n return value == null ? \"—\" : `${value.toFixed(1)}%`;\n}\n\nfunction knownCpu(samples: ProcessSampleRow[]): number[] {\n return samples.flatMap((sample) => (sample.cpuPercent == null ? [] : [sample.cpuPercent]));\n}\n\n/** Each process's known CPU % over its samples, in tick order. */\nexport function cpuSeriesByKey(samples: ProcessSampleRow[]): Map<string, number[]> {\n const byKey = new Map<string, ProcessSampleRow[]>();\n for (const sample of samples) byKey.set(sample.key, [...(byKey.get(sample.key) ?? []), sample]);\n return new Map([...byKey].map(([key, list]) => [key, knownCpu(list.sort((a, b) => a.tick - b.tick))]));\n}\n\n/** One process's known CPU % and RSS bytes over its samples, in tick order. */\nexport function processSeries(samples: ProcessSampleRow[], key: string): { cpu: number[]; rss: number[] } {\n const own = samples.filter((sample) => sample.key === key).sort((a, b) => a.tick - b.tick);\n return { cpu: knownCpu(own), rss: own.map((sample) => sample.rssBytes) };\n}\n\n/**\n * The combined CPU % and RSS bytes of a process and all its descendants at\n * each sampling tick (one tick is one sampling round across every process), in\n * tick order, so the peak of a series is the most the subtree used at once. A\n * tick's CPU sums the known readings and is left out when none is known.\n * The latest tick retains its CPU and RSS totals even when CPU is unknown.\n */\nexport function subtreeSeries(rows: ProcessNodeRow[], samples: ProcessSampleRow[], key: string): {\n cpu: number[];\n rss: number[];\n latest: { cpu: number | null; rss: number } | undefined;\n} {\n const keys = new Set([key]);\n for (let grew = true; grew; ) {\n grew = false;\n for (const row of rows) {\n if (row.parentKey && keys.has(row.parentKey) && !keys.has(row.key)) {\n keys.add(row.key);\n grew = true;\n }\n }\n }\n const ticks = new Map<number, { cpu: number | null; rss: number }>();\n for (const sample of samples) {\n if (!keys.has(sample.key)) continue;\n const total = ticks.get(sample.tick) ?? { cpu: null, rss: 0 };\n total.rss += sample.rssBytes;\n if (sample.cpuPercent != null) total.cpu = (total.cpu ?? 0) + sample.cpuPercent;\n ticks.set(sample.tick, total);\n }\n const ordered = [...ticks].sort(([a], [b]) => a - b).map(([, total]) => total);\n return {\n cpu: ordered.flatMap((total) => (total.cpu === null ? [] : [total.cpu])),\n rss: ordered.map((total) => total.rss),\n latest: ordered.at(-1),\n };\n}\n\n/** SVG polyline points for `values` in a `width` x `height` box, zero at the bottom and the maximum at the top. */\nexport function sparklinePoints(values: number[], width: number, height: number): string | undefined {\n if (values.length < 2) return undefined;\n const max = Math.max(...values);\n return values\n .map((value, index) => {\n const x = (index / (values.length - 1)) * width;\n const y = max === 0 ? height : height - (value / max) * height;\n return `${x.toFixed(1)},${y.toFixed(1)}`;\n })\n .join(\" \");\n}\n"],"mappings":";AASA,IAAM,WAAW,GAAoB,MACnC,KAAK,MAAM,EAAE,IAAI,SAAS,IAAI,KAAK,MAAM,EAAE,IAAI,SAAS,KAAK,EAAE,IAAI,MAAM,EAAE,IAAI;;;;;;;AAQjF,SAAgB,mBAAmB,MAA2C;CAC5E,MAAM,wBAAQ,IAAI,I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AAG;EACrC,QAAQ,QAAQ,GAAG,EAAE;CACvB;AACF;;AAGA,SAAgB,gBAAgB,QAAkB,OAAe,QAAoC;CACnG,IAAI,OAAO,SAAS,GAAG,OAAO,KAAA;CAC9B,MAAM,MAAM,KAAK,IAAI,GAAG,MAAM;CAC9B,OAAO,OACJ,KAAK,OAAO,UAAU;EACrB,MAAM,IAAK,SAAS,OAAO,SAAS,KAAM;EAC1C,MAAM,IAAI,QAAQ,IAAI,SAAS,SAAU,QAAQ,MAAO;EACxD,OAAO,GAAG,EAAE,QAAQ,CAAC,EAAE,GAAG,EAAE,QAAQ,CAAC;CACvC,CAAC,CAAC,CACD,KAAK,GAAG;AACb"}
|
|
@@ -35,6 +35,21 @@ export declare function processSeries(samples: ProcessSampleRow[], key: string):
|
|
|
35
35
|
cpu: number[];
|
|
36
36
|
rss: number[];
|
|
37
37
|
};
|
|
38
|
+
/**
|
|
39
|
+
* The combined CPU % and RSS bytes of a process and all its descendants at
|
|
40
|
+
* each sampling tick (one tick is one sampling round across every process), in
|
|
41
|
+
* tick order, so the peak of a series is the most the subtree used at once. A
|
|
42
|
+
* tick's CPU sums the known readings and is left out when none is known.
|
|
43
|
+
* The latest tick retains its CPU and RSS totals even when CPU is unknown.
|
|
44
|
+
*/
|
|
45
|
+
export declare function subtreeSeries(rows: ProcessNodeRow[], samples: ProcessSampleRow[], key: string): {
|
|
46
|
+
cpu: number[];
|
|
47
|
+
rss: number[];
|
|
48
|
+
latest: {
|
|
49
|
+
cpu: number | null;
|
|
50
|
+
rss: number;
|
|
51
|
+
} | undefined;
|
|
52
|
+
};
|
|
38
53
|
/** SVG polyline points for `values` in a `width` x `height` box, zero at the bottom and the maximum at the top. */
|
|
39
54
|
export declare function sparklinePoints(values: number[], width: number, height: number): string | undefined;
|
|
40
55
|
//# sourceMappingURL=process-tree.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"process-tree.d.ts","sourceRoot":"","sources":["../../../src/data/traces/process-tree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AAE,GAAG,EAAE,MAAM,EAAE,CAAC;IAAC,GAAG,EAAE,MAAM,EAAE,CAAA;CAAE,CAGxG;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,cAAc,EAAE,EAAE,OAAO,EAAE,gBAAgB,EAAE,EAAE,GAAG,EAAE,MAAM,GAAG;IAC/F,GAAG,EAAE,MAAM,EAAE,CAAC;IACd,GAAG,EAAE,MAAM,EAAE,CAAC;IACd,MAAM,EAAE;QAAE,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS,CAAC;CACzD,CAyBA;AAED,mHAAmH;AACnH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAUnG"}
|
|
@@ -90,6 +90,40 @@ function processSeries(samples, key) {
|
|
|
90
90
|
rss: own.map((sample) => sample.rssBytes)
|
|
91
91
|
};
|
|
92
92
|
}
|
|
93
|
+
/**
|
|
94
|
+
* The combined CPU % and RSS bytes of a process and all its descendants at
|
|
95
|
+
* each sampling tick (one tick is one sampling round across every process), in
|
|
96
|
+
* tick order, so the peak of a series is the most the subtree used at once. A
|
|
97
|
+
* tick's CPU sums the known readings and is left out when none is known.
|
|
98
|
+
* The latest tick retains its CPU and RSS totals even when CPU is unknown.
|
|
99
|
+
*/
|
|
100
|
+
function subtreeSeries(rows, samples, key) {
|
|
101
|
+
const keys = /* @__PURE__ */ new Set([key]);
|
|
102
|
+
for (let grew = true; grew;) {
|
|
103
|
+
grew = false;
|
|
104
|
+
for (const row of rows) if (row.parentKey && keys.has(row.parentKey) && !keys.has(row.key)) {
|
|
105
|
+
keys.add(row.key);
|
|
106
|
+
grew = true;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
const ticks = /* @__PURE__ */ new Map();
|
|
110
|
+
for (const sample of samples) {
|
|
111
|
+
if (!keys.has(sample.key)) continue;
|
|
112
|
+
const total = ticks.get(sample.tick) ?? {
|
|
113
|
+
cpu: null,
|
|
114
|
+
rss: 0
|
|
115
|
+
};
|
|
116
|
+
total.rss += sample.rssBytes;
|
|
117
|
+
if (sample.cpuPercent != null) total.cpu = (total.cpu ?? 0) + sample.cpuPercent;
|
|
118
|
+
ticks.set(sample.tick, total);
|
|
119
|
+
}
|
|
120
|
+
const ordered = [...ticks].sort(([a], [b]) => a - b).map(([, total]) => total);
|
|
121
|
+
return {
|
|
122
|
+
cpu: ordered.flatMap((total) => total.cpu === null ? [] : [total.cpu]),
|
|
123
|
+
rss: ordered.map((total) => total.rss),
|
|
124
|
+
latest: ordered.at(-1)
|
|
125
|
+
};
|
|
126
|
+
}
|
|
93
127
|
/** SVG polyline points for `values` in a `width` x `height` box, zero at the bottom and the maximum at the top. */
|
|
94
128
|
function sparklinePoints(values, width, height) {
|
|
95
129
|
if (values.length < 2) return void 0;
|
|
@@ -100,6 +134,6 @@ function sparklinePoints(values, width, height) {
|
|
|
100
134
|
return `${x.toFixed(1)},${y.toFixed(1)}`;
|
|
101
135
|
}).join(" ");
|
|
102
136
|
}
|
|
103
|
-
export { buildProcessForest, cpuSeriesByKey, flattenForest, formatCpuPercent, formatProcessTimestamp, isProcessExited, processLifetimeMs, processSeries, pruneExitedProcesses, sparklinePoints };
|
|
137
|
+
export { buildProcessForest, cpuSeriesByKey, flattenForest, formatCpuPercent, formatProcessTimestamp, isProcessExited, processLifetimeMs, processSeries, pruneExitedProcesses, sparklinePoints, subtreeSeries };
|
|
104
138
|
|
|
105
139
|
//# sourceMappingURL=process-tree.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"process-tree.js","names":[],"sources":["../../../src/data/traces/process-tree.ts"],"sourcesContent":["import type { ProcessNodeRow, ProcessSampleRow } from \"./types\";\n\nexport type ProcessTreeNode = {\n row: ProcessNodeRow;\n children: ProcessTreeNode[];\n /** The process has exited: by its status, or because an exit time was recorded. */\n exited: boolean;\n};\n\nconst byStart = (a: ProcessTreeNode, b: ProcessTreeNode) =>\n Date.parse(a.row.startedAt) - Date.parse(b.row.startedAt) || a.row.pid - b.row.pid;\n\n/**\n * Builds the forest a `process_tree` stream describes: each row under its\n * `parentKey`. A row whose parent was never recorded (the capture began below\n * it) becomes a root. The stream holds each process once, so a repeated key or a\n * parent cycle is a corrupt capture and throws.\n */\nexport function buildProcessForest(rows: ProcessNodeRow[]): ProcessTreeNode[] {\n const nodes = new Map<string, ProcessTreeNode>();\n for (const row of rows) {\n if (nodes.has(row.key)) throw new Error(`process tree key \"${row.key}\" appears twice`);\n nodes.set(row.key, { row, children: [], exited: isProcessExited(row) });\n }\n\n const roots: ProcessTreeNode[] = [];\n for (const node of nodes.values()) {\n const parent = node.row.parentKey ? nodes.get(node.row.parentKey) : undefined;\n (parent ? parent.children : roots).push(node);\n }\n\n roots.sort((a, b) => Number(Boolean(b.row.isRoot)) - Number(Boolean(a.row.isRoot)) || byStart(a, b));\n const reached = flattenForest(roots);\n if (reached.length !== nodes.size) {\n const lost = [...nodes.keys()].filter((key) => !reached.some((node) => node.row.key === key));\n throw new Error(`process tree has a parent cycle among keys ${lost.map((key) => `\"${key}\"`).join(\", \")}`);\n }\n for (const node of nodes.values()) node.children.sort(byStart);\n return roots;\n}\n\n/**\n * Drops exited processes from a forest, keeping an exited process only while it\n * still has a live descendant to hang off. Returns new nodes; the input is not\n * modified.\n */\nexport function pruneExitedProcesses(roots: ProcessTreeNode[]): ProcessTreeNode[] {\n return roots.flatMap((node) => {\n const children = pruneExitedProcesses(node.children);\n return node.exited && children.length === 0 ? [] : [{ ...node, children }];\n });\n}\n\n/** How long the process lived: to its exit, else to the last time it was seen. */\nexport function processLifetimeMs(row: ProcessNodeRow): number {\n return Date.parse(row.exitedAt ?? row.lastSeenAt) - Date.parse(row.startedAt);\n}\n\n/** A trace timestamp as local `YYYY-MM-DD HH:MM:SS`; text that is not a date is returned unchanged. */\nexport function formatProcessTimestamp(iso: string): string {\n const date = new Date(iso);\n if (Number.isNaN(date.getTime())) return iso;\n const pad = (n: number) => String(n).padStart(2, \"0\");\n return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}`;\n}\n\n/** The process has exited: by its status, or because an exit time was recorded. */\nexport function isProcessExited(row: ProcessNodeRow): boolean {\n return row.status === \"exited\" || Boolean(row.exitedAt);\n}\n\n/** The forest depth-first, parents before children. */\nexport function flattenForest(roots: ProcessTreeNode[]): ProcessTreeNode[] {\n const flat: ProcessTreeNode[] = [];\n const visit = (node: ProcessTreeNode) => {\n flat.push(node);\n node.children.forEach(visit);\n };\n roots.forEach(visit);\n return flat;\n}\n\n/** A CPU % for display, \"—\" while it is still unknown. */\nexport function formatCpuPercent(value: number | null | undefined): string {\n return value == null ? \"—\" : `${value.toFixed(1)}%`;\n}\n\nfunction knownCpu(samples: ProcessSampleRow[]): number[] {\n return samples.flatMap((sample) => (sample.cpuPercent == null ? [] : [sample.cpuPercent]));\n}\n\n/** Each process's known CPU % over its samples, in tick order. */\nexport function cpuSeriesByKey(samples: ProcessSampleRow[]): Map<string, number[]> {\n const byKey = new Map<string, ProcessSampleRow[]>();\n for (const sample of samples) byKey.set(sample.key, [...(byKey.get(sample.key) ?? []), sample]);\n return new Map([...byKey].map(([key, list]) => [key, knownCpu(list.sort((a, b) => a.tick - b.tick))]));\n}\n\n/** One process's known CPU % and RSS bytes over its samples, in tick order. */\nexport function processSeries(samples: ProcessSampleRow[], key: string): { cpu: number[]; rss: number[] } {\n const own = samples.filter((sample) => sample.key === key).sort((a, b) => a.tick - b.tick);\n return { cpu: knownCpu(own), rss: own.map((sample) => sample.rssBytes) };\n}\n\n/** SVG polyline points for `values` in a `width` x `height` box, zero at the bottom and the maximum at the top. */\nexport function sparklinePoints(values: number[], width: number, height: number): string | undefined {\n if (values.length < 2) return undefined;\n const max = Math.max(...values);\n return values\n .map((value, index) => {\n const x = (index / (values.length - 1)) * width;\n const y = max === 0 ? height : height - (value / max) * height;\n return `${x.toFixed(1)},${y.toFixed(1)}`;\n })\n .join(\" \");\n}\n"],"mappings":";AASA,IAAM,WAAW,GAAoB,MACnC,KAAK,MAAM,EAAE,IAAI,SAAS,IAAI,KAAK,MAAM,EAAE,IAAI,SAAS,KAAK,EAAE,IAAI,MAAM,EAAE,IAAI;;;;;;;AAQjF,SAAgB,mBAAmB,MAA2C;CAC5E,MAAM,wBAAQ,IAAI,IAA6B;CAC/C,KAAK,MAAM,OAAO,MAAM;EACtB,IAAI,MAAM,IAAI,IAAI,GAAG,GAAG,MAAM,IAAI,MAAM,qBAAqB,IAAI,IAAI,gBAAgB;EACrF,MAAM,IAAI,IAAI,KAAK;GAAE;GAAK,UAAU,CAAC;GAAG,QAAQ,gBAAgB,GAAG;EAAE,CAAC;CACxE;CAEA,MAAM,QAA2B,CAAC;CAClC,KAAK,MAAM,QAAQ,MAAM,OAAO,GAAG;EACjC,MAAM,SAAS,KAAK,IAAI,YAAY,MAAM,IAAI,KAAK,IAAI,SAAS,IAAI,KAAA;EACpE,CAAC,SAAS,OAAO,WAAW,MAAA,CAAO,KAAK,IAAI;CAC9C;CAEA,MAAM,MAAM,GAAG,MAAM,OAAO,QAAQ,EAAE,IAAI,MAAM,CAAC,IAAI,OAAO,QAAQ,EAAE,IAAI,MAAM,CAAC,KAAK,QAAQ,GAAG,CAAC,CAAC;CACnG,MAAM,UAAU,cAAc,KAAK;CACnC,IAAI,QAAQ,WAAW,MAAM,MAAM;EACjC,MAAM,OAAO,CAAC,GAAG,MAAM,KAAK,CAAC,CAAC,CAAC,QAAQ,QAAQ,CAAC,QAAQ,MAAM,SAAS,KAAK,IAAI,QAAQ,GAAG,CAAC;EAC5F,MAAM,IAAI,MAAM,8CAA8C,KAAK,KAAK,QAAQ,IAAI,IAAI,EAAE,CAAC,CAAC,KAAK,IAAI,GAAG;CAC1G;CACA,KAAK,MAAM,Q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,OAAO,cAAc,OAAO,CAAC,IAAI,CAAC,OAAO,UAAU,CAAE;AAC3F;;AAGA,SAAgB,eAAe,SAAoD;CACjF,MAAM,wBAAQ,IAAI,IAAgC;CAClD,KAAK,MAAM,UAAU,SAAS,MAAM,IAAI,OAAO,KAAK,CAAC,GAAI,MAAM,IAAI,OAAO,GAAG,KAAK,CAAC,GAAI,MAAM,CAAC;CAC9F,OAAO,IAAI,IAAI,CAAC,GAAG,KAAK,CAAC,CAAC,KAAK,CAAC,KAAK,UAAU,CAAC,KAAK,SAAS,KAAK,MAAM,GAAG,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;AACvG;;AAGA,SAAgB,cAAc,SAA6B,KAA+C;CACxG,MAAM,MAAM,QAAQ,QAAQ,WAAW,OAAO,QAAQ,GAAG,CAAC,CAAC,MAAM,GAAG,MAAM,EAAE,OAAO,EAAE,IAAI;CACzF,OAAO;EAAE,KAAK,SAAS,GAAG;EAAG,KAAK,IAAI,KAAK,WAAW,OAAO,QAAQ;CAAE;AACzE;;AAGA,SAAgB,gBAAgB,QAAkB,OAAe,QAAoC;CACnG,IAAI,OAAO,SAAS,GAAG,OAAO,KAAA;CAC9B,MAAM,MAAM,KAAK,IAAI,GAAG,MAAM;CAC9B,OAAO,OACJ,KAAK,OAAO,UAAU;EACrB,MAAM,IAAK,SAAS,OAAO,SAAS,KAAM;EAC1C,MAAM,IAAI,QAAQ,IAAI,SAAS,SAAU,QAAQ,MAAO;EACxD,OAAO,GAAG,EAAE,QAAQ,CAAC,EAAE,GAAG,EAAE,QAAQ,CAAC;CACvC,CAAC,CAAC,CACD,KAAK,GAAG;AACb"}
|
|
1
|
+
{"version":3,"file":"process-tree.js","names":[],"sources":["../../../src/data/traces/process-tree.ts"],"sourcesContent":["import type { ProcessNodeRow, ProcessSampleRow } from \"./types\";\n\nexport type ProcessTreeNode = {\n row: ProcessNodeRow;\n children: ProcessTreeNode[];\n /** The process has exited: by its status, or because an exit time was recorded. */\n exited: boolean;\n};\n\nconst byStart = (a: ProcessTreeNode, b: ProcessTreeNode) =>\n Date.parse(a.row.startedAt) - Date.parse(b.row.startedAt) || a.row.pid - b.row.pid;\n\n/**\n * Builds the forest a `process_tree` stream describes: each row under its\n * `parentKey`. A row whose parent was never recorded (the capture began below\n * it) becomes a root. The stream holds each process once, so a repeated key or a\n * parent cycle is a corrupt capture and throws.\n */\nexport function buildProcessForest(rows: ProcessNodeRow[]): ProcessTreeNode[] {\n const nodes = new Map<string, ProcessTreeNode>();\n for (const row of rows) {\n if (nodes.has(row.key)) throw new Error(`process tree key \"${row.key}\" appears twice`);\n nodes.set(row.key, { row, children: [], exited: isProcessExited(row) });\n }\n\n const roots: ProcessTreeNode[] = [];\n for (const node of nodes.values()) {\n const parent = node.row.parentKey ? nodes.get(node.row.parentKey) : undefined;\n (parent ? parent.children : roots).push(node);\n }\n\n roots.sort((a, b) => Number(Boolean(b.row.isRoot)) - Number(Boolean(a.row.isRoot)) || byStart(a, b));\n const reached = flattenForest(roots);\n if (reached.length !== nodes.size) {\n const lost = [...nodes.keys()].filter((key) => !reached.some((node) => node.row.key === key));\n throw new Error(`process tree has a parent cycle among keys ${lost.map((key) => `\"${key}\"`).join(\", \")}`);\n }\n for (const node of nodes.values()) node.children.sort(byStart);\n return roots;\n}\n\n/**\n * Drops exited processes from a forest, keeping an exited process only while it\n * still has a live descendant to hang off. Returns new nodes; the input is not\n * modified.\n */\nexport function pruneExitedProcesses(roots: ProcessTreeNode[]): ProcessTreeNode[] {\n return roots.flatMap((node) => {\n const children = pruneExitedProcesses(node.children);\n return node.exited && children.length === 0 ? [] : [{ ...node, children }];\n });\n}\n\n/** How long the process lived: to its exit, else to the last time it was seen. */\nexport function processLifetimeMs(row: ProcessNodeRow): number {\n return Date.parse(row.exitedAt ?? row.lastSeenAt) - Date.parse(row.startedAt);\n}\n\n/** A trace timestamp as local `YYYY-MM-DD HH:MM:SS`; text that is not a date is returned unchanged. */\nexport function formatProcessTimestamp(iso: string): string {\n const date = new Date(iso);\n if (Number.isNaN(date.getTime())) return iso;\n const pad = (n: number) => String(n).padStart(2, \"0\");\n return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}`;\n}\n\n/** The process has exited: by its status, or because an exit time was recorded. */\nexport function isProcessExited(row: ProcessNodeRow): boolean {\n return row.status === \"exited\" || Boolean(row.exitedAt);\n}\n\n/** The forest depth-first, parents before children. */\nexport function flattenForest(roots: ProcessTreeNode[]): ProcessTreeNode[] {\n const flat: ProcessTreeNode[] = [];\n const visit = (node: ProcessTreeNode) => {\n flat.push(node);\n node.children.forEach(visit);\n };\n roots.forEach(visit);\n return flat;\n}\n\n/** A CPU % for display, \"—\" while it is still unknown. */\nexport function formatCpuPercent(value: number | null | undefined): string {\n return value == null ? \"—\" : `${value.toFixed(1)}%`;\n}\n\nfunction knownCpu(samples: ProcessSampleRow[]): number[] {\n return samples.flatMap((sample) => (sample.cpuPercent == null ? [] : [sample.cpuPercent]));\n}\n\n/** Each process's known CPU % over its samples, in tick order. */\nexport function cpuSeriesByKey(samples: ProcessSampleRow[]): Map<string, number[]> {\n const byKey = new Map<string, ProcessSampleRow[]>();\n for (const sample of samples) byKey.set(sample.key, [...(byKey.get(sample.key) ?? []), sample]);\n return new Map([...byKey].map(([key, list]) => [key, knownCpu(list.sort((a, b) => a.tick - b.tick))]));\n}\n\n/** One process's known CPU % and RSS bytes over its samples, in tick order. */\nexport function processSeries(samples: ProcessSampleRow[], key: string): { cpu: number[]; rss: number[] } {\n const own = samples.filter((sample) => sample.key === key).sort((a, b) => a.tick - b.tick);\n return { cpu: knownCpu(own), rss: own.map((sample) => sample.rssBytes) };\n}\n\n/**\n * The combined CPU % and RSS bytes of a process and all its descendants at\n * each sampling tick (one tick is one sampling round across every process), in\n * tick order, so the peak of a series is the most the subtree used at once. A\n * tick's CPU sums the known readings and is left out when none is known.\n * The latest tick retains its CPU and RSS totals even when CPU is unknown.\n */\nexport function subtreeSeries(rows: ProcessNodeRow[], samples: ProcessSampleRow[], key: string): {\n cpu: number[];\n rss: number[];\n latest: { cpu: number | null; rss: number } | undefined;\n} {\n const keys = new Set([key]);\n for (let grew = true; grew; ) {\n grew = false;\n for (const row of rows) {\n if (row.parentKey && keys.has(row.parentKey) && !keys.has(row.key)) {\n keys.add(row.key);\n grew = true;\n }\n }\n }\n const ticks = new Map<number, { cpu: number | null; rss: number }>();\n for (const sample of samples) {\n if (!keys.has(sample.key)) continue;\n const total = ticks.get(sample.tick) ?? { cpu: null, rss: 0 };\n total.rss += sample.rssBytes;\n if (sample.cpuPercent != null) total.cpu = (total.cpu ?? 0) + sample.cpuPercent;\n ticks.set(sample.tick, total);\n }\n const ordered = [...ticks].sort(([a], [b]) => a - b).map(([, total]) => total);\n return {\n cpu: ordered.flatMap((total) => (total.cpu === null ? [] : [total.cpu])),\n rss: ordered.map((total) => total.rss),\n latest: ordered.at(-1),\n };\n}\n\n/** SVG polyline points for `values` in a `width` x `height` box, zero at the bottom and the maximum at the top. */\nexport function sparklinePoints(values: number[], width: number, height: number): string | undefined {\n if (values.length < 2) return undefined;\n const max = Math.max(...values);\n return values\n .map((value, index) => {\n const x = (index / (values.length - 1)) * width;\n const y = max === 0 ? height : height - (value / max) * height;\n return `${x.toFixed(1)},${y.toFixed(1)}`;\n })\n .join(\" \");\n}\n"],"mappings":";AASA,IAAM,WAAW,GAAoB,MACnC,KAAK,MAAM,EAAE,IAAI,SAAS,IAAI,KAAK,MAAM,EAAE,IAAI,SAAS,KAAK,EAAE,IAAI,MAAM,EAAE,IAAI;;;;;;;AAQjF,SAAgB,mBAAmB,MAA2C;CAC5E,MAAM,wBAAQ,IAAI,IAA6B;CAC/C,KAAK,MAAM,OAAO,MAAM;EACtB,IAAI,MAAM,IAAI,IAAI,GAAG,GAAG,MAAM,IAAI,MAAM,qBAAqB,IAAI,IAAI,gBAAgB;EACrF,MAAM,IAAI,IAAI,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M,KAAK,IAAI,GAAG,MAAM;CAC9B,OAAO,OACJ,KAAK,OAAO,UAAU;EACrB,MAAM,IAAK,SAAS,OAAO,SAAS,KAAM;EAC1C,MAAM,IAAI,QAAQ,IAAI,SAAS,SAAU,QAAQ,MAAO;EACxD,OAAO,GAAG,EAAE,QAAQ,CAAC,EAAE,GAAG,EAAE,QAAQ,CAAC;CACvC,CAAC,CAAC,CACD,KAAK,GAAG;AACb"}
|
|
@@ -14,9 +14,9 @@ function detectMode() {
|
|
|
14
14
|
/** Resolve build + runtime version metadata. */
|
|
15
15
|
function getVersionInfo() {
|
|
16
16
|
return {
|
|
17
|
-
commit: read(() => "
|
|
18
|
-
tag: read(() => "page-runtime-build@0.1.
|
|
19
|
-
date: read(() => "2026-12-
|
|
17
|
+
commit: read(() => "ff09b77e9", ""),
|
|
18
|
+
tag: read(() => "page-runtime-build@0.1.3", ""),
|
|
19
|
+
date: read(() => "2026-12-03T00:00:17.982Z", ""),
|
|
20
20
|
dirty: read(() => true, false),
|
|
21
21
|
mode: detectMode()
|
|
22
22
|
};
|
|
@@ -14,9 +14,9 @@ function detectMode() {
|
|
|
14
14
|
/** Resolve build + runtime version metadata. */
|
|
15
15
|
function getVersionInfo() {
|
|
16
16
|
return {
|
|
17
|
-
commit: read(() => "
|
|
18
|
-
tag: read(() => "page-runtime-build@0.1.
|
|
19
|
-
date: read(() => "2026-12-
|
|
17
|
+
commit: read(() => "ff09b77e9", ""),
|
|
18
|
+
tag: read(() => "page-runtime-build@0.1.3", ""),
|
|
19
|
+
date: read(() => "2026-12-02T23:59:53.777Z", ""),
|
|
20
20
|
dirty: read(() => true, false),
|
|
21
21
|
mode: detectMode()
|
|
22
22
|
};
|