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

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

Issue 196133017: Experimental parser: merge r19949 (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/parser
Patch Set: Created 6 years, 9 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 | « test/cctest/test-heap.cc ('k') | test/cctest/test-log.cc » ('j') | 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 }
2509
2510
2511 static inline i::Address ToAddress(int n) {
2512 return reinterpret_cast<i::Address>(n);
2513 }
2514
2515
2516 TEST(AddressToTraceMap) {
2517 i::AddressToTraceMap map;
2518
2519 CHECK_EQ(0, map.GetTraceNodeId(ToAddress(150)));
2520
2521 // [0x100, 0x200) -> 1
2522 map.AddRange(ToAddress(0x100), 0x100, 1U);
2523 CHECK_EQ(0, map.GetTraceNodeId(ToAddress(0x50)));
2524 CHECK_EQ(1, map.GetTraceNodeId(ToAddress(0x100)));
2525 CHECK_EQ(1, map.GetTraceNodeId(ToAddress(0x150)));
2526 CHECK_EQ(0, map.GetTraceNodeId(ToAddress(0x100 + 0x100)));
2527 CHECK_EQ(1, static_cast<int>(map.size()));
2528
2529 // [0x100, 0x200) -> 1, [0x200, 0x300) -> 2
2530 map.AddRange(ToAddress(0x200), 0x100, 2U);
2531 CHECK_EQ(2, map.GetTraceNodeId(ToAddress(0x2a0)));
2532 CHECK_EQ(2, static_cast<int>(map.size()));
2533
2534 // [0x100, 0x180) -> 1, [0x180, 0x280) -> 3, [0x280, 0x300) -> 2
2535 map.AddRange(ToAddress(0x180), 0x100, 3U);
2536 CHECK_EQ(1, map.GetTraceNodeId(ToAddress(0x17F)));
2537 CHECK_EQ(2, map.GetTraceNodeId(ToAddress(0x280)));
2538 CHECK_EQ(3, map.GetTraceNodeId(ToAddress(0x180)));
2539 CHECK_EQ(3, static_cast<int>(map.size()));
2540
2541 // [0x100, 0x180) -> 1, [0x180, 0x280) -> 3, [0x280, 0x300) -> 2,
2542 // [0x400, 0x500) -> 4
2543 map.AddRange(ToAddress(0x400), 0x100, 4U);
2544 CHECK_EQ(1, map.GetTraceNodeId(ToAddress(0x17F)));
2545 CHECK_EQ(2, map.GetTraceNodeId(ToAddress(0x280)));
2546 CHECK_EQ(3, map.GetTraceNodeId(ToAddress(0x180)));
2547 CHECK_EQ(4, map.GetTraceNodeId(ToAddress(0x450)));
2548 CHECK_EQ(0, map.GetTraceNodeId(ToAddress(0x500)));
2549 CHECK_EQ(0, map.GetTraceNodeId(ToAddress(0x350)));
2550 CHECK_EQ(4, static_cast<int>(map.size()));
2551
2552 // [0x100, 0x180) -> 1, [0x180, 0x200) -> 3, [0x200, 0x600) -> 5
2553 map.AddRange(ToAddress(0x200), 0x400, 5U);
2554 CHECK_EQ(5, map.GetTraceNodeId(ToAddress(0x200)));
2555 CHECK_EQ(5, map.GetTraceNodeId(ToAddress(0x400)));
2556 CHECK_EQ(3, static_cast<int>(map.size()));
2557
2558 // [0x100, 0x180) -> 1, [0x180, 0x200) -> 7, [0x200, 0x600) ->5
2559 map.AddRange(ToAddress(0x180), 0x80, 6U);
2560 map.AddRange(ToAddress(0x180), 0x80, 7U);
2561 CHECK_EQ(7, map.GetTraceNodeId(ToAddress(0x180)));
2562 CHECK_EQ(5, map.GetTraceNodeId(ToAddress(0x200)));
2563 CHECK_EQ(3, static_cast<int>(map.size()));
2564
2565 map.Clear();
2566 CHECK_EQ(0, static_cast<int>(map.size()));
2567 CHECK_EQ(0, map.GetTraceNodeId(ToAddress(0x400)));
2568 }
OLDNEW
« no previous file with comments | « test/cctest/test-heap.cc ('k') | test/cctest/test-log.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698