Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minimize blocking file system activity (existSync()) in _postLoad() #84

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions lib/shimmer.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ var path = require('path')

var CORE_INSTRUMENTATION = {http : 'http.js', https : 'http.js'};

/**
* Store an array of .js instrumentation files to minimize
* blocking file system activity in _postLoad()
*/
var notCoreInstrumentation = fs.readdirSync(path.join(__dirname, 'instrumentation'))
.filter(function (name) {return path.extname(name) === '.js'});

/**
* Unwrapping is only likely to be used by test code, and is a fairly drastic
* maneuver, but it should be pretty safe if there's a desire to reboot the
Expand Down Expand Up @@ -42,8 +49,11 @@ function instrument(agent, shortName, fileName, nodule) {
}

function _postLoad(agent, nodule, name) {
// necessary to prevent instrument() from causing an infinite loop
if (path.extname(name) !== '.js') {
/**
* Necessary to prevent instrument() from causing an infinite loop.
* Also using notCoreInstrumentation array to minimize blocking file system activity (existsSync).
*/
if (path.extname(name) !== '.js' && notCoreInstrumentation.indexOf(name + '.js') !== -1) {
name = path.basename(name);
var filename = path.join(__dirname, 'instrumentation', name + '.js');

Expand Down