1*6fa2df46SAndroid Build Coastguard Worker // Copyright (C) 2021 The Android Open Source Project 2*6fa2df46SAndroid Build Coastguard Worker // 3*6fa2df46SAndroid Build Coastguard Worker // Licensed under the Apache License, Version 2.0 (the "License"); 4*6fa2df46SAndroid Build Coastguard Worker // you may not use this file except in compliance with the License. 5*6fa2df46SAndroid Build Coastguard Worker // You may obtain a copy of the License at 6*6fa2df46SAndroid Build Coastguard Worker // 7*6fa2df46SAndroid Build Coastguard Worker // http://www.apache.org/licenses/LICENSE-2.0 8*6fa2df46SAndroid Build Coastguard Worker // 9*6fa2df46SAndroid Build Coastguard Worker // Unless required by applicable law or agreed to in writing, software 10*6fa2df46SAndroid Build Coastguard Worker // distributed under the License is distributed on an "AS IS" BASIS, 11*6fa2df46SAndroid Build Coastguard Worker // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12*6fa2df46SAndroid Build Coastguard Worker // See the License for the specific language governing permissions and 13*6fa2df46SAndroid Build Coastguard Worker // limitations under the License. 14*6fa2df46SAndroid Build Coastguard Worker 15*6fa2df46SAndroid Build Coastguard Worker #pragma once 16*6fa2df46SAndroid Build Coastguard Worker 17*6fa2df46SAndroid Build Coastguard Worker #include <result.pb.h> 18*6fa2df46SAndroid Build Coastguard Worker 19*6fa2df46SAndroid Build Coastguard Worker #include <time.h> 20*6fa2df46SAndroid Build Coastguard Worker 21*6fa2df46SAndroid Build Coastguard Worker #include <map> 22*6fa2df46SAndroid Build Coastguard Worker #include <memory> 23*6fa2df46SAndroid Build Coastguard Worker #include <set> 24*6fa2df46SAndroid Build Coastguard Worker #include <string> 25*6fa2df46SAndroid Build Coastguard Worker #include <vector> 26*6fa2df46SAndroid Build Coastguard Worker 27*6fa2df46SAndroid Build Coastguard Worker namespace dittosuite { 28*6fa2df46SAndroid Build Coastguard Worker 29*6fa2df46SAndroid Build Coastguard Worker enum class ResultsOutput { kNull, kReport, kCsv, kPb }; 30*6fa2df46SAndroid Build Coastguard Worker 31*6fa2df46SAndroid Build Coastguard Worker class Result { 32*6fa2df46SAndroid Build Coastguard Worker public: 33*6fa2df46SAndroid Build Coastguard Worker struct Statistics { 34*6fa2df46SAndroid Build Coastguard Worker double min, max, mean, median, sd; 35*6fa2df46SAndroid Build Coastguard Worker }; 36*6fa2df46SAndroid Build Coastguard Worker 37*6fa2df46SAndroid Build Coastguard Worker explicit Result(const std::string& name, int repeat); 38*6fa2df46SAndroid Build Coastguard Worker 39*6fa2df46SAndroid Build Coastguard Worker void AddMeasurement(const std::string& type, const std::vector<double>& samples); 40*6fa2df46SAndroid Build Coastguard Worker void AddSubResult(std::unique_ptr<Result> result); 41*6fa2df46SAndroid Build Coastguard Worker std::vector<double> GetSamples(const std::string& measurement_name) const; 42*6fa2df46SAndroid Build Coastguard Worker int GetRepeat() const; 43*6fa2df46SAndroid Build Coastguard Worker void Print(ResultsOutput results_output, const std::string& instruction_path); 44*6fa2df46SAndroid Build Coastguard Worker 45*6fa2df46SAndroid Build Coastguard Worker void SetStatistics(const std::string& name, const Statistics& stats); 46*6fa2df46SAndroid Build Coastguard Worker 47*6fa2df46SAndroid Build Coastguard Worker dittosuiteproto::Result ToPb(); 48*6fa2df46SAndroid Build Coastguard Worker static std::unique_ptr<Result> FromPb(const dittosuiteproto::Result &pb); 49*6fa2df46SAndroid Build Coastguard Worker 50*6fa2df46SAndroid Build Coastguard Worker private: 51*6fa2df46SAndroid Build Coastguard Worker struct TimeUnit { 52*6fa2df46SAndroid Build Coastguard Worker int dividing_factor; // dividing factor used for transforming the current time 53*6fa2df46SAndroid Build Coastguard Worker // unit (ns) in another one (ex 1000 for microseconds) 54*6fa2df46SAndroid Build Coastguard Worker std::string name; 55*6fa2df46SAndroid Build Coastguard Worker }; 56*6fa2df46SAndroid Build Coastguard Worker struct BandwidthUnit { 57*6fa2df46SAndroid Build Coastguard Worker int dividing_factor; // dividing factor used for transforming the bandwidth 58*6fa2df46SAndroid Build Coastguard Worker // unit (KB/s) in another one (ex GB/s) 59*6fa2df46SAndroid Build Coastguard Worker std::string name; 60*6fa2df46SAndroid Build Coastguard Worker }; 61*6fa2df46SAndroid Build Coastguard Worker TimeUnit time_unit_; 62*6fa2df46SAndroid Build Coastguard Worker BandwidthUnit bandwidth_unit_; 63*6fa2df46SAndroid Build Coastguard Worker std::string name_; 64*6fa2df46SAndroid Build Coastguard Worker std::map<std::string, std::vector<double>> samples_; 65*6fa2df46SAndroid Build Coastguard Worker std::map<std::string, Statistics> statistics_; 66*6fa2df46SAndroid Build Coastguard Worker std::vector<std::unique_ptr<Result>> sub_results_; 67*6fa2df46SAndroid Build Coastguard Worker int repeat_; 68*6fa2df46SAndroid Build Coastguard Worker 69*6fa2df46SAndroid Build Coastguard Worker void PrintHistograms(const std::string& instruction_path); 70*6fa2df46SAndroid Build Coastguard Worker void PrintStatisticsTables(); 71*6fa2df46SAndroid Build Coastguard Worker void MakeStatisticsCsv(); 72*6fa2df46SAndroid Build Coastguard Worker void MakeStatisticsPb(); 73*6fa2df46SAndroid Build Coastguard Worker 74*6fa2df46SAndroid Build Coastguard Worker void AnalyseMeasurement(const std::string& name); 75*6fa2df46SAndroid Build Coastguard Worker std::vector<int> ComputeNormalizedFrequencyVector(const std::string& measurement_name); 76*6fa2df46SAndroid Build Coastguard Worker std::set<std::string> GetMeasurementsNames(); 77*6fa2df46SAndroid Build Coastguard Worker void PrintStatisticsTableContent(const std::string& instruction_path, 78*6fa2df46SAndroid Build Coastguard Worker const std::string& measurement_name); 79*6fa2df46SAndroid Build Coastguard Worker 80*6fa2df46SAndroid Build Coastguard Worker std::string ComputeNextInstructionPath(const std::string& instruction_path); 81*6fa2df46SAndroid Build Coastguard Worker void PrintStatisticInCsv(std::ostream& csv_stream, const std::string& instruction_path, 82*6fa2df46SAndroid Build Coastguard Worker const std::set<std::string>& measurements_names); 83*6fa2df46SAndroid Build Coastguard Worker void PrintHistogramHeader(const std::string& measurement_name); 84*6fa2df46SAndroid Build Coastguard Worker void MakeHistogramFromVector(const std::vector<int>& freq_vector, int min_value); 85*6fa2df46SAndroid Build Coastguard Worker TimeUnit GetTimeUnit(int64_t min_value); 86*6fa2df46SAndroid Build Coastguard Worker BandwidthUnit GetBandwidthUnit(int64_t min_value); 87*6fa2df46SAndroid Build Coastguard Worker void PrintMeasurementStatisticInCsv(std::ostream& csv_stream, const std::string& name); 88*6fa2df46SAndroid Build Coastguard Worker 89*6fa2df46SAndroid Build Coastguard Worker void __ToPb(dittosuiteproto::Result* result_pb); 90*6fa2df46SAndroid Build Coastguard Worker void StoreStatisticsInPb(dittosuiteproto::Metrics* metrics, const std::string& name); 91*6fa2df46SAndroid Build Coastguard Worker }; 92*6fa2df46SAndroid Build Coastguard Worker 93*6fa2df46SAndroid Build Coastguard Worker void PrintPb(const dittosuiteproto::Result &pb); 94*6fa2df46SAndroid Build Coastguard Worker 95*6fa2df46SAndroid Build Coastguard Worker } // namespace dittosuite 96