Skip to content

Commit

Permalink
make piping work, add readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Swatinem committed Oct 28, 2013
1 parent 1186f53 commit 4ccf23b
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 9 deletions.
1 change: 1 addition & 0 deletions .npmignore
Expand Up @@ -10,3 +10,4 @@ Makefile
.travis.yml
perf.data*
*.cpuprofile
example.png
25 changes: 23 additions & 2 deletions README.md
Expand Up @@ -8,12 +8,33 @@ Converts linux `perf` tool output to .cpuprofile files readable by chromiums dev

## Installation

$ npm install perf-cpuprofile
$ npm install -g perf-cpuprofile

## Usage

Generate a `perf` trace:

$ perf record -p `pidof sourceview` -g dwarf

Then simply run:

$ perf-cpuprofile

Or if you have custom file names or just love to pipe:

$ cat custom.perf.data | perf script | perf-cpuprofile -- > custom.cpuprofile

Calling `perf-cpuprofile` with the argument `--` makes it output to stdout instead
of writing to the default `perf.cpuprofile` file.

Then just open up the file in chromiums devtools profile tab, and voilà:

![chromiums profiler next to perf](example.png?raw=true)

It still has some issues with unresolvable functions and finding the callers for
`_mcount`, but overall, I’m very happy with it :-)

## License

LGPLv3
GPLv3

17 changes: 13 additions & 4 deletions bin/_perf-cpuprofile.js
@@ -1,10 +1,19 @@
#!/usr/bin/env node

var spawn = require('child_process').spawn;
var write = require('fs').writeFileSync;
var perfCpuprofile = require('../');

// TODO: detect if we are running through a pipe, and automatically
// pipe through `perf script` into `perf.cpuprofile` if not
var input = process.stdin;
if (input.isTTY) {
var perf = spawn('perf', ['script']);
input = perf.stdout;
}

perfCpuprofile(process.stdin, function (profile) {
console.log(JSON.stringify(profile));
perfCpuprofile(input, function (profile) {
var out = JSON.stringify(profile);
if (process.argv[2] == '--')
console.log(out);
else
write('perf.cpuprofile', out);
});
4 changes: 2 additions & 2 deletions bin/perf-cpuprofile.js
Expand Up @@ -4,6 +4,6 @@
// We need this so we can actually pass `--harmony` to the real process

var spawn = require('child_process').spawn
, args = [ __dirname + '/_perf-cpuprofile.js' ];
, args = [ __dirname + '/_perf-cpuprofile.js' ].concat(process.argv.slice(2));

spawn(process.argv[0], ['--harmony'].concat(args), { customFds: [0,1,2] });
spawn(process.argv[0], ['--harmony'].concat(args), {stdio: [0,1,2]});
Binary file added example.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -4,7 +4,7 @@
"version": "0.0.1",
"keywords": [],
"bin": {
"perfcpuprofile": "./bin/perfcpuprofile.js"
"perf-cpuprofile": "./bin/perf-cpuprofile.js"
},
"main": "./index",
"maintainers": [
Expand Down

0 comments on commit 4ccf23b

Please sign in to comment.