1# Copyright 2021 gRPC authors. 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"""Configuration macros for grpc microbenchmarking""" 15 16load("//bazel:grpc_build_system.bzl", "grpc_cc_test") 17 18HISTORY = 1 19 20def grpc_benchmark_args(): 21 """Command line arguments for running a microbenchmark as a test""" 22 return ["--benchmark_min_time=0.001s"] 23 24def grpc_cc_benchmark(name, external_deps = [], tags = [], uses_polling = False, uses_event_engine = False, **kwargs): 25 """Base rule for gRPC benchmarks. 26 27 This is an opinionated configuration for gRPC benchmarks. 28 29 We disable uses_polling, uses_event_engine by default so that we minimize 30 unnecessary uses of CI time. 31 32 Similarly, we disable running on Windows, Mac to save testing time there 33 (our principle target for performance work is Linux). 34 35 linkstatic is enabled always: this is the configuration real binaries use, and 36 it affects performance, so we should use it on our benchmarks too! 37 38 Args: 39 name: base name of the test 40 external_deps: per grpc_cc_test 41 tags: per grpc_cc_test 42 uses_polling: per grpc_cc_test, but defaulted False 43 uses_event_engine: per grpc_cc_test, but defaulted False 44 **kwargs: per grpc_cc_test 45 """ 46 kwargs.pop("monitoring", None) 47 grpc_cc_test( 48 name = name, 49 args = grpc_benchmark_args(), 50 external_deps = ["benchmark"] + external_deps, 51 tags = tags + ["no_mac", "no_windows", "bazel_only"], 52 uses_polling = uses_polling, 53 uses_event_engine = uses_event_engine, 54 # cc_binary defaults to 1, and we are interested in performance 55 # for that, so duplicate that setting here. 56 linkstatic = 1, 57 **kwargs 58 ) 59