Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(640)

Side by Side Diff: test/cctest/test-heap-profiler.cc

Issue 95283003: Do not put allocated block into HeapObjectsMap (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Reupload take 3 Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/serialize.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 2046 matching lines...) Expand 10 before | Expand all | Expand 10 after
2057 args.GetReturnValue().Set(untracked_objects); 2057 args.GetReturnValue().Set(untracked_objects);
2058 CHECK_EQ(0, untracked_objects); 2058 CHECK_EQ(0, untracked_objects);
2059 } 2059 }
2060 2060
2061 2061
2062 static HeapProfilerExtension kHeapProfilerExtension; 2062 static HeapProfilerExtension kHeapProfilerExtension;
2063 v8::DeclareExtension kHeapProfilerExtensionDeclaration( 2063 v8::DeclareExtension kHeapProfilerExtensionDeclaration(
2064 &kHeapProfilerExtension); 2064 &kHeapProfilerExtension);
2065 2065
2066 2066
2067 // This is an example of using checking of JS allocations tracking in a test.
2068 TEST(HeapObjectsTracker) {
2069 const char* extensions[] = { HeapProfilerExtension::kName };
2070 v8::ExtensionConfiguration config(1, extensions);
2071 LocalContext env(&config);
2072 v8::HandleScope scope(env->GetIsolate());
2073 HeapObjectsTracker tracker;
2074 CompileRun("var a = 1.2");
2075 CompileRun("var a = 1.2; var b = 1.0; var c = 1.0;");
2076 CompileRun(
2077 "var a = [];\n"
2078 "for (var i = 0; i < 5; ++i)\n"
2079 " a[i] = i;\n"
2080 "findUntrackedObjects();\n"
2081 "for (var i = 0; i < 3; ++i)\n"
2082 " a.shift();\n"
2083 "findUntrackedObjects();\n");
2084 }
2085
2086
2087 static const v8::HeapGraphNode* GetNodeByPath(const v8::HeapSnapshot* snapshot, 2067 static const v8::HeapGraphNode* GetNodeByPath(const v8::HeapSnapshot* snapshot,
2088 const char* path[], 2068 const char* path[],
2089 int depth) { 2069 int depth) {
2090 const v8::HeapGraphNode* node = snapshot->GetRoot(); 2070 const v8::HeapGraphNode* node = snapshot->GetRoot();
2091 for (int current_depth = 0; current_depth < depth; ++current_depth) { 2071 for (int current_depth = 0; current_depth < depth; ++current_depth) {
2092 int i, count = node->GetChildrenCount(); 2072 int i, count = node->GetChildrenCount();
2093 for (i = 0; i < count; ++i) { 2073 for (i = 0; i < count; ++i) {
2094 const v8::HeapGraphEdge* edge = node->GetChild(i); 2074 const v8::HeapGraphEdge* edge = node->GetChild(i);
2095 const v8::HeapGraphNode* to_node = edge->GetToNode(); 2075 const v8::HeapGraphNode* to_node = edge->GetToNode();
2096 v8::String::Utf8Value edge_name(edge->GetName()); 2076 v8::String::Utf8Value edge_name(edge->GetName());
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
2198 if (info && strcmp(info->name, name) == 0) { 2178 if (info && strcmp(info->name, name) == 0) {
2199 node = children[j]; 2179 node = children[j];
2200 break; 2180 break;
2201 } 2181 }
2202 } 2182 }
2203 } 2183 }
2204 return node; 2184 return node;
2205 } 2185 }
2206 2186
2207 2187
2188 TEST(ArrayGrowLeftTrim) {
2189 LocalContext env;
2190 v8::HandleScope scope(env->GetIsolate());
2191 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
2192 heap_profiler->StartRecordingHeapAllocations();
2193
2194 CompileRun(
2195 "var a = [];\n"
2196 "for (var i = 0; i < 5; ++i)\n"
2197 " a[i] = i;\n"
2198 "for (var i = 0; i < 3; ++i)\n"
2199 " a.shift();\n");
2200
2201 const char* names[] = { "(anonymous function)" };
2202 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot(
2203 v8::String::NewFromUtf8(env->GetIsolate(), "Test1"));
2204 i::HeapSnapshotsCollection* collection = ToInternal(snapshot)->collection();
2205 AllocationTracker* tracker = collection->allocation_tracker();
2206 CHECK_NE(NULL, tracker);
2207 // Resolve all function locations.
2208 tracker->PrepareForSerialization();
2209 // Print for better diagnostics in case of failure.
2210 tracker->trace_tree()->Print(tracker);
2211
2212 AllocationTraceNode* node =
2213 FindNode(tracker, Vector<const char*>(names, ARRAY_SIZE(names)));
2214 CHECK_NE(NULL, node);
2215 CHECK_GE(node->allocation_count(), 2);
2216 CHECK_GE(node->allocation_size(), 4 * 5);
2217 heap_profiler->StopRecordingHeapAllocations();
2218 }
2219
2220
2208 TEST(TrackHeapAllocations) { 2221 TEST(TrackHeapAllocations) {
2209 v8::HandleScope scope(v8::Isolate::GetCurrent()); 2222 v8::HandleScope scope(v8::Isolate::GetCurrent());
2210 LocalContext env; 2223 LocalContext env;
2211 2224
2212 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 2225 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
2213 heap_profiler->StartRecordingHeapAllocations(); 2226 heap_profiler->StartRecordingHeapAllocations();
2214 2227
2215 CompileRun(record_trace_tree_source); 2228 CompileRun(record_trace_tree_source);
2216 2229
2217 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot( 2230 const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot(
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
2307 2320
2308 AllocationTraceNode* node = 2321 AllocationTraceNode* node =
2309 FindNode(tracker, Vector<const char*>(names, ARRAY_SIZE(names))); 2322 FindNode(tracker, Vector<const char*>(names, ARRAY_SIZE(names)));
2310 CHECK_NE(NULL, node); 2323 CHECK_NE(NULL, node);
2311 CHECK_LT(node->allocation_count(), 100); 2324 CHECK_LT(node->allocation_count(), 100);
2312 2325
2313 CcTest::heap()->DisableInlineAllocation(); 2326 CcTest::heap()->DisableInlineAllocation();
2314 heap_profiler->StopRecordingHeapAllocations(); 2327 heap_profiler->StopRecordingHeapAllocations();
2315 } 2328 }
2316 } 2329 }
OLDNEW
« no previous file with comments | « src/serialize.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698