diff --git a/src/analytics.zig b/src/analytics.zig index 650c6e4007..bf103dd90b 100644 --- a/src/analytics.zig +++ b/src/analytics.zig @@ -89,10 +89,13 @@ pub const Features = struct { pub var yarn_migration: usize = 0; pub var pnpm_migration: usize = 0; pub var yaml_parse: usize = 0; + pub var cpu_profile: usize = 0; + pub var heap_snapshot: usize = 0; comptime { @export(&napi_module_register, .{ .name = "Bun__napi_module_register_count" }); @export(&process_dlopen, .{ .name = "Bun__process_dlopen_count" }); + @export(&heap_snapshot, .{ .name = "Bun__Feature__heap_snapshot" }); } pub fn formatter() Formatter { diff --git a/src/bun.js.zig b/src/bun.js.zig index 84ab5016b1..37086368f0 100644 --- a/src/bun.js.zig +++ b/src/bun.js.zig @@ -280,6 +280,7 @@ pub const Run = struct { .dir = cpu_prof_opts.dir, }; CPUProfiler.startCPUProfiler(vm.jsc_vm); + bun.analytics.Features.cpu_profile += 1; } this.addConditionalGlobals(); diff --git a/src/bun.js/bindings/BunObject.cpp b/src/bun.js/bindings/BunObject.cpp index 2eb6bd9df0..f9ccf3cf5d 100644 --- a/src/bun.js/bindings/BunObject.cpp +++ b/src/bun.js/bindings/BunObject.cpp @@ -48,6 +48,8 @@ #include #endif +extern "C" size_t Bun__Feature__heap_snapshot; + BUN_DECLARE_HOST_FUNCTION(Bun__DNS__lookup); BUN_DECLARE_HOST_FUNCTION(Bun__DNS__resolve); BUN_DECLARE_HOST_FUNCTION(Bun__DNS__resolveSrv); @@ -598,6 +600,8 @@ JSC_DEFINE_HOST_FUNCTION(functionGenerateHeapSnapshot, (JSC::JSGlobalObject * gl auto& heapProfiler = *vm.heapProfiler(); heapProfiler.clearSnapshots(); + Bun__Feature__heap_snapshot += 1; + JSValue arg0 = callFrame->argument(0); auto throwScope = DECLARE_THROW_SCOPE(vm); bool useV8 = false; diff --git a/src/bun.js/bindings/bindings.cpp b/src/bun.js/bindings/bindings.cpp index 945c31bda4..e7a072faaa 100644 --- a/src/bun.js/bindings/bindings.cpp +++ b/src/bun.js/bindings/bindings.cpp @@ -152,6 +152,8 @@ #include #endif +extern "C" size_t Bun__Feature__heap_snapshot; + #if OS(DARWIN) #if ASSERT_ENABLED #if !__has_feature(address_sanitizer) @@ -3659,6 +3661,8 @@ JSC::EncodedJSValue JSC__JSGlobalObject__generateHeapSnapshot(JSC::JSGlobalObjec // JSC::DeferTermination deferScope(vm); auto scope = DECLARE_THROW_SCOPE(vm); + Bun__Feature__heap_snapshot += 1; + JSC::HeapSnapshotBuilder snapshotBuilder(vm.ensureHeapProfiler()); snapshotBuilder.buildSnapshot(); diff --git a/src/bun.js/modules/BunJSCModule.h b/src/bun.js/modules/BunJSCModule.h index f9804d70bc..461b04c679 100644 --- a/src/bun.js/modules/BunJSCModule.h +++ b/src/bun.js/modules/BunJSCModule.h @@ -58,6 +58,8 @@ #endif #endif +extern "C" size_t Bun__Feature__heap_snapshot; + using namespace JSC; using namespace WTF; using namespace WebCore; @@ -732,6 +734,9 @@ JSC_DEFINE_HOST_FUNCTION(functionGenerateHeapSnapshotForDebugging, JSLockHolder lock(vm); DeferTermination deferScope(vm); auto scope = DECLARE_THROW_SCOPE(vm); + + Bun__Feature__heap_snapshot += 1; + String jsonString; { DeferGCForAWhile deferGC(vm); // Prevent concurrent GC from interfering with