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

Side by Side Diff: chrome/browser/chromeos/system/syslogs_provider.cc

Issue 10151005: cros: Log per-process memory use on low memory events (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/chromeos/system/syslogs_provider.h" 5 #include "chrome/browser/chromeos/system/syslogs_provider.h"
6 6
7 #include <functional>
8 #include <set>
9 7
10 #include "base/bind.h" 8 #include "base/bind.h"
11 #include "base/bind_helpers.h" 9 #include "base/bind_helpers.h"
12 #include "base/command_line.h" 10 #include "base/command_line.h"
13 #include "base/file_path.h" 11 #include "base/file_path.h"
14 #include "base/file_util.h" 12 #include "base/file_util.h"
15 #include "base/logging.h" 13 #include "base/logging.h"
16 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
17 #include "base/memory/singleton.h" 15 #include "base/memory/singleton.h"
18 #include "base/string_util.h" 16 #include "base/string_util.h"
19 #include "base/stringprintf.h"
20 #include "base/utf_string_conversions.h"
21 #include "chrome/browser/memory_details.h" 17 #include "chrome/browser/memory_details.h"
22 #include "chrome/common/chrome_switches.h" 18 #include "chrome/common/chrome_switches.h"
23 #include "content/public/browser/browser_thread.h" 19 #include "content/public/browser/browser_thread.h"
24 20
25 using content::BrowserThread; 21 using content::BrowserThread;
26 22
27 namespace chromeos { 23 namespace chromeos {
28 namespace system { 24 namespace system {
29 namespace { 25 namespace {
30 26
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 SyslogsMemoryHandler( 241 SyslogsMemoryHandler(
246 scoped_refptr<CancelableRequest<ReadCompleteCallback> > request, 242 scoped_refptr<CancelableRequest<ReadCompleteCallback> > request,
247 LogDictionaryType* logs, 243 LogDictionaryType* logs,
248 std::string* zip_content) 244 std::string* zip_content)
249 : request_(request), 245 : request_(request),
250 logs_(logs), 246 logs_(logs),
251 zip_content_(zip_content) { 247 zip_content_(zip_content) {
252 } 248 }
253 249
254 virtual void OnDetailsAvailable() OVERRIDE { 250 virtual void OnDetailsAvailable() OVERRIDE {
255 const ProcessData& chrome = processes()[0]; // Chrome is the first entry. 251 // TODO(jamescook): Maybe we don't need to do this?
256 // Process info, sorted by memory used (highest to lowest). 252 UpdateHistograms();
257 typedef std::pair<int, std::string> ProcInfo; 253
258 typedef std::set<ProcInfo, std::greater<ProcInfo> > ProcInfoSet; 254 (*logs_)["mem_usage"] = ToLogString();
259 ProcInfoSet process_info;
260 for (ProcessMemoryInformationList::const_iterator iter1 =
261 chrome.processes.begin();
262 iter1 != chrome.processes.end(); ++iter1) {
263 std::string process_string(
264 ProcessMemoryInformation::GetFullTypeNameInEnglish(
265 iter1->type, iter1->renderer_type));
266 if (!iter1->titles.empty()) {
267 std::string titles(" [");
268 for (std::vector<string16>::const_iterator iter2 =
269 iter1->titles.begin();
270 iter2 != iter1->titles.end(); ++iter2) {
271 if (iter2 != iter1->titles.begin())
272 titles += "|";
273 titles += UTF16ToUTF8(*iter2);
274 }
275 titles += "]";
276 process_string += titles;
277 }
278 // Use private working set for memory used calculation.
279 int ws_mbytes = static_cast<int>(iter1->working_set.priv) / 1024;
280 process_info.insert(std::make_pair(ws_mbytes, process_string));
281 }
282 // Add one line for each reverse-sorted entry.
283 std::string mem_string;
284 for (ProcInfoSet::iterator iter = process_info.begin();
285 iter != process_info.end(); ++iter) {
286 mem_string +=
287 iter->second + base::StringPrintf(": %d MB", iter->first) + "\n";
288 }
289 (*logs_)["mem_usage"] = mem_string;
290 // This will call the callback on the calling thread. 255 // This will call the callback on the calling thread.
291 request_->ForwardResult(logs_, zip_content_); 256 request_->ForwardResult(logs_, zip_content_);
292 } 257 }
293 258
294 private: 259 private:
295 virtual ~SyslogsMemoryHandler() {} 260 virtual ~SyslogsMemoryHandler() {}
296 261
297 scoped_refptr<CancelableRequest<ReadCompleteCallback> > request_; 262 scoped_refptr<CancelableRequest<ReadCompleteCallback> > request_;
298 LogDictionaryType* logs_; 263 LogDictionaryType* logs_;
299 std::string* zip_content_; 264 std::string* zip_content_;
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 return Singleton<SyslogsProviderImpl, 337 return Singleton<SyslogsProviderImpl,
373 DefaultSingletonTraits<SyslogsProviderImpl> >::get(); 338 DefaultSingletonTraits<SyslogsProviderImpl> >::get();
374 } 339 }
375 340
376 SyslogsProvider* SyslogsProvider::GetInstance() { 341 SyslogsProvider* SyslogsProvider::GetInstance() {
377 return SyslogsProviderImpl::GetInstance(); 342 return SyslogsProviderImpl::GetInstance();
378 } 343 }
379 344
380 } // namespace system 345 } // namespace system
381 } // namespace chromeos 346 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698