mirror of https://github.com/lukechilds/node.git
Browse Source
PR-URL: https://github.com/iojs/io.js/pull/124 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>archived-io.js-v0.12
9 changed files with 1 additions and 253 deletions
@ -1,66 +0,0 @@ |
|||
# Tracing |
|||
|
|||
Stability: 1 - Experimental |
|||
|
|||
The tracing module is designed for instrumenting your Node application. It is |
|||
not meant for general purpose use. |
|||
|
|||
`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 |
|||
} |
|||
``` |
|||
|
|||
### setFlagsFromString() |
|||
|
|||
Set additional V8 command line flags. Use with care; changing settings |
|||
after the VM has started may result in unpredictable behavior, including |
|||
crashes and data loss. Or it may simply do nothing. |
|||
|
|||
Usage: |
|||
|
|||
``` |
|||
// Print GC events to stdout for one minute. |
|||
var v8 = require('tracing').v8; |
|||
v8.setFlagsFromString('--trace_gc'); |
|||
setTimeout(function() { v8.setFlagsFromString('--notrace_gc'); }, 60e3); |
|||
``` |
|||
|
|||
|
@ -1,65 +0,0 @@ |
|||
// 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.
|
|||
|
|||
'use strict'; |
|||
|
|||
var EventEmitter = require('events'); |
|||
var v8binding, process; |
|||
|
|||
// This needs to be loaded early, and before the "process" object is made
|
|||
// global. So allow src/node.js to pass the process object in during
|
|||
// initialization.
|
|||
exports._nodeInitialization = function nodeInitialization(pobj) { |
|||
process = pobj; |
|||
v8binding = process.binding('v8'); |
|||
|
|||
// Finish setting up the v8 Object.
|
|||
v8.getHeapStatistics = v8binding.getHeapStatistics; |
|||
v8.setFlagsFromString = v8binding.setFlagsFromString; |
|||
|
|||
// Do a little housekeeping.
|
|||
delete exports._nodeInitialization; |
|||
}; |
|||
|
|||
|
|||
// v8
|
|||
|
|||
var v8 = exports.v8 = new EventEmitter(); |
|||
|
|||
|
|||
function emitGC(before, after) { |
|||
v8.emit('gc', before, after); |
|||
} |
|||
|
|||
|
|||
v8.on('newListener', function(name) { |
|||
if (name === 'gc' && EventEmitter.listenerCount(this, name) === 0) { |
|||
v8binding.startGarbageCollectionTracking(emitGC); |
|||
} |
|||
}); |
|||
|
|||
|
|||
v8.on('removeListener', function(name) { |
|||
if (name === 'gc' && EventEmitter.listenerCount(this, name) === 0) { |
|||
v8binding.stopGarbageCollectionTracking(); |
|||
} |
|||
}); |
|||
|
@ -1,26 +0,0 @@ |
|||
// Copyright (c) 2014, StrongLoop Inc.
|
|||
//
|
|||
// Permission to use, copy, modify, and/or distribute this software for any
|
|||
// purpose with or without fee is hereby granted, provided that the above
|
|||
// copyright notice and this permission notice appear in all copies.
|
|||
//
|
|||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|||
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|||
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|||
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|||
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|||
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|||
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
|
|||
var common = require('../common'); |
|||
var assert = require('assert'); |
|||
var v8 = require('tracing').v8; |
|||
var vm = require('vm'); |
|||
|
|||
v8.setFlagsFromString('--allow_natives_syntax'); |
|||
assert(eval('%_IsSmi(42)')); |
|||
assert(vm.runInThisContext('%_IsSmi(42)')); |
|||
|
|||
v8.setFlagsFromString('--noallow_natives_syntax'); |
|||
assert.throws(function() { eval('%_IsSmi(42)') }, SyntaxError); |
|||
assert.throws(function() { vm.runInThisContext('%_IsSmi(42)') }, SyntaxError); |
@ -1,53 +0,0 @@ |
|||
// 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.
|
|||
|
|||
// Flags: --expose_gc
|
|||
|
|||
var common = require('../common'); |
|||
var assert = require('assert'); |
|||
var v8 = require('tracing').v8; |
|||
|
|||
assert(typeof gc === 'function', 'Run this test with --expose_gc.'); |
|||
|
|||
var ncalls = 0; |
|||
var before; |
|||
var after; |
|||
|
|||
function ongc(before_, after_) { |
|||
// Try very hard to not create garbage because that could kick off another
|
|||
// garbage collection cycle.
|
|||
before = before_; |
|||
after = after_; |
|||
ncalls += 1; |
|||
} |
|||
|
|||
gc(); |
|||
v8.on('gc', ongc); |
|||
gc(); |
|||
v8.removeListener('gc', ongc); |
|||
gc(); |
|||
|
|||
assert.equal(ncalls, 1); |
|||
assert.equal(typeof before, 'object'); |
|||
assert.equal(typeof after, 'object'); |
|||
assert.equal(typeof before.timestamp, 'number'); |
|||
assert.equal(typeof after.timestamp, 'number'); |
|||
assert.equal(before.timestamp <= after.timestamp, true); |
@ -1,36 +0,0 @@ |
|||
// 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 common = require('../common'); |
|||
var assert = require('assert'); |
|||
var v8 = require('tracing').v8; |
|||
|
|||
var s = v8.getHeapStatistics(); |
|||
var keys = [ |
|||
'heap_size_limit', |
|||
'total_heap_size', |
|||
'total_heap_size_executable', |
|||
'total_physical_size', |
|||
'used_heap_size']; |
|||
assert.deepEqual(Object.keys(s).sort(), keys); |
|||
keys.forEach(function(key) { |
|||
assert.equal(typeof s[key], 'number'); |
|||
}); |
Loading…
Reference in new issue