-
-
Notifications
You must be signed in to change notification settings - Fork 360
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: gather process tree information (#364)
* feat: gather process tree information Add a `--show-process-tree` that shows a pretty tree of all spawned processes after `nyc` has run. The data files for that are stored in `processinfo` are stored in `(temp directory)/processinfo` so that they don’t interfere with the fixed format of the coverage files. Fixes: #158 * [squash] cleanup: make ProcessTree instances nodes of the tree themselves This is in preparation for per-subtree coverage at some point. * [squash] add short section about --show-process-tree to readme
- Loading branch information
Showing
9 changed files
with
267 additions
and
12 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
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
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,64 @@ | ||
'use strict' | ||
var archy = require('archy') | ||
|
||
function ProcessInfo (defaults) { | ||
defaults = defaults || {} | ||
|
||
this.pid = String(process.pid) | ||
this.argv = process.argv | ||
this.execArgv = process.execArgv | ||
this.cwd = process.cwd() | ||
this.time = Date.now() | ||
this.ppid = null | ||
this.root = null | ||
this.coverageFilename = null | ||
this.nodes = [] // list of children, filled by buildProcessTree() | ||
|
||
for (var key in defaults) { | ||
this[key] = defaults[key] | ||
} | ||
} | ||
|
||
Object.defineProperty(ProcessInfo.prototype, 'label', { | ||
get: function () { | ||
if (this._label) { | ||
return this._label | ||
} | ||
|
||
return this.argv.join(' ') | ||
} | ||
}) | ||
|
||
ProcessInfo.buildProcessTree = function (infos) { | ||
var treeRoot = new ProcessInfo({ _label: 'nyc' }) | ||
var nodes = { } | ||
|
||
infos = infos.sort(function (a, b) { | ||
return a.time - b.time | ||
}) | ||
|
||
infos.forEach(function (p) { | ||
nodes[p.root + ':' + p.pid] = p | ||
}) | ||
|
||
infos.forEach(function (p) { | ||
if (!p.ppid) { | ||
return | ||
} | ||
|
||
var parent = nodes[p.root + ':' + p.ppid] | ||
if (!parent) { | ||
parent = treeRoot | ||
} | ||
|
||
parent.nodes.push(p) | ||
}) | ||
|
||
return treeRoot | ||
} | ||
|
||
ProcessInfo.prototype.render = function () { | ||
return archy(this) | ||
} | ||
|
||
module.exports = ProcessInfo |
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 |
---|---|---|
|
@@ -72,6 +72,7 @@ | |
"author": "Ben Coe <[email protected]>", | ||
"license": "ISC", | ||
"dependencies": { | ||
"archy": "^1.0.0", | ||
"arrify": "^1.0.1", | ||
"caching-transform": "^1.0.0", | ||
"convert-source-map": "^1.3.0", | ||
|
@@ -124,6 +125,7 @@ | |
"url": "[email protected]:istanbuljs/nyc.git" | ||
}, | ||
"bundledDependencies": [ | ||
"archy", | ||
"arrify", | ||
"caching-transform", | ||
"convert-source-map", | ||
|
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,30 @@ | ||
'use strict'; | ||
var cp = require('child_process'); | ||
|
||
var index = +process.argv[2] || 0 | ||
if (index <= 1) { | ||
console.log(0) | ||
return | ||
} | ||
if (index == 2) { | ||
console.log(1) | ||
return | ||
} | ||
|
||
function getFromChild(n, cb) { | ||
var proc = cp.spawn(process.execPath, [__filename, n]) | ||
var stdout = '' | ||
proc.stdout.on('data', function (data) { stdout += data }) | ||
proc.on('close', function () { | ||
cb(null, +stdout) | ||
}) | ||
proc.on('error', cb) | ||
} | ||
|
||
getFromChild(index - 1, function(err, result1) { | ||
if (err) throw err | ||
getFromChild(index - 2, function(err, result2) { | ||
if (err) throw err | ||
console.log(result1 + result2) | ||
}) | ||
}) |
Oops, something went wrong.