-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add heap profiler add-on regression test
Add a regression test for #1827. PR-URL: #1828 Reviewed-By: Trevor Norris <[email protected]>
- Loading branch information
1 parent
3a1bc06
commit 4e90c82
Showing
3 changed files
with
47 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#include "node.h" | ||
#include "v8.h" | ||
#include "v8-profiler.h" | ||
|
||
namespace { | ||
|
||
inline void Test(const v8::FunctionCallbackInfo<v8::Value>& args) { | ||
v8::Isolate* const isolate = args.GetIsolate(); | ||
const v8::HeapSnapshot* const heap_snapshot = | ||
isolate->GetHeapProfiler()->TakeHeapSnapshot(v8::String::Empty(isolate)); | ||
struct : public v8::OutputStream { | ||
WriteResult WriteAsciiChunk(char*, int) override { return kContinue; } | ||
void EndOfStream() override {} | ||
} output_stream; | ||
heap_snapshot->Serialize(&output_stream, v8::HeapSnapshot::kJSON); | ||
const_cast<v8::HeapSnapshot*>(heap_snapshot)->Delete(); | ||
} | ||
|
||
inline void Initialize(v8::Local<v8::Object> binding) { | ||
v8::Isolate* const isolate = binding->GetIsolate(); | ||
binding->Set(v8::String::NewFromUtf8(isolate, "test"), | ||
v8::FunctionTemplate::New(isolate, Test)->GetFunction()); | ||
} | ||
|
||
NODE_MODULE(test, Initialize) | ||
|
||
} // anonymous namespace |
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,8 @@ | ||
{ | ||
'targets': [ | ||
{ | ||
'target_name': 'binding', | ||
'sources': [ 'binding.cc' ] | ||
} | ||
] | ||
} |
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,12 @@ | ||
'use strict'; | ||
|
||
const binding = require('./build/Release/binding'); | ||
|
||
// Create an AsyncWrap object. | ||
const timer = setTimeout(function() {}, 1); | ||
timer.unref(); | ||
|
||
// Stress-test the heap profiler. | ||
binding.test(); | ||
|
||
clearTimeout(timer); |