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

Side by Side Diff: chrome/browser/memory/tab_manager_delegate_chromeos.cc

Issue 2527973003: Consolidate code monitoring low memory kills and OOM kills to MemoryKillsMonitor on ChromeOS. (Closed)
Patch Set: move unittest to chromeos only build rule Created 4 years 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
« no previous file with comments | « chrome/browser/memory/tab_manager_delegate_chromeos.h ('k') | components/arc/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 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/memory/tab_manager_delegate_chromeos.h" 5 #include "chrome/browser/memory/tab_manager_delegate_chromeos.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <map> 10 #include <map>
11 #include <string> 11 #include <string>
12 #include <vector> 12 #include <vector>
13 13
14 #include "ash/shell.h" 14 #include "ash/shell.h"
15 #include "base/bind.h" 15 #include "base/bind.h"
16 #include "base/command_line.h" 16 #include "base/command_line.h"
17 #include "base/files/file_path.h" 17 #include "base/files/file_path.h"
18 #include "base/files/file_util.h" 18 #include "base/files/file_util.h"
19 #include "base/memory/memory_pressure_monitor_chromeos.h" 19 #include "base/memory/memory_pressure_monitor_chromeos.h"
20 #include "base/metrics/histogram_macros.h" 20 #include "base/metrics/histogram_macros.h"
21 #include "base/process/process_handle.h" // kNullProcessHandle. 21 #include "base/process/process_handle.h" // kNullProcessHandle.
22 #include "base/process/process_metrics.h" 22 #include "base/process/process_metrics.h"
23 #include "base/strings/string16.h" 23 #include "base/strings/string16.h"
24 #include "base/strings/string_number_conversions.h" 24 #include "base/strings/string_number_conversions.h"
25 #include "base/strings/string_util.h" 25 #include "base/strings/string_util.h"
26 #include "base/strings/utf_string_conversions.h" 26 #include "base/strings/utf_string_conversions.h"
27 #include "base/time/time.h" 27 #include "base/time/time.h"
28 #include "chrome/browser/chromeos/arc/process/arc_process.h" 28 #include "chrome/browser/chromeos/arc/process/arc_process.h"
29 #include "chrome/browser/chromeos/arc/process/arc_process_service.h" 29 #include "chrome/browser/chromeos/arc/process/arc_process_service.h"
30 #include "chrome/browser/memory/memory_kills_monitor.h"
30 #include "chrome/browser/memory/tab_stats.h" 31 #include "chrome/browser/memory/tab_stats.h"
31 #include "chrome/browser/ui/browser.h" 32 #include "chrome/browser/ui/browser.h"
32 #include "chrome/browser/ui/browser_list.h" 33 #include "chrome/browser/ui/browser_list.h"
33 #include "chrome/browser/ui/tabs/tab_strip_model.h" 34 #include "chrome/browser/ui/tabs/tab_strip_model.h"
34 #include "chrome/common/chrome_constants.h" 35 #include "chrome/common/chrome_constants.h"
35 #include "chrome/common/chrome_features.h" 36 #include "chrome/common/chrome_features.h"
36 #include "chromeos/dbus/dbus_thread_manager.h" 37 #include "chromeos/dbus/dbus_thread_manager.h"
37 #include "components/arc/arc_bridge_service.h" 38 #include "components/arc/arc_bridge_service.h"
38 #include "components/arc/common/process.mojom.h" 39 #include "components/arc/common/process.mojom.h"
39 #include "components/arc/metrics/oom_kills_histogram.h"
40 #include "components/exo/shell_surface.h" 40 #include "components/exo/shell_surface.h"
41 #include "content/public/browser/browser_thread.h" 41 #include "content/public/browser/browser_thread.h"
42 #include "content/public/browser/notification_service.h" 42 #include "content/public/browser/notification_service.h"
43 #include "content/public/browser/notification_types.h" 43 #include "content/public/browser/notification_types.h"
44 #include "content/public/browser/render_process_host.h" 44 #include "content/public/browser/render_process_host.h"
45 #include "content/public/browser/render_widget_host.h" 45 #include "content/public/browser/render_widget_host.h"
46 #include "content/public/browser/zygote_host_linux.h" 46 #include "content/public/browser/zygote_host_linux.h"
47 #include "ui/aura/window.h" 47 #include "ui/aura/window.h"
48 #include "ui/wm/public/activation_client.h" 48 #include "ui/wm/public/activation_client.h"
49 49
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 266
267 int TabManagerDelegate::MemoryStat::EstimatedMemoryFreedKB( 267 int TabManagerDelegate::MemoryStat::EstimatedMemoryFreedKB(
268 base::ProcessHandle pid) { 268 base::ProcessHandle pid) {
269 std::unique_ptr<base::ProcessMetrics> process_metrics( 269 std::unique_ptr<base::ProcessMetrics> process_metrics(
270 base::ProcessMetrics::CreateProcessMetrics(pid)); 270 base::ProcessMetrics::CreateProcessMetrics(pid));
271 base::WorkingSetKBytes mem_usage; 271 base::WorkingSetKBytes mem_usage;
272 process_metrics->GetWorkingSetKBytes(&mem_usage); 272 process_metrics->GetWorkingSetKBytes(&mem_usage);
273 return mem_usage.priv; 273 return mem_usage.priv;
274 } 274 }
275 275
276 class TabManagerDelegate::UmaReporter {
277 public:
278 UmaReporter() : total_kills_(0) {}
279 ~UmaReporter() {}
280
281 void ReportKill(const int memory_freed);
282
283 private:
284 base::Time last_kill_time_;
285 int total_kills_;
286 };
287
288 void TabManagerDelegate::UmaReporter::ReportKill(const int memory_freed) {
289 base::Time now = base::Time::Now();
290 const TimeDelta time_delta =
291 last_kill_time_.is_null() ?
292 TimeDelta::FromSeconds(arc::kMaxOomMemoryKillTimeDeltaSecs) :
293 (now - last_kill_time_);
294 UMA_HISTOGRAM_OOM_KILL_TIME_INTERVAL(
295 "Arc.LowMemoryKiller.TimeDelta", time_delta);
296 last_kill_time_ = now;
297
298 ++total_kills_;
299 UMA_HISTOGRAM_CUSTOM_COUNTS(
300 "Arc.LowMemoryKiller.Count", total_kills_, 1, 1000, 1001);
301
302 UMA_HISTOGRAM_MEMORY_KB("Arc.LowMemoryKiller.FreedSize",
303 memory_freed);
304 }
305
306 TabManagerDelegate::TabManagerDelegate( 276 TabManagerDelegate::TabManagerDelegate(
307 const base::WeakPtr<TabManager>& tab_manager) 277 const base::WeakPtr<TabManager>& tab_manager)
308 : TabManagerDelegate(tab_manager, new MemoryStat()) { 278 : TabManagerDelegate(tab_manager, new MemoryStat()) {
309 } 279 }
310 280
311 TabManagerDelegate::TabManagerDelegate( 281 TabManagerDelegate::TabManagerDelegate(
312 const base::WeakPtr<TabManager>& tab_manager, 282 const base::WeakPtr<TabManager>& tab_manager,
313 TabManagerDelegate::MemoryStat* mem_stat) 283 TabManagerDelegate::MemoryStat* mem_stat)
314 : tab_manager_(tab_manager), 284 : tab_manager_(tab_manager),
315 focused_process_(new FocusedProcess()), 285 focused_process_(new FocusedProcess()),
316 mem_stat_(mem_stat), 286 mem_stat_(mem_stat),
317 uma_(new UmaReporter()),
318 weak_ptr_factory_(this) { 287 weak_ptr_factory_(this) {
319 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, 288 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED,
320 content::NotificationService::AllBrowserContextsAndSources()); 289 content::NotificationService::AllBrowserContextsAndSources());
321 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, 290 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED,
322 content::NotificationService::AllBrowserContextsAndSources()); 291 content::NotificationService::AllBrowserContextsAndSources());
323 registrar_.Add(this, content::NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED, 292 registrar_.Add(this, content::NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED,
324 content::NotificationService::AllBrowserContextsAndSources()); 293 content::NotificationService::AllBrowserContextsAndSources());
325 auto* activation_client = GetActivationClient(); 294 auto* activation_client = GetActivationClient();
326 if (activation_client) 295 if (activation_client)
327 activation_client->AddObserver(this); 296 activation_client->AddObserver(this);
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 process_type == ProcessType::FOCUSED_APP || 593 process_type == ProcessType::FOCUSED_APP ||
625 process_type == ProcessType::FOCUSED_TAB) { 594 process_type == ProcessType::FOCUSED_TAB) {
626 VLOG(2) << "Skipped killing " << *it; 595 VLOG(2) << "Skipped killing " << *it;
627 continue; 596 continue;
628 } 597 }
629 if (it->app()) { 598 if (it->app()) {
630 int estimated_memory_freed_kb = 599 int estimated_memory_freed_kb =
631 mem_stat_->EstimatedMemoryFreedKB(it->app()->pid()); 600 mem_stat_->EstimatedMemoryFreedKB(it->app()->pid());
632 if (KillArcProcess(it->app()->nspid())) { 601 if (KillArcProcess(it->app()->nspid())) {
633 target_memory_to_free_kb -= estimated_memory_freed_kb; 602 target_memory_to_free_kb -= estimated_memory_freed_kb;
634 uma_->ReportKill(estimated_memory_freed_kb); 603 MemoryKillsMonitor::LogLowMemoryKill("APP", estimated_memory_freed_kb);
635 VLOG(2) << "Killed " << *it; 604 VLOG(2) << "Killed " << *it;
636 } 605 }
637 } else { 606 } else {
638 int64_t tab_id = it->tab()->tab_contents_id; 607 int64_t tab_id = it->tab()->tab_contents_id;
639 // The estimation is problematic since multiple tabs may share the same 608 // The estimation is problematic since multiple tabs may share the same
640 // process, while the calculation counts memory used by the whole process. 609 // process, while the calculation counts memory used by the whole process.
641 // So |estimated_memory_freed_kb| is an over-estimation. 610 // So |estimated_memory_freed_kb| is an over-estimation.
642 int estimated_memory_freed_kb = 611 int estimated_memory_freed_kb =
643 mem_stat_->EstimatedMemoryFreedKB(it->tab()->renderer_handle); 612 mem_stat_->EstimatedMemoryFreedKB(it->tab()->renderer_handle);
644 if (KillTab(tab_id)) { 613 if (KillTab(tab_id)) {
645 target_memory_to_free_kb -= estimated_memory_freed_kb; 614 target_memory_to_free_kb -= estimated_memory_freed_kb;
646 uma_->ReportKill(estimated_memory_freed_kb); 615 MemoryKillsMonitor::LogLowMemoryKill("TAB", estimated_memory_freed_kb);
647 VLOG(2) << "Killed " << *it; 616 VLOG(2) << "Killed " << *it;
648 } 617 }
649 } 618 }
650 if (target_memory_to_free_kb < 0) 619 if (target_memory_to_free_kb < 0)
651 break; 620 break;
652 } 621 }
653 } 622 }
654 623
655 void TabManagerDelegate::AdjustOomPrioritiesImpl( 624 void TabManagerDelegate::AdjustOomPrioritiesImpl(
656 const TabStatsList& tab_list, 625 const TabStatsList& tab_list,
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
747 } 716 }
748 priority += priority_increment; 717 priority += priority_increment;
749 } 718 }
750 719
751 if (oom_scores_to_change.size()) 720 if (oom_scores_to_change.size())
752 GetDebugDaemonClient()->SetOomScoreAdj( 721 GetDebugDaemonClient()->SetOomScoreAdj(
753 oom_scores_to_change, base::Bind(&OnSetOomScoreAdj)); 722 oom_scores_to_change, base::Bind(&OnSetOomScoreAdj));
754 } 723 }
755 724
756 } // namespace memory 725 } // namespace memory
OLDNEW
« no previous file with comments | « chrome/browser/memory/tab_manager_delegate_chromeos.h ('k') | components/arc/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698