This repository has been archived by the owner on Sep 17, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
94 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
|
||
coverage/ | ||
lib/ | ||
binaries/ | ||
|
||
node_modules/ | ||
memory_db | ||
|
Binary file not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* eslint-env node */ | ||
const os = require('os'); | ||
const path = require('path'); | ||
const abi = require('node-abi'); | ||
|
||
function getModuleName() { | ||
return `sentry_cpu_profiler-v${abi.getAbi(process.versions.node, 'node')}-${os.platform()}-${os.arch()}.node`; | ||
} | ||
|
||
const source = path.join(__dirname, '..', 'build', 'Release', 'sentry_cpu_profiler.node'); | ||
const target = path.join(__dirname, '..', 'binaries', getModuleName()); | ||
|
||
module.exports.target = target; | ||
module.exports.source = source; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* eslint-env node */ | ||
const cp = require('child_process'); | ||
const os = require('os'); | ||
|
||
const { target } = require('./binaries'); | ||
|
||
function recompileFromSource() { | ||
try { | ||
console.log('@sentry/profiling-node: Precompiled binary not found, compiling from source...'); | ||
cp.execSync(`npm run build:configure --arch=${os.arch()}`); | ||
cp.execSync(`npm run build:bindings`); | ||
cp.execSync('node scripts/copy-target.js'); | ||
return true; | ||
} catch (e) { | ||
console.error( | ||
'@sentry/profiling-node: Failed to build from source, please report this a bug at https://github.com/getsentry/profiling-node/issues/new?assignees=&labels=Type%3A+Bug&template=bug.yml' | ||
); | ||
return false; | ||
} | ||
} | ||
|
||
try { | ||
require(target); | ||
console.log('@sentry/profiling-node: Precompiled binary found, skipping build from source.'); | ||
} catch (e) { | ||
// Check for node version missmatch | ||
if (/was compiled against a different Node.js/.test(e.message)) { | ||
const success = recompileFromSource(); | ||
if (success) { | ||
process.exit(0); | ||
} | ||
} | ||
// Not sure if this could even happen, but just in case it somehow does, | ||
// we can provide a better experience than just crashing with cannot find module message. | ||
if (/Cannot find module/.test(e.message)) { | ||
const success = recompileFromSource(); | ||
if (success) { | ||
process.exit(0); | ||
} | ||
} | ||
|
||
// re-throw so we dont end up swallowing errors | ||
throw e; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import * as Sentry from '@sentry/node'; | ||
import '@sentry/tracing'; // this has a addExtensionMethods side effect | ||
import { ProfilingIntegration } from './index'; // this has a addExtensionMethods side effect | ||
import { importCppBindingsModule } from './cpu_profiler'; | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/6625302', | ||
|
@@ -11,8 +12,7 @@ Sentry.init({ | |
integrations: [new ProfilingIntegration()] | ||
}); | ||
|
||
// @ts-expect-error file extension errors | ||
import profiler from './../build/Release/sentry_cpu_profiler'; | ||
const profiler = importCppBindingsModule(); | ||
|
||
describe('hubextensions', () => { | ||
beforeEach(() => { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters