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

Unified Diff: src/api.cc

Issue 1058253003: Adding V8 api to get memory statistics of spaces in V8::Heap. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 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 side-by-side diff with in-line comments
Download patch
« include/v8.h ('K') | « include/v8.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index 28c84106df4c260cfbd2e96972a12efcd1f10964..89e3b3714bef60c836b1d160eeda194332e95f0b 100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -30,6 +30,7 @@
#include "src/deoptimizer.h"
#include "src/execution.h"
#include "src/global-handles.h"
+#include "src/heap/spaces.h"
#include "src/heap-profiler.h"
#include "src/heap-snapshot-generator-inl.h"
#include "src/icu_util.h"
@@ -6957,15 +6958,55 @@ Isolate::SuppressMicrotaskExecutionScope::~SuppressMicrotaskExecutionScope() {
}
+class HeapStatisticsHelper {
rmcilroy 2015/04/13 12:48:23 I don't think we should have a seperate class just
+ public:
+ static void ExtractHeapStatistics(HeapStatistics* heap_statistics,
+ i::Heap* heap) {
+ heap_statistics->total_heap_size_ = heap->CommittedMemory();
+ heap_statistics->total_heap_size_executable_ =
+ heap->CommittedMemoryExecutable();
+ heap_statistics->total_physical_size_ = heap->CommittedPhysicalMemory();
+ heap_statistics->used_heap_size_ = heap->SizeOfObjects();
+ heap_statistics->heap_size_limit_ = heap->MaxReserved();
+
+ heap_statistics->new_space_statistics()->size_of_objects_ =
+ heap->new_space()->Size();
+ heap_statistics->new_space_statistics()->available_memory_ =
+ heap->new_space()->Available();
+ heap_statistics->new_space_statistics()->committed_memory_ =
+ heap->new_space()->CommittedMemory();
+
+ heap_statistics->lo_space_statistics()->size_of_objects_ =
+ heap->lo_space()->SizeOfObjects();
+ heap_statistics->lo_space_statistics()->available_memory_ =
+ heap->lo_space()->Available();
+ heap_statistics->lo_space_statistics()->committed_memory_ =
+ heap->lo_space()->CommittedMemory();
+
+ ExtractSpaceStatisticsFromPagedSpace(
+ heap->old_space(), heap_statistics->old_space_statistics());
+ ExtractSpaceStatisticsFromPagedSpace(
+ heap->code_space(), heap_statistics->code_space_statistics());
+ ExtractSpaceStatisticsFromPagedSpace(
+ heap->map_space(), heap_statistics->map_space_statistics());
+ ExtractSpaceStatisticsFromPagedSpace(
+ heap->cell_space(), heap_statistics->cell_space_statistics());
+ }
+
+ static void ExtractSpaceStatisticsFromPagedSpace(
+ i::PagedSpace* paged_space,
+ HeapStatistics::SpaceStatistics* space_stats) {
+ space_stats->size_of_objects_ = paged_space->SizeOfObjects();
+ space_stats->committed_memory_ = paged_space->CommittedMemory();
+ space_stats->available_memory_ = paged_space->Available();
+ }
+};
+
+
void Isolate::GetHeapStatistics(HeapStatistics* heap_statistics) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
i::Heap* heap = isolate->heap();
- heap_statistics->total_heap_size_ = heap->CommittedMemory();
- heap_statistics->total_heap_size_executable_ =
- heap->CommittedMemoryExecutable();
- heap_statistics->total_physical_size_ = heap->CommittedPhysicalMemory();
- heap_statistics->used_heap_size_ = heap->SizeOfObjects();
- heap_statistics->heap_size_limit_ = heap->MaxReserved();
+ HeapStatisticsHelper::ExtractHeapStatistics(heap_statistics, heap);
}
« include/v8.h ('K') | « include/v8.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698