Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add heap profiler add-on regression test #1828

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions test/addons/heap-profiler/binding.cc
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
8 changes: 8 additions & 0 deletions test/addons/heap-profiler/binding.gyp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
'targets': [
{
'target_name': 'binding',
'sources': [ 'binding.cc' ]
}
]
}
12 changes: 12 additions & 0 deletions test/addons/heap-profiler/test.js
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);