Skip to content

Commit

Permalink
Added tests and example for v8 profile converter
Browse files Browse the repository at this point in the history
  • Loading branch information
slonka committed Nov 12, 2018
1 parent a9c848c commit 3621d22
Show file tree
Hide file tree
Showing 11 changed files with 6,662 additions and 46 deletions.
9 changes: 9 additions & 0 deletions examples/v8-profiler/.gitignore
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
14 changes: 14 additions & 0 deletions examples/v8-profiler/README.md
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)
Binary file added examples/v8-profiler/flamegraph.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 36 additions & 0 deletions examples/v8-profiler/index.js
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)
Loading

0 comments on commit 3621d22

Please sign in to comment.