From ec526df16ff4c3b878f23820b1d3de115e441359 Mon Sep 17 00:00:00 2001 From: "mikhail.naganov@gmail.com" Date: Mon, 20 Jul 2009 09:38:44 +0000 Subject: [PATCH] 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. 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 | 2 ++ src/log.cc | 22 ++++++++++++++++------ src/log.h | 2 ++ tools/process-heap-prof.py | 6 +++++- 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/heap.cc b/src/heap.cc index 9f5d303..cad1755 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); diff --git a/src/log.cc b/src/log.cc index 16f3fb5..33cf8e2 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 } diff --git a/src/log.h b/src/log.h index f68234f..95c9cde 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, diff --git a/tools/process-heap-prof.py b/tools/process-heap-prof.py index 79c49f8..b8ab2d3 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': -- 2.7.4