Chromium Code Reviews| Index: chrome/browser/chrome_browser_main_linux.cc |
| diff --git a/chrome/browser/chrome_browser_main_linux.cc b/chrome/browser/chrome_browser_main_linux.cc |
| index 870a95c53670669280fffd38d6492facb7d74dff..2c46b56f4582e02b1275bc9a2471fbfc89dd5339 100644 |
| --- a/chrome/browser/chrome_browser_main_linux.cc |
| +++ b/chrome/browser/chrome_browser_main_linux.cc |
| @@ -4,6 +4,8 @@ |
| #include "chrome/browser/chrome_browser_main_linux.h" |
| +#include "base/debug/trace_memory.h" |
| + |
| #if !defined(OS_CHROMEOS) |
| #include "chrome/browser/storage_monitor/storage_monitor_linux.h" |
| #include "content/public/browser/browser_thread.h" |
| @@ -101,6 +103,45 @@ bool IsCrashReportingEnabled(const PrefService* local_state) { |
| } |
| #endif // defined(USE_LINUX_BREAKPAD) |
| +class MemoryDumpHolder : public base::debug::ConvertableToTraceFormat { |
| + public: |
| + // Takes ownership of dump, which must be a JSON string, allocated with |
| + // malloc() and NULL terminated. |
| + explicit MemoryDumpHolder(char* dump) : dump_(dump) {} |
| + virtual ~MemoryDumpHolder() { free(dump_); } |
| + |
| + // base::debug::ConvertableToTraceFormat overrides: |
| + virtual void AppendAsTraceFormat(std::string* out) const OVERRIDE { |
| + LOG(ERROR) << "JAMESDEBUG AppendAsTraceFormat dump len " << strlen(dump_); |
|
James Cook
2013/05/21 01:45:41
I'm now seeing this string printed after taking a
|
| + out->append(dump_); |
| + } |
| + |
| + private: |
| + char* dump_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(MemoryDumpHolder); |
| +}; |
| + |
| +void DumpMemoryProfile() { |
| + // Check to see if tracing is enabled for the memory category. |
| + bool enabled; |
| + TRACE_EVENT_CATEGORY_GROUP_ENABLED("memory", &enabled); |
| + if (enabled) { |
| + // We take ownership of this string. |
| + char* dump = base::TraceMemoryDumpAsString(); |
| + scoped_ptr<MemoryDumpHolder> dump_holder(new MemoryDumpHolder(dump)); |
| + const int kSnapshotId = 1; |
| + TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID( |
| + "memory", |
| + "memory::Heap", |
| + kSnapshotId, |
| + dump_holder.PassAs<base::debug::ConvertableToTraceFormat>()); |
| + } |
| + MessageLoop::current()->PostDelayedTask(FROM_HERE, |
| + base::Bind(&DumpMemoryProfile), |
| + base::TimeDelta::FromSeconds(10)); |
| +} |
| + |
| } // namespace |
| ChromeBrowserMainPartsLinux::ChromeBrowserMainPartsLinux( |
| @@ -141,6 +182,19 @@ void ChromeBrowserMainPartsLinux::PostProfileInit() { |
| ChromeBrowserMainPartsPosix::PostProfileInit(); |
| } |
| +void ChromeBrowserMainPartsLinux::PreMainMessageLoopRun() { |
| + ChromeBrowserMainPartsPosix::PreMainMessageLoopRun(); |
| + |
| + // TODO(jamescook): This could be moved earlier in startup to capture more |
| + // startup allocations. |
| + base::TraceMemoryStart(); |
| + |
| + // Dump a heap profile every 10 seconds, forever. |
| + MessageLoop::current()->PostDelayedTask(FROM_HERE, |
| + base::Bind(&DumpMemoryProfile), |
| + base::TimeDelta::FromSeconds(10)); |
| +} |
| + |
| void ChromeBrowserMainPartsLinux::PostMainMessageLoopRun() { |
| #if !defined(OS_CHROMEOS) |
| // Delete it now. Otherwise the FILE thread would be gone when we try to |
| @@ -149,5 +203,8 @@ void ChromeBrowserMainPartsLinux::PostMainMessageLoopRun() { |
| storage_monitor_.reset(); |
| #endif |
| + base::TraceMemoryDump(); |
| + base::TraceMemoryStop(); |
| + |
| ChromeBrowserMainPartsPosix::PostMainMessageLoopRun(); |
| } |