Pre-work for centralized trace flags

PiperOrigin-RevId: 635971487
pull/36682/head
AJ Heller 9 months ago committed by Copybara-Service
parent 40e578d330
commit b3e061e086
  1. 6
      BUILD
  2. 7
      bazel/grpc_build_system.bzl
  3. 13
      src/core/lib/debug/trace_flags.cc
  4. 18
      src/core/lib/debug/trace_flags.h
  5. 0
      src/core/lib/debug/trace_flags.yaml
  6. 56
      tools/codegen/core/templates/trace_flags.cc.mako
  7. 40
      tools/codegen/core/templates/trace_flags.h.mako
  8. 48
      tools/codegen/core/templates/trace_flags.md.mako

@ -19,6 +19,7 @@ load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
load(
"//bazel:grpc_build_system.bzl",
"grpc_cc_library",
"grpc_filegroup",
"grpc_generate_one_off_targets",
"grpc_upb_proto_library",
"grpc_upb_proto_reflection_library",
@ -3037,6 +3038,11 @@ grpc_cc_library(
],
)
grpc_filegroup(
name = "trace_flag_files",
srcs = ["//src/core:lib/debug/trace_flags.yaml"],
)
grpc_cc_library(
name = "load_config",
srcs = [

@ -735,6 +735,13 @@ def grpc_package(name, visibility = "private", features = []):
features = features,
)
def grpc_filegroup(name, srcs, **kwargs):
native.filegroup(
name = name,
srcs = srcs,
**kwargs
)
def grpc_objc_library(
name,
srcs = [],

@ -0,0 +1,13 @@
// Copyright 2024 gRPC authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

@ -0,0 +1,18 @@
// Copyright 2024 gRPC authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef GRPC_SRC_CORE_LIB_DEBUG_TRACE_FLAGS_H
#define GRPC_SRC_CORE_LIB_DEBUG_TRACE_FLAGS_H
#endif // GRPC_SRC_CORE_LIB_DEBUG_TRACE_FLAGS_H

@ -0,0 +1,56 @@
// Copyright 2024 gRPC authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Automatically generated by tools/codegen/core/gen_trace_flags.py
//
#include "${absl_prefix}absl/container/flat_hash_map.h"
#include "src/core/lib/debug/trace.h"
#include "src/core/lib/gprpp/no_destruct.h"
namespace grpc_core {
% for flag, settings in trace_flags.items():
% if "debug_only" in settings and settings["debug_only"]:
DebugOnlyTraceFlag ${flag}_trace(${str(settings["default"]).lower()}, "${flag}");
% endif
% endfor
% for flag, settings in trace_flags.items():
% if "debug_only" not in settings or not settings["debug_only"]:
TraceFlag ${flag}_trace(${str(settings["default"]).lower()}, "${flag}");
% endif
% endfor
const absl::flat_hash_map<std::string, TraceFlag*>& GetAllTraceFlags() {
static const NoDestruct<absl::flat_hash_map<std::string, TraceFlag*>>
all(absl::flat_hash_map<std::string, TraceFlag*>({
% for flag, settings in trace_flags.items():
% if "debug_only" not in settings or not settings["debug_only"]:
{"${flag}", &${flag}_trace},
% endif
% endfor
#ifndef NDEBUG
% for flag, settings in trace_flags.items():
% if "debug_only" in settings and settings["debug_only"]:
{"${flag}", &${flag}_trace},
% endif
% endfor
#endif
}));
return *all;
}
} // namespace grpc_core

@ -0,0 +1,40 @@
// Copyright 2015 gRPC authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Automatically generated by tools/codegen/core/gen_trace_flags.py
//
#ifndef GRPC_SRC_CORE_LIB_DEBUG_TRACE_FLAGS_H
#define GRPC_SRC_CORE_LIB_DEBUG_TRACE_FLAGS_H
#include "src/core/lib/debug/trace_impl.h"
namespace grpc_core {
% for flag, settings in trace_flags.items():
% if "debug_only" in settings and settings["debug_only"]:
extern DebugOnlyTraceFlag ${flag}_trace;
% endif
% endfor
% for flag, settings in trace_flags.items():
% if not "debug_only" in settings or not settings["debug_only"]:
extern TraceFlag ${flag}_trace;
% endif
% endfor
} // namespace grpc_core
#endif // GRPC_SRC_CORE_LIB_DEBUG_TRACE_FLAGS_H

@ -0,0 +1,48 @@
<!---
Automatically generated by tools/codegen/core/gen_trace_flags.py
--->
gRPC Trace Flags
----------------
The `GRPC_TRACE` environment variable supports a comma-separated list of tracer
names or glob patterns that provide additional insight into how gRPC C core is
processing requests via debug logs. Available tracers include:
% for flag, settings in trace_flags.items():
% if "internal" in settings and settings["internal"]:
<% continue %>
% endif
% if "debug_only" not in settings or not settings["debug_only"]:
% if settings["description"]:
- ${flag} - ${settings["description"]}
% else:
- ${flag}
% endif
% endif
% endfor
The following tracers will only run in binaries built in DEBUG mode. This is
accomplished by invoking `bazel build --config=dbg <target>`
% for flag, settings in trace_flags.items():
% if "internal" in settings and settings["internal"]:
<% continue %>
% endif
% if "debug_only" in settings and settings["debug_only"]:
% if settings["description"]:
- ${flag} - ${settings["description"]}
% else:
- ${flag}
% endif
% endif
% endfor
Glob patterns and special cases:
- `*` can be used to turn all traces on.
- Individual traces can be disabled by prefixing them with `-`.
- `*refcount*` will turn on all of the tracers for refcount debugging.
- if `list_tracers` is present, then all of the available tracers will be
printed when the program starts up.
Example:
export GRPC_TRACE=*,-pending_tags
Loading…
Cancel
Save