OLD | NEW |
---|---|
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 Loading... | |
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 /* | |
107 * std::string my_str; | |
108 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | |
109 "cc::Picture", clone.get(), my_str); | |
110 | |
111 std::string* my_str; | |
112 tcmalloc_dump(&my_str); | |
113 MyStringOnwer : base::Debug::ConvdrtableToTraceLog // cc/debug/traced_picture.h for example | |
114 scoped_ptr<MyStringOwner> mystr = ...; | |
115 | |
116 | |
117 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID("tcmalloc", "tcmalloc::Heap", 1, my_str); | |
118 */ | |
119 class MemoryDumpHolder : public base::debug::ConvertableToTraceFormat { | |
120 public: | |
121 // Takes ownership of dump, which must be allocated with malloc() and NULL | |
122 // terminated. | |
123 explicit MemoryDumpHolder(char* dump) : dump_(dump) {} | |
124 virtual ~MemoryDumpHolder() { free(dump_); } | |
125 | |
126 // base::debug::ConvertableToTraceFormat overrides: | |
127 virtual void AppendAsTraceFormat(std::string* out) const OVERRIDE { | |
128 out->append("{\"heap_dump\": "); | |
129 //TODO - use JSON version | |
130 out->append(dump_); | |
131 LOG(ERROR) << "JAMESDEBUG1\n" << dump_; | |
132 out->append("\"}"); | |
133 } | |
134 | |
135 private: | |
136 char* dump_; | |
137 | |
138 DISALLOW_COPY_AND_ASSIGN(MemoryDumpHolder); | |
139 }; | |
140 | |
141 void DumpMemoryProfile() { | |
142 // Check to see if tracing is enabled for the memory category. | |
143 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("
| |
144 if (enabled) { | |
145 // We take ownership of this string. | |
146 char* dump = base::TraceMemoryDumpAsString(); | |
147 // LOG(ERROR) << "JAMESDEBUG2\n" << dump; | |
148 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.
| |
149 // const int kSnapshotId = 1; | |
150 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID( | |
151 "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
| |
152 } | |
153 MessageLoop::current()->PostDelayedTask(FROM_HERE, | |
154 base::Bind(&DumpMemoryProfile), | |
155 base::TimeDelta::FromSeconds(10)); | |
156 } | |
157 | |
104 } // namespace | 158 } // namespace |
105 | 159 |
106 ChromeBrowserMainPartsLinux::ChromeBrowserMainPartsLinux( | 160 ChromeBrowserMainPartsLinux::ChromeBrowserMainPartsLinux( |
107 const content::MainFunctionParams& parameters) | 161 const content::MainFunctionParams& parameters) |
108 : ChromeBrowserMainPartsPosix(parameters) { | 162 : ChromeBrowserMainPartsPosix(parameters) { |
109 } | 163 } |
110 | 164 |
111 ChromeBrowserMainPartsLinux::~ChromeBrowserMainPartsLinux() { | 165 ChromeBrowserMainPartsLinux::~ChromeBrowserMainPartsLinux() { |
112 } | 166 } |
113 | 167 |
(...skipping 20 matching lines...) Expand all Loading... | |
134 } | 188 } |
135 | 189 |
136 void ChromeBrowserMainPartsLinux::PostProfileInit() { | 190 void ChromeBrowserMainPartsLinux::PostProfileInit() { |
137 #if !defined(OS_CHROMEOS) | 191 #if !defined(OS_CHROMEOS) |
138 storage_monitor_->Init(); | 192 storage_monitor_->Init(); |
139 #endif | 193 #endif |
140 | 194 |
141 ChromeBrowserMainPartsPosix::PostProfileInit(); | 195 ChromeBrowserMainPartsPosix::PostProfileInit(); |
142 } | 196 } |
143 | 197 |
198 void ChromeBrowserMainPartsLinux::PreMainMessageLoopRun() { | |
199 ChromeBrowserMainPartsPosix::PreMainMessageLoopRun(); | |
200 | |
201 // TODO(jamescook): This could be moved earlier in startup to capture more | |
202 // startup allocations. | |
203 base::TraceMemoryStart(); | |
204 | |
205 // Dump a heap profile every 10 seconds, forever. | |
206 MessageLoop::current()->PostDelayedTask(FROM_HERE, | |
207 base::Bind(&DumpMemoryProfile), | |
208 base::TimeDelta::FromSeconds(10)); | |
209 } | |
210 | |
144 void ChromeBrowserMainPartsLinux::PostMainMessageLoopRun() { | 211 void ChromeBrowserMainPartsLinux::PostMainMessageLoopRun() { |
145 #if !defined(OS_CHROMEOS) | 212 #if !defined(OS_CHROMEOS) |
146 // Delete it now. Otherwise the FILE thread would be gone when we try to | 213 // 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 | 214 // release it in the dtor and Valgrind would report a leak on almost every |
148 // single browser_test. | 215 // single browser_test. |
149 storage_monitor_.reset(); | 216 storage_monitor_.reset(); |
150 #endif | 217 #endif |
151 | 218 |
219 base::TraceMemoryDump(); | |
220 base::TraceMemoryStop(); | |
221 | |
152 ChromeBrowserMainPartsPosix::PostMainMessageLoopRun(); | 222 ChromeBrowserMainPartsPosix::PostMainMessageLoopRun(); |
153 } | 223 } |
OLD | NEW |