1 /* 2 * Copyright (C) 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.android.tradefed.postprocessor; 17 18 import com.android.tradefed.metrics.proto.MetricMeasurement.Metric; 19 import com.android.tradefed.result.ILogSaverListener; 20 import com.android.tradefed.result.ITestInvocationListener; 21 import com.android.tradefed.result.TestDescription; 22 import com.android.tradefed.util.IDisableable; 23 24 import com.google.common.collect.ListMultimap; 25 26 import java.util.HashMap; 27 import java.util.Map; 28 29 /** 30 * Post processors is a Trade Federation object meant to allow the processing of metrics and logs 31 * AFTER the tests and BEFORE result reporting. This allows to post-process some data and have all 32 * result_reporter objects receive it, rather than doing the post-processing inside only one 33 * result_reporter and having issue to pass the new data around. 34 */ 35 public interface IPostProcessor extends ITestInvocationListener, ILogSaverListener, IDisableable { 36 37 /** 38 * Initialization step of the post processor. Ensured to be called before any of the tests 39 * callbacks. 40 */ init(ITestInvocationListener listener)41 public ITestInvocationListener init(ITestInvocationListener listener); 42 43 /** 44 * Implement this method in order to generate a set of new metrics from the existing one. Only 45 * the newly generated metrics should be returned, and with unique key name (no collision with 46 * existing keys are allowed). 47 * 48 * @param rawMetrics The set of raw metrics available for the run. 49 * @return The set of newly generated metrics from the run metrics. 50 */ processRunMetrics(HashMap<String, Metric> rawMetrics)51 public Map<String, Metric.Builder> processRunMetrics(HashMap<String, Metric> rawMetrics); 52 53 /** 54 * Implement this method to process metrics from each test. 55 * 56 * @param testDescription The TestDescription object describing the test. 57 * @param testMetrics The set of metrics from the test. 58 * @return The set of newly generated metrics from the test metrics. 59 */ processTestMetrics( TestDescription testDescription, HashMap<String, Metric> testMetrics)60 public Map<String, Metric.Builder> processTestMetrics( 61 TestDescription testDescription, HashMap<String, Metric> testMetrics); 62 63 /** 64 * Implement this method to aggregate test metrics. 65 * 66 * @param allTestMetrics A HashMultimap storing the metrics from each test grouped by metric 67 * names. 68 * @return The set of newly generated metrics from all test metrics. 69 */ processAllTestMetrics( ListMultimap<String, Metric> allTestMetrics)70 public Map<String, Metric.Builder> processAllTestMetrics( 71 ListMultimap<String, Metric> allTestMetrics); 72 } 73