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

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

Issue 10049002: Introduce a way to grab heap stats. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: comments addressed Created 8 years, 8 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/profile-generator.h ('k') | test/cctest/test-heap-profiler.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 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 1388 matching lines...) Expand 10 before | Expand all | Expand 10 after
1399 entry_info.accessed = true; 1399 entry_info.accessed = true;
1400 ASSERT(static_cast<uint32_t>(entries_->length()) > 1400 ASSERT(static_cast<uint32_t>(entries_->length()) >
1401 entries_map_.occupancy()); 1401 entries_map_.occupancy());
1402 return entry_info.id; 1402 return entry_info.id;
1403 } else { 1403 } else {
1404 return 0; 1404 return 0;
1405 } 1405 }
1406 } 1406 }
1407 1407
1408 1408
1409 SnapshotObjectId HeapObjectsMap::FindOrAddEntry(Address addr) {
1410 ASSERT(static_cast<uint32_t>(entries_->length()) > entries_map_.occupancy());
1411 HashMap::Entry* entry = entries_map_.Lookup(addr, AddressHash(addr), true);
1412 if (entry->value != NULL) {
1413 int entry_index =
1414 static_cast<int>(reinterpret_cast<intptr_t>(entry->value));
1415 EntryInfo& entry_info = entries_->at(entry_index);
1416 entry_info.accessed = true;
1417 return entry_info.id;
1418 }
1419 entry->value = reinterpret_cast<void*>(entries_->length());
1420 SnapshotObjectId id = next_id_;
1421 next_id_ += kObjectIdStep;
1422 entries_->Add(EntryInfo(id, addr));
1423 ASSERT(static_cast<uint32_t>(entries_->length()) > entries_map_.occupancy());
1424 return id;
1425 }
1426
1427
1428 void HeapObjectsMap::StopHeapObjectsTracking() {
1429 time_intervals_.Clear();
1430 }
1431
1432 void HeapObjectsMap::UpdateHeapObjectsMap() {
1433 HEAP->CollectAllGarbage(Heap::kMakeHeapIterableMask,
1434 "HeapSnapshotsCollection::UpdateHeapObjectsMap");
1435 int entries = 0;
alexeif 2012/04/12 14:55:23 never used?
1436 HeapIterator iterator(HeapIterator::kFilterUnreachable);
1437 for (HeapObject* obj = iterator.next();
1438 obj != NULL;
1439 obj = iterator.next()) {
1440 FindOrAddEntry(obj->address());
1441 ++entries;
1442 }
1443 initial_fill_mode_ = false;
1444 RemoveDeadEntries();
1445 }
1446
1447
1448 void HeapObjectsMap::PushHeapObjectsStats(OutputStream* stream) {
1449 UpdateHeapObjectsMap();
1450 time_intervals_.Add(TimeInterval(next_id_));
1451 int prefered_chunk_size = stream->GetChunkSize();
1452 List<uint32_t> stats_buffer;
1453 ASSERT(!entries_->is_empty());
1454 EntryInfo* entry_info = &entries_->first();
1455 EntryInfo* end_entry_info = &entries_->last() + 1;
1456 uint32_t entries_count = 0;
alexeif 2012/04/12 14:55:23 move it inside the loop.
1457 for (int time_interval_index = 0;
1458 time_interval_index < time_intervals_.length();
1459 ++time_interval_index) {
1460 TimeInterval& time_interval = time_intervals_[time_interval_index];
1461 SnapshotObjectId time_interval_id = time_interval.id;
1462 while (entry_info < end_entry_info && entry_info->id < time_interval_id) {
1463 ++entries_count;
alexeif 2012/04/12 14:55:23 you can eliminate this ++. just calc the differenc
1464 ++entry_info;
1465 }
1466 if (time_interval.count != entries_count) {
1467 stats_buffer.Add(time_interval_index);
1468 stats_buffer.Add(time_interval.count = entries_count);
1469 if (stats_buffer.length() >= prefered_chunk_size) {
1470 OutputStream::WriteResult result = stream->WriteUint32Chunk(
1471 &stats_buffer.first(), stats_buffer.length());
1472 if (result == OutputStream::kAbort) return;
1473 stats_buffer.Clear();
1474 }
1475 }
1476 entries_count = 0;
1477 }
1478 ASSERT(entry_info == end_entry_info);
1479 if (!stats_buffer.is_empty()) {
1480 OutputStream::WriteResult result =
1481 stream->WriteUint32Chunk(&stats_buffer.first(), stats_buffer.length());
1482 if (result == OutputStream::kAbort) return;
1483 }
1484 stream->EndOfStream();
1485 }
1486
1487
1409 void HeapObjectsMap::RemoveDeadEntries() { 1488 void HeapObjectsMap::RemoveDeadEntries() {
1410 ASSERT(entries_->length() > 0 && 1489 ASSERT(entries_->length() > 0 &&
1411 entries_->at(0).id == 0 && 1490 entries_->at(0).id == 0 &&
1412 entries_->at(0).addr == NULL); 1491 entries_->at(0).addr == NULL);
1413 int first_free_entry = 1; 1492 int first_free_entry = 1;
1414 for (int i = 1; i < entries_->length(); ++i) { 1493 for (int i = 1; i < entries_->length(); ++i) {
1415 EntryInfo& entry_info = entries_->at(i); 1494 EntryInfo& entry_info = entries_->at(i);
1416 if (entry_info.accessed) { 1495 if (entry_info.accessed) {
1417 if (first_free_entry != i) { 1496 if (first_free_entry != i) {
1418 entries_->at(first_free_entry) = entry_info; 1497 entries_->at(first_free_entry) = entry_info;
(...skipping 2367 matching lines...) Expand 10 before | Expand all | Expand 10 after
3786 3865
3787 3866
3788 void HeapSnapshotJSONSerializer::SortHashMap( 3867 void HeapSnapshotJSONSerializer::SortHashMap(
3789 HashMap* map, List<HashMap::Entry*>* sorted_entries) { 3868 HashMap* map, List<HashMap::Entry*>* sorted_entries) {
3790 for (HashMap::Entry* p = map->Start(); p != NULL; p = map->Next(p)) 3869 for (HashMap::Entry* p = map->Start(); p != NULL; p = map->Next(p))
3791 sorted_entries->Add(p); 3870 sorted_entries->Add(p);
3792 sorted_entries->Sort(SortUsingEntryValue); 3871 sorted_entries->Sort(SortUsingEntryValue);
3793 } 3872 }
3794 3873
3795 } } // namespace v8::internal 3874 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/profile-generator.h ('k') | test/cctest/test-heap-profiler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698