Reduce uploader shutdown stalls and add bounded runtime profiling
CI / verify (push) Canceled after 0s
CI / verify (push) Canceled after 0s
This commit is contained in:
1 parent
80eb878f1b
commit
fe3797fd18
10 files changed
+121
-18
No files matched your search
+16
-10
@@ -50,21 +50,27 @@ function createStartupDiagnostics({ fs, path, directory, metadata = {}, now = Da
|
||||
const startedAt = now();
|
||||
const session = `${startedAt}-${process.pid}`;
|
||||
let sequence = 0;
|
||||
let pending = Promise.resolve(true);
|
||||
const reportedPhases = new Set();
|
||||
const write = (event, details = {}) => {
|
||||
const entry = { session, sequence: sequence++, timestamp: new Date(now()).toISOString(), elapsedMs: Math.max(0, now() - startedAt), event, ...details };
|
||||
try {
|
||||
fs.mkdirSync(directory, { recursive: true });
|
||||
if (fs.existsSync(filePath) && fs.statSync(filePath).size >= 1024 * 1024) {
|
||||
if (!fs.promises) return false;
|
||||
const line = JSON.stringify(entry) + '\n';
|
||||
pending = pending.then(async () => {
|
||||
await fs.promises.mkdir(directory, { recursive: true });
|
||||
const stat = await fs.promises.stat(filePath).catch(error => {
|
||||
if (error.code !== 'ENOENT') throw error;
|
||||
return null;
|
||||
});
|
||||
if (stat && stat.size >= 1024 * 1024) {
|
||||
const backup = filePath + '.1';
|
||||
if (fs.existsSync(backup)) fs.unlinkSync(backup);
|
||||
fs.renameSync(filePath, backup);
|
||||
await fs.promises.unlink(backup).catch(error => { if (error.code !== 'ENOENT') throw error; });
|
||||
await fs.promises.rename(filePath, backup);
|
||||
}
|
||||
fs.appendFileSync(filePath, JSON.stringify(entry) + '\n', 'utf8');
|
||||
await fs.promises.appendFile(filePath, line, 'utf8');
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}).catch(() => false);
|
||||
return true;
|
||||
};
|
||||
const recordPhase = (phase, generation) => {
|
||||
if (typeof phase !== 'string' || !STARTUP_PHASES.has(phase)) return false;
|
||||
@@ -75,7 +81,7 @@ function createStartupDiagnostics({ fs, path, directory, metadata = {}, now = Da
|
||||
return write('renderer-phase', { phase, generation });
|
||||
};
|
||||
write('process-start', metadata);
|
||||
return { filePath, write, recordPhase };
|
||||
return { filePath, write, recordPhase, drain: () => pending };
|
||||
}
|
||||
|
||||
function summarizeStartupPixels(image) {
|
||||
|
||||
Reference in new issue
Block a user