1 /*
2  * Copyright (C) 2024 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 
17 package com.android.bedstead.performanceanalyzer
18 
19 /**
20  * A summary of the analysis performed by [PerformanceAnalyzer].
21  */
22 internal class PerformanceSummary private constructor(
23     private val expectedTimeInMs: Long,
24     private val iterations: Int,
25     private val executionTimesUnderExpectedTimePc: Double,
26     private val failuresCount: Int,
27     private val percentile90: Long,
28     private val percentile99: Long
29 ) {
30     companion object {
31         /**
32          * Returns a summary of [PerformanceStats].
33          */
ofnull34         fun of(stats: PerformanceStats): PerformanceSummary {
35             return PerformanceSummary(stats.expectedTimeInMs, stats.iterations,
36                 stats.executionTimesUnderExpectedTimePc, stats.failuresCount, stats.percentile90,
37                 stats.percentile99)
38         }
39     }
40 
toStringnull41     override fun toString(): String {
42         return "Performance Test Summary: \n" +
43                 "Number of executions: ${iterations} \n" +
44                 "Expected time: ${expectedTimeInMs} ms \n" +
45                 "Expected runtime SLO: ${RUNTIME_SLO}% \n" +
46                 "% of executions that followed SLO: ${executionTimesUnderExpectedTimePc}% \n" +
47                 "90th percentile: ${percentile90} ms \n" +
48                 "99th percentile: ${percentile99} ms \n" +
49                 "Number of failures: ${failuresCount}"
50     }
51 }
52