This repository has been archived by the owner on Apr 22, 2023. It is now read-only.
tracing: add v8 specific tracing api #6985
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
05635d1
src: update MakeCallback() function prototype
bnoordhuis 728f733
src: fix MakeCallback() handle leak
bnoordhuis cfea67f
src: add tracing.v8.on('gc') statistics hooks
bnoordhuis a453df4
src: add v8.getHeapStatistics() function
bnoordhuis 3c51577
doc: add tracing api
tjfontaine File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 |
---|---|---|
|
@@ -35,3 +35,4 @@ | |
@include debugger | ||
@include cluster | ||
@include smalloc | ||
@include tracing |
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,61 @@ | ||
# Tracing | ||
|
||
Stability: 1 - Experimental | ||
|
||
The tracing module is designed for instrumenting your Node application. It is | ||
not meant for general purpose use. | ||
|
||
***Be very careful with callbacks used in conjunction with this module*** | ||
|
||
Many of these callbacks interact directly with asynchronous subsystems in a | ||
synchronous fashion. That is to say, you may be in a callback where a call to | ||
`console.log()` could result in an infinite recursive loop. Also of note, many | ||
of these callbacks are in hot execution code paths. That is to say your | ||
callbacks are executed quite often in the normal operation of Node, so be wary | ||
of doing CPU bound or synchronous workloads in these functions. Consider a ring | ||
buffer and a timer to defer processing. | ||
|
||
`require('tracing')` to use this module. | ||
|
||
## v8 | ||
|
||
The `v8` property is an [EventEmitter][], it exposes events and interfaces | ||
specific to the version of `v8` built with node. These interfaces are subject | ||
to change by upstream and are therefore not covered under the stability index. | ||
|
||
### Event: 'gc' | ||
|
||
`function (before, after) { }` | ||
|
||
Emitted each time a GC run is completed. | ||
|
||
`before` and `after` are objects with the following properties: | ||
|
||
``` | ||
{ | ||
type: 'mark-sweep-compact', | ||
flags: 0, | ||
timestamp: 905535650119053, | ||
total_heap_size: 6295040, | ||
total_heap_size_executable: 4194304, | ||
total_physical_size: 6295040, | ||
used_heap_size: 2855416, | ||
heap_size_limit: 1535115264 | ||
} | ||
``` | ||
|
||
### getHeapStatistics() | ||
|
||
Returns an object with the following properties | ||
|
||
``` | ||
{ | ||
total_heap_size: 7326976, | ||
total_heap_size_executable: 4194304, | ||
total_physical_size: 7326976, | ||
used_heap_size: 3476208, | ||
heap_size_limit: 1535115264 | ||
} | ||
``` | ||
|
||
[EventEmitter]: events.html#events_class_events_eventemitter |
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,41 @@ | ||
// Copyright Joyent, Inc. and other Node contributors. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a | ||
// copy of this software and associated documentation files (the | ||
// "Software"), to deal in the Software without restriction, including | ||
// without limitation the rights to use, copy, modify, merge, publish, | ||
// distribute, sublicense, and/or sell copies of the Software, and to permit | ||
// persons to whom the Software is furnished to do so, subject to the | ||
// following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included | ||
// in all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | ||
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN | ||
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE | ||
// USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
var EventEmitter = require('events'); | ||
var binding = process.binding('v8'); | ||
|
||
var v8 = exports.v8 = new EventEmitter(); | ||
|
||
v8.on('newListener', function(name) { | ||
if (name === 'gc' && EventEmitter.listenerCount(this, name) === 0) { | ||
binding.startGarbageCollectionTracking(function emitGC(before, after) { | ||
v8.emit('gc', before, after); | ||
}); | ||
} | ||
}); | ||
|
||
v8.on('removeListener', function(name) { | ||
if (name === 'gc' && EventEmitter.listenerCount(this, name) === 0) { | ||
binding.stopGarbageCollectionTracking(); | ||
} | ||
}); | ||
|
||
v8.getHeapStatistics = binding.getHeapStatistics; |
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move
emitGC()
out of the upper scope. Every timestartGarbageCollectionTracking()
is calledemitGC()
will be re-parsed and re-optimized. So it'd just be changed to:Dumb I know.