timer.ts — astro Source File
Architecture documentation for timer.ts, a typescript file in the astro codebase. 1 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 587108a1_d18f_e006_6243_92250d699327["timer.ts"] e16a223b_37f3_6b25_1ee1_2b7bcb9d9415["node:fs"] 587108a1_d18f_e006_6243_92250d699327 --> e16a223b_37f3_6b25_1ee1_2b7bcb9d9415 style 587108a1_d18f_e006_6243_92250d699327 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import fs from 'node:fs';
// Type used by `bench-memory.js`
interface Stat {
elapsedTime: number;
heapUsedChange: number;
heapUsedTotal: number;
}
interface OngoingStat {
startTime: number;
startHeap: number;
}
/**
* Timer to track certain operations' performance. Used by Astro's scripts only.
* Set `process.env.ASTRO_TIMER_PATH` truthy to enable.
*/
export class AstroTimer {
private enabled: boolean;
private ongoingTimers = new Map<string, OngoingStat>();
private stats: Record<string, Stat> = {};
constructor() {
this.enabled = !!process.env.ASTRO_TIMER_PATH;
}
/**
* Start a timer for a scope with a given name.
*/
start(name: string) {
if (!this.enabled) return;
globalThis.gc?.();
this.ongoingTimers.set(name, {
startTime: performance.now(),
startHeap: process.memoryUsage().heapUsed,
});
}
/**
* End a timer for a scope with a given name.
*/
end(name: string) {
if (!this.enabled) return;
const stat = this.ongoingTimers.get(name);
if (!stat) return;
globalThis.gc?.();
const endHeap = process.memoryUsage().heapUsed;
this.stats[name] = {
elapsedTime: performance.now() - stat.startTime,
heapUsedChange: endHeap - stat.startHeap,
heapUsedTotal: endHeap,
};
this.ongoingTimers.delete(name);
}
/**
* Write stats to `process.env.ASTRO_TIMER_PATH`
*/
writeStats() {
if (!this.enabled) return;
// @ts-expect-error
fs.writeFileSync(process.env.ASTRO_TIMER_PATH, JSON.stringify(this.stats, null, 2));
}
}
Domain
Subdomains
Classes
Types
Dependencies
- node:fs
Source
Frequently Asked Questions
What does timer.ts do?
timer.ts is a source file in the astro codebase, written in typescript. It belongs to the CoreAstro domain, RenderingEngine subdomain.
What does timer.ts depend on?
timer.ts imports 1 module(s): node:fs.
Where is timer.ts in the architecture?
timer.ts is located at packages/astro/src/core/config/timer.ts (domain: CoreAstro, subdomain: RenderingEngine, directory: packages/astro/src/core/config).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free