GeezerVison is showing github.com — test: add cpu-profiler-crash test · nodejs/node@89046d7
File tree
Expand file treeCollapse file tree
Open diff view settings
test/addons/cpu-profiler-crash
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboard +16Lines changed: 16 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +#include "node.h" |
| 2 | +#include "v8.h" |
| 3 | +#include "v8-profiler.h" |
| 4 | + |
| 5 | +static void StartCpuProfiler(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 6 | + v8::CpuProfiler* profiler = v8::CpuProfiler::New(args.GetIsolate()); |
| 7 | + v8::Local<v8::String> profile_title = v8::String::NewFromUtf8( |
| 8 | + args.GetIsolate(), |
| 9 | + "testing", |
| 10 | + v8::NewStringType::kInternalized).ToLocalChecked(); |
| 11 | + profiler->StartProfiling(profile_title, true); |
| 12 | +} |
| 13 | + |
| 14 | +NODE_MODULE_INIT(/* exports, module, context */) { |
| 15 | + NODE_SET_METHOD(exports, "startCpuProfiler", StartCpuProfiler); |
| 16 | +} |
Collapse file
Copy file name to clipboard +9Lines changed: 9 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +{ |
| 2 | + 'targets': [ |
| 3 | + { |
| 4 | + 'target_name': 'binding', |
| 5 | + 'sources': [ 'binding.cc' ], |
| 6 | + 'includes': ['../common.gypi'], |
| 7 | + } |
| 8 | + ] |
| 9 | +} |
Collapse file
Copy file name to clipboard +20Lines changed: 20 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +// This test crashes most of the time unless the v8 patch: |
| 4 | +// https://github.com/v8/v8/commit/beebee4f80ff2eb91187ef1e8fa00b8ff82a20b3 |
| 5 | +// is applied. |
| 6 | +const common = require('../../common'); |
| 7 | +const bindings = require(`./build/${common.buildType}/binding`); |
| 8 | + |
| 9 | +function fn() { setImmediate(fn); } |
| 10 | +setInterval(function() { |
| 11 | + for (let i = 0; i < 1000000; i++) |
| 12 | + fn(); |
| 13 | + clearInterval(this); |
| 14 | + setTimeout(process.reallyExit, 2000); |
| 15 | +}, 0); |
| 16 | + |
| 17 | + |
| 18 | +setTimeout(() => { |
| 19 | + bindings.startCpuProfiler(); |
| 20 | +}, 1000); |