| // Copyright 2022 The Dawn & Tint Authors |
| // |
| // Redistribution and use in source and binary forms, with or without |
| // modification, are permitted provided that the following conditions are met: |
| // |
| // 1. Redistributions of source code must retain the above copyright notice, this |
| // list of conditions and the following disclaimer. |
| // |
| // 2. Redistributions in binary form must reproduce the above copyright notice, |
| // this list of conditions and the following disclaimer in the documentation |
| // and/or other materials provided with the distribution. |
| // |
| // 3. Neither the name of the copyright holder nor the names of its |
| // contributors may be used to endorse or promote products derived from |
| // this software without specific prior written permission. |
| // |
| // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
| // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| |
| #include <iomanip> |
| #include <iostream> |
| |
| #include "src/tint/cmd/bench/bench.h" |
| #include "src/tint/utils/text/string.h" |
| |
| /// ChromePerfReporter is a custom benchmark reporter used to output benchmark results in the format |
| /// required for the Chrome Perf waterfall, as described here: |
| /// [chromium]//src/tools/perf/generate_legacy_perf_dashboard_json.py |
| class ChromePerfReporter final : public benchmark::BenchmarkReporter { |
| public: |
| bool ReportContext([[maybe_unused]] const Context& context) override { return true; } |
| |
| void ReportRunsConfig([[maybe_unused]] double min_time, |
| [[maybe_unused]] bool has_explicit_iters, |
| [[maybe_unused]] benchmark::IterationCount iters) override {} |
| |
| void ReportRuns(const std::vector<Run>& report) override { |
| for (auto& run : report) { |
| auto fullname = run.benchmark_name(); |
| |
| if (run.skipped) { |
| std::cout << "FAILED " << fullname << ": " << run.skip_message << "\n"; |
| continue; |
| } |
| |
| auto graph_and_trace = tint::Split(fullname, "/"); |
| TINT_ASSERT(graph_and_trace.Length() <= 2u); |
| if (graph_and_trace.Length() == 1u) { |
| graph_and_trace.Push(graph_and_trace[0]); |
| graph_and_trace[0] = "TintInternals"; |
| } |
| |
| std::cout << "*RESULT " << graph_and_trace[0] << ": " << graph_and_trace[1] << "= " |
| << std::fixed << run.GetAdjustedRealTime() << " "; |
| switch (run.time_unit) { |
| case benchmark::kNanosecond: |
| std::cout << "ns"; |
| break; |
| case benchmark::kMicrosecond: |
| std::cout << "us"; |
| break; |
| case benchmark::kMillisecond: |
| std::cout << "ms"; |
| break; |
| case benchmark::kSecond: |
| std::cout << "s"; |
| break; |
| } |
| std::cout << "\n"; |
| } |
| } |
| |
| void Finalize() override {} |
| }; |
| |
| int main(int argc, char** argv) { |
| benchmark::Initialize(&argc, argv); |
| if (benchmark::ReportUnrecognizedArguments(argc, argv)) { |
| return 1; |
| } |
| benchmark::RunSpecifiedBenchmarks(new ChromePerfReporter); |
| } |