Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 1 | //===-- BenchmarkResult.h ---------------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | /// |
| 10 | /// \file |
| 11 | /// Defines classes to represent measurements and serialize/deserialize them to |
| 12 | // Yaml. |
| 13 | /// |
| 14 | //===----------------------------------------------------------------------===// |
| 15 | |
| 16 | #ifndef LLVM_TOOLS_LLVM_EXEGESIS_BENCHMARKRESULT_H |
| 17 | #define LLVM_TOOLS_LLVM_EXEGESIS_BENCHMARKRESULT_H |
| 18 | |
| 19 | #include "llvm/ADT/StringRef.h" |
| 20 | #include "llvm/Support/YAMLTraits.h" |
Clement Courbet | ae8ae5dc | 2018-05-24 12:41:02 +0000 | [diff] [blame] | 21 | #include <limits> |
Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 22 | #include <string> |
| 23 | #include <vector> |
| 24 | |
| 25 | namespace exegesis { |
| 26 | |
Clement Courbet | a66bfaa4 | 2018-05-15 13:07:05 +0000 | [diff] [blame] | 27 | struct InstructionBenchmarkKey { |
| 28 | // The LLVM opcode name. |
| 29 | std::string OpcodeName; |
Clement Courbet | 2cb97b9 | 2018-06-04 11:43:40 +0000 | [diff] [blame] | 30 | enum ModeE { Unknown, Latency, Uops }; |
| 31 | ModeE Mode; |
Clement Courbet | a66bfaa4 | 2018-05-15 13:07:05 +0000 | [diff] [blame] | 32 | // An opaque configuration, that can be used to separate several benchmarks of |
| 33 | // the same instruction under different configurations. |
| 34 | std::string Config; |
Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 35 | }; |
| 36 | |
| 37 | struct BenchmarkMeasure { |
| 38 | std::string Key; |
| 39 | double Value; |
| 40 | std::string DebugString; |
| 41 | }; |
| 42 | |
| 43 | // The result of an instruction benchmark. |
| 44 | struct InstructionBenchmark { |
Clement Courbet | a66bfaa4 | 2018-05-15 13:07:05 +0000 | [diff] [blame] | 45 | InstructionBenchmarkKey Key; |
Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 46 | std::string CpuName; |
| 47 | std::string LLVMTriple; |
Clement Courbet | 8fb6e40 | 2018-04-04 12:01:46 +0000 | [diff] [blame] | 48 | int NumRepetitions = 0; |
Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 49 | std::vector<BenchmarkMeasure> Measurements; |
| 50 | std::string Error; |
Clement Courbet | a66bfaa4 | 2018-05-15 13:07:05 +0000 | [diff] [blame] | 51 | std::string Info; |
Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 52 | |
| 53 | static InstructionBenchmark readYamlOrDie(llvm::StringRef Filename); |
Clement Courbet | 0e69e2d | 2018-05-17 10:52:18 +0000 | [diff] [blame] | 54 | static std::vector<InstructionBenchmark> |
Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 55 | |
Clement Courbet | 0e69e2d | 2018-05-17 10:52:18 +0000 | [diff] [blame] | 56 | // Read functions. |
| 57 | readYamlsOrDie(llvm::StringRef Filename); |
| 58 | void readYamlFrom(llvm::StringRef InputContent); |
| 59 | |
| 60 | // Write functions, non-const because of YAML traits. |
| 61 | void writeYamlTo(llvm::raw_ostream &S); |
Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 62 | void writeYamlOrDie(const llvm::StringRef Filename); |
| 63 | }; |
| 64 | |
Clement Courbet | ae8ae5dc | 2018-05-24 12:41:02 +0000 | [diff] [blame] | 65 | //------------------------------------------------------------------------------ |
| 66 | // Utilities to work with Benchmark measures. |
| 67 | |
| 68 | // A class that measures stats over benchmark measures. |
| 69 | class BenchmarkMeasureStats { |
| 70 | public: |
| 71 | void push(const BenchmarkMeasure &BM); |
| 72 | |
| 73 | double avg() const { |
| 74 | assert(NumValues); |
| 75 | return SumValues / NumValues; |
| 76 | } |
| 77 | double min() const { return MinValue; } |
| 78 | double max() const { return MaxValue; } |
| 79 | |
Clement Courbet | 7228721 | 2018-06-04 11:11:55 +0000 | [diff] [blame] | 80 | const std::string &key() const { return Key; } |
| 81 | |
Clement Courbet | ae8ae5dc | 2018-05-24 12:41:02 +0000 | [diff] [blame] | 82 | private: |
| 83 | std::string Key; |
| 84 | double SumValues = 0.0; |
| 85 | int NumValues = 0; |
| 86 | double MaxValue = std::numeric_limits<double>::min(); |
| 87 | double MinValue = std::numeric_limits<double>::max(); |
| 88 | }; |
| 89 | |
Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 90 | } // namespace exegesis |
| 91 | |
| 92 | #endif // LLVM_TOOLS_LLVM_EXEGESIS_BENCHMARKRESULT_H |