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

Unified Diff: telemetry/telemetry/internal/actions/action_runner.py

Issue 2123713005: [Telemetry] Add MeasureMemory method to action_runner (Closed) Base URL: git@github.com:catapult-project/catapult@master
Patch Set: rephrase comment Created 4 years, 4 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: telemetry/telemetry/internal/actions/action_runner.py
diff --git a/telemetry/telemetry/internal/actions/action_runner.py b/telemetry/telemetry/internal/actions/action_runner.py
index ebb61f7c5d7caeb765f62b59c5d31a01717aa33f..f16a497573d0c35d3a19b0c96f069630a6b32cd3 100644
--- a/telemetry/telemetry/internal/actions/action_runner.py
+++ b/telemetry/telemetry/internal/actions/action_runner.py
@@ -29,6 +29,9 @@ from telemetry.internal.actions.wait import WaitForElementAction
from telemetry.web_perf import timeline_interaction_record
+_DUMP_WAIT_TIME = 3
+
+
class ActionRunner(object):
def __init__(self, tab, skip_waits=False):
@@ -105,6 +108,36 @@ class ActionRunner(object):
"""
return self.CreateInteraction('Gesture_' + label, repeatable)
+ def MeasureMemory(self, deterministic_mode=False):
+ """Add a memory measurement to the trace being recorded.
+
+ Behaves as a no-op if tracing is not enabled.
+
+ TODO(perezju): Also behave as a no-op if tracing is enabled but
+ memory-infra is not.
+
+ Args:
+ deterministic_mode: A boolean indicating whether to attempt or not to
+ control the environment (force GCs, clear caches) before making the
+ measurement in an attempt to obtain more deterministic results.
+
+ Returns:
+ GUID of the generated dump if one was triggered, None otherwise.
+ """
+ platform = self.tab.browser.platform
+ if not platform.tracing_controller.is_tracing_running:
+ logging.warning('Tracing is off. No memory dumps are being recorded.')
+ return None
+ if deterministic_mode:
+ self.Wait(_DUMP_WAIT_TIME)
+ self.ForceGarbageCollection()
+ if platform.CanElevatePrivilege():
+ platform.FlushEntireSystemCache()
+ self.Wait(_DUMP_WAIT_TIME)
+ dump_id = self.tab.browser.DumpMemory()
+ assert dump_id, 'Unable to obtain memory dump'
+ return dump_id
+
def Navigate(self, url, script_to_evaluate_on_commit=None,
timeout_in_seconds=60):
"""Navigates to |url|.
« no previous file with comments | « telemetry/telemetry/core/platform.py ('k') | telemetry/telemetry/internal/actions/action_runner_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698