Index: tools/telemetry/telemetry/core/browser.py |
diff --git a/tools/telemetry/telemetry/core/browser.py b/tools/telemetry/telemetry/core/browser.py |
index c317e6a248068e21278e08fa0d926c4ae8925050..19ca2d3ab7b1c7e7e661a22cb772cacf2f20e983 100644 |
--- a/tools/telemetry/telemetry/core/browser.py |
+++ b/tools/telemetry/telemetry/core/browser.py |
@@ -10,7 +10,7 @@ from telemetry.core import exceptions |
from telemetry.core import extension_dict |
from telemetry.core import local_server |
from telemetry.core import memory_cache_http_server |
-from telemetry.core import platform |
+from telemetry.core import platform as platform_module |
from telemetry.core import tab_list |
from telemetry.core import wpr_modes |
from telemetry.core import wpr_server |
@@ -29,12 +29,12 @@ class Browser(object): |
with browser_to_create.Create() as browser: |
... do all your operations on browser here |
""" |
- def __init__(self, backend, platform_backend): |
+ def __init__(self, backend, platform): |
+ assert isinstance(platform, platform_module.Platform) |
self._browser_backend = backend |
self._http_server = None |
self._wpr_server = None |
- self._platform_backend = platform_backend |
- self._platform = platform.Platform(platform_backend) |
+ self._platform = platform |
self._active_profilers = [] |
self._profilers_states = {} |
self._local_server_controller = local_server.LocalServerController(backend) |
@@ -101,6 +101,7 @@ class Browser(object): |
return profiler_name in [profiler.name() for |
profiler in self._active_profilers] |
+ |
def _GetStatsCommon(self, pid_stats_function): |
browser_pid = self._browser_backend.pid |
result = { |
@@ -110,9 +111,9 @@ class Browser(object): |
'Other': {'ProcessCount': 0} |
} |
process_count = 1 |
- for child_pid in self._platform_backend.GetChildPids(browser_pid): |
+ for child_pid in self._platform.GetChildPids(browser_pid): |
try: |
- child_cmd_line = self._platform_backend.GetCommandLine(child_pid) |
+ child_cmd_line = self._platform.GetCommandLine(child_pid) |
child_stats = pid_stats_function(child_pid) |
except exceptions.ProcessGoneException: |
# It is perfectly fine for a process to have gone away between calling |
@@ -175,14 +176,15 @@ class Browser(object): |
} |
Any of the above keys may be missing on a per-platform basis. |
""" |
- self._platform_backend.PurgeUnpinnedMemory() |
- result = self._GetStatsCommon(self._platform_backend.GetMemoryStats) |
+ self._platform.WillGetMemoryStats() |
+ result = self._GetStatsCommon(self._platform.GetMemoryStats) |
result['SystemCommitCharge'] = \ |
- self._platform_backend.GetSystemCommitCharge() |
+ self._platform.GetSystemCommitCharge() |
result['SystemTotalPhysicalMemory'] = \ |
- self._platform_backend.GetSystemTotalPhysicalMemory() |
+ self._platform.GetSystemTotalPhysicalMemory() |
return result |
+ |
@property |
def cpu_stats(self): |
tonyg
2014/08/02 15:58:18
I think the root of the problem here is that these
|
"""Returns a dict of cpu statistics for the system. |
@@ -201,11 +203,11 @@ class Browser(object): |
} |
Any of the above keys may be missing on a per-platform basis. |
""" |
- result = self._GetStatsCommon(self._platform_backend.GetCpuStats) |
+ result = self._GetStatsCommon(self._platform.GetCpuStats) |
del result['ProcessCount'] |
# We want a single time value, not the sum for all processes. |
- cpu_timestamp = self._platform_backend.GetCpuTimestamp() |
+ cpu_timestamp = self._platform.GetCpuTimestamp() |
for process_type in result: |
# Skip any process_types that are empty |
if not len(result[process_type]): |
@@ -236,7 +238,7 @@ class Browser(object): |
} |
} |
""" |
- result = self._GetStatsCommon(self._platform_backend.GetIOStats) |
+ result = self._GetStatsCommon(self._platform.GetIOStats) |
del result['ProcessCount'] |
return result |
@@ -254,9 +256,12 @@ class Browser(object): |
if not profiler_class in self._profilers_states: |
self._profilers_states[profiler_class] = {} |
- self._active_profilers.append( |
- profiler_class(self._browser_backend, self._platform_backend, |
- base_output_file, self._profilers_states[profiler_class])) |
+ profiler = self.platform.InstantiateProfiler( |
+ profiler_class, |
+ self._browser_backend, |
+ base_output_file, |
+ self._profilers_states[profiler_class]) |
+ self._active_profilers.append(profiler) |
def StopProfiling(self): |
"""Stops all active profilers and saves their results. |
@@ -298,9 +303,9 @@ class Browser(object): |
def Close(self): |
"""Closes this browser.""" |
- for profiler_class in self._profilers_states: |
- profiler_class.WillCloseBrowser(self._browser_backend, |
- self._platform_backend) |
+ profiler_classes = list(self._profilers_states.keys()) |
+ self._platform.WillCloseBrowser(self._browser_backend, |
+ profiler_classes) |
self.platform.SetFullPerformanceModeEnabled(False) |