mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-16 20:11:08 +00:00
* perf: add opt-in startup timeline and real-app startup harness - electron/perfTrace.cjs records first-occurrence startup marks in the main process when NETCATTY_PERF_TRACE=1 (a no-op otherwise), then writes the main-window renderer timeline (navigation, paint, netcatty:* marks, JS heap) and app.getAppMetrics() to JSON after the first renderer-ready signal. - Marks: main.cjs entry / modules loaded / whenReady, main window creation, registerBridges and plugin-host start/end, loadURL, did-finish-load, renderer ready, window shown. The renderer adds three performance.mark() calls (entry evaluated, App mounted, renderer ready), also visible in DevTools. - scripts/perf-startup.live.cjs (npm run perf:startup) launches the built app N times against a throwaway --user-data-dir profile with ssh:// deep-link registration disabled, optionally seeds synthetic hosts over CDP, and reports cold plus warm p50/p90. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * perf(harness): add --profile option to reuse a startup profile Lets the harness keep one profile across invocations, e.g. to compare warm V8 code caches across builds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore: retrigger CI after flaky monitorRuntimeIsolation failure Previous lint-and-test failed on known-preexisting `useEffect is not defined` in monitorRuntimeIsolation.test.ts. * chore: retrigger CI after monitorRuntimeIsolation useEffect flake Known pre-existing flake: monitor controls test fails with `useEffect is not defined`. Empty commit to re-run once. * test(app): bind React hooks in monitorRuntimeIsolation VM sandbox Extracting component declarations drops their React imports, leaving bare hooks such as useEffect undefined in the VM. Inject common React hooks and APIs while preserving explicit binding overrides to prevent intermittent monitor isolation failures in CI. Stub the startup performance mark through App test bindings so the mount effect can execute without browser globals. Production components remain unchanged. Validation: monitorRuntimeIsolation passed five consecutive runs. Plain npm run lint found 17 existing errors in git-ignored scratch files; excluding only _t.mjs and sim-4107.mjs passed with zero errors and eight existing warnings. * chore: retrigger CI after plugin-contract runner cancel Lint/schema passed; plugin-contract step cancelled by the runner (not a test failure). Empty commit to re-queue. --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: binaricat <binaricat@users.noreply.github.com>
88 lines
3.0 KiB
JavaScript
88 lines
3.0 KiB
JavaScript
"use strict";
|
|
|
|
const test = require("node:test");
|
|
const assert = require("node:assert/strict");
|
|
const fs = require("node:fs");
|
|
const os = require("node:os");
|
|
const path = require("node:path");
|
|
|
|
const { createPerfTrace } = require("./perfTrace.cjs");
|
|
|
|
function fakeClock(start = 1_000) {
|
|
let current = start;
|
|
return {
|
|
now: () => current,
|
|
advance: (ms) => { current += ms; },
|
|
};
|
|
}
|
|
|
|
function captureTimers() {
|
|
const pending = [];
|
|
return {
|
|
setTimer: (fn, ms) => { pending.push({ fn, ms }); return pending.length; },
|
|
pending,
|
|
};
|
|
}
|
|
|
|
test("perfTrace is a no-op unless NETCATTY_PERF_TRACE=1", () => {
|
|
const timers = captureTimers();
|
|
const trace = createPerfTrace({ env: {}, setTimer: timers.setTimer });
|
|
trace.mark("main:entry");
|
|
trace.noteRendererReady({ app: {}, webContents: {} });
|
|
assert.equal(trace.isEnabled(), false);
|
|
assert.deepEqual(trace.getMarks(), {});
|
|
assert.equal(timers.pending.length, 0);
|
|
});
|
|
|
|
test("perfTrace keeps only the first occurrence of each mark", () => {
|
|
const clock = fakeClock();
|
|
const trace = createPerfTrace({ env: { NETCATTY_PERF_TRACE: "1" }, now: clock.now, uptimeSeconds: () => 0.5 });
|
|
trace.mark("main:entry");
|
|
clock.advance(25);
|
|
trace.mark("main:entry");
|
|
trace.mark("main:when-ready");
|
|
assert.deepEqual(trace.getMarks(), { "main:entry": 1_000, "main:when-ready": 1_025 });
|
|
});
|
|
|
|
test("perfTrace writes one report after the first renderer-ready and quits when asked", async () => {
|
|
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "nc-perf-trace-"));
|
|
const outputFile = path.join(dir, "trace.json");
|
|
const timers = captureTimers();
|
|
const trace = createPerfTrace({
|
|
env: {
|
|
NETCATTY_PERF_TRACE: "1",
|
|
NETCATTY_PERF_TRACE_FILE: outputFile,
|
|
NETCATTY_PERF_TRACE_EXIT: "1",
|
|
NETCATTY_PERF_TRACE_SETTLE_MS: "50",
|
|
},
|
|
now: fakeClock(5_000).now,
|
|
uptimeSeconds: () => 2,
|
|
setTimer: timers.setTimer,
|
|
});
|
|
let quitCalls = 0;
|
|
const app = {
|
|
getAppMetrics: () => [{ type: "Browser", memory: { workingSetSize: 2048, privateBytes: 1024 } }],
|
|
getPath: () => dir,
|
|
quit: () => { quitCalls += 1; },
|
|
};
|
|
const webContents = {
|
|
executeJavaScript: async () => ({ marks: [{ name: "netcatty:renderer:ready", at: 5_400 }] }),
|
|
};
|
|
|
|
trace.mark("main:entry");
|
|
trace.noteRendererReady({ app, webContents });
|
|
trace.noteRendererReady({ app, webContents });
|
|
assert.equal(timers.pending.length, 1, "only the first renderer-ready schedules a report");
|
|
assert.equal(timers.pending[0].ms, 50);
|
|
|
|
await timers.pending[0].fn();
|
|
const report = JSON.parse(fs.readFileSync(outputFile, "utf8"));
|
|
assert.equal(report.processStartAt, 3_000);
|
|
assert.equal(report.main["main:entry"], 5_000);
|
|
assert.equal(report.main["main:renderer-ready"], 5_000);
|
|
assert.deepEqual(report.renderer.marks, [{ name: "netcatty:renderer:ready", at: 5_400 }]);
|
|
assert.deepEqual(report.processes, [{ type: "Browser", workingSetKB: 2048, privateKB: 1024 }]);
|
|
assert.equal(quitCalls, 1);
|
|
fs.rmSync(dir, { recursive: true, force: true });
|
|
});
|