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

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

Issue 177203002: Allocation tracker: add separate entry for allocations via V8 API (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Reverted v8globals.h changes Created 6 years, 10 months 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/heap-snapshot-generator.cc ('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 2198 matching lines...) Expand 10 before | Expand all | Expand 10 after
2209 2209
2210 2210
2211 static AllocationTraceNode* FindNode( 2211 static AllocationTraceNode* FindNode(
2212 AllocationTracker* tracker, const Vector<const char*>& names) { 2212 AllocationTracker* tracker, const Vector<const char*>& names) {
2213 AllocationTraceNode* node = tracker->trace_tree()->root(); 2213 AllocationTraceNode* node = tracker->trace_tree()->root();
2214 for (int i = 0; node != NULL && i < names.length(); i++) { 2214 for (int i = 0; node != NULL && i < names.length(); i++) {
2215 const char* name = names[i]; 2215 const char* name = names[i];
2216 Vector<AllocationTraceNode*> children = node->children(); 2216 Vector<AllocationTraceNode*> children = node->children();
2217 node = NULL; 2217 node = NULL;
2218 for (int j = 0; j < children.length(); j++) { 2218 for (int j = 0; j < children.length(); j++) {
2219 v8::SnapshotObjectId id = children[j]->function_id(); 2219 unsigned index = children[j]->function_info_index();
2220 AllocationTracker::FunctionInfo* info = tracker->GetFunctionInfo(id); 2220 AllocationTracker::FunctionInfo* info =
2221 tracker->function_info_list()[index];
2221 if (info && strcmp(info->name, name) == 0) { 2222 if (info && strcmp(info->name, name) == 0) {
2222 node = children[j]; 2223 node = children[j];
2223 break; 2224 break;
2224 } 2225 }
2225 } 2226 }
2226 } 2227 }
2227 return node; 2228 return node;
2228 } 2229 }
2229 2230
2230 2231
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
2357 FindNode(tracker, Vector<const char*>(names, ARRAY_SIZE(names))); 2358 FindNode(tracker, Vector<const char*>(names, ARRAY_SIZE(names)));
2358 CHECK_NE(NULL, node); 2359 CHECK_NE(NULL, node);
2359 CHECK_LT(node->allocation_count(), 100); 2360 CHECK_LT(node->allocation_count(), 100);
2360 2361
2361 CcTest::heap()->DisableInlineAllocation(); 2362 CcTest::heap()->DisableInlineAllocation();
2362 heap_profiler->StopTrackingHeapObjects(); 2363 heap_profiler->StopTrackingHeapObjects();
2363 } 2364 }
2364 } 2365 }
2365 2366
2366 2367
2368 TEST(TrackV8ApiAllocation) {
2369 v8::HandleScope scope(v8::Isolate::GetCurrent());
2370 LocalContext env;
2371
2372 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
2373 const char* names[] = { "(V8 API)" };
2374 heap_profiler->StartTrackingHeapObjects(true);
2375
2376 v8::Handle<v8::Object> o1 = v8::Object::New(env->GetIsolate());
2377 o1->Clone();
2378
2379 AllocationTracker* tracker =
2380 reinterpret_cast<i::HeapProfiler*>(heap_profiler)->allocation_tracker();
2381 CHECK_NE(NULL, tracker);
2382 // Resolve all function locations.
2383 tracker->PrepareForSerialization();
2384 // Print for better diagnostics in case of failure.
2385 tracker->trace_tree()->Print(tracker);
2386
2387 AllocationTraceNode* node =
2388 FindNode(tracker, Vector<const char*>(names, ARRAY_SIZE(names)));
2389 CHECK_NE(NULL, node);
2390 CHECK_GE(node->allocation_count(), 2);
2391 CHECK_GE(node->allocation_size(), 4 * node->allocation_count());
2392 heap_profiler->StopTrackingHeapObjects();
2393 }
2394
2395
2367 TEST(ArrayBufferAndArrayBufferView) { 2396 TEST(ArrayBufferAndArrayBufferView) {
2368 LocalContext env; 2397 LocalContext env;
2369 v8::HandleScope scope(env->GetIsolate()); 2398 v8::HandleScope scope(env->GetIsolate());
2370 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler(); 2399 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
2371 CompileRun("arr1 = new Uint32Array(100);\n"); 2400 CompileRun("arr1 = new Uint32Array(100);\n");
2372 const v8::HeapSnapshot* snapshot = 2401 const v8::HeapSnapshot* snapshot =
2373 heap_profiler->TakeHeapSnapshot(v8_str("snapshot")); 2402 heap_profiler->TakeHeapSnapshot(v8_str("snapshot"));
2374 CHECK(ValidateSnapshot(snapshot)); 2403 CHECK(ValidateSnapshot(snapshot));
2375 const v8::HeapGraphNode* global = GetGlobalObject(snapshot); 2404 const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
2376 const v8::HeapGraphNode* arr1_obj = 2405 const v8::HeapGraphNode* arr1_obj =
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
2470 const v8::HeapGraphNode* global_node = GetGlobalObject(snapshot); 2499 const v8::HeapGraphNode* global_node = GetGlobalObject(snapshot);
2471 const v8::HeapGraphNode* box_node = 2500 const v8::HeapGraphNode* box_node =
2472 GetProperty(global_node, v8::HeapGraphEdge::kElement, "0"); 2501 GetProperty(global_node, v8::HeapGraphEdge::kElement, "0");
2473 CHECK_NE(NULL, box_node); 2502 CHECK_NE(NULL, box_node);
2474 v8::String::Utf8Value box_node_name(box_node->GetName()); 2503 v8::String::Utf8Value box_node_name(box_node->GetName());
2475 CHECK_EQ("system / Box", *box_node_name); 2504 CHECK_EQ("system / Box", *box_node_name);
2476 const v8::HeapGraphNode* box_value = 2505 const v8::HeapGraphNode* box_value =
2477 GetProperty(box_node, v8::HeapGraphEdge::kInternal, "value"); 2506 GetProperty(box_node, v8::HeapGraphEdge::kInternal, "value");
2478 CHECK_NE(NULL, box_value); 2507 CHECK_NE(NULL, box_value);
2479 } 2508 }
OLDNEW
« no previous file with comments | « src/heap-snapshot-generator.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698