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..355401e83a7bedf84c1dccf3cac7cfe5b78d93f0 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,58 @@ bool IsCrashReportingEnabled(const PrefService* local_state) { |
} |
#endif // defined(USE_LINUX_BREAKPAD) |
+/* |
+ * std::string my_str; |
+ TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID(TRACE_DISABLED_BY_DEFAULT("cc.debug"), |
+ "cc::Picture", clone.get(), my_str); |
+ |
+std::string* my_str; |
+tcmalloc_dump(&my_str); |
+MyStringOnwer : base::Debug::ConvdrtableToTraceLog // cc/debug/traced_picture.h for example |
+scoped_ptr<MyStringOwner> mystr = ...; |
+ |
+ |
+TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID("tcmalloc", "tcmalloc::Heap", 1, my_str); |
+*/ |
+class MemoryDumpHolder : public base::debug::ConvertableToTraceFormat { |
+ public: |
+ // Takes ownership of dump, which must be 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 { |
+ out->append("{\"heap_dump\": "); |
+ //TODO - use JSON version |
+ out->append(dump_); |
+ LOG(ERROR) << "JAMESDEBUG1\n" << dump_; |
+ out->append("\"}"); |
+ } |
+ |
+ 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_API_GET_CATEGORY_GROUP_ENABLED("tcmalloc2"); |
nduca
2013/05/20 23:03:41
static bool* enabled = ...
if (*enabled) {
}
dsinclair
2013/05/21 00:32:07
bool enabled;
TRACE_EVENT_CATEGORY_GROUP_ENABLED("
|
+ if (enabled) { |
+ // We take ownership of this string. |
+ char* dump = base::TraceMemoryDumpAsString(); |
+// LOG(ERROR) << "JAMESDEBUG2\n" << dump; |
+ scoped_ptr<MemoryDumpHolder> dump_holder(new MemoryDumpHolder(dump)); |
nduca
2013/05/20 23:04:44
maybe this needs to be scoped_ptr<base::debug::Con
dsinclair
2013/05/21 00:32:07
Doesn't have to be, you can use PassAs below.
|
+// const int kSnapshotId = 1; |
+ TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID( |
+ "tcmalloc2", "tcmalloc2::Heap", dump_holder.get(), dump_holder); |
nduca
2013/05/20 23:03:41
3rd arg should be 1
dsinclair
2013/05/21 00:32:07
You don't want to do the .get() on dump_holder. Th
|
+ } |
+ MessageLoop::current()->PostDelayedTask(FROM_HERE, |
+ base::Bind(&DumpMemoryProfile), |
+ base::TimeDelta::FromSeconds(10)); |
+} |
+ |
} // namespace |
ChromeBrowserMainPartsLinux::ChromeBrowserMainPartsLinux( |
@@ -141,6 +195,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 +216,8 @@ void ChromeBrowserMainPartsLinux::PostMainMessageLoopRun() { |
storage_monitor_.reset(); |
#endif |
+ base::TraceMemoryDump(); |
+ base::TraceMemoryStop(); |
+ |
ChromeBrowserMainPartsPosix::PostMainMessageLoopRun(); |
} |