-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added tests and example for v8 profile converter
- Loading branch information
Showing
11 changed files
with
6,662 additions
and
46 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
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.