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

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

Issue 93843004: Add methods for finding object by its snapshot id and id for an object (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: One more time 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/heap-profiler.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 1023 matching lines...) Expand 10 before | Expand all | Expand 10 after
1034 CHECK_EQ(2, stats_update.updates_written()); 1034 CHECK_EQ(2, stats_update.updates_written());
1035 CHECK_LT(entries_size, stats_update.entries_size()); 1035 CHECK_LT(entries_size, stats_update.entries_size());
1036 CHECK_EQ(2, stats_update.entries_count()); 1036 CHECK_EQ(2, stats_update.entries_count());
1037 CHECK_EQ(8, stats_update.first_interval_index()); 1037 CHECK_EQ(8, stats_update.first_interval_index());
1038 } 1038 }
1039 1039
1040 heap_profiler->StopTrackingHeapObjects(); 1040 heap_profiler->StopTrackingHeapObjects();
1041 } 1041 }
1042 1042
1043 1043
1044 TEST(HeapObjectIds) {
1045 LocalContext env;
1046 v8::Isolate* isolate = env->GetIsolate();
1047 v8::HandleScope scope(isolate);
1048 v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
1049
1050 const int kLength = 10;
1051 v8::Handle<v8::Object> objects[kLength];
1052 v8::SnapshotObjectId ids[kLength];
1053
1054 heap_profiler->StartTrackingHeapObjects(false);
1055
1056 for (int i = 0; i < kLength; i++) {
1057 objects[i] = v8::Object::New(isolate);
1058 }
1059 GetHeapStatsUpdate(heap_profiler);
1060
1061 for (int i = 0; i < kLength; i++) {
1062 v8::SnapshotObjectId id = heap_profiler->GetObjectId(objects[i]);
1063 CHECK_NE(v8::HeapProfiler::kUnknownObjectId, static_cast<int>(id));
1064 ids[i] = id;
1065 }
1066
1067 heap_profiler->StopTrackingHeapObjects();
1068 CcTest::heap()->CollectAllAvailableGarbage();
1069
1070 for (int i = 0; i < kLength; i++) {
1071 v8::SnapshotObjectId id = heap_profiler->GetObjectId(objects[i]);
1072 CHECK_EQ(static_cast<int>(ids[i]), static_cast<int>(id));
1073 v8::Handle<v8::Value> obj = heap_profiler->FindObjectById(ids[i]);
1074 CHECK_EQ(objects[i], obj);
1075 }
1076
1077 heap_profiler->ClearObjectIds();
1078 for (int i = 0; i < kLength; i++) {
1079 v8::SnapshotObjectId id = heap_profiler->GetObjectId(objects[i]);
1080 CHECK_EQ(v8::HeapProfiler::kUnknownObjectId, static_cast<int>(id));
1081 v8::Handle<v8::Value> obj = heap_profiler->FindObjectById(ids[i]);
1082 CHECK(obj.IsEmpty());
1083 }
1084 }
1085
1086
1044 static void CheckChildrenIds(const v8::HeapSnapshot* snapshot, 1087 static void CheckChildrenIds(const v8::HeapSnapshot* snapshot,
1045 const v8::HeapGraphNode* node, 1088 const v8::HeapGraphNode* node,
1046 int level, int max_level) { 1089 int level, int max_level) {
1047 if (level > max_level) return; 1090 if (level > max_level) return;
1048 CHECK_EQ(node, snapshot->GetNodeById(node->GetId())); 1091 CHECK_EQ(node, snapshot->GetNodeById(node->GetId()));
1049 for (int i = 0, count = node->GetChildrenCount(); i < count; ++i) { 1092 for (int i = 0, count = node->GetChildrenCount(); i < count; ++i) {
1050 const v8::HeapGraphEdge* prop = node->GetChild(i); 1093 const v8::HeapGraphEdge* prop = node->GetChild(i);
1051 const v8::HeapGraphNode* child = 1094 const v8::HeapGraphNode* child =
1052 snapshot->GetNodeById(prop->GetToNode()->GetId()); 1095 snapshot->GetNodeById(prop->GetToNode()->GetId());
1053 CHECK_EQ_SNAPSHOT_OBJECT_ID(prop->GetToNode()->GetId(), child->GetId()); 1096 CHECK_EQ_SNAPSHOT_OBJECT_ID(prop->GetToNode()->GetId(), child->GetId());
(...skipping 1255 matching lines...) Expand 10 before | Expand all | Expand 10 after
2309 2352
2310 AllocationTraceNode* node = 2353 AllocationTraceNode* node =
2311 FindNode(tracker, Vector<const char*>(names, ARRAY_SIZE(names))); 2354 FindNode(tracker, Vector<const char*>(names, ARRAY_SIZE(names)));
2312 CHECK_NE(NULL, node); 2355 CHECK_NE(NULL, node);
2313 CHECK_LT(node->allocation_count(), 100); 2356 CHECK_LT(node->allocation_count(), 100);
2314 2357
2315 CcTest::heap()->DisableInlineAllocation(); 2358 CcTest::heap()->DisableInlineAllocation();
2316 heap_profiler->StopTrackingHeapObjects(); 2359 heap_profiler->StopTrackingHeapObjects();
2317 } 2360 }
2318 } 2361 }
OLDNEW
« no previous file with comments | « src/heap-profiler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698