Commit 4e90c82 1 parent 3a1bc06 commit 4e90c82 Copy full SHA for 4e90c82
File tree 3 files changed +47
-0
lines changed
test/addons/heap-profiler
3 files changed +47
-0
lines changed 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
+ namespace {
6
+
7
+ inline void Test (const v8::FunctionCallbackInfo<v8::Value>& args) {
8
+ v8::Isolate* const isolate = args.GetIsolate ();
9
+ const v8::HeapSnapshot* const heap_snapshot =
10
+ isolate->GetHeapProfiler ()->TakeHeapSnapshot (v8::String::Empty (isolate));
11
+ struct : public v8 ::OutputStream {
12
+ WriteResult WriteAsciiChunk (char *, int ) override { return kContinue ; }
13
+ void EndOfStream () override {}
14
+ } output_stream;
15
+ heap_snapshot->Serialize (&output_stream, v8::HeapSnapshot::kJSON );
16
+ const_cast <v8::HeapSnapshot*>(heap_snapshot)->Delete ();
17
+ }
18
+
19
+ inline void Initialize (v8::Local<v8::Object> binding) {
20
+ v8::Isolate* const isolate = binding->GetIsolate ();
21
+ binding->Set (v8::String::NewFromUtf8 (isolate, " test" ),
22
+ v8::FunctionTemplate::New (isolate, Test)->GetFunction ());
23
+ }
24
+
25
+ NODE_MODULE (test, Initialize)
26
+
27
+ } // anonymous namespace
Original file line number Diff line number Diff line change
1
+ {
2
+ 'targets' : [
3
+ {
4
+ 'target_name' : 'binding' ,
5
+ 'sources' : [ 'binding.cc' ]
6
+ }
7
+ ]
8
+ }
Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
3
+ const binding = require ( './build/Release/binding' ) ;
4
+
5
+ // Create an AsyncWrap object.
6
+ const timer = setTimeout ( function ( ) { } , 1 ) ;
7
+ timer . unref ( ) ;
8
+
9
+ // Stress-test the heap profiler.
10
+ binding . test ( ) ;
11
+
12
+ clearTimeout ( timer ) ;
You can’t perform that action at this time.
0 commit comments