1# /usr/bin/env python3 2# 3# Copyright (C) 2019 The Android Open Source Project 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); you may not 6# use this file except in compliance with the License. You may obtain a copy of 7# the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14# License for the specific language governing permissions and limitations under 15# the License. 16 17import os 18import acts.test_utils.power.loggers.protos.power_metric_pb2 as power_protos 19 20from acts.metrics.core import ProtoMetric 21from acts.metrics.logger import MetricLogger 22 23# Initializes the path to the protobuf 24PROTO_PATH = os.path.join(os.path.dirname(__file__), 'protos', 25 'power_metric.proto') 26 27 28class PowerMetricLogger(MetricLogger): 29 """A logger for gathering Power test metrics 30 31 Attributes: 32 proto: Module used to store Power metrics in a proto 33 """ 34 35 def __init__(self, event): 36 super().__init__(event=event) 37 self.proto = power_protos.PowerMetric() 38 39 def set_dl_tput(self, avg_dl_tput): 40 self.proto.cellular_metric.avg_dl_tput = avg_dl_tput 41 42 def set_ul_tput(self, avg_ul_tput): 43 self.proto.cellular_metric.avg_ul_tput = avg_ul_tput 44 45 def set_avg_power(self, avg_power): 46 self.proto.avg_power = avg_power 47 48 def set_testbed(self, testbed): 49 self.proto.testbed = testbed 50 51 def set_branch(self, branch): 52 self.proto.branch = branch 53 54 def set_build_id(self, build_id): 55 self.proto.build_id = build_id 56 57 def set_target(self, target): 58 self.proto.target = target 59 60 def end(self, event): 61 metric = ProtoMetric(name='spanner_power_metric', data=self.proto) 62 return self.publisher.publish(metric) 63