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

Unified Diff: tools/telemetry/telemetry/core/platform/__init__.py

Issue 436873003: Make telemetry platform a singleton (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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
Index: tools/telemetry/telemetry/core/platform/__init__.py
diff --git a/tools/telemetry/telemetry/core/platform/__init__.py b/tools/telemetry/telemetry/core/platform/__init__.py
index 91c9747adba6e21dde1b1ad01499e04422795fa7..bf74b4610c141a29d2224b5fd91c5459a31ef247 100644
--- a/tools/telemetry/telemetry/core/platform/__init__.py
+++ b/tools/telemetry/telemetry/core/platform/__init__.py
@@ -2,12 +2,44 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
-from telemetry.core.platform import factory
-
+import sys
+
+def _CreateHostPlatformBackend():
+ if sys.platform.startswith('linux'):
+ from telemetry.core.platform import linux_platform_backend
+ return linux_platform_backend.LinuxPlatformBackend()
+ elif sys.platform == 'darwin':
+ from telemetry.core.platform import mac_platform_backend
+ return mac_platform_backend.MacPlatformBackend()
+ elif sys.platform == 'win32':
+ from telemetry.core.platform import win_platform_backend
+ return win_platform_backend.WinPlatformBackend()
+ else:
+ raise NotImplementedError()
+
+_host_platform = None
+
+def ResetHostPlatformSingleton():
tonyg 2014/08/02 15:58:18 What's the use case for resetting? I can't think o
+ global _host_platform
+ if _host_platform:
+ _host_platform.Close()
+ _host_platform = None
+
+def GetHostPlatformName():
+ if sys.platform.startswith('linux'):
+ return 'linux'
tonyg 2014/08/02 15:58:18 This ends up duplicating strings from the platform
+ elif sys.platform == 'darwin':
+ return 'mac'
+ elif sys.platform == 'win32':
+ return 'win'
+ else:
+ raise NotImplementedError()
def GetHostPlatform():
- return Platform(factory.GetPlatformBackendForCurrentOS())
-
+ global _host_platform
+ if not _host_platform:
+ _host_platform = Platform(_CreateHostPlatformBackend())
+ return _host_platform
class Platform(object):
"""The platform that the target browser is running on.
@@ -18,6 +50,10 @@ class Platform(object):
"""
def __init__(self, platform_backend):
self._platform_backend = platform_backend
+ self._platform_backend.SetPlatform(self)
+
+ def Close(self):
+ pass
def IsRawDisplayFrameRateSupported(self):
"""Platforms may be able to collect GL surface stats."""
@@ -235,3 +271,35 @@ class Platform(object):
}
"""
return self._platform_backend.StopMonitoringPower()
+
+ def GetChildPids(self, pid):
tonyg 2014/08/02 15:58:18 Isn't this a backendy thing? Are we really exposin
+ return self._platform_backend.GetChildPids(pid)
+
+ def GetCommandLine(self, pid):
+ return self._platform_backend.GetCommandLine(pid)
+
+ def WillGetMemoryStats(self):
tonyg 2014/08/02 15:58:18 Seems like another good thing to hide from the API
+ self._platform_backend.PurgeUnpinnedMemory()
+
+ def GetMemoryStats(self, pid):
+ return self._platform_backend.GetMemoryStats(pid)
+
+ def GetSystemCommitCharge(self):
+ return self._platform_backend.GetSystemCommitCharge()
+
+ def GetSystemTotalPhysicalMemory(self):
+ return self._platform_backend.GetSystemTotalPhysicalMemory()
+
+ def GetCpuStats(self, pid):
+ return self._platform_backend.GetCpuStats(pid)
+
+ def GetIOStats(self, pid):
+ return self._platform.GetIOStats(pid)
+
+ def InstantiateProfiler(self, profiler_class, browser_backend,
+ base_output_file, state):
+ return profiler_class(browser_backend, self, base_output_file, state)
+
+ def WillCloseBrowser(self, browser_backend, profiler_classes):
+ for cls in profiler_classes:
+ cls.WillCloseBrowser(browser_backend, self._platform_backend)

Powered by Google App Engine
This is Rietveld 408576698