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

Side by Side Diff: src/profile-generator.cc

Issue 10535096: Implement heap profiler memory usage reporting. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 6 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
« include/v8-profiler.h ('K') | « src/profile-generator.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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 } 162 }
163 return ""; 163 return "";
164 } 164 }
165 165
166 166
167 const char* StringsStorage::GetName(int index) { 167 const char* StringsStorage::GetName(int index) {
168 return GetFormatted("%d", index); 168 return GetFormatted("%d", index);
169 } 169 }
170 170
171 171
172 size_t StringsStorage::GetUsedMemorySize() const {
173 size_t size = sizeof(*this);
174 size += sizeof(HashMap::Entry) * names_.capacity();
175 for (HashMap::Entry* p = names_.Start(); p != NULL; p = names_.Next(p)) {
176 size += strlen(reinterpret_cast<const char*>(p->value)) + 1;
177 }
178 return size;
179 }
180
172 const char* const CodeEntry::kEmptyNamePrefix = ""; 181 const char* const CodeEntry::kEmptyNamePrefix = "";
173 182
174 183
175 void CodeEntry::CopyData(const CodeEntry& source) { 184 void CodeEntry::CopyData(const CodeEntry& source) {
176 tag_ = source.tag_; 185 tag_ = source.tag_;
177 name_prefix_ = source.name_prefix_; 186 name_prefix_ = source.name_prefix_;
178 name_ = source.name_; 187 name_ = source.name_;
179 resource_name_ = source.resource_name_; 188 resource_name_ = source.resource_name_;
180 line_number_ = source.line_number_; 189 line_number_ = source.line_number_;
181 } 190 }
(...skipping 1054 matching lines...) Expand 10 before | Expand all | Expand 10 after
1236 } 1245 }
1237 1246
1238 1247
1239 void HeapSnapshot::Print(int max_depth) { 1248 void HeapSnapshot::Print(int max_depth) {
1240 root()->Print("", "", max_depth, 0); 1249 root()->Print("", "", max_depth, 0);
1241 } 1250 }
1242 1251
1243 1252
1244 template<typename T, class P> 1253 template<typename T, class P>
1245 static size_t GetMemoryUsedByList(const List<T, P>& list) { 1254 static size_t GetMemoryUsedByList(const List<T, P>& list) {
1246 return list.capacity() * sizeof(T); 1255 return list.length() * sizeof(T) + sizeof(list);
1247 } 1256 }
1248 1257
1249 1258
1250 size_t HeapSnapshot::RawSnapshotSize() const { 1259 size_t HeapSnapshot::RawSnapshotSize() const {
1251 return 1260 return
1261 sizeof(*this) +
1252 GetMemoryUsedByList(entries_) + 1262 GetMemoryUsedByList(entries_) +
1253 GetMemoryUsedByList(edges_) + 1263 GetMemoryUsedByList(edges_) +
1254 GetMemoryUsedByList(children_) + 1264 GetMemoryUsedByList(children_) +
1255 GetMemoryUsedByList(sorted_entries_); 1265 GetMemoryUsedByList(sorted_entries_);
1256 } 1266 }
1257 1267
1258 1268
1259 // We split IDs on evens for embedder objects (see 1269 // We split IDs on evens for embedder objects (see
1260 // HeapObjectsMap::GenerateId) and odds for native objects. 1270 // HeapObjectsMap::GenerateId) and odds for native objects.
1261 const SnapshotObjectId HeapObjectsMap::kInternalRootObjectId = 1; 1271 const SnapshotObjectId HeapObjectsMap::kInternalRootObjectId = 1;
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
1439 static_cast<int>(strlen(label)), 1449 static_cast<int>(strlen(label)),
1440 HEAP->HashSeed()); 1450 HEAP->HashSeed());
1441 intptr_t element_count = info->GetElementCount(); 1451 intptr_t element_count = info->GetElementCount();
1442 if (element_count != -1) 1452 if (element_count != -1)
1443 id ^= ComputeIntegerHash(static_cast<uint32_t>(element_count), 1453 id ^= ComputeIntegerHash(static_cast<uint32_t>(element_count),
1444 v8::internal::kZeroHashSeed); 1454 v8::internal::kZeroHashSeed);
1445 return id << 1; 1455 return id << 1;
1446 } 1456 }
1447 1457
1448 1458
1459 size_t HeapObjectsMap::GetUsedMemorySize() const {
1460 return
1461 sizeof(*this) +
1462 sizeof(HashMap::Entry) * entries_map_.capacity() +
1463 GetMemoryUsedByList(entries_) +
1464 GetMemoryUsedByList(time_intervals_);
1465 }
1466
1467
1449 HeapSnapshotsCollection::HeapSnapshotsCollection() 1468 HeapSnapshotsCollection::HeapSnapshotsCollection()
1450 : is_tracking_objects_(false), 1469 : is_tracking_objects_(false),
1451 snapshots_uids_(HeapSnapshotsMatch), 1470 snapshots_uids_(HeapSnapshotsMatch),
1452 token_enumerator_(new TokenEnumerator()) { 1471 token_enumerator_(new TokenEnumerator()) {
1453 } 1472 }
1454 1473
1455 1474
1456 static void DeleteHeapSnapshot(HeapSnapshot** snapshot_ptr) { 1475 static void DeleteHeapSnapshot(HeapSnapshot** snapshot_ptr) {
1457 delete *snapshot_ptr; 1476 delete *snapshot_ptr;
1458 } 1477 }
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1518 if (ids_.FindEntry(obj->address()) == id) { 1537 if (ids_.FindEntry(obj->address()) == id) {
1519 ASSERT(object == NULL); 1538 ASSERT(object == NULL);
1520 object = obj; 1539 object = obj;
1521 // Can't break -- kFilterUnreachable requires full heap traversal. 1540 // Can't break -- kFilterUnreachable requires full heap traversal.
1522 } 1541 }
1523 } 1542 }
1524 return object != NULL ? Handle<HeapObject>(object) : Handle<HeapObject>(); 1543 return object != NULL ? Handle<HeapObject>(object) : Handle<HeapObject>();
1525 } 1544 }
1526 1545
1527 1546
1547 size_t HeapSnapshotsCollection::GetUsedMemorySize() const {
1548 size_t size = sizeof(*this);
mnaganov (inactive) 2012/06/11 09:47:19 I think we need to mention in declarations of all
loislo 2012/06/11 09:59:20 2 alexeif: please provide a run-time assert or eve
mnaganov (inactive) 2012/06/11 10:01:55 Compile-time assert is preferred.
alf 2012/06/12 17:51:28 Done.
1549 size += names_.GetUsedMemorySize();
1550 size += ids_.GetUsedMemorySize();
1551 size += sizeof(HashMap::Entry) * snapshots_uids_.capacity();
1552 size += GetMemoryUsedByList(snapshots_);
1553 for (int i = 0; i < snapshots_.length(); ++i) {
1554 size += snapshots_[i]->RawSnapshotSize();
1555 }
1556 return size;
1557 }
1558
1559
1528 HeapEntriesMap::HeapEntriesMap() 1560 HeapEntriesMap::HeapEntriesMap()
1529 : entries_(HeapThingsMatch) { 1561 : entries_(HeapThingsMatch) {
1530 } 1562 }
1531 1563
1532 1564
1533 int HeapEntriesMap::Map(HeapThing thing) { 1565 int HeapEntriesMap::Map(HeapThing thing) {
1534 HashMap::Entry* cache_entry = entries_.Lookup(thing, Hash(thing), false); 1566 HashMap::Entry* cache_entry = entries_.Lookup(thing, Hash(thing), false);
1535 if (cache_entry == NULL) return HeapEntry::kNoEntry; 1567 if (cache_entry == NULL) return HeapEntry::kNoEntry;
1536 return static_cast<int>(reinterpret_cast<intptr_t>(cache_entry->value)); 1568 return static_cast<int>(reinterpret_cast<intptr_t>(cache_entry->value));
1537 } 1569 }
(...skipping 1979 matching lines...) Expand 10 before | Expand all | Expand 10 after
3517 3549
3518 3550
3519 void HeapSnapshotJSONSerializer::SortHashMap( 3551 void HeapSnapshotJSONSerializer::SortHashMap(
3520 HashMap* map, List<HashMap::Entry*>* sorted_entries) { 3552 HashMap* map, List<HashMap::Entry*>* sorted_entries) {
3521 for (HashMap::Entry* p = map->Start(); p != NULL; p = map->Next(p)) 3553 for (HashMap::Entry* p = map->Start(); p != NULL; p = map->Next(p))
3522 sorted_entries->Add(p); 3554 sorted_entries->Add(p);
3523 sorted_entries->Sort(SortUsingEntryValue); 3555 sorted_entries->Sort(SortUsingEntryValue);
3524 } 3556 }
3525 3557
3526 } } // namespace v8::internal 3558 } } // namespace v8::internal
OLDNEW
« include/v8-profiler.h ('K') | « src/profile-generator.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698