1 // Copyright (c) 2021 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
7 #include "base/logging.h"
8 #include "base/numerics/checked_math.h"
9 #include "base/numerics/safe_conversions.h"
10 #include "base/time/time.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "testing/perf/perf_result_reporter.h"
16 TEST(VlogPerfTest, GetVlogLevel) {
17 const std::string kMetricThroughput = "throughput";
18 perf_test::PerfResultReporter reporter(/*metric_basename=*/"Vlog",
19 /*story_name=*/"GetVlogLevel");
20 reporter.RegisterImportantMetric(/*metric_suffix=*/kMetricThroughput,
21 /*units=*/"gets/microsecond");
23 const base::TimeTicks job_run_start(base::TimeTicks::Now());
25 const char kVModuleSwitch[] =
26 "foo/bar.cc=1,baz\\*\\qux.cc=2,*quux/*=3,*/*-inl.h=4";
28 constexpr size_t kNumFilenames = 3;
29 const char* const kFileNames[kNumFilenames] = {"baz/x/qux.cc", "foo/bar",
31 int min_log_level = 0;
32 VlogInfo vlog_info(std::string(), kVModuleSwitch, &min_log_level);
34 constexpr size_t kNumSets = 1 << 21;
35 constexpr size_t kNumReps = 3;
37 for (size_t set = 0; set < kNumSets; set++) {
38 const char* kFileName = kFileNames[set % kNumFilenames];
39 for (size_t rep = 0; rep < kNumReps; rep++) {
40 int res = vlog_info.GetVlogLevel(kFileName);
41 ASSERT_GE(res, min_log_level);
46 const base::TimeDelta kDuration = base::TimeTicks::Now() - job_run_start;
47 const int64_t kDurationUs = kDuration.InMicroseconds();
48 ASSERT_NE(kDurationUs, 0) << "Too fast, would divide by zero.";
50 base::CheckedNumeric<size_t> gets_per_us_checked = kNumSets;
51 gets_per_us_checked *= kNumReps;
52 gets_per_us_checked /= kDurationUs;
54 const size_t kGetsPerUs = gets_per_us_checked.ValueOrDie();
55 reporter.AddResult(kMetricThroughput, kGetsPerUs);
57 } // namespace logging