Revision: 11793
Author:   [email protected]
Date:     Wed Jun 13 04:02:24 2012
Log:      Implement heap profiler memory usage reporting.

Review URL: https://chromiumcodereview.appspot.com/10535096
http://code.google.com/p/v8/source/detail?r=11793

Modified:
 /branches/bleeding_edge/include/v8-profiler.h
 /branches/bleeding_edge/src/api.cc
 /branches/bleeding_edge/src/heap-profiler.cc
 /branches/bleeding_edge/src/heap-profiler.h
 /branches/bleeding_edge/src/profile-generator.cc
 /branches/bleeding_edge/src/profile-generator.h

=======================================
--- /branches/bleeding_edge/include/v8-profiler.h       Fri Jun  1 09:10:52 2012
+++ /branches/bleeding_edge/include/v8-profiler.h       Wed Jun 13 04:02:24 2012
@@ -482,6 +482,9 @@

   /** Returns the number of currently existing persistent handles. */
   static int GetPersistentHandleCount();
+
+  /** Returns memory used for profiler internal data and snapshots. */
+  static size_t GetMemorySizeUsedByProfiler();
 };


=======================================
--- /branches/bleeding_edge/src/api.cc  Fri Jun  8 00:45:11 2012
+++ /branches/bleeding_edge/src/api.cc  Wed Jun 13 04:02:24 2012
@@ -6268,6 +6268,11 @@
   i::Isolate* isolate = i::Isolate::Current();
   return isolate->global_handles()->NumberOfGlobalHandles();
 }
+
+
+size_t HeapProfiler::GetMemorySizeUsedByProfiler() {
+  return i::HeapProfiler::GetMemorySizeUsedByProfiler();
+}


 v8::Testing::StressType internal::Testing::stress_type_ =
=======================================
--- /branches/bleeding_edge/src/heap-profiler.cc        Fri Jun  1 09:10:52 2012
+++ /branches/bleeding_edge/src/heap-profiler.cc        Wed Jun 13 04:02:24 2012
@@ -166,6 +166,14 @@
 void HeapProfiler::StopHeapObjectsTrackingImpl() {
   snapshots_->StopHeapObjectsTracking();
 }
+
+
+size_t HeapProfiler::GetMemorySizeUsedByProfiler() {
+  HeapProfiler* profiler = Isolate::Current()->heap_profiler();
+  ASSERT(profiler != NULL);
+  size_t size = profiler->snapshots_->GetUsedMemorySize();
+  return size;
+}


 int HeapProfiler::GetSnapshotsCount() {
=======================================
--- /branches/bleeding_edge/src/heap-profiler.h Fri Jun  1 09:10:52 2012
+++ /branches/bleeding_edge/src/heap-profiler.h Wed Jun 13 04:02:24 2012
@@ -49,6 +49,8 @@
   static void SetUp();
   static void TearDown();

+  static size_t GetMemorySizeUsedByProfiler();
+
   static HeapSnapshot* TakeSnapshot(const char* name,
                                     int type,
                                     v8::ActivityControl* control);
=======================================
--- /branches/bleeding_edge/src/profile-generator.cc Sun Jun 10 23:59:56 2012 +++ /branches/bleeding_edge/src/profile-generator.cc Wed Jun 13 04:02:24 2012
@@ -169,6 +169,15 @@
 }


+size_t StringsStorage::GetUsedMemorySize() const {
+  size_t size = sizeof(*this);
+  size += sizeof(HashMap::Entry) * names_.capacity();
+  for (HashMap::Entry* p = names_.Start(); p != NULL; p = names_.Next(p)) {
+    size += strlen(reinterpret_cast<const char*>(p->value)) + 1;
+  }
+  return size;
+}
+
 const char* const CodeEntry::kEmptyNamePrefix = "";


