@sentry/node-cpu-profiler 2.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +10 -0
  3. package/binding.gyp +20 -0
  4. package/bindings/cpu_profiler.cc +1222 -0
  5. package/lib/index.d.ts +14 -0
  6. package/lib/index.d.ts.map +1 -0
  7. package/lib/index.js +217 -0
  8. package/lib/sentry_cpu_profiler-darwin-arm64-108.node +0 -0
  9. package/lib/sentry_cpu_profiler-darwin-arm64-115.node +0 -0
  10. package/lib/sentry_cpu_profiler-darwin-arm64-127.node +0 -0
  11. package/lib/sentry_cpu_profiler-darwin-arm64-137.node +0 -0
  12. package/lib/sentry_cpu_profiler-darwin-arm64-147.node +0 -0
  13. package/lib/sentry_cpu_profiler-darwin-x64-108.node +0 -0
  14. package/lib/sentry_cpu_profiler-darwin-x64-115.node +0 -0
  15. package/lib/sentry_cpu_profiler-darwin-x64-127.node +0 -0
  16. package/lib/sentry_cpu_profiler-darwin-x64-137.node +0 -0
  17. package/lib/sentry_cpu_profiler-darwin-x64-147.node +0 -0
  18. package/lib/sentry_cpu_profiler-linux-arm64-glibc-108.node +0 -0
  19. package/lib/sentry_cpu_profiler-linux-arm64-glibc-115.node +0 -0
  20. package/lib/sentry_cpu_profiler-linux-arm64-glibc-127.node +0 -0
  21. package/lib/sentry_cpu_profiler-linux-arm64-glibc-137.node +0 -0
  22. package/lib/sentry_cpu_profiler-linux-arm64-glibc-147.node +0 -0
  23. package/lib/sentry_cpu_profiler-linux-arm64-musl-108.node +0 -0
  24. package/lib/sentry_cpu_profiler-linux-arm64-musl-115.node +0 -0
  25. package/lib/sentry_cpu_profiler-linux-arm64-musl-127.node +0 -0
  26. package/lib/sentry_cpu_profiler-linux-arm64-musl-137.node +0 -0
  27. package/lib/sentry_cpu_profiler-linux-arm64-musl-147.node +0 -0
  28. package/lib/sentry_cpu_profiler-linux-x64-glibc-108.node +0 -0
  29. package/lib/sentry_cpu_profiler-linux-x64-glibc-115.node +0 -0
  30. package/lib/sentry_cpu_profiler-linux-x64-glibc-127.node +0 -0
  31. package/lib/sentry_cpu_profiler-linux-x64-glibc-137.node +0 -0
  32. package/lib/sentry_cpu_profiler-linux-x64-glibc-147.node +0 -0
  33. package/lib/sentry_cpu_profiler-linux-x64-musl-108.node +0 -0
  34. package/lib/sentry_cpu_profiler-linux-x64-musl-115.node +0 -0
  35. package/lib/sentry_cpu_profiler-linux-x64-musl-127.node +0 -0
  36. package/lib/sentry_cpu_profiler-linux-x64-musl-137.node +0 -0
  37. package/lib/sentry_cpu_profiler-linux-x64-musl-147.node +0 -0
  38. package/lib/sentry_cpu_profiler-win32-x64-108.node +0 -0
  39. package/lib/sentry_cpu_profiler-win32-x64-115.node +0 -0
  40. package/lib/sentry_cpu_profiler-win32-x64-127.node +0 -0
  41. package/lib/sentry_cpu_profiler-win32-x64-137.node +0 -0
  42. package/lib/sentry_cpu_profiler-win32-x64-147.node +0 -0
  43. package/lib/types.d.ts +53 -0
  44. package/lib/types.d.ts.map +1 -0
  45. package/lib/types.js +8 -0
  46. package/package.json +68 -0
  47. package/scripts/binaries.js +27 -0
  48. package/scripts/check-build.js +57 -0
  49. package/scripts/copy-target.js +28 -0
