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

Side by Side Diff: telemetry/telemetry/internal/platform/tracing_agent/battor_tracing_agent.py

Issue 1819183002: [Telemetry] Add battor tracing agent (Closed) Base URL: git@github.com:catapult-project/catapult@master
Patch Set: Created 4 years, 7 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 unified diff | Download patch
OLDNEW
(Empty)
1 # Copyright 2016 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 import logging
6
7 from battor import battor_error
8 from battor import battor_wrapper
9 from py_trace_event import trace_time
10 from telemetry.internal.platform import tracing_agent
11 from telemetry.timeline import trace_data
12
13
14 class BattOrTracingAgent(tracing_agent.TracingAgent):
15 """A tracing agent for getting power data from a BattOr device.
16
17 BattOrTracingAgent allows Telemetry to issue high-level tracing commands
18 (StartTracing, StopTracing, RecordClockSyncMarker) to BattOrs, which are
19 high-frequency power monitors used for battery testing.
20 """
21
22 def __init__(self, platform_backend):
23 super(BattOrTracingAgent, self).__init__(platform_backend)
24 self._platform_backend = platform_backend
25 android_device = (
26 platform_backend.device if platform_backend.GetOSName() == 'android'
27 else None)
28 self._battor = battor_wrapper.BattorWrapper(platform_backend.GetOSName(),
charliea (OOO until 10-5) 2016/05/09 21:30:32 We should change this from BattorWrapper to BattOr
rnephew (Reviews Here) 2016/05/10 15:51:44 Also need to change battor_error, I will do this i
29 android_device=android_device)
30
31 @classmethod
32 def IsSupported(cls, platform_backend):
33 """Returns True if BattOr tracing is available."""
34 if platform_backend.GetOSName() == 'android':
35 # TODO(rnephew): When we pass BattOr device map into telemetry, change
charliea (OOO until 10-5) 2016/05/09 21:30:32 nit: s/telemetry/Telemetry
rnephew (Reviews Here) 2016/05/10 15:51:44 Done.
36 # this to reflect that.
37 return battor_wrapper.IsBattOrConnected(
38 'android', android_device=platform_backend.device)
39 return battor_wrapper.IsBattOrConnected(platform_backend.GetOSName())
40
41 def StartAgentTracing(self, config, timeout):
42 """Start tracing on the BattOr.
43
44 Args:
45 config: A TracingConfig instance.
46 timeout: number of seconds that this tracing agent should try to start
47 tracing until timing out.
48
49 Returns:
50 True if the tracing agent started successfully.
51 """
52 if not config.enable_battor_trace:
53 return False
54 try:
55 self._battor.StartShell()
56 self._battor.StartTracing()
57 return True
58 except battor_error.BattorError:
59 logging.exception('Failure in starting tracing on BattOr.')
60 return False
61
62 def StopAgentTracing(self):
63 """Stops tracing on the BattOr."""
64 self._battor.StopTracing()
65
66 def SupportsExplicitClockSync(self):
67 return self._battor.SupportsExplicitClockSync()
68
69 def RecordClockSyncMarker(self, sync_id,
70 record_controller_clock_sync_marker_callback):
71 """Records a clock sync marker in the BattOr trace.
72
73 Args:
74 sync_id: Unique id for sync event.
75 record_controller_clock_sync_marker_callback: Function that takes a sync
76 ID and a timestamp as arguments. This function typically will record the
77 tracing controller clock sync marker.
78 """
79 timestamp = trace_time.Now()
80 self._battor.RecordClockSyncMarker(sync_id)
81 record_controller_clock_sync_marker_callback(sync_id, timestamp)
82
83 def CollectAgentTraceData(self, trace_data_builder, timeout=None):
84 data = '\n'.join(self._battor.CollectTraceData(timeout=timeout))
85 trace_data_builder.AddEventsTo(trace_data.BATTOR_TRACE_PART, [data])
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698