OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 2052 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2063 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); | 2063 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); |
2064 const v8::HeapGraphNode* foo_func = | 2064 const v8::HeapGraphNode* foo_func = |
2065 GetProperty(global, v8::HeapGraphEdge::kProperty, "foo"); | 2065 GetProperty(global, v8::HeapGraphEdge::kProperty, "foo"); |
2066 CHECK_NE(NULL, foo_func); | 2066 CHECK_NE(NULL, foo_func); |
2067 const v8::HeapGraphNode* code = | 2067 const v8::HeapGraphNode* code = |
2068 GetProperty(foo_func, v8::HeapGraphEdge::kInternal, "code"); | 2068 GetProperty(foo_func, v8::HeapGraphEdge::kInternal, "code"); |
2069 CHECK_NE(NULL, code); | 2069 CHECK_NE(NULL, code); |
2070 } | 2070 } |
2071 | 2071 |
2072 | 2072 |
2073 | |
2074 class HeapProfilerExtension : public v8::Extension { | |
2075 public: | |
2076 static const char* kName; | |
2077 HeapProfilerExtension() : v8::Extension(kName, kSource) { } | |
2078 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunctionTemplate( | |
2079 v8::Isolate* isolate, | |
2080 v8::Handle<v8::String> name); | |
2081 static void FindUntrackedObjects( | |
2082 const v8::FunctionCallbackInfo<v8::Value>& args); | |
2083 private: | |
2084 static const char* kSource; | |
2085 }; | |
2086 | |
2087 const char* HeapProfilerExtension::kName = "v8/heap-profiler"; | |
2088 | |
2089 | |
2090 const char* HeapProfilerExtension::kSource = | |
2091 "native function findUntrackedObjects();"; | |
2092 | |
2093 | |
2094 v8::Handle<v8::FunctionTemplate> | |
2095 HeapProfilerExtension::GetNativeFunctionTemplate(v8::Isolate* isolate, | |
2096 v8::Handle<v8::String> name) { | |
2097 if (name->Equals(v8::String::NewFromUtf8(isolate, "findUntrackedObjects"))) { | |
2098 return v8::FunctionTemplate::New( | |
2099 isolate, | |
2100 HeapProfilerExtension::FindUntrackedObjects); | |
2101 } else { | |
2102 CHECK(false); | |
2103 return v8::Handle<v8::FunctionTemplate>(); | |
2104 } | |
2105 } | |
2106 | |
2107 | |
2108 void HeapProfilerExtension::FindUntrackedObjects( | |
2109 const v8::FunctionCallbackInfo<v8::Value>& args) { | |
2110 i::HeapProfiler* heap_profiler = | |
2111 reinterpret_cast<i::HeapProfiler*>(args.GetIsolate()->GetHeapProfiler()); | |
2112 int untracked_objects = | |
2113 heap_profiler->heap_object_map()->FindUntrackedObjects(); | |
2114 args.GetReturnValue().Set(untracked_objects); | |
2115 CHECK_EQ(0, untracked_objects); | |
2116 } | |
2117 | |
2118 | |
2119 static HeapProfilerExtension kHeapProfilerExtension; | |
2120 v8::DeclareExtension kHeapProfilerExtensionDeclaration( | |
2121 &kHeapProfilerExtension); | |
2122 | |
2123 | |
2124 static const v8::HeapGraphNode* GetNodeByPath(const v8::HeapSnapshot* snapshot, | 2073 static const v8::HeapGraphNode* GetNodeByPath(const v8::HeapSnapshot* snapshot, |
2125 const char* path[], | 2074 const char* path[], |
2126 int depth) { | 2075 int depth) { |
2127 const v8::HeapGraphNode* node = snapshot->GetRoot(); | 2076 const v8::HeapGraphNode* node = snapshot->GetRoot(); |
2128 for (int current_depth = 0; current_depth < depth; ++current_depth) { | 2077 for (int current_depth = 0; current_depth < depth; ++current_depth) { |
2129 int i, count = node->GetChildrenCount(); | 2078 int i, count = node->GetChildrenCount(); |
2130 for (i = 0; i < count; ++i) { | 2079 for (i = 0; i < count; ++i) { |
2131 const v8::HeapGraphEdge* edge = node->GetChild(i); | 2080 const v8::HeapGraphEdge* edge = node->GetChild(i); |
2132 const v8::HeapGraphNode* to_node = edge->GetToNode(); | 2081 const v8::HeapGraphNode* to_node = edge->GetToNode(); |
2133 v8::String::Utf8Value edge_name(edge->GetName()); | 2082 v8::String::Utf8Value edge_name(edge->GetName()); |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2363 | 2312 |
2364 AllocationTraceNode* node = | 2313 AllocationTraceNode* node = |
2365 FindNode(tracker, Vector<const char*>(names, ARRAY_SIZE(names))); | 2314 FindNode(tracker, Vector<const char*>(names, ARRAY_SIZE(names))); |
2366 CHECK_NE(NULL, node); | 2315 CHECK_NE(NULL, node); |
2367 CHECK_LT(node->allocation_count(), 100); | 2316 CHECK_LT(node->allocation_count(), 100); |
2368 | 2317 |
2369 CcTest::heap()->DisableInlineAllocation(); | 2318 CcTest::heap()->DisableInlineAllocation(); |
2370 heap_profiler->StopTrackingHeapObjects(); | 2319 heap_profiler->StopTrackingHeapObjects(); |
2371 } | 2320 } |
2372 } | 2321 } |
OLD | NEW |