2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2016-05-11 21:34:52 +02:00
|
|
|
const common = require('../common');
|
2016-12-31 00:38:06 +01:00
|
|
|
const assert = require('assert');
|
|
|
|
const os = require('os');
|
2012-09-21 01:48:55 +02:00
|
|
|
|
2016-08-19 01:06:55 +02:00
|
|
|
if (!common.isSunOS) {
|
2016-05-11 21:34:52 +02:00
|
|
|
common.skip('no DTRACE support');
|
2015-07-07 17:25:55 +02:00
|
|
|
return;
|
2012-09-21 01:48:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Some functions to create a recognizable stack.
|
|
|
|
*/
|
2017-01-08 14:19:00 +01:00
|
|
|
const frames = [ 'stalloogle', 'bagnoogle', 'doogle' ];
|
2012-09-21 01:48:55 +02:00
|
|
|
|
2017-01-08 14:19:00 +01:00
|
|
|
const stalloogle = function(str) {
|
2016-04-02 06:40:21 +02:00
|
|
|
global.expected = str;
|
2012-09-21 01:48:55 +02:00
|
|
|
os.loadavg();
|
|
|
|
};
|
|
|
|
|
2017-01-08 14:19:00 +01:00
|
|
|
const bagnoogle = function(arg0, arg1) {
|
2012-09-21 01:48:55 +02:00
|
|
|
stalloogle(arg0 + ' is ' + arg1 + ' except that it is read-only');
|
|
|
|
};
|
|
|
|
|
2017-01-08 14:19:00 +01:00
|
|
|
let done = false;
|
2012-09-21 01:48:55 +02:00
|
|
|
|
2017-01-08 14:19:00 +01:00
|
|
|
const doogle = function() {
|
2012-09-21 01:48:55 +02:00
|
|
|
if (!done)
|
|
|
|
setTimeout(doogle, 10);
|
|
|
|
|
|
|
|
bagnoogle('The bfs command', '(almost) like ed(1)');
|
|
|
|
};
|
|
|
|
|
2016-12-31 00:38:06 +01:00
|
|
|
const spawn = require('child_process').spawn;
|
2012-09-21 01:48:55 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We're going to use DTrace to stop us, gcore us, and set us running again
|
|
|
|
* when we call getloadavg() -- with the implicit assumption that our
|
|
|
|
* deepest function is the only caller of os.loadavg().
|
|
|
|
*/
|
2017-01-08 14:19:00 +01:00
|
|
|
const dtrace = spawn('dtrace', [ '-qwn', 'syscall::getloadavg:entry/pid == ' +
|
2012-09-21 01:48:55 +02:00
|
|
|
process.pid + '/{ustack(100, 8192); exit(0); }' ]);
|
|
|
|
|
2017-01-08 14:19:00 +01:00
|
|
|
let output = '';
|
2012-09-21 01:48:55 +02:00
|
|
|
|
2015-05-19 13:00:06 +02:00
|
|
|
dtrace.stderr.on('data', function(data) {
|
2012-09-21 01:48:55 +02:00
|
|
|
console.log('dtrace: ' + data);
|
|
|
|
});
|
|
|
|
|
2015-05-19 13:00:06 +02:00
|
|
|
dtrace.stdout.on('data', function(data) {
|
2012-09-21 01:48:55 +02:00
|
|
|
output += data;
|
|
|
|
});
|
|
|
|
|
2015-05-19 13:00:06 +02:00
|
|
|
dtrace.on('exit', function(code) {
|
2016-08-19 01:06:55 +02:00
|
|
|
if (code !== 0) {
|
2012-09-21 01:48:55 +02:00
|
|
|
console.error('dtrace exited with code ' + code);
|
|
|
|
process.exit(code);
|
|
|
|
}
|
|
|
|
|
|
|
|
done = true;
|
|
|
|
|
2017-01-08 14:19:00 +01:00
|
|
|
const sentinel = '(anon) as ';
|
|
|
|
const lines = output.split('\n');
|
2012-09-21 01:48:55 +02:00
|
|
|
|
2017-01-08 14:19:00 +01:00
|
|
|
for (let i = 0; i < lines.length; i++) {
|
|
|
|
const line = lines[i];
|
2012-09-21 01:48:55 +02:00
|
|
|
|
2016-08-19 01:06:55 +02:00
|
|
|
if (line.indexOf(sentinel) === -1 || frames.length === 0)
|
2012-09-21 01:48:55 +02:00
|
|
|
continue;
|
|
|
|
|
2017-01-08 14:19:00 +01:00
|
|
|
const frame = line.substr(line.indexOf(sentinel) + sentinel.length);
|
|
|
|
const top = frames.shift();
|
2012-09-21 01:48:55 +02:00
|
|
|
|
2017-01-08 16:36:25 +01:00
|
|
|
assert.strictEqual(frame.indexOf(top), 0, 'unexpected frame where ' +
|
2012-09-21 01:48:55 +02:00
|
|
|
top + ' was expected');
|
|
|
|
}
|
|
|
|
|
2017-01-08 16:36:25 +01:00
|
|
|
assert.strictEqual(frames.length, 0,
|
|
|
|
'did not find expected frame ' + frames[0]);
|
2012-09-21 01:48:55 +02:00
|
|
|
process.exit(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
setTimeout(doogle, 10);
|