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.LogFile; 22 import com.android.tradefed.result.TestDescription; 23 import com.android.tradefed.util.IDisableable; 24 25 import com.google.common.collect.ListMultimap; 26 27 import java.util.HashMap; 28 import java.util.Map; 29 30 /** 31 * Post processors is a Trade Federation object meant to allow the processing of metrics and logs 32 * AFTER the tests and BEFORE result reporting. This allows to post-process some data and have all 33 * result_reporter objects receive it, rather than doing the post-processing inside only one 34 * result_reporter and having issue to pass the new data around. 35 */ 36 public interface IPostProcessor extends ITestInvocationListener, ILogSaverListener, IDisableable { 37 38 /** 39 * Initialization step of the post processor. Ensured to be called before any of the tests 40 * callbacks. 41 */ init(ITestInvocationListener listener)42 public ITestInvocationListener init(ITestInvocationListener listener); 43 44 /** 45 * Implement this method in order to generate a set of new metrics from the existing metrics and 46 * logs. Only the newly generated metrics should be returned, and with unique key name (no 47 * collision with existing keys are allowed). 48 * 49 * @param rawMetrics The set of raw metrics available for the run. 50 * @param runLogs The set of log files for the test run. 51 * @return The set of newly generated metrics from the run metrics. 52 */ processRunMetricsAndLogs( HashMap<String, Metric> rawMetrics, Map<String, LogFile> runLogs)53 public Map<String, Metric.Builder> processRunMetricsAndLogs( 54 HashMap<String, Metric> rawMetrics, Map<String, LogFile> runLogs); 55 56 /** 57 * Implement this method to post process metrics and logs from each test. Only the newly 58 * generated metrics should be returned, and with unique key name (no collision with existing 59 * keys are allowed). 60 * 61 * @param testDescription The TestDescription object describing the test. 62 * @param testMetrics The set of metrics from the test. 63 * @param testLogs The set of files logged during the test. 64 * @return The set of newly generated metrics from the test metrics. 65 */ processTestMetricsAndLogs( TestDescription testDescription, HashMap<String, Metric> testMetrics, Map<String, LogFile> testLogs)66 public Map<String, Metric.Builder> processTestMetricsAndLogs( 67 TestDescription testDescription, 68 HashMap<String, Metric> testMetrics, 69 Map<String, LogFile> testLogs); 70 71 /** 72 * Implement this method to aggregate metrics and logs across all tests. Metrics coming out of 73 * this method will be reporter as run metrics. Only the newly generated metrics should be 74 * returned, and with unique key name (no collision with existing keys are allowed). 75 * 76 * @param allTestMetrics A HashMultimap storing the metrics from each test grouped by metric 77 * names. 78 * @param allTestLogs A map storing each test's map of log files keyed by their data names, 79 * using the each test's {@link TestDescription} as keys. 80 * @return The set of newly generated metrics from all test metrics. 81 */ processAllTestMetricsAndLogs( ListMultimap<String, Metric> allTestMetrics, Map<TestDescription, Map<String, LogFile>> allTestLogs)82 public Map<String, Metric.Builder> processAllTestMetricsAndLogs( 83 ListMultimap<String, Metric> allTestMetrics, 84 Map<TestDescription, Map<String, LogFile>> allTestLogs); 85 } 86