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

Issue 2925123002: NOCOMMIT PROTOTYPE [GRC] Tab CPU Usage Observer (Closed)

Created:
3 years, 6 months ago by matthalp
Modified:
3 years, 6 months ago
CC:
chromium-reviews
Target Ref:
refs/heads/master
Project:
chromium
Visibility:
Public.

Description

NOCOMMIT PROTOTYPE [GRC] Tab CPU Usage Observer This is a CoordinationUnitGraphObserver implementation that performs tab-level CPU usage attribution. Each process is given a namespace via a ProcessObserver class which itself holds onto a collection of TabObserver class instances that correspond to the tabs that are contained within it. Currently the implementation makes some naive assumptions: - Process CPU is evenly attributable among the tabs within it. For example, if a process with two CPU tabs has 50% utilization then each tab is attributed with 25%. - Any parentless-frame is assumed to correspond to a tab. In reality a tab (e.g. WebContents) can have have multiple parentless-frames because multiple navigations can exist within a single instance. R=*oysteine@chromium.org,*zhenw@chromium.org,lpy@google.com,fmeawad@chromium.org BUG=724306

Patch Set 1 #

Patch Set 2 : Add upstream dependency #

Patch Set 3 : Rename observer #

Patch Set 4 : Rebase #

Patch Set 5 : Rebase #

Patch Set 6 : Add url tracking #

Patch Set 7 : Rebase, Lint, Format #

Patch Set 8 : Rebase #

Patch Set 9 : Rebase #

Patch Set 10 : Rebase #

Total comments: 1
Unified diffs Side-by-side diffs Delta from patch set Stats (+374 lines, -22 lines) Patch
M chrome/browser/resource_coordinator/DEPS View 1 2 3 4 5 6 1 chunk +1 line, -0 lines 0 comments Download
M chrome/browser/resource_coordinator/resource_coordinator_web_contents_observer.h View 1 2 3 4 5 6 2 chunks +7 lines, -0 lines 0 comments Download
M chrome/browser/resource_coordinator/resource_coordinator_web_contents_observer.cc View 1 2 3 4 5 6 2 chunks +52 lines, -0 lines 0 comments Download
M services/resource_coordinator/BUILD.gn View 1 2 3 4 5 6 7 8 9 1 chunk +2 lines, -0 lines 0 comments Download
M services/resource_coordinator/coordination_unit/coordination_unit_impl.h View 1 2 3 4 5 6 7 8 1 chunk +0 lines, -4 lines 0 comments Download
M services/resource_coordinator/coordination_unit/coordination_unit_impl.cc View 1 2 3 4 5 6 7 8 2 chunks +0 lines, -7 lines 0 comments Download
M services/resource_coordinator/coordination_unit/coordination_unit_manager.cc View 1 2 3 4 5 6 1 chunk +4 lines, -1 line 0 comments Download
M services/resource_coordinator/coordination_unit/coordination_unit_provider_impl.cc View 1 2 3 4 5 6 1 chunk +0 lines, -1 line 0 comments Download
M services/resource_coordinator/coordination_unit/process_coordination_unit_impl.h View 1 2 3 1 chunk +0 lines, -2 lines 0 comments Download
M services/resource_coordinator/coordination_unit/process_coordination_unit_impl.cc View 1 2 3 4 5 2 chunks +3 lines, -6 lines 0 comments Download
M services/resource_coordinator/coordination_unit/process_coordination_unit_impl_unittest.cc View 1 2 3 2 chunks +5 lines, -1 line 0 comments Download
A services/resource_coordinator/coordination_unit/tab_cpu_usage_observer.h View 1 2 3 4 5 6 1 chunk +97 lines, -0 lines 0 comments Download
A services/resource_coordinator/coordination_unit/tab_cpu_usage_observer.cc View 1 2 3 4 5 6 1 chunk +192 lines, -0 lines 1 comment Download
M services/resource_coordinator/public/cpp/resource_coordinator_interface.h View 1 2 3 4 5 1 chunk +1 line, -0 lines 0 comments Download
M services/resource_coordinator/public/cpp/resource_coordinator_interface.cc View 1 2 3 4 5 6 1 chunk +10 lines, -0 lines 0 comments Download

Depends on Patchset:

Messages

Total messages: 10 (7 generated)
matthalp
3 years, 6 months ago (2017-06-07 18:16:31 UTC) #1
matthalp
Adding reviewers
3 years, 6 months ago (2017-06-07 21:58:09 UTC) #3
Zhen Wang
3 years, 6 months ago (2017-06-16 22:47:45 UTC) #10
https://codereview.chromium.org/2925123002/diff/180001/services/resource_coor...
File services/resource_coordinator/coordination_unit/tab_cpu_usage_observer.cc
(right):

https://codereview.chromium.org/2925123002/diff/180001/services/resource_coor...
services/resource_coordinator/coordination_unit/tab_cpu_usage_observer.cc:153:
mojom::PropertyType::kProcessCPUUsage);
I see your point here that one may want to listen to multiple property types (or
CU types for other listeners).

But I think you can get this done similarly with the typical observer pattern. I
admit that you need one more switch to dispatch the 2 property types.


void TabCPUUsageObserver::TabCoordinationUnitCreated(tab_coordination_unit) {
  DCHECK(!tab_observers_.count(tab_coordination_unit->id()));
  auto& tab_observer = tab_observers_[tab_coordination_unit->id()];
  tab_observer.SetTabCPUUsageObserver(this);

  cu->ObservePropertyChangeEvent(this, mojom::PropertyType::kTabURL);
  // And other ones...
}

void
TabCPUUsageObserver::ProcessCoordinationUnitCreated(process_coordination_unit) {
  DCHECK(!process_observers_.count(process_coordination_unit->id()));
  ProcessObserver& process_observer =
      process_observers_[process_coordination_unit->id()];
  process_observer.SetTabCPUUsageObserver(this);

  cu->ObservePropertyChangeEvent(this, mojom::PropertyType::kProcessCPUUsage);
  // And other ones...
}

// This is the new API replacing the callback way.
TabCPUUsageObserver::OnPropertyChanged(cu, property) {
  switch (property.type) {
    case mojom::PropertyType::kTabURL:
      GetTabObserver(cu)->TabURLChanged(cu, property);
    case mojom::PropertyType::kProcessCPUUsage:
      GetProcessObserver(cu)->NewCPUUsageMeasurement(cu, property);
    default:
      DCHECK(false); // should never happen
  }
}

TabCPUUsageObserver::GetTabObserver(cu) {
  // can be implemented with a map
}

TabCPUUsageObserver::GetTabObserver(cu) {
  // can be implemented with a map
}

Powered by Google App Engine
This is Rietveld 408576698