1 /*
2  * Copyright (C) 2016 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.util;
17 
18 import com.android.tradefed.log.LogUtil.CLog;
19 
20 import java.util.HashMap;
21 import java.util.Map;
22 
23 /**
24  * Object to hold all simpleperf test results
25  * @see <a href="https://android.googlesource.com/platform/system/extras/+/master/simpleperf/">
26  * Introduction of simpleperf</a>
27  */
28 public class SimplePerfResult {
29 
30     private String commandRawOutput;
31     private String simplePerfRawOutput;
32     private Map<String, String> benchmarkMetrics;
33     private Map<String, String> benchmarkComments;
34     private String totalTestTime;
35 
36     /**
37      * Constructor
38      */
SimplePerfResult()39     public SimplePerfResult() {
40         commandRawOutput = "";
41         simplePerfRawOutput = "";
42         totalTestTime = "";
43         benchmarkMetrics = new HashMap<>();
44         benchmarkComments = new HashMap<>();
45     }
46 
47     /**
48      * Get command raw output string
49      * <p/>
50      * If no output, an empty string will be returned
51      *
52      * @return {@link String} contains output for user-specified command
53      */
getCommandRawOutput()54     public String getCommandRawOutput() {
55         return commandRawOutput;
56     }
57 
setCommandRawOutput(String s)58     protected void setCommandRawOutput(String s) {
59         if (s != null) {
60             commandRawOutput = s.trim();
61         } else {
62             CLog.e("Null command raw output passed in");
63         }
64     }
65 
66     /**
67      * Get simpleperf raw output string
68      * <p/>
69      * If no output, an empty string will be returned
70      *
71      * @return {@link String} contains output on simpleperf results information
72      */
getSimplePerfRawOutput()73     public String getSimplePerfRawOutput() {
74         return simplePerfRawOutput;
75     }
76 
setSimplePerfRawOutput(String s)77     protected void setSimplePerfRawOutput(String s) {
78         if (s != null) {
79             simplePerfRawOutput = s.trim();
80         } else {
81             CLog.e("Null simpleperf raw output passed in");
82         }
83     }
84 
addBenchmarkMetrics(String key, String val)85     protected void addBenchmarkMetrics(String key, String val) {
86         benchmarkMetrics.put(key, val);
87     }
88 
89     /**
90      * Get benchmark metrics
91      *
92      * @return {@link Map} key: benchmark name, value: metrics
93      */
getBenchmarkMetrics()94     public Map<String, String> getBenchmarkMetrics() {
95         return benchmarkMetrics;
96     }
97 
addBenchmarkComment(String key, String val)98     protected void addBenchmarkComment(String key, String val) {
99         benchmarkComments.put(key, val);
100     }
101 
102     /**
103      * Get benchmark comments
104      *
105      * @return {@link Map} key: benchmark name, value: comment
106      */
getBenchmarkComments()107     public Map<String, String> getBenchmarkComments() {
108         return benchmarkComments;
109     }
110 
111     /**
112      * Get total test time
113      *
114      * @return {@link String} indicates total test time
115      */
getTotalTestTime()116     public String getTotalTestTime() {
117         return totalTestTime;
118     }
119 
setTotalTestTime(String time)120     protected void setTotalTestTime(String time) {
121         if (time != null) {
122             totalTestTime = time;
123         }
124     }
125 }
126