Commit 4c8c96b1 authored by Zentaro Kavanagh's avatar Zentaro Kavanagh Committed by Commit Bot

Diagnostics: Add support for observing CPU usage

Bug: 1125150
Test: browser_tests --gtest_filter=DiagnosticsApp*
Change-Id: I1f3d4a7c29fb1bac0f5d4fd2b5ebd42217d79f2c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2420775
Commit-Queue: Zentaro Kavanagh <zentaro@chromium.org>
Reviewed-by: default avatarBailey Berro <baileyberro@chromium.org>
Cr-Commit-Position: refs/heads/master@{#809617}
parent da38db9b
...@@ -7,7 +7,7 @@ import 'chrome://resources/mojo/mojo/public/js/mojo_bindings_lite.js'; ...@@ -7,7 +7,7 @@ import 'chrome://resources/mojo/mojo/public/js/mojo_bindings_lite.js';
import 'chrome://diagnostics/diagnostics_app.js'; import 'chrome://diagnostics/diagnostics_app.js';
import {SystemDataProviderInterface} from 'chrome://diagnostics/diagnostics_types.js'; import {SystemDataProviderInterface} from 'chrome://diagnostics/diagnostics_types.js';
import {fakeBatteryInfo, fakeSystemInfo} from 'chrome://diagnostics/fake_data.js'; import {fakeBatteryInfo, fakeCpuUsage, fakeSystemInfo} from 'chrome://diagnostics/fake_data.js';
import {FakeMethodResolver} from 'chrome://diagnostics/fake_method_resolver.js'; import {FakeMethodResolver} from 'chrome://diagnostics/fake_method_resolver.js';
import {FakeObservables} from 'chrome://diagnostics/fake_observables.js'; import {FakeObservables} from 'chrome://diagnostics/fake_observables.js';
import {FakeSystemDataProvider} from 'chrome://diagnostics/fake_system_data_provider.js'; import {FakeSystemDataProvider} from 'chrome://diagnostics/fake_system_data_provider.js';
...@@ -373,4 +373,17 @@ suite('FakeSystemDataProviderTest', () => { ...@@ -373,4 +373,17 @@ suite('FakeSystemDataProviderTest', () => {
assertDeepEquals(fakeBatteryInfo, batteryInfo); assertDeepEquals(fakeBatteryInfo, batteryInfo);
}); });
}); });
test('ObserveCpuUsage', () => {
provider.setFakeCpuUsage(fakeCpuUsage);
/** @type {!CpuUsageObserver} */
const cpuObserverRemote = {
onCpuUsageUpdated: (cpuUsage) => {
assertDeepEquals(fakeCpuUsage[0], cpuUsage);
}
};
return provider.observeCpuUsage(cpuObserverRemote);
});
}); });
...@@ -10,12 +10,19 @@ ...@@ -10,12 +10,19 @@
* re-aliased to the corresponding mojo types, or replaced by them. * re-aliased to the corresponding mojo types, or replaced by them.
*/ */
/**
* Type of SystemDataProviderInterface.ObserveCpuUsage function.
* @typedef {!function(!CpuUsageObserver): !Promise}
*/
export let ObserveCpuUsageFunction;
/** /**
* Type alias for the SystemDataProviderInterface. * Type alias for the SystemDataProviderInterface.
* TODO(zentaro): Replace with a real mojo type when implemented. * TODO(zentaro): Replace with a real mojo type when implemented.
* @typedef {{ * @typedef {{
* getBatteryInfo: !function(): !Promise<!BatteryInfo>, * getBatteryInfo: !function(): !Promise<!BatteryInfo>,
* getSystemInfo: !function(): !Promise<!SystemInfo>, * getSystemInfo: !function(): !Promise<!SystemInfo>,
* observeCpuUsage: !ObserveCpuUsageFunction,
* }} * }}
*/ */
export let SystemDataProviderInterface; export let SystemDataProviderInterface;
...@@ -57,3 +64,21 @@ export let SystemInfo; ...@@ -57,3 +64,21 @@ export let SystemInfo;
* }} * }}
*/ */
export let BatteryInfo; export let BatteryInfo;
/**
* Type alias for CpuUsageObserver.
* @typedef {{
* onCpuUsageUpdated: !function(!CpuUsage),
* }}
*/
export let CpuUsageObserver;
/**
* Type alias for CpuUsage.
* @typedef {{
* cpu_temp_degrees_celcius: number,
* percent_usage_system: number,
* percent_usage_user: number,
* }}
*/
export let CpuUsage;
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import {SystemInfo} from './diagnostics_types.js' import {CpuUsage, SystemInfo} from './diagnostics_types.js'
/* @type {!BatteryInfo} */ /* @type {!BatteryInfo} */
export const fakeBatteryInfo = { export const fakeBatteryInfo = {
...@@ -10,6 +10,13 @@ export const fakeBatteryInfo = { ...@@ -10,6 +10,13 @@ export const fakeBatteryInfo = {
manufacturer: 'BatterCorp USA', manufacturer: 'BatterCorp USA',
}; };
/* @type {!Array<!CpuUsage>} */
export const fakeCpuUsage = [{
cpu_temp_degrees_celcius: 107,
percent_usage_system: 15,
percent_usage_user: 20,
}];
/* @type {!SystemInfo} */ /* @type {!SystemInfo} */
export const fakeSystemInfo = { export const fakeSystemInfo = {
board_name: 'CrOS Board', board_name: 'CrOS Board',
......
...@@ -2,8 +2,9 @@ ...@@ -2,8 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import {BatteryInfo, SystemInfo} from './diagnostics_types.js'; import {BatteryInfo, CpuUsage, CpuUsageObserver, SystemInfo} from './diagnostics_types.js';
import {FakeMethodResolver} from './fake_method_resolver.js'; import {FakeMethodResolver} from './fake_method_resolver.js';
import {FakeObservables} from './fake_observables.js';
/** /**
* @fileoverview * @fileoverview
...@@ -15,9 +16,15 @@ export class FakeSystemDataProvider { ...@@ -15,9 +16,15 @@ export class FakeSystemDataProvider {
/** @private {!FakeMethodResolver} */ /** @private {!FakeMethodResolver} */
this.methods_ = new FakeMethodResolver(); this.methods_ = new FakeMethodResolver();
/** @private {!FakeObservables} */
this.observables_ = new FakeObservables();
// Setup method resolvers. // Setup method resolvers.
this.methods_.register('getSystemInfo'); this.methods_.register('getSystemInfo');
this.methods_.register('getBatteryInfo'); this.methods_.register('getBatteryInfo');
// Setup observables.
this.observables_.register('CpuUsageObserver_onCpuUsageUpdated');
} }
/** /**
...@@ -50,4 +57,31 @@ export class FakeSystemDataProvider { ...@@ -50,4 +57,31 @@ export class FakeSystemDataProvider {
setFakeBatteryInfo(batteryInfo) { setFakeBatteryInfo(batteryInfo) {
this.methods_.setResult('getBatteryInfo', batteryInfo); this.methods_.setResult('getBatteryInfo', batteryInfo);
} }
/*
* Implements SystemDataProviderInterface.ObserveCpuUsage.
* @param {!CpuUsageObserver} remote
* @return {!Promise}
*/
observeCpuUsage(remote) {
return new Promise((resolve) => {
this.observables_.observe(
'CpuUsageObserver_onCpuUsageUpdated', (cpuUsage) => {
remote.onCpuUsageUpdated(
/** @type {!CpuUsage} */ (cpuUsage));
});
this.observables_.trigger('CpuUsageObserver_onCpuUsageUpdated');
resolve();
});
}
/**
* Sets the values that will observed from observeCpuUsage.
* @param {!Array<!CpuUsage>} cpuUsageList
*/
setFakeCpuUsage(cpuUsageList) {
this.observables_.setObservableData(
'CpuUsageObserver_onCpuUsageUpdated', cpuUsageList);
}
} }
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