Heap profiling: add logging of heap memory stats (capacity, used) under 'log-gc'...
authormikhail.naganov@gmail.com <mikhail.naganov@gmail.com@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Mon, 20 Jul 2009 09:38:44 +0000 (09:38 +0000)
committermikhail.naganov@gmail.com <mikhail.naganov@gmail.com@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Mon, 20 Jul 2009 09:38:44 +0000 (09:38 +0000)
Also changed time reporting to system time to be able to get synchronized with other memory (e.g. DOM) size status.

Review URL: http://codereview.chromium.org/155764

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@2509 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

src/heap.cc
src/log.cc
src/log.h
tools/process-heap-prof.py

index 9f5d303..cad1755 100644 (file)
@@ -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 16f3fb5..33cf8e2 100644 (file)
@@ -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 f68234f..95c9cde 100644 (file)
--- 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 79c49f8..b8ab2d3 100755 (executable)
@@ -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':