Reviewers: Mads Ager,

Description:
Heap profiling: add logging of heap memory stats (capacity, used) under
'log-gc' flag.

Also changed time reporting to system time to be able to get
synchronized with other memory (e.g. DOM) size status.

Please review this at http://codereview.chromium.org/155764

Affected files:
   M src/heap.cc
   M src/log.h
   M src/log.cc
   M tools/process-heap-prof.py


Index: src/heap.cc
diff --git a/src/heap.cc b/src/heap.cc
index  
9f5d30385bd701596c5c5e4d7147cb722e1121b4..cad175587fc1870e97c680d1297a4adc23925633
  
100644
--- a/src/heap.cc
+++ b/src/heap.cc
@@ -3406,6 +3406,8 @@ void HeapProfiler::CollectStats(HeapObject* obj,  
HistogramInfo* info) {
  #ifdef ENABLE_LOGGING_AND_PROFILING
  void HeapProfiler::WriteSample() {
    LOG(HeapSampleBeginEvent("Heap", "allocated"));
+  LOG(HeapSampleStats(
+      "Heap", "allocated", Heap::Capacity(), Heap::SizeOfObjects()));

    HistogramInfo info[LAST_TYPE+1];
  #define DEF_TYPE_NAME(name) info[name].set_name(#name);
Index: src/log.cc
diff --git a/src/log.cc b/src/log.cc
index  
16f3fb5bf81044be2147322d2442fd90291be6cf..33cf8e271affd4dcb6bd2ae6d3e53ad1ff1e8005
  
100644
--- a/src/log.cc
+++ b/src/log.cc
@@ -843,12 +843,22 @@ void Logger::HeapSampleBeginEvent(const char* space,  
const char* kind) {
  #ifdef ENABLE_LOGGING_AND_PROFILING
    if (!Log::IsEnabled() || !FLAG_log_gc) return;
    LogMessageBuilder msg;
-  msg.Append("heap-sample-begin,\"%s\",\"%s\"", space, kind);
-  uint32_t sec, usec;
-  if (OS::GetUserTime(&sec, &usec) != -1) {
-    msg.Append(",%d,%d", sec, usec);
-  }
-  msg.Append('\n');
+  // Using non-relative system time in order to be able to synchronize with
+  // external memory profiling events (e.g. DOM memory size).
+  msg.Append("heap-sample-begin,\"%s\",\"%s\",%.0f\n",
+             space, kind, OS::TimeCurrentMillis());
+  msg.WriteToLogFile();
+#endif
+}
+
+
+void Logger::HeapSampleStats(const char* space, const char* kind,
+                             int capacity, int used) {
+#ifdef ENABLE_LOGGING_AND_PROFILING
+  if (!Log::IsEnabled() || !FLAG_log_gc) return;
+  LogMessageBuilder msg;
+  msg.Append("heap-sample-stats,\"%s\",\"%s\",%d,%d\n",
+             space, kind, capacity, used);
    msg.WriteToLogFile();
  #endif
  }
Index: src/log.h
diff --git a/src/log.h b/src/log.h
index  
f68234f1e6306000117eefe89d4a95b48d075caa..95c9cdedc76d06b69564855ff38959b0802e5794
  
100644
--- a/src/log.h
+++ b/src/log.h
@@ -219,6 +219,8 @@ class Logger {
    static void HeapSampleBeginEvent(const char* space, const char* kind);
    static void HeapSampleEndEvent(const char* space, const char* kind);
    static void HeapSampleItemEvent(const char* type, int number, int bytes);
+  static void HeapSampleStats(const char* space, const char* kind,
+                              int capacity, int used);

    static void SharedLibraryEvent(const char* library_path,
                                   uintptr_t start,
Index: tools/process-heap-prof.py
diff --git a/tools/process-heap-prof.py b/tools/process-heap-prof.py
index  
79c49f83d8ca300d2aa3f2f16ac5ff7cc0b05e2b..b8ab2d39863e345d7572f6a6d541a25d32401eb9
  
100755
--- a/tools/process-heap-prof.py
+++ b/tools/process-heap-prof.py
@@ -39,6 +39,7 @@
  import csv, sys, time

  def process_logfile(filename):
+  first_call_time = None
    sample_time = 0.0
    sampling = False
    try:
@@ -53,7 +54,10 @@ def process_logfile(filename):

        for row in logreader:
          if row[0] == 'heap-sample-begin' and row[1] == 'Heap':
-          sample_time = float(row[3]) + float(row[4])/1000000.0
+          sample_time = float(row[3])/1000.0
+          if first_call_time == None:
+            first_call_time = sample_time
+          sample_time -= first_call_time
            print('BEGIN_SAMPLE %.2f' % sample_time)
            sampling = True
          elif row[0] == 'heap-sample-end' and row[1] == 'Heap':



--~--~---------~--~----~------------~-------~--~----~
v8-dev mailing list
v8-dev@googlegroups.com
http://groups.google.com/group/v8-dev
-~----------~----~----~----~------~----~------~--~---

Reply via email to