1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/memory/oom_memory_details.h"
7 #include "base/logging.h"
8 #include "base/process/process_metrics.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/memory/oom_memory_details.h"
11 #include "ui/base/text/bytes_formatting.h"
16 void OomMemoryDetails::Log(const std::string
& title
,
17 const base::Closure
& callback
) {
18 // Deletes itself upon completion.
19 OomMemoryDetails
* details
= new OomMemoryDetails(title
, callback
);
20 details
->StartFetch(MemoryDetails::FROM_CHROME_ONLY
);
23 OomMemoryDetails::OomMemoryDetails(const std::string
& title
,
24 const base::Closure
& callback
)
25 : title_(title
), callback_(callback
) {
26 AddRef(); // Released in OnDetailsAvailable().
27 start_time_
= base::TimeTicks::Now();
30 OomMemoryDetails::~OomMemoryDetails() {
33 void OomMemoryDetails::OnDetailsAvailable() {
34 base::TimeDelta delta
= base::TimeTicks::Now() - start_time_
;
35 // These logs are collected by user feedback reports. We want them to help
36 // diagnose user-reported problems with frequently discarded tabs.
37 std::string log_string
= ToLogString();
38 #if defined(OS_CHROMEOS)
39 base::SystemMemoryInfoKB memory
;
40 if (base::GetSystemMemoryInfo(&memory
) && memory
.gem_size
!= -1) {
41 log_string
+= "Graphics ";
42 log_string
+= base::UTF16ToASCII(ui::FormatBytes(memory
.gem_size
));
45 LOG(WARNING
) << title_
<< " (" << delta
.InMilliseconds() << " ms):\n"
47 if (!callback_
.is_null())
49 // Delete ourselves so we don't have to worry about OomPriorityManager
50 // deleting us when we're still working.