asynctrace
Advanced tools
Comparing version 1.0.5 to 1.0.6
@@ -19,5 +19,5 @@ { | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "mocha --require ." | ||
}, | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"dependencies": { | ||
@@ -27,2 +27,3 @@ "shimmer": "" | ||
"devDependencies": { | ||
"chai": "latest", | ||
"istanbul": "latest", | ||
@@ -29,0 +30,0 @@ "mocha": "latest" |
@@ -5,1 +5,94 @@ asynctrace | ||
Deep stack traces based on AsyncListener API | ||
[![Build Status](https://travis-ci.org/Empeeric/asynctrace.png?branch=master "Build Status")](https://travis-ci.org/Empeeric/asynctrace) | ||
## Install | ||
You know the drill | ||
``` | ||
npm i asynctrace --save-dev | ||
``` | ||
## Example Usage | ||
```js | ||
// simply require, somewhere near the process entry point | ||
require('asynctrace') | ||
``` | ||
specificaly made compatible with mocha | ||
``` | ||
mocha --require asynctrace | ||
``` | ||
## Example | ||
for this code: | ||
``` | ||
'use strict'; | ||
require('asynctrace') | ||
setImmediate(function a() { | ||
setImmediate(function b() { | ||
setImmediate(function c() { | ||
setImmediate(function d() { | ||
setImmediate(function e() { | ||
throw new Error('gaga'); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
``` | ||
You'll get the following stack trace: | ||
``` | ||
throw new Error('gaga'); | ||
^ | ||
Error: gaga | ||
at Immediate.e [as _onImmediate] (C:\projects\trowExample\trowwer.js:9:27) | ||
at processImmediate [as _immediateCallback] (timers.js:374:17) | ||
- - - - - - async boundary - - - - - - | ||
at Immediate.d [as _onImmediate] (C:\projects\trowExample\trowwer.js:8:17) | ||
- - - - - - async boundary - - - - - - | ||
at Immediate.c [as _onImmediate] (C:\projects\trowExample\trowwer.js:7:13) | ||
- - - - - - async boundary - - - - - - | ||
at Immediate.b [as _onImmediate] (C:\projects\trowExample\trowwer.js:6:9) | ||
- - - - - - async boundary - - - - - - | ||
at Immediate.a [as _onImmediate] (C:\projects\trowExample\trowwer.js:5:5) | ||
- - - - - - async boundary - - - - - - | ||
at Object.<anonymous> (C:\projects\trowExample\trowwer.js:4:1) | ||
- - - - - - async boundary - - - - - - | ||
``` | ||
## Performance | ||
There is a performance price with user AsyncListner, but we were able to minimize it. For example here are timing on running the full visionmedia/express test suite: | ||
``` | ||
[10:50:28 /empeeric/3party/express] time mocha --require asynctrace --require test/support/env --reporter dot --check-leaks test/ test/acceptance/ | ||
............................................................................................................... | ||
................................................................................................................ | ||
................................................................................................................ | ||
................................................................................................................ | ||
.................................................................. | ||
513 passing (7s) | ||
real 0m8.061s | ||
user 0m0.045s | ||
sys 0m0.075s | ||
[10:50:41 /empeeric/3party/express] time mocha --require test/support/env --reporter dot --check-leaks test/ test/acceptance/ | ||
............................................................................................................... | ||
................................................................................................................ | ||
................................................................................................................ | ||
................................................................................................................ | ||
.................................................................. | ||
513 passing (5s) | ||
real 0m6.314s | ||
user 0m0.030s | ||
sys 0m0.075s | ||
``` |
22
trace.js
'use strict'; | ||
var verParts = process.version.split(/\.|-/g); | ||
if (verParts[1] < 11 || verParts[2] < 12) { | ||
console.error("asynctrace needs node at least of version 0.11.12 to work"); | ||
console.error("So it'll do nothing here :("); | ||
return; | ||
} | ||
var tracing = require('tracing'); | ||
var util = require('util'); | ||
var prefix = process.cwd().toLowerCase(); | ||
var sep = require('path').sep; | ||
@@ -44,4 +52,13 @@ var BOUNDRY = ' - - - - - - async boundary - - - - - -'; | ||
var sep = require('path').sep; | ||
function isInteresting(callSite) { | ||
var name = callSite && callSite.getFileName(); | ||
if (!name) return false; | ||
name = name.toLowerCase(); | ||
if (!~name.indexOf(sep)) return false; | ||
if (name.indexOf(prefix) != 0) return false; | ||
if (~name.replace(prefix, '').indexOf('node_modules')) return false; | ||
return true; | ||
} | ||
function reducer(seed, callSite) { | ||
@@ -52,4 +69,3 @@ if (typeof callSite == 'string') { | ||
} | ||
var name = callSite && callSite.getFileName(); | ||
if (name && !~name.indexOf('node_modules') && ~name.indexOf(sep)) seed.push(callSite); | ||
if (isInteresting(callSite)) seed.push(callSite); | ||
return seed; | ||
@@ -56,0 +72,0 @@ } |
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
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
12570
9
204
1
98
3