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