summaryrefslogtreecommitdiff
path: root/doc/api/inspector.md
diff options
context:
space:
mode:
authorAli Ijaz Sheikh <ofrobots@google.com>2018-03-06 09:08:47 -0800
committerAli Ijaz Sheikh <ofrobots@google.com>2018-03-07 17:00:31 -0800
commitfbf7ff92d7f7a7f63ad4649519e8316d90b04826 (patch)
tree86340fb883125eb712ba1cc7e686dbf7c0bd138b /doc/api/inspector.md
parent50b1cb39bd11811866b77b74b2822620aeb405cb (diff)
downloadandroid-node-v8-fbf7ff92d7f7a7f63ad4649519e8316d90b04826.tar.gz
android-node-v8-fbf7ff92d7f7a7f63ad4649519e8316d90b04826.tar.bz2
android-node-v8-fbf7ff92d7f7a7f63ad4649519e8316d90b04826.zip
doc: add inspector usage example
Add a simple example showing how to use the inspector API to access the CPU profiler. PR-URL: https://github.com/nodejs/node/pull/19172 Reviewed-By: Eugene Ostroukhov <eostroukhov@google.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Khaidi Chu <i@2333.moe>
Diffstat (limited to 'doc/api/inspector.md')
-rw-r--r--doc/api/inspector.md26
1 files changed, 26 insertions, 0 deletions
diff --git a/doc/api/inspector.md b/doc/api/inspector.md
index b6f702f0dd..c801510b75 100644
--- a/doc/api/inspector.md
+++ b/doc/api/inspector.md
@@ -136,8 +136,34 @@ with an error. [`session.connect()`] will need to be called to be able to send
messages again. Reconnected session will lose all inspector state, such as
enabled agents or configured breakpoints.
+## Example usage
+
+### CPU Profiler
+
+Apart from the debugger, various V8 Profilers are available through the DevTools
+protocol. Here's a simple example showing how to use the [CPU profiler][]:
+
+```js
+const inspector = require('inspector');
+
+const session = new inspector.Session();
+session.connect();
+
+session.post('Profiler.enable', () => {
+ session.post('Profiler.start', () => {
+ // invoke business logic under measurement here...
+
+ // some time later...
+ session.post('Profiler.stop', ({ profile }) => {
+ // write profile to disk, upload, etc.
+ });
+ });
+});
+```
+
[`session.connect()`]: #inspector_session_connect
[`Debugger.paused`]: https://chromedevtools.github.io/devtools-protocol/v8/Debugger/#event-paused
[`EventEmitter`]: events.html#events_class_eventemitter
[Chrome DevTools Protocol Viewer]: https://chromedevtools.github.io/devtools-protocol/v8/
+[CPU Profiler]: https://chromedevtools.github.io/devtools-protocol/v8/Profiler