Reviewers: Primiano Tucci, rmcilroy (OOO till 18th May),

Message:
Adding object count if track_gc_object_stats flag is set.

Description:
Adding api to get last gc object statistics for chrome://tracing.

For dumping the number of objects and size of objects alive after the
last gc into chrome://tracing memory dumps, this CL adds new api to
get these number for each isolate.

BUG=476013
LOG=Y

Please review this at https://codereview.chromium.org/1113233002/

Base URL: https://chromium.googlesource.com/v8/v8.git@master

Affected files (+47, -0 lines):
  M include/v8.h
  M src/api.cc
  M src/heap/heap.h
  M src/heap/heap.cc


Index: include/v8.h
diff --git a/include/v8.h b/include/v8.h
index 89c9042ea8e9c5f2ffb1fa67ea7e43412e3e48ca..f6d355d6864726a2391980dc21e6dd99748bc171 100644
--- a/include/v8.h
+++ b/include/v8.h
@@ -5201,6 +5201,25 @@ class V8_EXPORT Isolate {
                               size_t index);

   /**
+   * Returns the number of types of objects in the heap.
+   */
+  size_t NumberOfHeapObjectsTypes();
+
+  /**
+   * Get statistics about objects in the heap.
+   *
+   * \param object_count The address to fill in number of objects of given
+   *   type, which were live in the previous GC.
+   * \param object_size The address to fill in the size of objects of the
+   *   given type, which were live in the previous GC.
+ * \param type_index The index of the type of object to fill details about,
+   *   which ranges from 0 to NumberOfHeapObjectsTypes() - 1.
+   * \returns true on success.
+   */
+  bool GetLastGcObjectStatistics(size_t* object_count, size_t* object_size,
+                                 size_t type_index);
+
+  /**
    * Get a call stack sample from the isolate.
    * \param state Execution state.
    * \param frames Caller allocated buffer to store stack frames.
Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index de0b0076e0901093d5c8dab59880495ad567342e..adf0956a09c3b4223af2ffd54469cb3796c0a3ff 100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -6930,6 +6930,19 @@ bool Isolate::GetHeapSpaceStatistics(HeapSpaceStatistics* space_statistics,
 }


+size_t Isolate::NumberOfHeapObjectsTypes() {
+  return i::Heap::OBJECT_STATS_COUNT;
+}
+
+bool Isolate::GetLastGcObjectStatistics(size_t* object_count,
+                                        size_t* object_size,
+                                        size_t type_index) {
+  i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
+  i::Heap* heap = isolate->heap();
+ return heap->GetLastGcObjectStatistics(object_count, object_size, type_index);
+}
+
+
 void Isolate::GetStackSample(const RegisterState& state, void** frames,
size_t frames_limit, SampleInfo* sample_info) {
   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
Index: src/heap/heap.cc
diff --git a/src/heap/heap.cc b/src/heap/heap.cc
index 8d34738dae81757b9e5918875d6adf41cecf98bb..eec895b7ac998f005842dc30da09edddd1f3883e 100644
--- a/src/heap/heap.cc
+++ b/src/heap/heap.cc
@@ -372,6 +372,18 @@ void Heap::PrintShortHeapStatistics() {
 }


+bool Heap::GetLastGcObjectStatistics(size_t* object_count, size_t* object_size,
+                                     size_t type_index) {
+  if (!object_count || !object_size) return false;
+  if (type_index >= OBJECT_STATS_COUNT) return false;
+  if (!FLAG_track_gc_object_stats) return false;
+
+  *object_count = object_counts_last_time_[type_index];
+  *object_size = object_sizes_last_time_[type_index];
+  return true;
+}
+
+
 // TODO(1238405): Combine the infrastructure for --heap-stats and
 // --log-gc to avoid the complicated preprocessor and flag testing.
 void Heap::ReportStatisticsAfterGC() {
Index: src/heap/heap.h
diff --git a/src/heap/heap.h b/src/heap/heap.h
index d019293c7b0e08cac803f3a6dfb756100b500c60..327674667914c0d8da05efa37fe4c58e5c441f90 100644
--- a/src/heap/heap.h
+++ b/src/heap/heap.h
@@ -1024,6 +1024,9 @@ class Heap {
   // Print short heap statistics.
   void PrintShortHeapStatistics();

+  bool GetLastGcObjectStatistics(size_t* object_count, size_t* object_size,
+                                 size_t type_index);
+
   // Write barrier support for address[offset] = o.
   INLINE(void RecordWrite(Address address, int offset));



--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to