-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #197 from slonka/visualize-v8-profile
Add support for visualizing v8 profile
- Loading branch information
Showing
17 changed files
with
6,739 additions
and
57 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.DS_Store | ||
node_modules | ||
*.0x | ||
.__browserify_string_empty.js | ||
win | ||
todo | ||
.vscode | ||
flamegraph.html | ||
v8-profile.json |
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,14 @@ | ||
# 0x-visualize-v8-profile-example | ||
|
||
You need curl installed. This will probably work on linux and macOS. | ||
|
||
Running: | ||
|
||
```bash | ||
npm i | ||
./test.sh | ||
``` | ||
|
||
Then open flamegraph.html, click on `v8` button and you should see something like this: | ||
|
||
![flamegraph](flamegraph.png) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,36 @@ | ||
const v8Profiler = require('v8-profiler-next') | ||
const Koa = require('koa') | ||
const Router = require('koa-router') | ||
const fs = require('fs') | ||
const { promisify } = require('util') | ||
|
||
const writeFile = promisify(fs.writeFile) | ||
|
||
let app = new Koa() | ||
let router = new Router() | ||
|
||
router.get('/', (ctx, next) => { | ||
// ctx.router available | ||
ctx.body = 'ok' | ||
}) | ||
|
||
router.get('/start-profiling', (ctx, next) => { | ||
v8Profiler.startProfiling('p1') | ||
ctx.body = 'started' | ||
}) | ||
|
||
router.get('/stop-profiling', async (ctx, next) => { | ||
const result = v8Profiler.stopProfiling('p1') | ||
if (result) { | ||
await writeFile('./v8-profile.json', JSON.stringify(result)) | ||
ctx.body = 'saved profile' | ||
} else { | ||
ctx.body = 'nothing to show' | ||
} | ||
}) | ||
|
||
app | ||
.use(router.routes()) | ||
.use(router.allowedMethods()) | ||
|
||
app.listen(3000) |
Oops, something went wrong.