Skip to content

Navigation Menu

Sign in
Sign up

Commit 7f70b01

Browse files
feat: support CPU profiling via environment variables (oven-sh#26313)
Adds environment variable support for enabling CPU profiling without CLI flags: - `BUN_CPU_PROFILE=1` — enables the CPU profiler - `BUN_CPU_PROFILE_DIR=<path>` — sets the output directory for the profile - `BUN_CPU_PROFILE_NAME=<name>` — sets the profile file name These are used as fallbacks when the corresponding `--cpu-prof` CLI options are not provided. This is useful for profiling in contexts where modifying the command line isn't practical (e.g. scripts invoked by other tools).
1 parent 08103aa commit 7f70b01

3 files changed

Lines changed: 8 additions & 5 deletions

File tree

‎src/bun.js.zig‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,12 +277,12 @@ pub const Run = struct {
277277
vm.onUnhandledRejection = &onUnhandledRejectionBeforeClose;
278278

279279
// Start CPU profiler if enabled
280-
if (this.ctx.runtime_options.cpu_prof.enabled) {
280+
if (this.ctx.runtime_options.cpu_prof.enabledorbun.env_var.BUN_CPU_PROFILE.get()) {
281281
const cpu_prof_opts = this.ctx.runtime_options.cpu_prof;
282282

283283
vm.cpu_profiler_config = CPUProfiler.CPUProfilerConfig{
284-
.name = cpu_prof_opts.name,
285-
.dir = cpu_prof_opts.dir,
284+
.name = cpu_prof_opts.nameorelsebun.env_var.BUN_CPU_PROFILE_NAME.get() orelse"",
285+
.dir = cpu_prof_opts.dirorelsebun.env_var.BUN_CPU_PROFILE_DIR.get() orelse"",
286286
};
287287
CPUProfiler.startCPUProfiler(vm.jsc_vm);
288288
bun.analytics.Features.cpu_profile += 1;

‎src/cli.zig‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,8 +390,8 @@ pub const Command = struct {
390390
console_depth: ?u16 = null,
391391
cpu_prof: struct {
392392
enabled: bool = false,
393-
name: []const u8 = "",
394-
dir: []const u8 = "",
393+
name: ?[]const u8 = null,
394+
dir: ?[]const u8 = null,
395395
} = .{},
396396
};
397397

‎src/env_var.zig‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ pub const BUN_CONFIG_DISABLE_ioctl_ficlonerange = New(kind.boolean, "BUN_CONFIG_
3737
///
3838
/// It's unclear why this was done.
3939
pub const BUN_CONFIG_DNS_TIME_TO_LIVE_SECONDS = New(kind.unsigned, "BUN_CONFIG_DNS_TIME_TO_LIVE_SECONDS", .{ .default = 30 });
40+
pub const BUN_CPU_PROFILE = New(kind.boolean, "BUN_CPU_PROFILE", .{ .default = false });
41+
pub const BUN_CPU_PROFILE_DIR = New(kind.string, "BUN_CPU_PROFILE_DIR", .{});
42+
pub const BUN_CPU_PROFILE_NAME = New(kind.string, "BUN_CPU_PROFILE_NAME", .{});
4043
pub const BUN_CRASH_REPORT_URL = New(kind.string, "BUN_CRASH_REPORT_URL", .{});
4144
pub const BUN_DEBUG = New(kind.string, "BUN_DEBUG", .{});
4245
pub const BUN_DEBUG_ALL = New(kind.boolean, "BUN_DEBUG_ALL", .{});

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /