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_contrib.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 def __init__(self, event): 35 super().__init__(event=event) 36 self.proto = power_protos.PowerMetric() 37 38 def set_dl_tput(self, avg_dl_tput): 39 self.proto.cellular_metric.avg_dl_tput = avg_dl_tput 40 41 def set_ul_tput(self, avg_ul_tput): 42 self.proto.cellular_metric.avg_ul_tput = avg_ul_tput 43 44 def set_dl_tput_threshold(self, avg_dl_tput_threshold): 45 self.proto.cellular_metric.avg_dl_tput_threshold = avg_dl_tput_threshold 46 47 def set_ul_tput_threshold(self, avg_ul_tput_threshold): 48 self.proto.cellular_metric.avg_ul_tput_threshold = avg_ul_tput_threshold 49 50 def set_avg_power(self, avg_power): 51 self.proto.avg_power = avg_power 52 53 def set_avg_current(self, avg_current): 54 self.proto.avg_current = avg_current 55 56 def set_voltage(self, voltage): 57 self.proto.voltage = voltage 58 59 def set_testbed(self, testbed): 60 self.proto.testbed = testbed 61 62 def set_branch(self, branch): 63 self.proto.branch = branch 64 65 def set_build_id(self, build_id): 66 self.proto.build_id = build_id 67 68 def set_incremental_build_id(self, incremental_build_id): 69 self.proto.incremental_build_id = incremental_build_id 70 71 def set_target(self, target): 72 self.proto.target = target 73 74 def set_test_suite_display_name(self, test_suite_display_name): 75 self.proto.test_suite_display_name = test_suite_display_name 76 77 def set_test_case_display_name(self, test_case_display_name): 78 self.proto.test_case_display_name = test_case_display_name 79 80 def set_avg_current_threshold(self, avg_current_threshold): 81 self.proto.avg_current_threshold = avg_current_threshold 82 83 def set_pass_fail_status(self, status): 84 self.proto.pass_fail_status = status 85 86 def end(self, event): 87 metric = ProtoMetric(name='spanner_power_metric', data=self.proto) 88 return self.publisher.publish(metric) 89