@@ -83,14 +83,14 @@ export class Profiler<T extends ActionTrackConfigs> {
8383 * @param options.track - Default track name for measurements
8484 * @param options.trackGroup - Default track group for organization
8585 * @param options.color - Default color for track entries
86- * @param options.enabled - Whether profiling is enabled (defaults to false )
86+ * @param options.enabled - Whether profiling is enabled (defaults to CP_PROFILING env var )
8787 *
8888 */
8989 constructor ( options : ProfilerOptions < T > ) {
90- const { tracks, prefix, enabled = false , ...defaults } = options ;
90+ const { tracks, prefix, enabled, ...defaults } = options ;
9191 const dataType = 'track-entry' ;
9292
93- this . #enabled = enabled ;
93+ this . #enabled = enabled ?? isEnvVarEnabled ( PROFILER_ENABLED_ENV_VAR ) ;
9494 this . #defaults = { ...defaults , dataType } ;
9595 this . tracks = tracks
9696 ? setupTracks ( { ...defaults , dataType } , tracks )
@@ -105,11 +105,13 @@ export class Profiler<T extends ActionTrackConfigs> {
105105 /**
106106 * Sets enabled state for this profiler.
107107 *
108+ * Also sets the `CP_PROFILING` environment variable.
108109 * This means any future {@link Profiler} instantiations (including child processes) will use the same enabled state.
109110 *
110111 * @param enabled - Whether profiling should be enabled
111112 */
112113 setEnabled ( enabled : boolean ) : void {
114+ process . env [ PROFILER_ENABLED_ENV_VAR ] = `${ enabled } ` ;
113115 this . #enabled = enabled ;
114116 }
115117
0 commit comments