package/lib/index.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ import type { PrivateV8CpuProfilerBindings, ProfileFormat, RawChunkCpuProfile, RawThreadCpuProfile, V8CpuProfilerBindings } from './types';
2
+ /**
3
+ * Imports cpp bindings based on the current platform and architecture.
4
+ */
5
+ export declare function importCppBindingsModule(): PrivateV8CpuProfilerBindings;
6
+ export declare const PrivateCpuProfilerBindings: PrivateV8CpuProfilerBindings;
7
+ declare class Bindings implements V8CpuProfilerBindings {
8
+ startProfiling(name: string): void;
9
+ stopProfiling(name: string, format: ProfileFormat.THREAD): RawThreadCpuProfile | null;
10
+ stopProfiling(name: string, format: ProfileFormat.CHUNK): RawChunkCpuProfile | null;
11
+ }
12
+ export declare const CpuProfilerBindings: Bindings;
13
+ export * from './types';
14
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EACV,4BAA4B,EAC5B,aAAa,EACb,kBAAkB,EAClB,mBAAmB,EACnB,qBAAqB,EACtB,MAAM,SAAS,CAAC;AAQjB;;GAEG;AAEH,wBAAgB,uBAAuB,IAAI,4BAA4B,CA+JtE;AAED,eAAO,MAAM,0BAA0B,EAAE,4BAAwD,CAAC;AAElG,cAAM,QAAS,YAAW,qBAAqB;IACtC,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAclC,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,CAAC,MAAM,GAAG,mBAAmB,GAAG,IAAI;IACrF,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,CAAC,KAAK,GAAG,kBAAkB,GAAG,IAAI;CAsB3F;AAED,eAAO,MAAM,mBAAmB,UAAiB,CAAC;AAElD,cAAc,SAAS,CAAC"}
package/lib/index.js ADDED
@@ -0,0 +1,217 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.CpuProfilerBindings = exports.PrivateCpuProfilerBindings = void 0;
18
+ exports.importCppBindingsModule = importCppBindingsModule;
19
+ /* eslint-disable no-console */
20
+ var detect_libc_1 = require("detect-libc");
21
+ var node_abi_1 = require("node-abi");
22
+ var node_os_1 = require("node:os");
23
+ var node_path_1 = require("node:path");
24
+ var node_process_1 = require("node:process");
25
+ var node_worker_threads_1 = require("node:worker_threads");
26
+ var stdlib = (0, detect_libc_1.familySync)();
27
+ var platform = process.env['BUILD_PLATFORM'] || (0, node_os_1.platform)();
28
+ var arch = process.env['BUILD_ARCH'] || (0, node_os_1.arch)();
29
+ var abi = (0, node_abi_1.getAbi)(node_process_1.versions.node, 'node');
30
+ var identifier = [platform, arch, stdlib, abi].filter(function (c) { return c !== undefined && c !== null; }).join('-');
31
+ /**
32
+ * Imports cpp bindings based on the current platform and architecture.
33
+ */
34
+ // eslint-disable-next-line complexity
35
+ function importCppBindingsModule() {
36
+ // If a binary path is specified, use that.
37
+ if (node_process_1.env['SENTRY_PROFILER_BINARY_PATH']) {
38
+ var envPath = node_process_1.env['SENTRY_PROFILER_BINARY_PATH'];
39
+ return require(envPath);
40
+ }
41
+ // If a user specifies a different binary dir, they are in control of the binaries being moved there
42
+ if (node_process_1.env['SENTRY_PROFILER_BINARY_DIR']) {
43
+ var binaryPath = (0, node_path_1.join)((0, node_path_1.resolve)(node_process_1.env['SENTRY_PROFILER_BINARY_DIR']), "sentry_cpu_profiler-".concat(identifier, ".node"));
44
+ return require(binaryPath);
45
+ }
46
+ if (process.versions.electron) {
47
+ try {
48
+ return require('../build/Release/sentry_cpu_profiler.node');
49
+ }
50
+ catch (e) {
51
+ console.warn("The '@sentry/profiling-node' binary could not be found. Use '@electron/rebuild' to ensure the native module is built for Electron.");
52
+ throw e;
53
+ }
54
+ }
55
+ // We need the fallthrough so that in the end, we can fallback to the dynamic require.
56
+ // This is for cases where precompiled binaries were not provided, but may have been compiled from source.
57
+ if (platform === 'darwin') {
58
+ if (arch === 'x64') {
59
+ if (abi === '108') {
60
+ return require('./sentry_cpu_profiler-darwin-x64-108.node');
61
+ }
62
+ if (abi === '115') {
63
+ return require('./sentry_cpu_profiler-darwin-x64-115.node');
64
+ }
65
+ if (abi === '127') {
66
+ return require('./sentry_cpu_profiler-darwin-x64-127.node');
67
+ }
68
+ if (abi === '137') {
69
+ return require('./sentry_cpu_profiler-darwin-x64-137.node');
70
+ }
71
+ if (abi === '147') {
72
+ return require('./sentry_cpu_profiler-darwin-x64-147.node');
73
+ }
74
+ }
75
+ if (arch === 'arm64') {
76
+ if (abi === '108') {
77
+ return require('./sentry_cpu_profiler-darwin-arm64-108.node');
78
+ }
79
+ if (abi === '115') {
80
+ return require('./sentry_cpu_profiler-darwin-arm64-115.node');
81
+ }
82
+ if (abi === '127') {
83
+ return require('./sentry_cpu_profiler-darwin-arm64-127.node');
84
+ }
85
+ if (abi === '137') {
86
+ return require('./sentry_cpu_profiler-darwin-arm64-137.node');
87
+ }
88
+ if (abi === '147') {
89
+ return require('./sentry_cpu_profiler-darwin-arm64-147.node');
90
+ }
91
+ }
92
+ }
93
+ if (platform === 'win32') {
94
+ if (arch === 'x64') {
95
+ if (abi === '108') {
96
+ return require('./sentry_cpu_profiler-win32-x64-108.node');
97
+ }
98
+ if (abi === '115') {
99
+ return require('./sentry_cpu_profiler-win32-x64-115.node');
100
+ }
101
+ if (abi === '127') {
102
+ return require('./sentry_cpu_profiler-win32-x64-127.node');
103
+ }
104
+ if (abi === '137') {
105
+ return require('./sentry_cpu_profiler-win32-x64-137.node');
106
+ }
107
+ if (abi === '147') {
108
+ return require('./sentry_cpu_profiler-win32-x64-147.node');
109
+ }
110
+ }
111
+ }
112
+ if (platform === 'linux') {
113
+ if (arch === 'x64') {
114
+ if (stdlib === 'musl') {
115
+ if (abi === '108') {
116
+ return require('./sentry_cpu_profiler-linux-x64-musl-108.node');
117
+ }
118
+ if (abi === '115') {
119
+ return require('./sentry_cpu_profiler-linux-x64-musl-115.node');
120
+ }
121
+ if (abi === '127') {
122
+ return require('./sentry_cpu_profiler-linux-x64-musl-127.node');
123
+ }
124
+ if (abi === '137') {
125
+ return require('./sentry_cpu_profiler-linux-x64-musl-137.node');
126
+ }
127
+ if (abi === '147') {
128
+ return require('./sentry_cpu_profiler-linux-x64-musl-147.node');
129
+ }
130
+ }
131
+ if (stdlib === 'glibc') {
132
+ if (abi === '108') {
133
+ return require('./sentry_cpu_profiler-linux-x64-glibc-108.node');
134
+ }
135
+ if (abi === '115') {
136
+ return require('./sentry_cpu_profiler-linux-x64-glibc-115.node');
137
+ }
138
+ if (abi === '127') {
139
+ return require('./sentry_cpu_profiler-linux-x64-glibc-127.node');
140
+ }
141
+ if (abi === '137') {
142
+ return require('./sentry_cpu_profiler-linux-x64-glibc-137.node');
143
+ }
144
+ if (abi === '147') {
145
+ return require('./sentry_cpu_profiler-linux-x64-glibc-147.node');
146
+ }
147
+ }
148
+ }
149
+ if (arch === 'arm64') {
150
+ if (stdlib === 'musl') {
151
+ if (abi === '108') {
152
+ return require('./sentry_cpu_profiler-linux-arm64-musl-108.node');
153
+ }
154
+ if (abi === '115') {
155
+ return require('./sentry_cpu_profiler-linux-arm64-musl-115.node');
156
+ }
157
+ if (abi === '127') {
158
+ return require('./sentry_cpu_profiler-linux-arm64-musl-127.node');
159
+ }
160
+ if (abi === '137') {
161
+ return require('./sentry_cpu_profiler-linux-arm64-musl-137.node');
162
+ }
163
+ if (abi === '147') {
164
+ return require('./sentry_cpu_profiler-linux-arm64-musl-147.node');
165
+ }
166
+ }
167
+ if (stdlib === 'glibc') {
168
+ if (abi === '108') {
169
+ return require('./sentry_cpu_profiler-linux-arm64-glibc-108.node');
170
+ }
171
+ if (abi === '115') {
172
+ return require('./sentry_cpu_profiler-linux-arm64-glibc-115.node');
173
+ }
174
+ if (abi === '127') {
175
+ return require('./sentry_cpu_profiler-linux-arm64-glibc-127.node');
176
+ }
177
+ if (abi === '137') {
178
+ return require('./sentry_cpu_profiler-linux-arm64-glibc-137.node');
179
+ }
180
+ if (abi === '147') {
181
+ return require('./sentry_cpu_profiler-linux-arm64-glibc-147.node');
182
+ }
183
+ }
184
+ }
185
+ }
186
+ return require("./sentry_cpu_profiler-".concat(identifier, ".node"));
187
+ }
188
+ exports.PrivateCpuProfilerBindings = importCppBindingsModule();
189
+ var Bindings = /** @class */ (function () {
190
+ function Bindings() {
191
+ }
192
+ Bindings.prototype.startProfiling = function (name) {
193
+ if (!exports.PrivateCpuProfilerBindings) {
194
+ console.log('[Profiling] Bindings not loaded, ignoring call to startProfiling.');
195
+ return;
196
+ }
197
+ if (typeof exports.PrivateCpuProfilerBindings.startProfiling !== 'function') {
198
+ console.log('[Profiling] Native startProfiling function is not available, ignoring call to startProfiling.');
199
+ return;
200
+ }
201
+ return exports.PrivateCpuProfilerBindings.startProfiling(name);
202
+ };
203
+ Bindings.prototype.stopProfiling = function (name, format) {
204
+ if (!exports.PrivateCpuProfilerBindings) {
205
+ console.log('[Profiling] Bindings not loaded or profile was never started, ignoring call to stopProfiling.');
206
+ return null;
207
+ }
208
+ if (typeof exports.PrivateCpuProfilerBindings.stopProfiling !== 'function') {
209
+ console.log('[Profiling] Native stopProfiling function is not available, ignoring call to stopProfiling.');
210
+ return null;
211
+ }
212
+ return exports.PrivateCpuProfilerBindings.stopProfiling(name, format, node_worker_threads_1.threadId, !!global._sentryDebugIds);
213
+ };
214
+ return Bindings;
215
+ }());
216
+ exports.CpuProfilerBindings = new Bindings();
217
+ __exportStar(require("./types"), exports);
package/lib/types.d.ts ADDED
@@ -0,0 +1,53 @@
1
+ export interface Sample {
2
+ stack_id: number;
3
+ thread_id: string;
4
+ elapsed_since_start_ns: string;
5
+ }
6
+ export interface ChunkSample {
7
+ stack_id: number;
8
+ thread_id: string;
9
+ timestamp: number;
10
+ }
11
+ export type Frame = {
12
+ function: string;
13
+ file: string;
14
+ lineno: number;
15
+ colno: number;
16
+ };
17
+ export interface Measurement {
18
+ unit: string;
19
+ values: {
20
+ elapsed_since_start_ns: number;
21
+ value: number;
22
+ }[];
23
+ }
24
+ export interface BaseProfile {
25
+ profile_id?: string;
26
+ stacks: number[][];
27
+ frames: Frame[];
28
+ resources: string[];
29
+ profiler_logging_mode: 'eager' | 'lazy';
30
+ measurements: Record<string, Measurement>;
31
+ }
32
+ export interface RawThreadCpuProfile extends BaseProfile {
33
+ samples: Sample[];
34
+ }
35
+ export interface RawChunkCpuProfile extends BaseProfile {
36
+ samples: ChunkSample[];
37
+ }
38
+ export interface PrivateV8CpuProfilerBindings {
39
+ startProfiling?: (name: string) => void;
40
+ stopProfiling?(name: string, format: ProfileFormat.THREAD, threadId: number, collectResources: boolean): RawThreadCpuProfile | null;
41
+ stopProfiling?(name: string, format: ProfileFormat.CHUNK, threadId: number, collectResources: boolean): RawChunkCpuProfile | null;
42
+ getFrameModule(abs_path: string): string;
43
+ }
44
+ export declare enum ProfileFormat {
45
+ THREAD = 0,
46
+ CHUNK = 1
47
+ }
48
+ export interface V8CpuProfilerBindings {
49
+ startProfiling(name: string): void;
50
+ stopProfiling(name: string, format: ProfileFormat.THREAD): RawThreadCpuProfile | null;
51
+ stopProfiling(name: string, format: ProfileFormat.CHUNK): RawChunkCpuProfile | null;
52
+ }
53
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,MAAM;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,sBAAsB,EAAE,MAAM,CAAC;CAChC;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,MAAM,KAAK,GAAG;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE;QACN,sBAAsB,EAAE,MAAM,CAAC;QAC/B,KAAK,EAAE,MAAM,CAAC;KACf,EAAE,CAAC;CACL;AAED,MAAM,WAAW,WAAW;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC;IACnB,MAAM,EAAE,KAAK,EAAE,CAAC;IAChB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,qBAAqB,EAAE,OAAO,GAAG,MAAM,CAAC;IACxC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;CAC3C;AACD,MAAM,WAAW,mBAAoB,SAAQ,WAAW;IACtD,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,MAAM,WAAW,kBAAmB,SAAQ,WAAW;IACrD,OAAO,EAAE,WAAW,EAAE,CAAC;CACxB;AAED,MAAM,WAAW,4BAA4B;IAC3C,cAAc,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAExC,aAAa,CAAC,CACZ,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,aAAa,CAAC,MAAM,EAC5B,QAAQ,EAAE,MAAM,EAChB,gBAAgB,EAAE,OAAO,GACxB,mBAAmB,GAAG,IAAI,CAAC;IAC9B,aAAa,CAAC,CACZ,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,aAAa,CAAC,KAAK,EAC3B,QAAQ,EAAE,MAAM,EAChB,gBAAgB,EAAE,OAAO,GACxB,kBAAkB,GAAG,IAAI,CAAC;IAG7B,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC;CAC1C;AAED,oBAAY,aAAa;IACvB,MAAM,IAAI;IACV,KAAK,IAAI;CACV;AAED,MAAM,WAAW,qBAAqB;IACpC,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAEnC,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,CAAC,MAAM,GAAG,mBAAmB,GAAG,IAAI,CAAC;IACtF,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,CAAC,KAAK,GAAG,kBAAkB,GAAG,IAAI,CAAC;CACrF"}
package/lib/types.js ADDED
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ProfileFormat = void 0;
4
+ var ProfileFormat;
5
+ (function (ProfileFormat) {
6
+ ProfileFormat[ProfileFormat["THREAD"] = 0] = "THREAD";
7
+ ProfileFormat[ProfileFormat["CHUNK"] = 1] = "CHUNK";
8
+ })(ProfileFormat || (exports.ProfileFormat = ProfileFormat = {}));
package/package.json ADDED
@@ -0,0 +1,68 @@
1
+ {
2
+ "name": "@sentry/node-cpu-profiler",
3
+ "version": "2.4.2",
4
+ "description": "Binaries for Sentry Node Profiling",
5
+ "repository": "git://github.com/getsentry/sentry-javascript-profiling-node-binaries.git",
6
+ "homepage": "https://github.com/getsentry/sentry-javascript/tree/master/packages/profiling-node",
7
+ "author": "Sentry",
8
+ "license": "MIT",
9
+ "main": "lib/index.js",
10
+ "types": "lib/index.d.ts",
11
+ "engines": {
12
+ "node": ">=18"
13
+ },
14
+ "publishConfig": {
15
+ "access": "public"
16
+ },
17
+ "files": [
18
+ "/lib",
19
+ "/bindings",
20
+ "/binding.gyp",
21
+ "package.json",
22
+ "/scripts/binaries.js",
23
+ "/scripts/check-build.js",
24
+ "/scripts/copy-target.js"
25
+ ],
26
+ "scripts": {
27
+ "install": "node scripts/check-build.js",
28
+ "clean": "rm -rf build && rm -rf lib",
29
+ "lint": "yarn lint:eslint && yarn lint:clang",
30
+ "lint:eslint": "eslint . --format stylish",
31
+ "lint:clang": "node scripts/clang-format.js",
32
+ "fix": "yarn fix:eslint && yarn fix:clang",
33
+ "fix:eslint": "eslint . --format stylish --fix",
34
+ "fix:clang": "node scripts/clang-format.js --fix",
35
+ "build": "yarn build:lib && yarn build:bindings:configure && yarn build:bindings",
36
+ "build:lib": "tsc",
37
+ "build:bindings:configure": "node-gyp configure",
38
+ "build:bindings:configure:arm64": "node-gyp configure --arch=arm64 --target_arch=arm64",
39
+ "build:bindings": "node-gyp build && node scripts/copy-target.js",
40
+ "build:bindings:arm64": "node-gyp build --arch=arm64 && node scripts/copy-target.js",
41
+ "build:dev": "yarn clean && yarn build:bindings:configure && yarn build",
42
+ "build:tarball": "npm pack",
43
+ "test": "yarn test:bindings && yarn test:bundling && yarn test:electron",
44
+ "test:bundling": "node test/prepare.mjs bundler && vitest run --testTimeout 60000 ./test/bundler",
45
+ "test:electron": "node test/prepare.mjs electron && vitest run --testTimeout 120000 ./test/electron",
46
+ "test:bindings": "node test/prepare.mjs bindings && vitest run --testTimeout 60000 ./test/bindings"
47
+ },
48
+ "dependencies": {
49
+ "detect-libc": "^2.0.3",
50
+ "node-abi": "^3.73.0"
51
+ },
52
+ "devDependencies": {
53
+ "@sentry-internal/eslint-config-sdk": "^8.51.0",
54
+ "@types/node": "^18.19.1",
55
+ "@types/node-abi": "^3.0.3",
56
+ "clang-format": "^1.8.0",
57
+ "cross-env": "^7.0.3",
58
+ "eslint": "^7.0.0",
59
+ "node-gyp": "^11.2.0",
60
+ "typescript": "^5.7.3",
61
+ "vitest": "^3.0.5"
62
+ },
63
+ "sideEffects": false,
64
+ "volta": {
65
+ "node": "24.0.0",
66
+ "yarn": "1.22.22"
67
+ }
68
+ }
@@ -0,0 +1,27 @@
1
+ const os = require('os');
2
+ const path = require('path');
3
+
4
+ const abi = require('node-abi');
5
+ const libc = require('detect-libc');
6
+
7
+ function getModuleName() {
8
+ const stdlib = libc.familySync();
9
+ const platform = process.env['BUILD_PLATFORM'] || os.platform();
10
+ const arch = process.env['BUILD_ARCH'] || os.arch();
11
+
12
+ if (platform === 'darwin' && arch === 'arm64') {
13
+ const identifier = [platform, 'arm64', abi.getAbi(process.versions.node, 'node')].filter(Boolean).join('-');
14
+ return `sentry_cpu_profiler-${identifier}.node`;
15
+ }
16
+
17
+ const identifier = [platform, arch, stdlib, abi.getAbi(process.versions.node, 'node')].filter(Boolean).join('-');
18
+
19
+ return `sentry_cpu_profiler-${identifier}.node`;
20
+ }
21
+
22
+ const source = path.join(__dirname, '..', 'build', 'Release', 'sentry_cpu_profiler.node');
23
+ const target = path.join(__dirname, '..', 'lib', getModuleName());
24
+
25
+ module.exports.source = source;
26
+ module.exports.target = target;
27
+ module.exports.getModuleName = getModuleName;
@@ -0,0 +1,57 @@
1
+ // This is a build script, so some logging is desirable as it allows
2
+ // us to follow the code path that triggered the error.
3
+ /* eslint-disable no-console */
4
+ const fs = require('fs');
5
+ const child_process = require('child_process');
6
+
7
+ const binaries = require('./binaries.js');
8
+
9
+ function clean(err) {
10
+ return err.toString().trim();
11
+ }
12
+
13
+ function recompileFromSource() {
14
+ console.log('@sentry/profiling-node: Compiling from source...');
15
+ let spawn = child_process.spawnSync('npm', ['run', 'build:bindings:configure'], {
16
+ stdio: ['inherit', 'inherit', 'pipe'],
17
+ env: process.env,
18
+ shell: true,
19
+ });
20
+
21
+ if (spawn.status !== 0) {
22
+ console.log('@sentry/profiling-node: Failed to configure gyp');
23
+ console.log('@sentry/profiling-node:', clean(spawn.stderr));
24
+ return;
25
+ }
26
+
27
+ spawn = child_process.spawnSync('npm', ['run', 'build:bindings'], {
28
+ stdio: ['inherit', 'inherit', 'pipe'],
29
+ env: process.env,
30
+ shell: true,
31
+ });
32
+ if (spawn.status !== 0) {
33
+ console.log('@sentry/profiling-node: Failed to build bindings');
34
+ console.log('@sentry/profiling-node:', clean(spawn.stderr));
35
+ return;
36
+ }
37
+ }
38
+
39
+ if (fs.existsSync(binaries.target)) {
40
+ try {
41
+ console.log(`@sentry/profiling-node: Precompiled binary found, attempting to load ${binaries.target}`);
42
+ require(binaries.target);
43
+ console.log('@sentry/profiling-node: Precompiled binary found, skipping build from source.');
44
+ } catch (e) {
45
+ console.log('@sentry/profiling-node: Precompiled binary found but failed loading');
46
+ console.log('@sentry/profiling-node:', e);
47
+ try {
48
+ recompileFromSource();
49
+ } catch (e) {
50
+ console.log('@sentry/profiling-node: Failed to compile from source');
51
+ throw e;
52
+ }
53
+ }
54
+ } else {
55
+ console.log('@sentry/profiling-node: No precompiled binary found');
56
+ recompileFromSource();
57
+ }
@@ -0,0 +1,28 @@
1
+ // This is a build script, so some logging is desirable as it allows
2
+ // us to follow the code path that triggered the error.
3
+ /* eslint-disable no-console */
4
+ const fs = require('fs');
5
+ const path = require('path');
6
+ const process = require('process');
7
+
8
+ const binaries = require('./binaries.js');
9
+
10
+ const build = path.resolve(__dirname, '..', 'lib');
11
+
12
+ if (!fs.existsSync(build)) {
13
+ fs.mkdirSync(build, { recursive: true });
14
+ }
15
+
16
+ const source = path.join(__dirname, '..', 'build', 'Release', 'sentry_cpu_profiler.node');
17
+ const target = path.join(__dirname, '..', 'lib', binaries.getModuleName());
18
+
19
+ if (!fs.existsSync(source)) {
20
+ console.log('Source file does not exist:', source);
21
+ process.exit(1);
22
+ } else {
23
+ if (fs.existsSync(target)) {
24
+ console.log('Target file already exists, overwriting it');
25
+ }
26
+ console.log('Renaming', source, 'to', target);
27
+ fs.renameSync(source, target);
28
+ }