heimdalljs-fs-monitor
Advanced tools
Comparing version 1.1.0 to 1.1.1
@@ -1,8 +0,15 @@ | ||
# 1.1.0 | ||
## 1.1.1 | ||
- add opt-in ability to get file location trigger fs operations via `process.env.HEIMDALL_FS_MONITOR_CALL_TRACING = 1; | ||
` | ||
# 1.0.0 | ||
#### :bug: Bug Fixes | ||
* [#153](https://github.com/heimdalljs/heimdalljs/pull/153) Monitor realpath.native ([@hjdivad](https://github.com/hjdivad)) | ||
Previously when monitoring `realpath` and `realpathSync` would be replaced by functions that lacked the corresponding `.native` property. `realpath.native` and `realpathSync.native` are now included when monitoring and are themselves monitored. | ||
## 1.1.0 | ||
- add opt-in ability to get file location trigger fs operations via `process.env.HEIMDALL_FS_MONITOR_CALL_TRACING = 1; ` | ||
## 1.0.0 | ||
- remove node@6 support | ||
- adds invocation data behind a flag to know where fs calls are coming from |
117
index.js
@@ -27,3 +27,3 @@ 'use strict'; | ||
'Stats', | ||
'WriteStream' | ||
'WriteStream', | ||
]; | ||
@@ -33,3 +33,5 @@ } | ||
get captureTracing() { | ||
return parseInt(process.env.HEIMDALL_FS_MONITOR_CALL_TRACING) === 1 || false | ||
return ( | ||
parseInt(process.env.HEIMDALL_FS_MONITOR_CALL_TRACING) === 1 || false | ||
); | ||
} | ||
@@ -43,5 +45,7 @@ | ||
} else { | ||
logger.warn('Multiple instances of heimdalljs-fs-monitor have been created' | ||
+ ' in the same session. Since this can cause fs operations to be counted' | ||
+ ' multiple times, this instance has been disabled.'); | ||
logger.warn( | ||
'Multiple instances of heimdalljs-fs-monitor have been created' + | ||
' in the same session. Since this can cause fs operations to be counted' + | ||
' multiple times, this instance has been disabled.' | ||
); | ||
} | ||
@@ -68,3 +72,3 @@ } | ||
let metrics = heimdall.statsFor('fs'); | ||
let m = metrics[name] = metrics[name] || new Metric(); | ||
let m = (metrics[name] = metrics[name] || new Metric()); | ||
@@ -81,22 +85,17 @@ m.start(location); | ||
_attach() { | ||
_attachMember(parent, member, old, name = member) { | ||
let monitor = this; | ||
parent[member] = (function (old, member) { | ||
return function () { | ||
if (monitor.shouldMeasure()) { | ||
let args = new Array(arguments.length); | ||
for (let i = 0; i < arguments.length; i++) { | ||
args[i] = arguments[i]; | ||
} | ||
for (let member in fs) { | ||
if (this.blacklist.indexOf(member) === -1) { | ||
let old = fs[member]; | ||
if (typeof old === 'function') { | ||
fs[member] = (function(old, member) { | ||
return function() { | ||
if (monitor.shouldMeasure()) { | ||
let args = new Array(arguments.length); | ||
for (let i = 0; i < arguments.length; i++) { | ||
args[i] = arguments[i]; | ||
} | ||
let location; | ||
let location; | ||
if(monitor.captureTracing) { | ||
try { | ||
/* | ||
if (monitor.captureTracing) { | ||
try { | ||
/* | ||
Uses error to build a stack of where the fs call was coming from. | ||
@@ -121,25 +120,41 @@ | ||
*/ | ||
const error = new Error(); | ||
const calls = callsites(); | ||
const error = new Error(); | ||
const calls = callsites(); | ||
location = { | ||
fileName: calls[1].getFileName(), | ||
lineNumber: calls[1].getLineNumber(), | ||
stackTrace: cleanStack(extractStack(error), { pretty: true }), | ||
} | ||
} catch(ex) { | ||
debug(`could not generate stack because: ${ex.message}`) | ||
} | ||
} | ||
location = { | ||
fileName: calls[1].getFileName(), | ||
lineNumber: calls[1].getLineNumber(), | ||
stackTrace: cleanStack(extractStack(error), { | ||
pretty: true, | ||
}), | ||
}; | ||
} catch (ex) { | ||
debug(`could not generate stack because: ${ex.message}`); | ||
} | ||
} | ||
return monitor._measure(member, old, fs, args, location); | ||
} else { | ||
return old.apply(fs, arguments); | ||
} | ||
}; | ||
}(old, member)); | ||
return monitor._measure(name, old, fs, args, location); | ||
} else { | ||
return old.apply(fs, arguments); | ||
} | ||
}; | ||
})(old, member); | ||
fs[member].__restore = function() { | ||
fs[member] = old; | ||
}; | ||
parent[member].__restore = function () { | ||
parent[member] = old; | ||
}; | ||
return parent[member]; | ||
} | ||
_attach() { | ||
for (let member in fs) { | ||
if (this.blacklist.indexOf(member) === -1) { | ||
let old = fs[member]; | ||
if (typeof old === 'function') { | ||
let monitored = this._attachMember(fs, member, old); | ||
if ('native' in old) { | ||
this._attachMember(monitored, 'native', old, `${member}.native`); | ||
} | ||
} | ||
@@ -153,3 +168,6 @@ } | ||
let maybeFunction = fs[member]; | ||
if (typeof maybeFunction === 'function' && typeof maybeFunction.__restore === 'function') { | ||
if ( | ||
typeof maybeFunction === 'function' && | ||
typeof maybeFunction.__restore === 'function' | ||
) { | ||
maybeFunction.__restore(); | ||
@@ -178,4 +196,4 @@ } | ||
// we want to push all the locations of our invocations to an array | ||
if(location) { | ||
if(!this.invocations[location.stackTrace]) { | ||
if (location) { | ||
if (!this.invocations[location.stackTrace]) { | ||
this.invocations[location.stackTrace] = { | ||
@@ -185,3 +203,3 @@ lineNumber: location.lineNumber, | ||
count: 0, | ||
} | ||
}; | ||
} | ||
@@ -198,3 +216,4 @@ this.invocations[location.stackTrace].count += 1; | ||
this.time += (now[0] - this.startTime[0]) * 1e9 + (now[1] - this.startTime[1]); | ||
this.time += | ||
(now[0] - this.startTime[0]) * 1e9 + (now[1] - this.startTime[1]); | ||
this.startTime = undefined; | ||
@@ -207,5 +226,5 @@ } | ||
count: this.count, | ||
time: this.time | ||
time: this.time, | ||
}; | ||
} | ||
} |
{ | ||
"name": "heimdalljs-fs-monitor", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "fs operation monitoring for heimdalljs", | ||
@@ -29,4 +29,4 @@ "main": "index.js", | ||
"debug": "^4.1.1", | ||
"mocha": "^7.1.2" | ||
"mocha": "^9.1.1" | ||
} | ||
} |
@@ -5,5 +5,4 @@ # heimdall-fs-monitor | ||
file system monitor plugin for [heimdalljs](https://github.com/heimdalljs/heimdalljs-lib) | ||
file system monitor plugin for [heimdalljs](https://github.com/heimdalljs/heimdalljs) | ||
## Installation | ||
@@ -77,4 +76,4 @@ | ||
## License | ||
## License | ||
`heimdall-fs-monitor` is licensed under the [ISC License](https://opensource.org/licenses/isc-license.txt). |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10479
188
78