Commit b22e1f69 authored by Alexander Alekseev's avatar Alexander Alekseev Committed by Commit Bot

Ash: Move HUD graphs to a separate view.


Bug: 1075612
Change-Id: I702b9bb935bf5a25071bf350a90e00d94b2a0512
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2249050
Commit-Queue: Alexander Alekseev <alemate@chromium.org>
Reviewed-by: default avatarMitsuru Oshima (slow:gardening) <oshima@chromium.org>
Cr-Commit-Position: refs/heads/master@{#779497}
parent 80b024e9
......@@ -420,6 +420,8 @@ component("ash") {
"hud_display/data_source.h",
"hud_display/graph.cc",
"hud_display/graph.h",
"hud_display/graphs_container_view.cc",
"hud_display/graphs_container_view.h",
"hud_display/hud_display.cc",
"hud_display/hud_display.h",
"hud_display/memory_status.cc",
......
// Copyright 2020 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/hud_display/graphs_container_view.h"
#include <numeric>
#include "base/bind.h"
#include "base/task/post_task.h"
#include "ui/gfx/canvas.h"
namespace ash {
namespace hud_display {
namespace {
// UI refresh interval.
constexpr base::TimeDelta kGraphsDataRefreshInterval =
base::TimeDelta::FromMilliseconds(500);
} // namespace
////////////////////////////////////////////////////////////////////////////////
// GraphsContainerView, public:
GraphsContainerView::GraphsContainerView()
: graph_chrome_rss_private_(Graph::Baseline::BASELINE_BOTTOM,
Graph::Fill::SOLID,
SK_ColorRED),
graph_mem_free_(Graph::Baseline::BASELINE_BOTTOM,
Graph::Fill::NONE,
SK_ColorDKGRAY),
graph_mem_used_unknown_(Graph::Baseline::BASELINE_BOTTOM,
Graph::Fill::SOLID,
SK_ColorLTGRAY),
graph_renderers_rss_private_(Graph::Baseline::BASELINE_BOTTOM,
Graph::Fill::SOLID,
SK_ColorCYAN),
graph_arc_rss_private_(Graph::Baseline::BASELINE_BOTTOM,
Graph::Fill::SOLID,
SK_ColorMAGENTA),
graph_gpu_rss_private_(Graph::Baseline::BASELINE_BOTTOM,
Graph::Fill::SOLID,
SK_ColorRED),
graph_gpu_kernel_(Graph::Baseline::BASELINE_BOTTOM,
Graph::Fill::SOLID,
SK_ColorYELLOW),
graph_chrome_rss_shared_(Graph::Baseline::BASELINE_BOTTOM,
Graph::Fill::NONE,
SK_ColorBLUE) {
DCHECK_CALLED_ON_VALID_SEQUENCE(ui_sequence_checker_);
refresh_timer_.Start(FROM_HERE, kGraphsDataRefreshInterval, this,
&GraphsContainerView::UpdateData);
}
GraphsContainerView::~GraphsContainerView() {
DCHECK_CALLED_ON_VALID_SEQUENCE(ui_sequence_checker_);
}
////////////////////////////////////////////////////////////////////////////////
void GraphsContainerView::OnPaint(gfx::Canvas* canvas) {
// TODO: Should probably update last graph point more often than shift graph.
// Layout graphs.
const gfx::Rect rect = GetContentsBounds();
graph_chrome_rss_private_.Layout(rect, nullptr /* base*/);
graph_mem_free_.Layout(rect, &graph_chrome_rss_private_);
graph_mem_used_unknown_.Layout(rect, &graph_mem_free_);
graph_renderers_rss_private_.Layout(rect, &graph_mem_used_unknown_);
graph_arc_rss_private_.Layout(rect, &graph_renderers_rss_private_);
graph_gpu_rss_private_.Layout(rect, &graph_arc_rss_private_);
graph_gpu_kernel_.Layout(rect, &graph_gpu_rss_private_);
// Not stacked.
graph_chrome_rss_shared_.Layout(rect, nullptr /* base*/);
// Paint damaged area now that all parameters have been determined.
graph_chrome_rss_private_.Draw(canvas);
graph_mem_free_.Draw(canvas);
graph_mem_used_unknown_.Draw(canvas);
graph_renderers_rss_private_.Draw(canvas);
graph_arc_rss_private_.Draw(canvas);
graph_gpu_rss_private_.Draw(canvas);
graph_gpu_kernel_.Draw(canvas);
graph_chrome_rss_shared_.Draw(canvas);
}
void GraphsContainerView::UpdateData() {
// TODO: Should probably update last graph point more often than shift graph.
const DataSource::Snapshot snapshot = data_source_.GetSnapshotAndReset();
const double total = snapshot.total_ram;
// Nothing to do if data is not available yet.
if (total < 1)
return;
const float chrome_rss_private =
(snapshot.browser_rss - snapshot.browser_rss_shared) / total;
const float mem_free = snapshot.free_ram / total;
// mem_used_unknown is calculated below.
const float renderers_rss_private =
(snapshot.renderers_rss - snapshot.renderers_rss_shared) / total;
const float arc_rss_private =
(snapshot.arc_rss - snapshot.arc_rss_shared) / total;
const float gpu_rss_private =
(snapshot.gpu_rss - snapshot.gpu_rss_shared) / total;
const float gpu_kernel = snapshot.gpu_kernel / total;
// not stacked.
const float chrome_rss_shared = snapshot.browser_rss_shared / total;
std::vector<float> used_buckets;
used_buckets.push_back(chrome_rss_private);
used_buckets.push_back(mem_free);
used_buckets.push_back(renderers_rss_private);
used_buckets.push_back(arc_rss_private);
used_buckets.push_back(gpu_rss_private);
used_buckets.push_back(gpu_kernel);
float mem_used_unknown =
1 - std::accumulate(used_buckets.begin(), used_buckets.end(), 0.0f);
if (mem_used_unknown < 0)
LOG(WARNING) << "mem_used_unknown=" << mem_used_unknown << " < 0 !";
// Update graph data.
graph_chrome_rss_private_.AddValue(chrome_rss_private);
graph_mem_free_.AddValue(mem_free);
graph_mem_used_unknown_.AddValue(std::max(mem_used_unknown, 0.0f));
graph_renderers_rss_private_.AddValue(renderers_rss_private);
graph_arc_rss_private_.AddValue(arc_rss_private);
graph_gpu_rss_private_.AddValue(gpu_rss_private);
graph_gpu_kernel_.AddValue(gpu_kernel);
// Not stacked.
graph_chrome_rss_shared_.AddValue(chrome_rss_shared);
if (GetVisible())
SchedulePaint();
}
} // namespace hud_display
} // namespace ash
// Copyright 2020 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_HUD_DISPLAY_GRAPHS_CONTAINER_VIEW_H_
#define ASH_HUD_DISPLAY_GRAPHS_CONTAINER_VIEW_H_
#include "ash/hud_display/data_source.h"
#include "ash/hud_display/graph.h"
#include "base/sequence_checker.h"
#include "base/timer/timer.h"
#include "ui/views/view.h"
namespace ash {
namespace hud_display {
// GraphsContainerView class draws a bunch of graphs.
class GraphsContainerView : public views::View {
public:
GraphsContainerView();
~GraphsContainerView() override;
GraphsContainerView(const GraphsContainerView&) = delete;
GraphsContainerView& operator=(const GraphsContainerView&) = delete;
// view::
void OnPaint(gfx::Canvas* canvas) override;
// Synchrnously reads system counters and updates data.
void UpdateData();
private:
// HUD is updatd with new data every tick.
base::RepeatingTimer refresh_timer_;
// --- Stacked:
// Share of the total RAM occupied by Chrome browser private RSS.
Graph graph_chrome_rss_private_;
// Share of the total RAM reported as Free memory be kernel.
Graph graph_mem_free_;
// Total RAM - other graphs in this stack.
Graph graph_mem_used_unknown_;
// Share of the total RAM occupied by Chrome type=renderer processes private
// RSS.
Graph graph_renderers_rss_private_;
// Share of the total RAM occupied by ARC++ processes private RSS.
Graph graph_arc_rss_private_;
// Share of the total RAM occupied by Chrome type=gpu process private RSS.
Graph graph_gpu_rss_private_;
// Share of the total RAM used by kernel GPU driver.
Graph graph_gpu_kernel_;
// Not stacked:
// Share of the total RAM occupied by Chrome browser process shared RSS.
Graph graph_chrome_rss_shared_;
DataSource data_source_;
SEQUENCE_CHECKER(ui_sequence_checker_);
};
} // namespace hud_display
} // namespace ash
#endif // ASH_HUD_DISPLAY_GRAPHS_CONTAINER_VIEW_H_
......@@ -4,26 +4,18 @@
#include "ash/hud_display/hud_display.h"
#include <unistd.h>
#include <cmath>
#include <numeric>
#include "ash/fast_ink/view_tree_host_root_view.h"
#include "ash/fast_ink/view_tree_host_widget.h"
#include "ash/hud_display/data_source.h"
#include "ash/hud_display/graphs_container_view.h"
#include "ash/public/cpp/shell_window_ids.h"
#include "ash/root_window_controller.h"
#include "ash/shell.h"
#include "base/bind.h"
#include "base/task/post_task.h"
#include "third_party/skia/include/core/SkTypeface.h"
#include "ui/aura/window.h"
#include "ui/base/hit_test.h"
#include "ui/events/base_event_utils.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/presentation_feedback.h"
#include "ui/gfx/skia_util.h"
#include "ui/views/background.h"
#include "ui/views/border.h"
#include "ui/views/layout/fill_layout.h"
#include "ui/views/widget/widget.h"
namespace ash {
......@@ -32,10 +24,6 @@ namespace {
std::unique_ptr<views::Widget> g_hud_widget;
// UI refresh interval.
constexpr base::TimeDelta kHUDRefreshInterval =
base::TimeDelta::FromMilliseconds(500);
constexpr SkColor kBackground = SkColorSetARGB(208, 17, 17, 17);
} // namespace
......@@ -67,37 +55,15 @@ void HUDDisplayView::Toggle() {
g_hud_widget = base::WrapUnique(widget);
}
HUDDisplayView::HUDDisplayView()
: graph_chrome_rss_private_(Graph::Baseline::BASELINE_BOTTOM,
Graph::Fill::SOLID,
SK_ColorRED),
graph_mem_free_(Graph::Baseline::BASELINE_BOTTOM,
Graph::Fill::NONE,
SK_ColorDKGRAY),
graph_mem_used_unknown_(Graph::Baseline::BASELINE_BOTTOM,
Graph::Fill::SOLID,
SK_ColorLTGRAY),
graph_renderers_rss_private_(Graph::Baseline::BASELINE_BOTTOM,
Graph::Fill::SOLID,
SK_ColorCYAN),
graph_arc_rss_private_(Graph::Baseline::BASELINE_BOTTOM,
Graph::Fill::SOLID,
SK_ColorMAGENTA),
graph_gpu_rss_private_(Graph::Baseline::BASELINE_BOTTOM,
Graph::Fill::SOLID,
SK_ColorRED),
graph_gpu_kernel_(Graph::Baseline::BASELINE_BOTTOM,
Graph::Fill::SOLID,
SK_ColorYELLOW),
graph_chrome_rss_shared_(Graph::Baseline::BASELINE_BOTTOM,
Graph::Fill::NONE,
SK_ColorBLUE) {
HUDDisplayView::HUDDisplayView() {
DCHECK_CALLED_ON_VALID_SEQUENCE(ui_sequence_checker_);
refresh_timer_.Start(FROM_HERE, kHUDRefreshInterval,
static_cast<views::View*>(this),
&views::View::SchedulePaint);
SetBackground(views::CreateSolidBackground(kBackground));
SetBorder(views::CreateEmptyBorder(gfx::Insets(5)));
SetLayoutManager(std::make_unique<views::FillLayout>());
AddChildView(std::make_unique<GraphsContainerView>());
}
HUDDisplayView::~HUDDisplayView() {
......@@ -106,85 +72,6 @@ HUDDisplayView::~HUDDisplayView() {
////////////////////////////////////////////////////////////////////////////////
void HUDDisplayView::OnPaint(gfx::Canvas* canvas) {
OnPaintBackground(canvas);
// TODO: Should probably update last graph point more often than shift graph.
const DataSource::Snapshot snapshot = data_source_.GetSnapshotAndReset();
const double total = snapshot.total_ram;
// Nothing to do if data is not available yet.
if (total < 1)
return;
const float chrome_rss_private =
(snapshot.browser_rss - snapshot.browser_rss_shared) / total;
const float mem_free = snapshot.free_ram / total;
// mem_used_unknown is calculated below.
const float renderers_rss_private =
(snapshot.renderers_rss - snapshot.renderers_rss_shared) / total;
const float arc_rss_private =
(snapshot.arc_rss - snapshot.arc_rss_shared) / total;
const float gpu_rss_private =
(snapshot.gpu_rss - snapshot.gpu_rss_shared) / total;
const float gpu_kernel = snapshot.gpu_kernel / total;
// not stacked.
const float chrome_rss_shared = snapshot.browser_rss_shared / total;
std::vector<float> used_buckets;
used_buckets.push_back(chrome_rss_private);
used_buckets.push_back(mem_free);
used_buckets.push_back(renderers_rss_private);
used_buckets.push_back(arc_rss_private);
used_buckets.push_back(gpu_rss_private);
used_buckets.push_back(gpu_kernel);
float mem_used_unknown =
1 - std::accumulate(used_buckets.begin(), used_buckets.end(), 0.0f);
if (mem_used_unknown < 0)
LOG(WARNING) << "mem_used_unknown=" << mem_used_unknown << " < 0 !";
// Update graph data.
graph_chrome_rss_private_.AddValue(chrome_rss_private);
graph_mem_free_.AddValue(mem_free);
graph_mem_used_unknown_.AddValue(std::max(mem_used_unknown, 0.0f));
graph_renderers_rss_private_.AddValue(renderers_rss_private);
graph_arc_rss_private_.AddValue(arc_rss_private);
graph_gpu_rss_private_.AddValue(gpu_rss_private);
graph_gpu_kernel_.AddValue(gpu_kernel);
// Not stacked.
graph_chrome_rss_shared_.AddValue(chrome_rss_shared);
gfx::Rect memory_stats_rect = GetLocalBounds();
memory_stats_rect.Inset(kHUDInset, kHUDInset);
// Layout graphs.
graph_chrome_rss_private_.Layout(memory_stats_rect, nullptr /* base*/);
graph_mem_free_.Layout(memory_stats_rect, &graph_chrome_rss_private_);
graph_mem_used_unknown_.Layout(memory_stats_rect, &graph_mem_free_);
graph_renderers_rss_private_.Layout(memory_stats_rect,
&graph_mem_used_unknown_);
graph_arc_rss_private_.Layout(memory_stats_rect,
&graph_renderers_rss_private_);
graph_gpu_rss_private_.Layout(memory_stats_rect, &graph_arc_rss_private_);
graph_gpu_kernel_.Layout(memory_stats_rect, &graph_gpu_rss_private_);
// Not stacked.
graph_chrome_rss_shared_.Layout(memory_stats_rect, nullptr /* base*/);
// Paint damaged area now that all parameters have been determined.
{
graph_chrome_rss_private_.Draw(canvas);
graph_mem_free_.Draw(canvas);
graph_mem_used_unknown_.Draw(canvas);
graph_renderers_rss_private_.Draw(canvas);
graph_arc_rss_private_.Draw(canvas);
graph_gpu_rss_private_.Draw(canvas);
graph_gpu_kernel_.Draw(canvas);
graph_chrome_rss_shared_.Draw(canvas);
}
}
// ClientView that return HTNOWHERE by default. A child view can receive event
// by setting kHitTestComponentKey property to HTCLIENT.
class HTClientView : public views::ClientView {
......
......@@ -5,17 +5,12 @@
#ifndef ASH_HUD_DISPLAY_HUD_DISPLAY_H_
#define ASH_HUD_DISPLAY_HUD_DISPLAY_H_
#include "ash/hud_display/data_source.h"
#include "ash/hud_display/graph.h"
#include "base/sequence_checker.h"
#include "base/timer/timer.h"
#include "ui/views/widget/widget_delegate.h"
namespace ash {
namespace hud_display {
class DataSource;
// HUDDisplayView class can be used to display a system monitoring overview.
class HUDDisplayView : public views::WidgetDelegateView {
public:
......@@ -31,9 +26,6 @@ class HUDDisplayView : public views::WidgetDelegateView {
HUDDisplayView(const HUDDisplayView&) = delete;
HUDDisplayView& operator=(const HUDDisplayView&) = delete;
// view::
void OnPaint(gfx::Canvas* canvas) override;
// WidgetDelegate:
views::ClientView* CreateClientView(views::Widget* widget) override;
void OnWidgetInitialized() override;
......@@ -45,32 +37,6 @@ class HUDDisplayView : public views::WidgetDelegateView {
static void Toggle();
private:
// HUD is updatd with new data every tick.
base::RepeatingTimer refresh_timer_;
// --- Stacked:
// Share of the total RAM occupied by Chrome browser private RSS.
Graph graph_chrome_rss_private_;
// Share of the total RAM reported as Free memory be kernel.
Graph graph_mem_free_;
// Total RAM - other graphs in this stack.
Graph graph_mem_used_unknown_;
// Share of the total RAM occupied by Chrome type=renderer processes private
// RSS.
Graph graph_renderers_rss_private_;
// Share of the total RAM occupied by ARC++ processes private RSS.
Graph graph_arc_rss_private_;
// Share of the total RAM occupied by Chrome type=gpu process private RSS.
Graph graph_gpu_rss_private_;
// Share of the total RAM used by kernel GPU driver.
Graph graph_gpu_kernel_;
// Not stacked:
// Share of the total RAM occupied by Chrome browser process shared RSS.
Graph graph_chrome_rss_shared_;
DataSource data_source_;
SEQUENCE_CHECKER(ui_sequence_checker_);
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment