-
-
Notifications
You must be signed in to change notification settings - Fork 360
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
feat: gather process tree information #364
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should also add archy to the bundled dependency list. |
||
"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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for doing this, would like us to get in the habit of splitting this repo into more modules.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need to add
process.js
to the list of files in./build-self-covered.js
, and should it be added to our exclude rules in the packages.json, I noticedindex.covered.js
is.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, yeah, but it is? I did change
build-self-coverage.js
here, and both.gitignore
and thefiles
field of thepackage.json
contain rules to exclude any*covered.js
file.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@addaleax shoot, missed the updated build-coverage, ignore me!