Uses the hz parameter from measurement_args to configure the sampling rate in bits.
Bug: 181039141
Test: Unit test included
Change-Id: I49c6b1e5091b6a8422d10f6e8251524c47088716
diff --git a/acts/framework/acts/controllers/bits.py b/acts/framework/acts/controllers/bits.py
index 4e057b4..f0868e5 100644
--- a/acts/framework/acts/controllers/bits.py
+++ b/acts/framework/acts/controllers/bits.py
@@ -272,7 +272,10 @@
measurement_args: A dictionary with the following structure:
{
'duration': <seconds to measure for>
+ 'hz': <samples per second>
}
+ The actual number of samples per second is limited by the
+ bits configuration. The value of hz is defaulted to 1000.
measurement_name: A name to give to the measurement (which is also
used as the Bits collection name. Bits collection names (and
therefore measurement names) need to be unique within the
@@ -286,9 +289,10 @@
duration = measurement_args.get('duration')
if duration is None:
raise ValueError(
-
'duration can not be left undefined within measurement_args')
+ hz = measurement_args.get('hz', 1000)
+
if self._active_collection:
raise BitsError(
'Attempted to start a collection while there is still an '
@@ -306,7 +310,8 @@
self._active_collection = _BitsCollection(measurement_name,
monsoon_output_path)
- self._client.start_collection(self._active_collection.name)
+ self._client.start_collection(self._active_collection.name,
+ default_sampling_rate=hz)
time.sleep(duration)
def get_metrics(self, *_, timestamps=None, **__):
diff --git a/acts/framework/acts/controllers/bits_lib/bits_client.py b/acts/framework/acts/controllers/bits_lib/bits_client.py
index 20d66bf..aa56248 100644
--- a/acts/framework/acts/controllers/bits_lib/bits_client.py
+++ b/acts/framework/acts/controllers/bits_lib/bits_client.py
@@ -209,7 +209,7 @@
self._log.info('disconnecting monsoon\'s usb')
job.run(cmd, timeout=10)
- def start_collection(self, collection_name):
+ def start_collection(self, collection_name, default_sampling_rate=1000):
"""Indicates Bits to start a collection.
Args:
@@ -217,6 +217,7 @@
Collection names must be unique at Bits' service level. If multiple
collections must be taken within the context of the same Bits'
service, ensure that each collection is given a different one.
+ default_sampling_rate: Samples per second to be collected
"""
cmd = [self._binary,
@@ -228,7 +229,7 @@
'--time',
ONE_YEAR,
'--default_sampling_rate',
- '1000']
+ str(default_sampling_rate)]
if self._server_config.has_kibbles:
cmd = cmd + ['--disk_space_saver']
diff --git a/acts/framework/tests/controllers/bits_lib/bits_client_test.py b/acts/framework/tests/controllers/bits_lib/bits_client_test.py
index 2ff56e6..b29353f 100644
--- a/acts/framework/tests/controllers/bits_lib/bits_client_test.py
+++ b/acts/framework/tests/controllers/bits_lib/bits_client_test.py
@@ -59,6 +59,36 @@
'did not expect call with usb_disconnect')
@mock.patch('acts.libs.proc.job.run')
+ def test_start_collection__frecuency_arg_gets_populated(self, mock_run):
+ client = bits_client.BitsClient('bits.par', self.mock_service,
+ service_config=MONSOONED_CONFIG)
+
+ client.start_collection('collection', default_sampling_rate=12345)
+
+ mock_run.assert_called()
+ args_list = mock_run.call_args_list
+ expected_calls = list(
+ filter(lambda call: '--time' in call.args[0], args_list))
+ self.assertEqual(len(expected_calls), 1, 'expected 1 calls with --time')
+ self.assertIn('--default_sampling_rate', expected_calls[0][0][0])
+ self.assertIn('12345', expected_calls[0][0][0])
+
+ @mock.patch('acts.libs.proc.job.run')
+ def test_start_collection__sampling_rate_defaults_to_1000(self, mock_run):
+ client = bits_client.BitsClient('bits.par', self.mock_service,
+ service_config=MONSOONED_CONFIG)
+
+ client.start_collection('collection')
+
+ mock_run.assert_called()
+ args_list = mock_run.call_args_list
+ expected_calls = list(
+ filter(lambda call: '--time' in call.args[0], args_list))
+ self.assertEqual(len(expected_calls), 1, 'expected 1 calls with --time')
+ self.assertIn('--default_sampling_rate', expected_calls[0][0][0])
+ self.assertIn('1000', expected_calls[0][0][0])
+
+ @mock.patch('acts.libs.proc.job.run')
def test_stop_collection__usb_not_automanaged__does_not_connect_monsoon(
self, mock_run):
client = bits_client.BitsClient('bits.par', self.mock_service,