Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(390)

Side by Side Diff: chrome/browser/chrome_browser_main_linux.cc

Issue 15418002: Record Chrome trace events in tcmalloc heap profiles (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: still no dots Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chrome_browser_main_linux.h" 5 #include "chrome/browser/chrome_browser_main_linux.h"
6 6
7 #include "base/debug/trace_memory.h"
8
7 #if !defined(OS_CHROMEOS) 9 #if !defined(OS_CHROMEOS)
8 #include "chrome/browser/storage_monitor/storage_monitor_linux.h" 10 #include "chrome/browser/storage_monitor/storage_monitor_linux.h"
9 #include "content/public/browser/browser_thread.h" 11 #include "content/public/browser/browser_thread.h"
10 #endif 12 #endif
11 13
12 #if defined(USE_LINUX_BREAKPAD) 14 #if defined(USE_LINUX_BREAKPAD)
13 #include <stdlib.h> 15 #include <stdlib.h>
14 16
15 #include "base/command_line.h" 17 #include "base/command_line.h"
16 #include "base/linux_util.h" 18 #include "base/linux_util.h"
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 breakpad_enabled = getenv(env_vars::kHeadless) != NULL; 96 breakpad_enabled = getenv(env_vars::kHeadless) != NULL;
95 if (!breakpad_enabled) 97 if (!breakpad_enabled)
96 breakpad_enabled = CommandLine::ForCurrentProcess()->HasSwitch( 98 breakpad_enabled = CommandLine::ForCurrentProcess()->HasSwitch(
97 switches::kEnableCrashReporterForTesting); 99 switches::kEnableCrashReporterForTesting);
98 } 100 }
99 101
100 return breakpad_enabled; 102 return breakpad_enabled;
101 } 103 }
102 #endif // defined(USE_LINUX_BREAKPAD) 104 #endif // defined(USE_LINUX_BREAKPAD)
103 105
106 class MemoryDumpHolder : public base::debug::ConvertableToTraceFormat {
107 public:
108 // Takes ownership of dump, which must be a JSON string, allocated with
109 // malloc() and NULL terminated.
110 explicit MemoryDumpHolder(char* dump) : dump_(dump) {}
111 virtual ~MemoryDumpHolder() { free(dump_); }
112
113 // base::debug::ConvertableToTraceFormat overrides:
114 virtual void AppendAsTraceFormat(std::string* out) const OVERRIDE {
115 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
116 out->append(dump_);
117 }
118
119 private:
120 char* dump_;
121
122 DISALLOW_COPY_AND_ASSIGN(MemoryDumpHolder);
123 };
124
125 void DumpMemoryProfile() {
126 // Check to see if tracing is enabled for the memory category.
127 bool enabled;
128 TRACE_EVENT_CATEGORY_GROUP_ENABLED("memory", &enabled);
129 if (enabled) {
130 // We take ownership of this string.
131 char* dump = base::TraceMemoryDumpAsString();
132 scoped_ptr<MemoryDumpHolder> dump_holder(new MemoryDumpHolder(dump));
133 const int kSnapshotId = 1;
134 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID(
135 "memory",
136 "memory::Heap",
137 kSnapshotId,
138 dump_holder.PassAs<base::debug::ConvertableToTraceFormat>());
139 }
140 MessageLoop::current()->PostDelayedTask(FROM_HERE,
141 base::Bind(&DumpMemoryProfile),
142 base::TimeDelta::FromSeconds(10));
143 }
144
104 } // namespace 145 } // namespace
105 146
106 ChromeBrowserMainPartsLinux::ChromeBrowserMainPartsLinux( 147 ChromeBrowserMainPartsLinux::ChromeBrowserMainPartsLinux(
107 const content::MainFunctionParams& parameters) 148 const content::MainFunctionParams& parameters)
108 : ChromeBrowserMainPartsPosix(parameters) { 149 : ChromeBrowserMainPartsPosix(parameters) {
109 } 150 }
110 151
111 ChromeBrowserMainPartsLinux::~ChromeBrowserMainPartsLinux() { 152 ChromeBrowserMainPartsLinux::~ChromeBrowserMainPartsLinux() {
112 } 153 }
113 154
(...skipping 20 matching lines...) Expand all
134 } 175 }
135 176
136 void ChromeBrowserMainPartsLinux::PostProfileInit() { 177 void ChromeBrowserMainPartsLinux::PostProfileInit() {
137 #if !defined(OS_CHROMEOS) 178 #if !defined(OS_CHROMEOS)
138 storage_monitor_->Init(); 179 storage_monitor_->Init();
139 #endif 180 #endif
140 181
141 ChromeBrowserMainPartsPosix::PostProfileInit(); 182 ChromeBrowserMainPartsPosix::PostProfileInit();
142 } 183 }
143 184
185 void ChromeBrowserMainPartsLinux::PreMainMessageLoopRun() {
186 ChromeBrowserMainPartsPosix::PreMainMessageLoopRun();
187
188 // TODO(jamescook): This could be moved earlier in startup to capture more
189 // startup allocations.
190 base::TraceMemoryStart();
191
192 // Dump a heap profile every 10 seconds, forever.
193 MessageLoop::current()->PostDelayedTask(FROM_HERE,
194 base::Bind(&DumpMemoryProfile),
195 base::TimeDelta::FromSeconds(10));
196 }
197
144 void ChromeBrowserMainPartsLinux::PostMainMessageLoopRun() { 198 void ChromeBrowserMainPartsLinux::PostMainMessageLoopRun() {
145 #if !defined(OS_CHROMEOS) 199 #if !defined(OS_CHROMEOS)
146 // Delete it now. Otherwise the FILE thread would be gone when we try to 200 // Delete it now. Otherwise the FILE thread would be gone when we try to
147 // release it in the dtor and Valgrind would report a leak on almost every 201 // release it in the dtor and Valgrind would report a leak on almost every
148 // single browser_test. 202 // single browser_test.
149 storage_monitor_.reset(); 203 storage_monitor_.reset();
150 #endif 204 #endif
151 205
206 base::TraceMemoryDump();
207 base::TraceMemoryStop();
208
152 ChromeBrowserMainPartsPosix::PostMainMessageLoopRun(); 209 ChromeBrowserMainPartsPosix::PostMainMessageLoopRun();
153 } 210 }
OLDNEW
« no previous file with comments | « chrome/browser/chrome_browser_main_linux.h ('k') | third_party/tcmalloc/chromium/src/gperftools/heap-profiler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698