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

Unified Diff: chrome/test/media_router/telemetry/extension/script.js

Issue 1843063004: Add new Telemetry tests to get CPU and memory usage for idle and flinging two test scenarios. Mirro… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix GN build failure Created 4 years, 8 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/test/media_router/telemetry/extension/manifest.json ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/media_router/telemetry/extension/script.js
diff --git a/chrome/test/media_router/telemetry/extension/script.js b/chrome/test/media_router/telemetry/extension/script.js
new file mode 100644
index 0000000000000000000000000000000000000000..1af1dfd84d37e8929bc749276918eaf17d24e09e
--- /dev/null
+++ b/chrome/test/media_router/telemetry/extension/script.js
@@ -0,0 +1,69 @@
+// Copyright 2016 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.
+
+
+// Collects CPU/memory usage information and posts to the page.
+function collectData(port) {
+ function processCpuListener(processes) {
+ _postData(processes, port, 'cpu');
+ }
+
+ function processMemoryListener(processes) {
+ _postData(processes, port, 'privateMemory');
+ }
+
+ chrome.processes.onUpdated.addListener(processCpuListener);
+ chrome.processes.onUpdatedWithMemory.addListener(processMemoryListener);
+ port.onDisconnect.addListener(function() {
+ chrome.processes.onUpdated.removeListener(processCpuListener);
+ chrome.processes.onUpdated.removeListener(processMemoryListener);
+ });
+}
+
+/**
+ * Posts the metric data to the page.
+ *
+ * @param processes list of current processes.
+ * @param port the port used for the communication between the page and
+ * extension.
+ * @param metric_name the metric name, e.g cpu.
+ */
+function _postData(processes, port, metric_name) {
+ var tabPid = port.sender.tab.id;
+ if (!tabPid) {
+ return;
+ }
+ var tabProcess = processes[tabPid];
+ if (!tabProcess) {
+ return;
+ }
+ var message = {};
+ message[metric_name] = {'current_tab': tabProcess[metric_name]};
+ for (var pid in processes) {
+ var process = processes[pid];
+ data = process[metric_name];
+ if (['browser', 'gpu', 'extension'].indexOf(process.type) > -1) {
+ if (process.type == 'extension'){
+ for (var index in process.tasks) {
+ var task = process.tasks[index];
+ if (task.title && task.title.indexOf('Chrome Media Router') > -1) {
+ message[metric_name]['mr_' + process.type] = data;
+ }
+ }
+ } else {
+ message[metric_name][process.type] = data;
+ }
+ }
+ }
+ port.postMessage(message);
+}
+
+chrome.runtime.onConnectExternal.addListener(function(port) {
+ if (port.name == 'collectData') {
+ collectData(port);
+ } else {
+ console.warn('Unknown port, disconnect the port.');
+ port.disconnect();
+ }
+});
« no previous file with comments | « chrome/test/media_router/telemetry/extension/manifest.json ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698