@@ -1083,12 +1092,16 @@
 template <> struct SnapshotSizeConstants<4> {
   static const int kExpectedHeapGraphEdgeSize = 12;
   static const int kExpectedHeapEntrySize = 24;
+  static const int kExpectedHeapSnapshotsCollectionSize = 96;
+  static const int kExpectedHeapSnapshotSize = 136;
   static const size_t kMaxSerializableSnapshotRawSize = 256 * MB;
 };

 template <> struct SnapshotSizeConstants<8> {
   static const int kExpectedHeapGraphEdgeSize = 24;
   static const int kExpectedHeapEntrySize = 32;
+  static const int kExpectedHeapSnapshotsCollectionSize = 144;
+  static const int kExpectedHeapSnapshotSize = 168;
   static const uint64_t kMaxSerializableSnapshotRawSize =
       static_cast<uint64_t>(6000) * MB;
 };
@@ -1243,12 +1256,15 @@

 template<typename T, class P>
 static size_t GetMemoryUsedByList(const List<T, P>& list) {
-  return list.capacity() * sizeof(T);
+  return list.length() * sizeof(T) + sizeof(list);
 }


 size_t HeapSnapshot::RawSnapshotSize() const {
+  STATIC_CHECK(sizeof(*this) ==
+      SnapshotSizeConstants<kPointerSize>::kExpectedHeapSnapshotSize);
   return
+      sizeof(*this) +
       GetMemoryUsedByList(entries_) +
       GetMemoryUsedByList(edges_) +
       GetMemoryUsedByList(children_) +
@@ -1444,6 +1460,15 @@
                              v8::internal::kZeroHashSeed);
   return id << 1;
 }
+
+
+size_t HeapObjectsMap::GetUsedMemorySize() const {
+  return
+      sizeof(*this) +
+      sizeof(HashMap::Entry) * entries_map_.capacity() +
+      GetMemoryUsedByList(entries_) +
+      GetMemoryUsedByList(time_intervals_);
+}


 HeapSnapshotsCollection::HeapSnapshotsCollection()
@@ -1523,6 +1548,22 @@
   }
return object != NULL ? Handle<HeapObject>(object) : Handle<HeapObject>();
 }
+
+
+size_t HeapSnapshotsCollection::GetUsedMemorySize() const {
+  STATIC_CHECK(
+      sizeof(*this) == SnapshotSizeConstants<kPointerSize>::
+          kExpectedHeapSnapshotsCollectionSize);
+  size_t size = sizeof(*this);
+  size += names_.GetUsedMemorySize();
+  size += ids_.GetUsedMemorySize();
+  size += sizeof(HashMap::Entry) * snapshots_uids_.capacity();
+  size += GetMemoryUsedByList(snapshots_);
+  for (int i = 0; i < snapshots_.length(); ++i) {
+    size += snapshots_[i]->RawSnapshotSize();
+  }
+  return size;
+}


 HeapEntriesMap::HeapEntriesMap()
=======================================
--- /branches/bleeding_edge/src/profile-generator.h     Wed Jun  6 03:57:20 2012
+++ /branches/bleeding_edge/src/profile-generator.h     Wed Jun 13 04:02:24 2012
@@ -72,6 +72,7 @@
   const char* GetName(int index);
   inline const char* GetFunctionName(String* name);
   inline const char* GetFunctionName(const char* name);
+  size_t GetUsedMemorySize() const;

  private:
   static const int kMaxNameSize = 1024;
@@ -650,6 +651,7 @@

   void StopHeapObjectsTracking();
   SnapshotObjectId PushHeapObjectsStats(OutputStream* stream);
+  size_t GetUsedMemorySize() const;

   static SnapshotObjectId GenerateId(v8::RetainedObjectInfo* info);
   static inline SnapshotObjectId GetNthGcSubrootId(int delta);
@@ -734,6 +736,7 @@
   SnapshotObjectId last_assigned_id() const {
     return ids_.last_assigned_id();
   }
+  size_t GetUsedMemorySize() const;

  private:
   INLINE(static bool HeapSnapshotsMatch(void* key1, void* key2)) {

--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to