From ae8ae5dc78b8c6950b57b37706dfc37131d4d913 Mon Sep 17 00:00:00 2001 From: Clement Courbet Date: Thu, 24 May 2018 12:41:02 +0000 Subject: [PATCH] [llvm-exegesis] Analysis: Show value extents. Summary: Screenshot attached in phabricator. Reviewers: gchatelet Subscribers: tschuett, llvm-commits Differential Revision: https://reviews.llvm.org/D47318 llvm-svn: 333181 --- llvm/tools/llvm-exegesis/lib/Analysis.cpp | 32 +++++++++++++------ .../llvm-exegesis/lib/BenchmarkResult.cpp | 10 ++++++ .../tools/llvm-exegesis/lib/BenchmarkResult.h | 24 ++++++++++++++ .../llvm-exegesis/BenchmarkResultTest.cpp | 10 ++++++ 4 files changed, 67 insertions(+), 9 deletions(-) diff --git a/llvm/tools/llvm-exegesis/lib/Analysis.cpp b/llvm/tools/llvm-exegesis/lib/Analysis.cpp index 6ad693fa42113..0802f84c55343 100644 --- a/llvm/tools/llvm-exegesis/lib/Analysis.cpp +++ b/llvm/tools/llvm-exegesis/lib/Analysis.cpp @@ -195,22 +195,30 @@ void Analysis::printSchedClassClustersHtml(std::vector PointIds, OS << ""; writeClusterId(OS, CurrentClusterId); OS << "
    "; - const auto &ClusterRepresentative = - Points[PointIds[I]]; // FIXME: average measurements. + std::vector MeasurementStats( + Points[PointIds[I]].Measurements.size()); for (; I < E && Clustering_.getClusterIdForPoint(PointIds[I]) == CurrentClusterId; ++I) { + const auto &Point = Points[PointIds[I]]; OS << "
  • "; - writeEscaped(OS, Points[PointIds[I]].Key.OpcodeName); + writeEscaped(OS, Point.Key.OpcodeName); OS << " "; - writeEscaped(OS, Points[PointIds[I]].Key.Config); + writeEscaped(OS, Point.Key.Config); OS << "
  • "; + for (size_t J = 0, F = Point.Measurements.size(); J < F; ++J) { + MeasurementStats[J].push(Point.Measurements[J]); + } } OS << "
"; - for (const auto &Measurement : ClusterRepresentative.Measurements) { - OS << ""; - writeMeasurementValue(OS, Measurement.Value); - OS << ""; + for (const auto &Stats : MeasurementStats) { + OS << ""; + writeMeasurementValue(OS, Stats.avg()); + OS << "
["; + writeMeasurementValue(OS, Stats.min()); + OS << ";"; + writeMeasurementValue(OS, Stats.max()); + OS << "]"; } OS << ""; } @@ -321,7 +329,7 @@ void Analysis::printSchedClassDescHtml(const llvm::MCSchedClassDesc &SCDesc, writeEscaped(OS, SubtargetInfo_->getSchedModel() .getProcResource(WPR.ProcResourceIdx) ->Name); - OS << ": " << WPR.Cycles << ""; + OS << ": " << WPR.Cycles << ""; } OS << ""; OS << ""; @@ -378,6 +386,12 @@ table.sched-class-desc td { span.mono { font-family: monospace; } +span.minmax { + color: #888; +} +td.measurement { + text-align: center; +} )"; diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp index b1083f4ed0a6a..ed449dbd94e2d 100644 --- a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp +++ b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp @@ -104,4 +104,14 @@ void InstructionBenchmark::writeYamlOrDie(const llvm::StringRef Filename) { } } +void BenchmarkMeasureStats::push(const BenchmarkMeasure &BM) { + if (Key.empty()) + Key = BM.Key; + assert(Key == BM.Key); + ++NumValues; + SumValues += BM.Value; + MaxValue = std::max(MaxValue, BM.Value); + MinValue = std::min(MinValue, BM.Value); +} + } // namespace exegesis diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.h b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.h index 3a7d241dbd08b..4362df86df678 100644 --- a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.h +++ b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.h @@ -18,6 +18,7 @@ #include "llvm/ADT/StringRef.h" #include "llvm/Support/YAMLTraits.h" +#include #include #include @@ -61,6 +62,29 @@ struct InstructionBenchmark { void writeYamlOrDie(const llvm::StringRef Filename); }; +//------------------------------------------------------------------------------ +// Utilities to work with Benchmark measures. + +// A class that measures stats over benchmark measures. +class BenchmarkMeasureStats { +public: + void push(const BenchmarkMeasure &BM); + + double avg() const { + assert(NumValues); + return SumValues / NumValues; + } + double min() const { return MinValue; } + double max() const { return MaxValue; } + +private: + std::string Key; + double SumValues = 0.0; + int NumValues = 0; + double MaxValue = std::numeric_limits::min(); + double MinValue = std::numeric_limits::max(); +}; + } // namespace exegesis #endif // LLVM_TOOLS_LLVM_EXEGESIS_BENCHMARKRESULT_H diff --git a/llvm/unittests/tools/llvm-exegesis/BenchmarkResultTest.cpp b/llvm/unittests/tools/llvm-exegesis/BenchmarkResultTest.cpp index 9e00510c7c037..33b139c88a272 100644 --- a/llvm/unittests/tools/llvm-exegesis/BenchmarkResultTest.cpp +++ b/llvm/unittests/tools/llvm-exegesis/BenchmarkResultTest.cpp @@ -77,5 +77,15 @@ TEST(BenchmarkResultTest, WriteToAndReadFromDisk) { } } +TEST(BenchmarkResultTest, BenchmarkMeasureStats) { + BenchmarkMeasureStats Stats; + Stats.push(BenchmarkMeasure{"a", 0.5, "debug a"}); + Stats.push(BenchmarkMeasure{"a", 1.5, "debug a"}); + Stats.push(BenchmarkMeasure{"a", -1.0, "debug a"}); + Stats.push(BenchmarkMeasure{"a", 0.0, "debug a"}); + EXPECT_EQ(Stats.min(), -1.0); + EXPECT_EQ(Stats.max(), 1.5); + EXPECT_EQ(Stats.avg(), 0.25); // (0.5+1.5-1.0+0.0) / 4 +} } // namespace } // namespace exegesis