diff options
author | davemoore@chromium.org <davemoore@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-31 22:16:18 +0000 |
---|---|---|
committer | davemoore@chromium.org <davemoore@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-31 22:16:18 +0000 |
commit | dbfe3dc13a70c2b4bf8aec2c61a7c6d5868db846 (patch) | |
tree | dc97505e536a24831ace4980f14f93afc37542ea /ash | |
parent | 1e0545f2f74a6fa366f9398d9efae56ad0298cde (diff) | |
download | chromium_src-dbfe3dc13a70c2b4bf8aec2c61a7c6d5868db846.zip chromium_src-dbfe3dc13a70c2b4bf8aec2c61a7c6d5868db846.tar.gz chromium_src-dbfe3dc13a70c2b4bf8aec2c61a7c6d5868db846.tar.bz2 |
Create ash memory monitor
BUG=None
TEST=Enable via about:flags/enable-memory-monitor
Review URL: https://codereview.chromium.org/11345017
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@165244 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash')
-rw-r--r-- | ash/ash.gyp | 2 | ||||
-rw-r--r-- | ash/ash_switches.cc | 3 | ||||
-rw-r--r-- | ash/ash_switches.h | 1 | ||||
-rw-r--r-- | ash/system/monitor/tray_monitor.cc | 62 | ||||
-rw-r--r-- | ash/system/monitor/tray_monitor.h | 39 | ||||
-rw-r--r-- | ash/system/tray/system_tray.cc | 9 |
6 files changed, 116 insertions, 0 deletions
diff --git a/ash/ash.gyp b/ash/ash.gyp index 114ff7e..68968c9 100644 --- a/ash/ash.gyp +++ b/ash/ash.gyp @@ -185,6 +185,8 @@ 'system/keyboard_brightness/keyboard_brightness_control_delegate.h', 'system/locale/tray_locale.cc', 'system/locale/tray_locale.h', + 'system/monitor/tray_monitor.cc', + 'system/monitor/tray_monitor.h', 'system/power/power_status_observer.h', 'system/power/power_status_view.cc', 'system/power/power_status_view.h', diff --git a/ash/ash_switches.cc b/ash/ash_switches.cc index 6094cf0..8026050 100644 --- a/ash/ash_switches.cc +++ b/ash/ash_switches.cc @@ -38,6 +38,9 @@ const char kAshDisablePanelFitting[] = "ash-disable-panel-fitting"; // Enable advanced gestures (e.g. for window management). const char kAshEnableAdvancedGestures[] = "ash-enable-advanced-gestures"; +// Enable memory monitoring. +const char kAshEnableMemoryMonitor[] = "ash-enable-memory-monitor"; + // Enables the Oak tree viewer. const char kAshEnableOak[] = "ash-enable-oak"; diff --git a/ash/ash_switches.h b/ash/ash_switches.h index 5ed521f..2a3e370 100644 --- a/ash/ash_switches.h +++ b/ash/ash_switches.h @@ -24,6 +24,7 @@ ASH_EXPORT extern const char kAshDisableAutoWindowPlacement[]; ASH_EXPORT extern const char kAshDisablePanelFitting[]; ASH_EXPORT extern const char kAshDisableBootAnimation2[]; ASH_EXPORT extern const char kAshEnableAdvancedGestures[]; +ASH_EXPORT extern const char kAshEnableMemoryMonitor[]; ASH_EXPORT extern const char kAshEnableOak[]; ASH_EXPORT extern const char kAshEnableTrayDragging[]; ASH_EXPORT extern const char kAshLauncherPerDisplay[]; diff --git a/ash/system/monitor/tray_monitor.cc b/ash/system/monitor/tray_monitor.cc new file mode 100644 index 0000000..4e4336d --- /dev/null +++ b/ash/system/monitor/tray_monitor.cc @@ -0,0 +1,62 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ash/system/monitor/tray_monitor.h" + +#include "ash/system/tray/tray_item_view.h" +#include "ash/system/tray/tray_views.h" +#include "base/process_util.h" +#include "base/stringprintf.h" +#include "base/utf_string_conversions.h" +#include "ui/base/text/bytes_formatting.h" +#include "ui/views/controls/label.h" +#include "ui/views/border.h" + +namespace { +const int kRefreshTimeoutMs = 1000; +} + +namespace ash { +namespace internal { + +TrayMonitor::TrayMonitor() : label_(NULL) { + refresh_timer_.Start(FROM_HERE, + base::TimeDelta::FromMilliseconds(kRefreshTimeoutMs), + this, &TrayMonitor::RefreshStats); +} + +TrayMonitor::~TrayMonitor() { + label_ = NULL; +} + +views::View* TrayMonitor::CreateTrayView(user::LoginStatus status) { + TrayItemView* view = new TrayItemView; + view->CreateLabel(); + label_ = view->label(); + SetupLabelForTray(label_); + return view; +} + +void TrayMonitor::DestroyTrayView() { + label_ = NULL; +} + +void TrayMonitor::RefreshStats() { + base::SystemMemoryInfoKB mem_info; + base::GetSystemMemoryInfo(&mem_info); + std::string output; + string16 free_bytes = + ui::FormatBytes(static_cast<int64>(mem_info.free) * 1024); + output = StringPrintf("%s free", UTF16ToUTF8(free_bytes).c_str()); + if (mem_info.gem_objects != -1 && mem_info.gem_size != -1) { + string16 gem_size = ui::FormatBytes(mem_info.gem_size); + output += StringPrintf(", %d gobjects alloced (%s)", + mem_info.gem_objects, + UTF16ToUTF8(gem_size).c_str()); + } + label_->SetText(UTF8ToUTF16(output)); +} + +} // namespace internal +} // namespace ash diff --git a/ash/system/monitor/tray_monitor.h b/ash/system/monitor/tray_monitor.h new file mode 100644 index 0000000..c397df4 --- /dev/null +++ b/ash/system/monitor/tray_monitor.h @@ -0,0 +1,39 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef ASH_SYSTEM_DATE_TRAY_MONITOR_H_ +#define ASH_SYSTEM_DATE_TRAY_MONITOR_H_ + +#include "ash/system/tray/system_tray_item.h" +#include "base/timer.h" + +namespace views { +class Label; +} + +namespace ash { +namespace internal { + +class TrayMonitor : public SystemTrayItem { + public: + TrayMonitor(); + virtual ~TrayMonitor(); + + private: + // Overridden from SystemTrayItem. + virtual views::View* CreateTrayView(user::LoginStatus status) OVERRIDE; + virtual void DestroyTrayView() OVERRIDE; + + void RefreshStats(); + + views::Label* label_; + base::RepeatingTimer<TrayMonitor> refresh_timer_; + + DISALLOW_COPY_AND_ASSIGN(TrayMonitor); +}; + +} // namespace internal +} // namespace ash + +#endif // ASH_SYSTEM_DATE_TRAY_MONITOR_H_ diff --git a/ash/system/tray/system_tray.cc b/ash/system/tray/system_tray.cc index e3a0e25..25d2929 100644 --- a/ash/system/tray/system_tray.cc +++ b/ash/system/tray/system_tray.cc @@ -4,6 +4,7 @@ #include "ash/system/tray/system_tray.h" +#include "ash/ash_switches.h" #include "ash/shell.h" #include "ash/shell/panel_window.h" #include "ash/shell_window_ids.h" @@ -15,6 +16,7 @@ #include "ash/system/drive/tray_drive.h" #include "ash/system/ime/tray_ime.h" #include "ash/system/locale/tray_locale.h" +#include "ash/system/monitor/tray_monitor.h" #include "ash/system/power/power_status_observer.h" #include "ash/system/power/power_supply_status.h" #include "ash/system/power/tray_power.h" @@ -30,6 +32,7 @@ #include "ash/system/user/login_status.h" #include "ash/system/user/tray_user.h" #include "ash/wm/shelf_layout_manager.h" +#include "base/command_line.h" #include "base/logging.h" #include "base/timer.h" #include "base/utf_string_conversions.h" @@ -196,6 +199,12 @@ void SystemTray::CreateItems() { AddTrayItem(tray_caps_lock); AddTrayItem(tray_settings); AddTrayItem(tray_date); + + // Add memory monitor if enabled. + CommandLine* cmd = CommandLine::ForCurrentProcess(); + if (cmd->HasSwitch(ash::switches::kAshEnableMemoryMonitor)) + AddTrayItem(new internal::TrayMonitor); + SetVisible(ash::Shell::GetInstance()->tray_delegate()-> GetTrayVisibilityOnStartup()); } |