Merge pull request #24245 from veblush/stacktrace

Add stack-tracer to gRPC
pull/24659/head
Esun Kim 4 years ago committed by GitHub
commit e0cbc7e5dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      BUILD
  2. 3
      BUILD.gn
  3. 109
      CMakeLists.txt
  4. 1
      Makefile
  5. 54
      build_autogenerated.yaml
  6. 1
      config.m4
  7. 1
      config.w32
  8. 2
      gRPC-C++.podspec
  9. 7
      gRPC-Core.podspec
  10. 2
      grpc.gemspec
  11. 6
      grpc.gyp
  12. 2
      package.xml
  13. 15
      src/core/lib/gpr/log_linux.cc
  14. 14
      src/core/lib/gpr/log_posix.cc
  15. 20
      src/core/lib/gpr/log_windows.cc
  16. 43
      src/core/lib/gprpp/examine_stack.cc
  17. 46
      src/core/lib/gprpp/examine_stack.h
  18. 1
      src/python/grpcio/grpc_core_dependencies.py
  19. 18
      test/core/gprpp/BUILD
  20. 82
      test/core/gprpp/examine_stack_test.cc
  21. 41
      test/core/util/BUILD
  22. 13
      test/core/util/stack_tracer.cc
  23. 20
      test/core/util/stack_tracer.h
  24. 41
      test/core/util/stack_tracer_test.cc
  25. 4
      test/core/util/test_config.cc
  26. 2
      tools/doxygen/Doxyfile.c++.internal
  27. 2
      tools/doxygen/Doxyfile.core.internal
  28. 44
      tools/run_tests/generated/tests.json

@ -529,6 +529,7 @@ grpc_cc_library(
"src/core/lib/gpr/tmpfile_windows.cc", "src/core/lib/gpr/tmpfile_windows.cc",
"src/core/lib/gpr/wrap_memcpy.cc", "src/core/lib/gpr/wrap_memcpy.cc",
"src/core/lib/gprpp/arena.cc", "src/core/lib/gprpp/arena.cc",
"src/core/lib/gprpp/examine_stack.cc",
"src/core/lib/gprpp/fork.cc", "src/core/lib/gprpp/fork.cc",
"src/core/lib/gprpp/global_config_env.cc", "src/core/lib/gprpp/global_config_env.cc",
"src/core/lib/gprpp/host_port.cc", "src/core/lib/gprpp/host_port.cc",
@ -558,6 +559,7 @@ grpc_cc_library(
"src/core/lib/gpr/useful.h", "src/core/lib/gpr/useful.h",
"src/core/lib/gprpp/arena.h", "src/core/lib/gprpp/arena.h",
"src/core/lib/gprpp/atomic.h", "src/core/lib/gprpp/atomic.h",
"src/core/lib/gprpp/examine_stack.h",
"src/core/lib/gprpp/fork.h", "src/core/lib/gprpp/fork.h",
"src/core/lib/gprpp/global_config.h", "src/core/lib/gprpp/global_config.h",
"src/core/lib/gprpp/global_config_custom.h", "src/core/lib/gprpp/global_config_custom.h",
@ -581,6 +583,7 @@ grpc_cc_library(
"absl/strings:str_format", "absl/strings:str_format",
"absl/synchronization", "absl/synchronization",
"absl/time:time", "absl/time:time",
"absl/types:optional",
], ],
language = "c++", language = "c++",
public_hdrs = GPR_PUBLIC_HDRS, public_hdrs = GPR_PUBLIC_HDRS,

@ -147,6 +147,8 @@ config("grpc_config") {
"src/core/lib/gprpp/arena.cc", "src/core/lib/gprpp/arena.cc",
"src/core/lib/gprpp/arena.h", "src/core/lib/gprpp/arena.h",
"src/core/lib/gprpp/atomic.h", "src/core/lib/gprpp/atomic.h",
"src/core/lib/gprpp/examine_stack.cc",
"src/core/lib/gprpp/examine_stack.h",
"src/core/lib/gprpp/fork.cc", "src/core/lib/gprpp/fork.cc",
"src/core/lib/gprpp/fork.h", "src/core/lib/gprpp/fork.h",
"src/core/lib/gprpp/global_config.h", "src/core/lib/gprpp/global_config.h",
@ -173,6 +175,7 @@ config("grpc_config") {
"src/core/lib/profiling/timers.h", "src/core/lib/profiling/timers.h",
] ]
deps = [ deps = [
":absl/types:optional",
":absl/time:time", ":absl/time:time",
":absl/synchronization:synchronization", ":absl/synchronization:synchronization",
":absl/strings:strings", ":absl/strings:strings",

@ -819,6 +819,9 @@ if(gRPC_BUILD_TESTS)
add_dependencies(buildtests_cxx error_details_test) add_dependencies(buildtests_cxx error_details_test)
add_dependencies(buildtests_cxx evaluate_args_test) add_dependencies(buildtests_cxx evaluate_args_test)
add_dependencies(buildtests_cxx eventmanager_libuv_test) add_dependencies(buildtests_cxx eventmanager_libuv_test)
if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
add_dependencies(buildtests_cxx examine_stack_test)
endif()
add_dependencies(buildtests_cxx exception_test) add_dependencies(buildtests_cxx exception_test)
add_dependencies(buildtests_cxx filter_end2end_test) add_dependencies(buildtests_cxx filter_end2end_test)
add_dependencies(buildtests_cxx flaky_network_test) add_dependencies(buildtests_cxx flaky_network_test)
@ -897,6 +900,9 @@ if(gRPC_BUILD_TESTS)
add_dependencies(buildtests_cxx settings_timeout_test) add_dependencies(buildtests_cxx settings_timeout_test)
add_dependencies(buildtests_cxx shutdown_test) add_dependencies(buildtests_cxx shutdown_test)
add_dependencies(buildtests_cxx simple_request_bad_client_test) add_dependencies(buildtests_cxx simple_request_bad_client_test)
if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
add_dependencies(buildtests_cxx stack_tracer_test)
endif()
add_dependencies(buildtests_cxx stat_test) add_dependencies(buildtests_cxx stat_test)
add_dependencies(buildtests_cxx static_metadata_test) add_dependencies(buildtests_cxx static_metadata_test)
add_dependencies(buildtests_cxx stats_test) add_dependencies(buildtests_cxx stats_test)
@ -1310,6 +1316,7 @@ add_library(gpr
src/core/lib/gpr/tmpfile_windows.cc src/core/lib/gpr/tmpfile_windows.cc
src/core/lib/gpr/wrap_memcpy.cc src/core/lib/gpr/wrap_memcpy.cc
src/core/lib/gprpp/arena.cc src/core/lib/gprpp/arena.cc
src/core/lib/gprpp/examine_stack.cc
src/core/lib/gprpp/fork.cc src/core/lib/gprpp/fork.cc
src/core/lib/gprpp/global_config_env.cc src/core/lib/gprpp/global_config_env.cc
src/core/lib/gprpp/host_port.cc src/core/lib/gprpp/host_port.cc
@ -1352,6 +1359,7 @@ target_include_directories(gpr
) )
target_link_libraries(gpr target_link_libraries(gpr
${_gRPC_ALLTARGETS_LIBRARIES} ${_gRPC_ALLTARGETS_LIBRARIES}
absl::optional
absl::time absl::time
absl::synchronization absl::synchronization
absl::strings absl::strings
@ -2086,7 +2094,6 @@ add_library(grpc_test_util
test/core/util/cmdline.cc test/core/util/cmdline.cc
test/core/util/debugger_macros.cc test/core/util/debugger_macros.cc
test/core/util/eval_args_mock_endpoint.cc test/core/util/eval_args_mock_endpoint.cc
test/core/util/examine_stack.cc
test/core/util/fuzzer_util.cc test/core/util/fuzzer_util.cc
test/core/util/grpc_profiler.cc test/core/util/grpc_profiler.cc
test/core/util/histogram.cc test/core/util/histogram.cc
@ -2100,6 +2107,7 @@ add_library(grpc_test_util
test/core/util/reconnect_server.cc test/core/util/reconnect_server.cc
test/core/util/resolve_localhost_ip46.cc test/core/util/resolve_localhost_ip46.cc
test/core/util/slice_splitter.cc test/core/util/slice_splitter.cc
test/core/util/stack_tracer.cc
test/core/util/subprocess_posix.cc test/core/util/subprocess_posix.cc
test/core/util/subprocess_windows.cc test/core/util/subprocess_windows.cc
test/core/util/test_config.cc test/core/util/test_config.cc
@ -2158,7 +2166,6 @@ add_library(grpc_test_util_unsecure
test/core/util/cmdline.cc test/core/util/cmdline.cc
test/core/util/debugger_macros.cc test/core/util/debugger_macros.cc
test/core/util/eval_args_mock_endpoint.cc test/core/util/eval_args_mock_endpoint.cc
test/core/util/examine_stack.cc
test/core/util/fuzzer_util.cc test/core/util/fuzzer_util.cc
test/core/util/grpc_profiler.cc test/core/util/grpc_profiler.cc
test/core/util/histogram.cc test/core/util/histogram.cc
@ -2172,6 +2179,7 @@ add_library(grpc_test_util_unsecure
test/core/util/reconnect_server.cc test/core/util/reconnect_server.cc
test/core/util/resolve_localhost_ip46.cc test/core/util/resolve_localhost_ip46.cc
test/core/util/slice_splitter.cc test/core/util/slice_splitter.cc
test/core/util/stack_tracer.cc
test/core/util/subprocess_posix.cc test/core/util/subprocess_posix.cc
test/core/util/subprocess_windows.cc test/core/util/subprocess_windows.cc
test/core/util/test_config.cc test/core/util/test_config.cc
@ -10980,6 +10988,49 @@ target_link_libraries(eventmanager_libuv_test
) )
endif()
if(gRPC_BUILD_TESTS)
if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
add_executable(examine_stack_test
test/core/gprpp/examine_stack_test.cc
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
)
target_include_directories(examine_stack_test
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/include
${_gRPC_ADDRESS_SORTING_INCLUDE_DIR}
${_gRPC_RE2_INCLUDE_DIR}
${_gRPC_SSL_INCLUDE_DIR}
${_gRPC_UPB_GENERATED_DIR}
${_gRPC_UPB_GRPC_GENERATED_DIR}
${_gRPC_UPB_INCLUDE_DIR}
${_gRPC_ZLIB_INCLUDE_DIR}
third_party/googletest/googletest/include
third_party/googletest/googletest
third_party/googletest/googlemock/include
third_party/googletest/googlemock
${_gRPC_PROTO_GENS_DIR}
)
target_link_libraries(examine_stack_test
${_gRPC_PROTOBUF_LIBRARIES}
${_gRPC_ALLTARGETS_LIBRARIES}
grpc_test_util
grpc
gpr
address_sorting
upb
absl::symbolize
absl::stacktrace
${_gRPC_GFLAGS_LIBRARIES}
)
endif()
endif() endif()
if(gRPC_BUILD_TESTS) if(gRPC_BUILD_TESTS)
@ -14249,6 +14300,48 @@ target_link_libraries(simple_request_bad_client_test
) )
endif()
if(gRPC_BUILD_TESTS)
if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
add_executable(stack_tracer_test
test/core/util/stack_tracer_test.cc
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
)
target_include_directories(stack_tracer_test
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/include
${_gRPC_ADDRESS_SORTING_INCLUDE_DIR}
${_gRPC_RE2_INCLUDE_DIR}
${_gRPC_SSL_INCLUDE_DIR}
${_gRPC_UPB_GENERATED_DIR}
${_gRPC_UPB_GRPC_GENERATED_DIR}
${_gRPC_UPB_INCLUDE_DIR}
${_gRPC_ZLIB_INCLUDE_DIR}
third_party/googletest/googletest/include
third_party/googletest/googletest
third_party/googletest/googlemock/include
third_party/googletest/googlemock
${_gRPC_PROTO_GENS_DIR}
)
target_link_libraries(stack_tracer_test
${_gRPC_PROTOBUF_LIBRARIES}
${_gRPC_ALLTARGETS_LIBRARIES}
grpc_test_util
grpc
gpr
address_sorting
upb
absl::symbolize
${_gRPC_GFLAGS_LIBRARIES}
)
endif()
endif() endif()
if(gRPC_BUILD_TESTS) if(gRPC_BUILD_TESTS)
@ -15155,7 +15248,6 @@ if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
test/core/util/cmdline.cc test/core/util/cmdline.cc
test/core/util/debugger_macros.cc test/core/util/debugger_macros.cc
test/core/util/eval_args_mock_endpoint.cc test/core/util/eval_args_mock_endpoint.cc
test/core/util/examine_stack.cc
test/core/util/fuzzer_util.cc test/core/util/fuzzer_util.cc
test/core/util/grpc_profiler.cc test/core/util/grpc_profiler.cc
test/core/util/histogram.cc test/core/util/histogram.cc
@ -15169,6 +15261,7 @@ if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
test/core/util/reconnect_server.cc test/core/util/reconnect_server.cc
test/core/util/resolve_localhost_ip46.cc test/core/util/resolve_localhost_ip46.cc
test/core/util/slice_splitter.cc test/core/util/slice_splitter.cc
test/core/util/stack_tracer.cc
test/core/util/subprocess_posix.cc test/core/util/subprocess_posix.cc
test/core/util/subprocess_windows.cc test/core/util/subprocess_windows.cc
test/core/util/test_config.cc test/core/util/test_config.cc
@ -16189,7 +16282,7 @@ generate_pkgconfig(
"gRPC platform support library" "gRPC platform support library"
"${gRPC_CORE_VERSION}" "${gRPC_CORE_VERSION}"
"" ""
"-lgpr -labsl_status -labsl_cord -labsl_str_format_internal -labsl_bad_optional_access -labsl_synchronization -labsl_graphcycles_internal -labsl_symbolize -labsl_demangle_internal -labsl_stacktrace -labsl_debugging_internal -labsl_malloc_internal -labsl_time -labsl_time_zone -labsl_civil_time -labsl_strings -labsl_strings_internal -labsl_throw_delegate -labsl_int128 -labsl_base -labsl_spinlock_wait -labsl_raw_logging_internal -labsl_log_severity" "-lgpr -labsl_status -labsl_cord -labsl_str_format_internal -labsl_synchronization -labsl_graphcycles_internal -labsl_symbolize -labsl_demangle_internal -labsl_stacktrace -labsl_debugging_internal -labsl_malloc_internal -labsl_time -labsl_time_zone -labsl_civil_time -labsl_strings -labsl_strings_internal -labsl_throw_delegate -labsl_int128 -labsl_base -labsl_spinlock_wait -labsl_bad_optional_access -labsl_raw_logging_internal -labsl_log_severity"
"" ""
"gpr.pc") "gpr.pc")
@ -16199,7 +16292,7 @@ generate_pkgconfig(
"high performance general RPC framework" "high performance general RPC framework"
"${gRPC_CORE_VERSION}" "${gRPC_CORE_VERSION}"
"gpr openssl" "gpr openssl"
"-lgrpc -laddress_sorting -lre2 -lupb -lcares -lz -labsl_raw_hash_set -labsl_hashtablez_sampler -labsl_exponential_biased -labsl_hash -labsl_bad_variant_access -labsl_city -labsl_status -labsl_cord -labsl_str_format_internal -labsl_bad_optional_access -labsl_synchronization -labsl_graphcycles_internal -labsl_symbolize -labsl_demangle_internal -labsl_stacktrace -labsl_debugging_internal -labsl_malloc_internal -labsl_time -labsl_time_zone -labsl_civil_time -labsl_strings -labsl_strings_internal -labsl_throw_delegate -labsl_int128 -labsl_base -labsl_spinlock_wait -labsl_raw_logging_internal -labsl_log_severity" "-lgrpc -laddress_sorting -lre2 -lupb -lcares -lz -labsl_raw_hash_set -labsl_hashtablez_sampler -labsl_exponential_biased -labsl_hash -labsl_bad_variant_access -labsl_city -labsl_status -labsl_cord -labsl_str_format_internal -labsl_synchronization -labsl_graphcycles_internal -labsl_symbolize -labsl_demangle_internal -labsl_stacktrace -labsl_debugging_internal -labsl_malloc_internal -labsl_time -labsl_time_zone -labsl_civil_time -labsl_strings -labsl_strings_internal -labsl_throw_delegate -labsl_int128 -labsl_base -labsl_spinlock_wait -labsl_bad_optional_access -labsl_raw_logging_internal -labsl_log_severity"
"" ""
"grpc.pc") "grpc.pc")
@ -16209,7 +16302,7 @@ generate_pkgconfig(
"high performance general RPC framework without SSL" "high performance general RPC framework without SSL"
"${gRPC_CORE_VERSION}" "${gRPC_CORE_VERSION}"
"gpr" "gpr"
"-lgrpc_unsecure -labsl_status -labsl_cord -labsl_str_format_internal -labsl_bad_optional_access -labsl_synchronization -labsl_graphcycles_internal -labsl_symbolize -labsl_demangle_internal -labsl_stacktrace -labsl_debugging_internal -labsl_malloc_internal -labsl_time -labsl_time_zone -labsl_civil_time -labsl_strings -labsl_strings_internal -labsl_throw_delegate -labsl_int128 -labsl_base -labsl_spinlock_wait -labsl_raw_logging_internal -labsl_log_severity" "-lgrpc_unsecure -labsl_status -labsl_cord -labsl_str_format_internal -labsl_synchronization -labsl_graphcycles_internal -labsl_symbolize -labsl_demangle_internal -labsl_stacktrace -labsl_debugging_internal -labsl_malloc_internal -labsl_time -labsl_time_zone -labsl_civil_time -labsl_strings -labsl_strings_internal -labsl_throw_delegate -labsl_int128 -labsl_base -labsl_spinlock_wait -labsl_bad_optional_access -labsl_raw_logging_internal -labsl_log_severity"
"" ""
"grpc_unsecure.pc") "grpc_unsecure.pc")
@ -16219,7 +16312,7 @@ generate_pkgconfig(
"C++ wrapper for gRPC" "C++ wrapper for gRPC"
"${gRPC_CPP_VERSION}" "${gRPC_CPP_VERSION}"
"grpc" "grpc"
"-lgrpc++ -labsl_raw_hash_set -labsl_hashtablez_sampler -labsl_exponential_biased -labsl_hash -labsl_bad_variant_access -labsl_city -labsl_status -labsl_cord -labsl_str_format_internal -labsl_bad_optional_access -labsl_synchronization -labsl_graphcycles_internal -labsl_symbolize -labsl_demangle_internal -labsl_stacktrace -labsl_debugging_internal -labsl_malloc_internal -labsl_time -labsl_time_zone -labsl_civil_time -labsl_strings -labsl_strings_internal -labsl_throw_delegate -labsl_int128 -labsl_base -labsl_spinlock_wait -labsl_raw_logging_internal -labsl_log_severity" "-lgrpc++ -labsl_raw_hash_set -labsl_hashtablez_sampler -labsl_exponential_biased -labsl_hash -labsl_bad_variant_access -labsl_city -labsl_status -labsl_cord -labsl_str_format_internal -labsl_synchronization -labsl_graphcycles_internal -labsl_symbolize -labsl_demangle_internal -labsl_stacktrace -labsl_debugging_internal -labsl_malloc_internal -labsl_time -labsl_time_zone -labsl_civil_time -labsl_strings -labsl_strings_internal -labsl_throw_delegate -labsl_int128 -labsl_base -labsl_spinlock_wait -labsl_bad_optional_access -labsl_raw_logging_internal -labsl_log_severity"
"" ""
"grpc++.pc") "grpc++.pc")
@ -16229,6 +16322,6 @@ generate_pkgconfig(
"C++ wrapper for gRPC without SSL" "C++ wrapper for gRPC without SSL"
"${gRPC_CPP_VERSION}" "${gRPC_CPP_VERSION}"
"grpc_unsecure" "grpc_unsecure"
"-lgrpc++_unsecure -labsl_status -labsl_cord -labsl_str_format_internal -labsl_bad_optional_access -labsl_synchronization -labsl_graphcycles_internal -labsl_symbolize -labsl_demangle_internal -labsl_stacktrace -labsl_debugging_internal -labsl_malloc_internal -labsl_time -labsl_time_zone -labsl_civil_time -labsl_strings -labsl_strings_internal -labsl_throw_delegate -labsl_int128 -labsl_base -labsl_spinlock_wait -labsl_raw_logging_internal -labsl_log_severity" "-lgrpc++_unsecure -labsl_status -labsl_cord -labsl_str_format_internal -labsl_synchronization -labsl_graphcycles_internal -labsl_symbolize -labsl_demangle_internal -labsl_stacktrace -labsl_debugging_internal -labsl_malloc_internal -labsl_time -labsl_time_zone -labsl_civil_time -labsl_strings -labsl_strings_internal -labsl_throw_delegate -labsl_int128 -labsl_base -labsl_spinlock_wait -labsl_bad_optional_access -labsl_raw_logging_internal -labsl_log_severity"
"" ""
"grpc++_unsecure.pc") "grpc++_unsecure.pc")

@ -1742,6 +1742,7 @@ LIBGPR_SRC = \
src/core/lib/gpr/tmpfile_windows.cc \ src/core/lib/gpr/tmpfile_windows.cc \
src/core/lib/gpr/wrap_memcpy.cc \ src/core/lib/gpr/wrap_memcpy.cc \
src/core/lib/gprpp/arena.cc \ src/core/lib/gprpp/arena.cc \
src/core/lib/gprpp/examine_stack.cc \
src/core/lib/gprpp/fork.cc \ src/core/lib/gprpp/fork.cc \
src/core/lib/gprpp/global_config_env.cc \ src/core/lib/gprpp/global_config_env.cc \
src/core/lib/gprpp/host_port.cc \ src/core/lib/gprpp/host_port.cc \

@ -295,6 +295,7 @@ libs:
- src/core/lib/gpr/useful.h - src/core/lib/gpr/useful.h
- src/core/lib/gprpp/arena.h - src/core/lib/gprpp/arena.h
- src/core/lib/gprpp/atomic.h - src/core/lib/gprpp/atomic.h
- src/core/lib/gprpp/examine_stack.h
- src/core/lib/gprpp/fork.h - src/core/lib/gprpp/fork.h
- src/core/lib/gprpp/global_config.h - src/core/lib/gprpp/global_config.h
- src/core/lib/gprpp/global_config_custom.h - src/core/lib/gprpp/global_config_custom.h
@ -343,6 +344,7 @@ libs:
- src/core/lib/gpr/tmpfile_windows.cc - src/core/lib/gpr/tmpfile_windows.cc
- src/core/lib/gpr/wrap_memcpy.cc - src/core/lib/gpr/wrap_memcpy.cc
- src/core/lib/gprpp/arena.cc - src/core/lib/gprpp/arena.cc
- src/core/lib/gprpp/examine_stack.cc
- src/core/lib/gprpp/fork.cc - src/core/lib/gprpp/fork.cc
- src/core/lib/gprpp/global_config_env.cc - src/core/lib/gprpp/global_config_env.cc
- src/core/lib/gprpp/host_port.cc - src/core/lib/gprpp/host_port.cc
@ -354,6 +356,7 @@ libs:
- src/core/lib/profiling/basic_timers.cc - src/core/lib/profiling/basic_timers.cc
- src/core/lib/profiling/stap_timers.cc - src/core/lib/profiling/stap_timers.cc
deps: deps:
- absl/types:optional
- absl/time:time - absl/time:time
- absl/synchronization:synchronization - absl/synchronization:synchronization
- absl/strings:strings - absl/strings:strings
@ -1415,7 +1418,6 @@ libs:
- test/core/util/cmdline.h - test/core/util/cmdline.h
- test/core/util/debugger_macros.h - test/core/util/debugger_macros.h
- test/core/util/eval_args_mock_endpoint.h - test/core/util/eval_args_mock_endpoint.h
- test/core/util/examine_stack.h
- test/core/util/fuzzer_util.h - test/core/util/fuzzer_util.h
- test/core/util/grpc_profiler.h - test/core/util/grpc_profiler.h
- test/core/util/histogram.h - test/core/util/histogram.h
@ -1428,6 +1430,7 @@ libs:
- test/core/util/reconnect_server.h - test/core/util/reconnect_server.h
- test/core/util/resolve_localhost_ip46.h - test/core/util/resolve_localhost_ip46.h
- test/core/util/slice_splitter.h - test/core/util/slice_splitter.h
- test/core/util/stack_tracer.h
- test/core/util/subprocess.h - test/core/util/subprocess.h
- test/core/util/test_config.h - test/core/util/test_config.h
- test/core/util/test_tcp_server.h - test/core/util/test_tcp_server.h
@ -1437,7 +1440,6 @@ libs:
- test/core/util/cmdline.cc - test/core/util/cmdline.cc
- test/core/util/debugger_macros.cc - test/core/util/debugger_macros.cc
- test/core/util/eval_args_mock_endpoint.cc - test/core/util/eval_args_mock_endpoint.cc
- test/core/util/examine_stack.cc
- test/core/util/fuzzer_util.cc - test/core/util/fuzzer_util.cc
- test/core/util/grpc_profiler.cc - test/core/util/grpc_profiler.cc
- test/core/util/histogram.cc - test/core/util/histogram.cc
@ -1451,6 +1453,7 @@ libs:
- test/core/util/reconnect_server.cc - test/core/util/reconnect_server.cc
- test/core/util/resolve_localhost_ip46.cc - test/core/util/resolve_localhost_ip46.cc
- test/core/util/slice_splitter.cc - test/core/util/slice_splitter.cc
- test/core/util/stack_tracer.cc
- test/core/util/subprocess_posix.cc - test/core/util/subprocess_posix.cc
- test/core/util/subprocess_windows.cc - test/core/util/subprocess_windows.cc
- test/core/util/test_config.cc - test/core/util/test_config.cc
@ -1473,7 +1476,6 @@ libs:
- test/core/util/cmdline.h - test/core/util/cmdline.h
- test/core/util/debugger_macros.h - test/core/util/debugger_macros.h
- test/core/util/eval_args_mock_endpoint.h - test/core/util/eval_args_mock_endpoint.h
- test/core/util/examine_stack.h
- test/core/util/fuzzer_util.h - test/core/util/fuzzer_util.h
- test/core/util/grpc_profiler.h - test/core/util/grpc_profiler.h
- test/core/util/histogram.h - test/core/util/histogram.h
@ -1486,6 +1488,7 @@ libs:
- test/core/util/reconnect_server.h - test/core/util/reconnect_server.h
- test/core/util/resolve_localhost_ip46.h - test/core/util/resolve_localhost_ip46.h
- test/core/util/slice_splitter.h - test/core/util/slice_splitter.h
- test/core/util/stack_tracer.h
- test/core/util/subprocess.h - test/core/util/subprocess.h
- test/core/util/test_config.h - test/core/util/test_config.h
- test/core/util/test_tcp_server.h - test/core/util/test_tcp_server.h
@ -1495,7 +1498,6 @@ libs:
- test/core/util/cmdline.cc - test/core/util/cmdline.cc
- test/core/util/debugger_macros.cc - test/core/util/debugger_macros.cc
- test/core/util/eval_args_mock_endpoint.cc - test/core/util/eval_args_mock_endpoint.cc
- test/core/util/examine_stack.cc
- test/core/util/fuzzer_util.cc - test/core/util/fuzzer_util.cc
- test/core/util/grpc_profiler.cc - test/core/util/grpc_profiler.cc
- test/core/util/histogram.cc - test/core/util/histogram.cc
@ -1509,6 +1511,7 @@ libs:
- test/core/util/reconnect_server.cc - test/core/util/reconnect_server.cc
- test/core/util/resolve_localhost_ip46.cc - test/core/util/resolve_localhost_ip46.cc
- test/core/util/slice_splitter.cc - test/core/util/slice_splitter.cc
- test/core/util/stack_tracer.cc
- test/core/util/subprocess_posix.cc - test/core/util/subprocess_posix.cc
- test/core/util/subprocess_windows.cc - test/core/util/subprocess_windows.cc
- test/core/util/test_config.cc - test/core/util/test_config.cc
@ -5928,6 +5931,26 @@ targets:
- address_sorting - address_sorting
- upb - upb
uses_polling: false uses_polling: false
- name: examine_stack_test
gtest: true
build: test
language: c++
headers: []
src:
- test/core/gprpp/examine_stack_test.cc
deps:
- grpc_test_util
- grpc
- gpr
- address_sorting
- upb
- absl/debugging:symbolize
- absl/debugging:stacktrace
platforms:
- linux
- posix
- mac
uses_polling: false
- name: exception_test - name: exception_test
gtest: true gtest: true
build: test build: test
@ -7335,6 +7358,25 @@ targets:
corpus_dirs: corpus_dirs:
- test/core/security/corpus/ssl_server_corpus - test/core/security/corpus/ssl_server_corpus
maxlen: 2048 maxlen: 2048
- name: stack_tracer_test
gtest: true
build: test
language: c++
headers: []
src:
- test/core/util/stack_tracer_test.cc
deps:
- grpc_test_util
- grpc
- gpr
- address_sorting
- upb
- absl/debugging:symbolize
platforms:
- linux
- posix
- mac
uses_polling: false
- name: stat_test - name: stat_test
gtest: true gtest: true
build: test build: test
@ -7701,7 +7743,6 @@ targets:
- test/core/util/cmdline.h - test/core/util/cmdline.h
- test/core/util/debugger_macros.h - test/core/util/debugger_macros.h
- test/core/util/eval_args_mock_endpoint.h - test/core/util/eval_args_mock_endpoint.h
- test/core/util/examine_stack.h
- test/core/util/fuzzer_util.h - test/core/util/fuzzer_util.h
- test/core/util/grpc_profiler.h - test/core/util/grpc_profiler.h
- test/core/util/histogram.h - test/core/util/histogram.h
@ -7714,6 +7755,7 @@ targets:
- test/core/util/reconnect_server.h - test/core/util/reconnect_server.h
- test/core/util/resolve_localhost_ip46.h - test/core/util/resolve_localhost_ip46.h
- test/core/util/slice_splitter.h - test/core/util/slice_splitter.h
- test/core/util/stack_tracer.h
- test/core/util/subprocess.h - test/core/util/subprocess.h
- test/core/util/test_config.h - test/core/util/test_config.h
- test/core/util/test_tcp_server.h - test/core/util/test_tcp_server.h
@ -7726,7 +7768,6 @@ targets:
- test/core/util/cmdline.cc - test/core/util/cmdline.cc
- test/core/util/debugger_macros.cc - test/core/util/debugger_macros.cc
- test/core/util/eval_args_mock_endpoint.cc - test/core/util/eval_args_mock_endpoint.cc
- test/core/util/examine_stack.cc
- test/core/util/fuzzer_util.cc - test/core/util/fuzzer_util.cc
- test/core/util/grpc_profiler.cc - test/core/util/grpc_profiler.cc
- test/core/util/histogram.cc - test/core/util/histogram.cc
@ -7740,6 +7781,7 @@ targets:
- test/core/util/reconnect_server.cc - test/core/util/reconnect_server.cc
- test/core/util/resolve_localhost_ip46.cc - test/core/util/resolve_localhost_ip46.cc
- test/core/util/slice_splitter.cc - test/core/util/slice_splitter.cc
- test/core/util/stack_tracer.cc
- test/core/util/subprocess_posix.cc - test/core/util/subprocess_posix.cc
- test/core/util/subprocess_windows.cc - test/core/util/subprocess_windows.cc
- test/core/util/test_config.cc - test/core/util/test_config.cc

@ -373,6 +373,7 @@ if test "$PHP_GRPC" != "no"; then
src/core/lib/gpr/tmpfile_windows.cc \ src/core/lib/gpr/tmpfile_windows.cc \
src/core/lib/gpr/wrap_memcpy.cc \ src/core/lib/gpr/wrap_memcpy.cc \
src/core/lib/gprpp/arena.cc \ src/core/lib/gprpp/arena.cc \
src/core/lib/gprpp/examine_stack.cc \
src/core/lib/gprpp/fork.cc \ src/core/lib/gprpp/fork.cc \
src/core/lib/gprpp/global_config_env.cc \ src/core/lib/gprpp/global_config_env.cc \
src/core/lib/gprpp/host_port.cc \ src/core/lib/gprpp/host_port.cc \

@ -340,6 +340,7 @@ if (PHP_GRPC != "no") {
"src\\core\\lib\\gpr\\tmpfile_windows.cc " + "src\\core\\lib\\gpr\\tmpfile_windows.cc " +
"src\\core\\lib\\gpr\\wrap_memcpy.cc " + "src\\core\\lib\\gpr\\wrap_memcpy.cc " +
"src\\core\\lib\\gprpp\\arena.cc " + "src\\core\\lib\\gprpp\\arena.cc " +
"src\\core\\lib\\gprpp\\examine_stack.cc " +
"src\\core\\lib\\gprpp\\fork.cc " + "src\\core\\lib\\gprpp\\fork.cc " +
"src\\core\\lib\\gprpp\\global_config_env.cc " + "src\\core\\lib\\gprpp\\global_config_env.cc " +
"src\\core\\lib\\gprpp\\host_port.cc " + "src\\core\\lib\\gprpp\\host_port.cc " +

@ -496,6 +496,7 @@ Pod::Spec.new do |s|
'src/core/lib/gprpp/atomic.h', 'src/core/lib/gprpp/atomic.h',
'src/core/lib/gprpp/debug_location.h', 'src/core/lib/gprpp/debug_location.h',
'src/core/lib/gprpp/dual_ref_counted.h', 'src/core/lib/gprpp/dual_ref_counted.h',
'src/core/lib/gprpp/examine_stack.h',
'src/core/lib/gprpp/fork.h', 'src/core/lib/gprpp/fork.h',
'src/core/lib/gprpp/global_config.h', 'src/core/lib/gprpp/global_config.h',
'src/core/lib/gprpp/global_config_custom.h', 'src/core/lib/gprpp/global_config_custom.h',
@ -1099,6 +1100,7 @@ Pod::Spec.new do |s|
'src/core/lib/gprpp/atomic.h', 'src/core/lib/gprpp/atomic.h',
'src/core/lib/gprpp/debug_location.h', 'src/core/lib/gprpp/debug_location.h',
'src/core/lib/gprpp/dual_ref_counted.h', 'src/core/lib/gprpp/dual_ref_counted.h',
'src/core/lib/gprpp/examine_stack.h',
'src/core/lib/gprpp/fork.h', 'src/core/lib/gprpp/fork.h',
'src/core/lib/gprpp/global_config.h', 'src/core/lib/gprpp/global_config.h',
'src/core/lib/gprpp/global_config_custom.h', 'src/core/lib/gprpp/global_config_custom.h',

@ -820,6 +820,8 @@ Pod::Spec.new do |s|
'src/core/lib/gprpp/atomic.h', 'src/core/lib/gprpp/atomic.h',
'src/core/lib/gprpp/debug_location.h', 'src/core/lib/gprpp/debug_location.h',
'src/core/lib/gprpp/dual_ref_counted.h', 'src/core/lib/gprpp/dual_ref_counted.h',
'src/core/lib/gprpp/examine_stack.cc',
'src/core/lib/gprpp/examine_stack.h',
'src/core/lib/gprpp/fork.cc', 'src/core/lib/gprpp/fork.cc',
'src/core/lib/gprpp/fork.h', 'src/core/lib/gprpp/fork.h',
'src/core/lib/gprpp/global_config.h', 'src/core/lib/gprpp/global_config.h',
@ -1627,6 +1629,7 @@ Pod::Spec.new do |s|
'src/core/lib/gprpp/atomic.h', 'src/core/lib/gprpp/atomic.h',
'src/core/lib/gprpp/debug_location.h', 'src/core/lib/gprpp/debug_location.h',
'src/core/lib/gprpp/dual_ref_counted.h', 'src/core/lib/gprpp/dual_ref_counted.h',
'src/core/lib/gprpp/examine_stack.h',
'src/core/lib/gprpp/fork.h', 'src/core/lib/gprpp/fork.h',
'src/core/lib/gprpp/global_config.h', 'src/core/lib/gprpp/global_config.h',
'src/core/lib/gprpp/global_config_custom.h', 'src/core/lib/gprpp/global_config_custom.h',
@ -2010,8 +2013,6 @@ Pod::Spec.new do |s|
'test/core/util/debugger_macros.h', 'test/core/util/debugger_macros.h',
'test/core/util/eval_args_mock_endpoint.cc', 'test/core/util/eval_args_mock_endpoint.cc',
'test/core/util/eval_args_mock_endpoint.h', 'test/core/util/eval_args_mock_endpoint.h',
'test/core/util/examine_stack.cc',
'test/core/util/examine_stack.h',
'test/core/util/fuzzer_util.cc', 'test/core/util/fuzzer_util.cc',
'test/core/util/fuzzer_util.h', 'test/core/util/fuzzer_util.h',
'test/core/util/grpc_profiler.cc', 'test/core/util/grpc_profiler.cc',
@ -2037,6 +2038,8 @@ Pod::Spec.new do |s|
'test/core/util/resolve_localhost_ip46.h', 'test/core/util/resolve_localhost_ip46.h',
'test/core/util/slice_splitter.cc', 'test/core/util/slice_splitter.cc',
'test/core/util/slice_splitter.h', 'test/core/util/slice_splitter.h',
'test/core/util/stack_tracer.cc',
'test/core/util/stack_tracer.h',
'test/core/util/subprocess.h', 'test/core/util/subprocess.h',
'test/core/util/subprocess_windows.cc', 'test/core/util/subprocess_windows.cc',
'test/core/util/test_config.cc', 'test/core/util/test_config.cc',

@ -737,6 +737,8 @@ Gem::Specification.new do |s|
s.files += %w( src/core/lib/gprpp/atomic.h ) s.files += %w( src/core/lib/gprpp/atomic.h )
s.files += %w( src/core/lib/gprpp/debug_location.h ) s.files += %w( src/core/lib/gprpp/debug_location.h )
s.files += %w( src/core/lib/gprpp/dual_ref_counted.h ) s.files += %w( src/core/lib/gprpp/dual_ref_counted.h )
s.files += %w( src/core/lib/gprpp/examine_stack.cc )
s.files += %w( src/core/lib/gprpp/examine_stack.h )
s.files += %w( src/core/lib/gprpp/fork.cc ) s.files += %w( src/core/lib/gprpp/fork.cc )
s.files += %w( src/core/lib/gprpp/fork.h ) s.files += %w( src/core/lib/gprpp/fork.h )
s.files += %w( src/core/lib/gprpp/global_config.h ) s.files += %w( src/core/lib/gprpp/global_config.h )

@ -379,6 +379,7 @@
'target_name': 'gpr', 'target_name': 'gpr',
'type': 'static_library', 'type': 'static_library',
'dependencies': [ 'dependencies': [
'absl/types:optional',
'absl/time:time', 'absl/time:time',
'absl/synchronization:synchronization', 'absl/synchronization:synchronization',
'absl/strings:strings', 'absl/strings:strings',
@ -421,6 +422,7 @@
'src/core/lib/gpr/tmpfile_windows.cc', 'src/core/lib/gpr/tmpfile_windows.cc',
'src/core/lib/gpr/wrap_memcpy.cc', 'src/core/lib/gpr/wrap_memcpy.cc',
'src/core/lib/gprpp/arena.cc', 'src/core/lib/gprpp/arena.cc',
'src/core/lib/gprpp/examine_stack.cc',
'src/core/lib/gprpp/fork.cc', 'src/core/lib/gprpp/fork.cc',
'src/core/lib/gprpp/global_config_env.cc', 'src/core/lib/gprpp/global_config_env.cc',
'src/core/lib/gprpp/host_port.cc', 'src/core/lib/gprpp/host_port.cc',
@ -1002,7 +1004,6 @@
'test/core/util/cmdline.cc', 'test/core/util/cmdline.cc',
'test/core/util/debugger_macros.cc', 'test/core/util/debugger_macros.cc',
'test/core/util/eval_args_mock_endpoint.cc', 'test/core/util/eval_args_mock_endpoint.cc',
'test/core/util/examine_stack.cc',
'test/core/util/fuzzer_util.cc', 'test/core/util/fuzzer_util.cc',
'test/core/util/grpc_profiler.cc', 'test/core/util/grpc_profiler.cc',
'test/core/util/histogram.cc', 'test/core/util/histogram.cc',
@ -1016,6 +1017,7 @@
'test/core/util/reconnect_server.cc', 'test/core/util/reconnect_server.cc',
'test/core/util/resolve_localhost_ip46.cc', 'test/core/util/resolve_localhost_ip46.cc',
'test/core/util/slice_splitter.cc', 'test/core/util/slice_splitter.cc',
'test/core/util/stack_tracer.cc',
'test/core/util/subprocess_posix.cc', 'test/core/util/subprocess_posix.cc',
'test/core/util/subprocess_windows.cc', 'test/core/util/subprocess_windows.cc',
'test/core/util/test_config.cc', 'test/core/util/test_config.cc',
@ -1040,7 +1042,6 @@
'test/core/util/cmdline.cc', 'test/core/util/cmdline.cc',
'test/core/util/debugger_macros.cc', 'test/core/util/debugger_macros.cc',
'test/core/util/eval_args_mock_endpoint.cc', 'test/core/util/eval_args_mock_endpoint.cc',
'test/core/util/examine_stack.cc',
'test/core/util/fuzzer_util.cc', 'test/core/util/fuzzer_util.cc',
'test/core/util/grpc_profiler.cc', 'test/core/util/grpc_profiler.cc',
'test/core/util/histogram.cc', 'test/core/util/histogram.cc',
@ -1054,6 +1055,7 @@
'test/core/util/reconnect_server.cc', 'test/core/util/reconnect_server.cc',
'test/core/util/resolve_localhost_ip46.cc', 'test/core/util/resolve_localhost_ip46.cc',
'test/core/util/slice_splitter.cc', 'test/core/util/slice_splitter.cc',
'test/core/util/stack_tracer.cc',
'test/core/util/subprocess_posix.cc', 'test/core/util/subprocess_posix.cc',
'test/core/util/subprocess_windows.cc', 'test/core/util/subprocess_windows.cc',
'test/core/util/test_config.cc', 'test/core/util/test_config.cc',

@ -717,6 +717,8 @@
<file baseinstalldir="/" name="src/core/lib/gprpp/atomic.h" role="src" /> <file baseinstalldir="/" name="src/core/lib/gprpp/atomic.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gprpp/debug_location.h" role="src" /> <file baseinstalldir="/" name="src/core/lib/gprpp/debug_location.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gprpp/dual_ref_counted.h" role="src" /> <file baseinstalldir="/" name="src/core/lib/gprpp/dual_ref_counted.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gprpp/examine_stack.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/gprpp/examine_stack.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gprpp/fork.cc" role="src" /> <file baseinstalldir="/" name="src/core/lib/gprpp/fork.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/gprpp/fork.h" role="src" /> <file baseinstalldir="/" name="src/core/lib/gprpp/fork.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gprpp/global_config.h" role="src" /> <file baseinstalldir="/" name="src/core/lib/gprpp/global_config.h" role="src" />

@ -38,8 +38,11 @@
#include <sys/syscall.h> #include <sys/syscall.h>
#include <time.h> #include <time.h>
#include <unistd.h> #include <unistd.h>
#include <string> #include <string>
#include "absl/strings/str_format.h" #include "absl/strings/str_format.h"
#include "src/core/lib/gprpp/examine_stack.h"
static long sys_gettid(void) { return syscall(__NR_gettid); } static long sys_gettid(void) { return syscall(__NR_gettid); }
@ -89,7 +92,17 @@ void gpr_default_log(gpr_log_func_args* args) {
std::string prefix = absl::StrFormat( std::string prefix = absl::StrFormat(
"%s%s.%09" PRId32 " %7ld %s:%d]", gpr_log_severity_string(args->severity), "%s%s.%09" PRId32 " %7ld %s:%d]", gpr_log_severity_string(args->severity),
time_buffer, now.tv_nsec, tid, display_file, args->line); time_buffer, now.tv_nsec, tid, display_file, args->line);
fprintf(stderr, "%-60s %s\n", prefix.c_str(), args->message);
absl::optional<std::string> stack_trace =
args->severity >= GPR_LOG_SEVERITY_ERROR
? grpc_core::GetCurrentStackTrace()
: absl::nullopt;
if (stack_trace) {
fprintf(stderr, "%-60s %s\n%s\n", prefix.c_str(), args->message,
stack_trace->c_str());
} else {
fprintf(stderr, "%-60s %s\n", prefix.c_str(), args->message);
}
} }
#endif /* GPR_LINUX_LOG */ #endif /* GPR_LINUX_LOG */

@ -30,7 +30,9 @@
#include <string.h> #include <string.h>
#include <time.h> #include <time.h>
#include <string> #include <string>
#include "absl/strings/str_format.h" #include "absl/strings/str_format.h"
#include "src/core/lib/gprpp/examine_stack.h"
static intptr_t sys_gettid(void) { return (intptr_t)pthread_self(); } static intptr_t sys_gettid(void) { return (intptr_t)pthread_self(); }
@ -87,7 +89,17 @@ void gpr_default_log(gpr_log_func_args* args) {
std::string prefix = absl::StrFormat( std::string prefix = absl::StrFormat(
"%s%s.%09d %7" PRIdPTR " %s:%d]", gpr_log_severity_string(args->severity), "%s%s.%09d %7" PRIdPTR " %s:%d]", gpr_log_severity_string(args->severity),
time_buffer, (int)(now.tv_nsec), sys_gettid(), display_file, args->line); time_buffer, (int)(now.tv_nsec), sys_gettid(), display_file, args->line);
fprintf(stderr, "%-70s %s\n", prefix.c_str(), args->message);
absl::optional<std::string> stack_trace =
args->severity >= GPR_LOG_SEVERITY_ERROR
? grpc_core::GetCurrentStackTrace()
: absl::nullopt;
if (stack_trace) {
fprintf(stderr, "%-70s %s\n%s\n", prefix.c_str(), args->message,
stack_trace->c_str());
} else {
fprintf(stderr, "%-70s %s\n", prefix.c_str(), args->message);
}
} }
#endif /* defined(GPR_POSIX_LOG) */ #endif /* defined(GPR_POSIX_LOG) */

@ -31,6 +31,7 @@
#include "src/core/lib/gpr/string.h" #include "src/core/lib/gpr/string.h"
#include "src/core/lib/gpr/string_windows.h" #include "src/core/lib/gpr/string_windows.h"
#include "src/core/lib/gprpp/examine_stack.h"
void gpr_log(const char* file, int line, gpr_log_severity severity, void gpr_log(const char* file, int line, gpr_log_severity severity,
const char* format, ...) { const char* format, ...) {
@ -92,10 +93,21 @@ void gpr_default_log(gpr_log_func_args* args) {
strcpy(time_buffer, "error:strftime"); strcpy(time_buffer, "error:strftime");
} }
fprintf(stderr, "%s%s.%09u %5lu %s:%d] %s\n", absl::optional<std::string> stack_trace =
gpr_log_severity_string(args->severity), time_buffer, args->severity >= GPR_LOG_SEVERITY_ERROR
(int)(now.tv_nsec), GetCurrentThreadId(), display_file, args->line, ? grpc_core::GetCurrentStackTrace()
args->message); : absl::nullopt;
if (stack_trace) {
fprintf(stderr, "%s%s.%09u %5lu %s:%d] %s\n%s\n",
gpr_log_severity_string(args->severity), time_buffer,
(int)(now.tv_nsec), GetCurrentThreadId(), display_file, args->line,
args->message, stack_trace->c_str());
} else {
fprintf(stderr, "%s%s.%09u %5lu %s:%d] %s\n",
gpr_log_severity_string(args->severity), time_buffer,
(int)(now.tv_nsec), GetCurrentThreadId(), display_file, args->line,
args->message);
}
fflush(stderr); fflush(stderr);
} }

@ -0,0 +1,43 @@
/*
*
* Copyright 2020 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.
*
*/
#include <grpc/support/port_platform.h>
#include "src/core/lib/gprpp/examine_stack.h"
namespace grpc_core {
gpr_current_stack_trace_func g_current_stack_trace_provider = nullptr;
gpr_current_stack_trace_func GetCurrentStackTraceProvider() {
return g_current_stack_trace_provider;
}
void SetCurrentStackTraceProvider(
gpr_current_stack_trace_func current_stack_trace_provider) {
g_current_stack_trace_provider = current_stack_trace_provider;
}
absl::optional<std::string> GetCurrentStackTrace() {
if (g_current_stack_trace_provider != nullptr) {
return g_current_stack_trace_provider();
}
return absl::nullopt;
}
} // namespace grpc_core

@ -0,0 +1,46 @@
/*
*
* Copyright 2020 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_CORE_LIB_GPRPP_EXAMINE_STACK_H
#define GRPC_CORE_LIB_GPRPP_EXAMINE_STACK_H
#include <grpc/support/port_platform.h>
#include <functional>
#include <string>
#include "absl/types/optional.h"
namespace grpc_core {
typedef std::string (*gpr_current_stack_trace_func)();
// Returns a current_stack_trace_provider.
gpr_current_stack_trace_func GetCurrentStackTraceProvider();
// Sets current_stack_trace_provider which provides a current-stack trace.
void SetCurrentStackTraceProvider(
gpr_current_stack_trace_func current_stack_trace_provider);
// Returns the current stack trace as a string via current_stack_trace_provider
// If current_stack_trace_provider is not set, it returns absl::nullopt.
absl::optional<std::string> GetCurrentStackTrace();
} // namespace grpc_core
#endif /* GRPC_CORE_LIB_GPRPP_EXAMINE_STACK_H */

@ -349,6 +349,7 @@ CORE_SOURCE_FILES = [
'src/core/lib/gpr/tmpfile_windows.cc', 'src/core/lib/gpr/tmpfile_windows.cc',
'src/core/lib/gpr/wrap_memcpy.cc', 'src/core/lib/gpr/wrap_memcpy.cc',
'src/core/lib/gprpp/arena.cc', 'src/core/lib/gprpp/arena.cc',
'src/core/lib/gprpp/examine_stack.cc',
'src/core/lib/gprpp/fork.cc', 'src/core/lib/gprpp/fork.cc',
'src/core/lib/gprpp/global_config_env.cc', 'src/core/lib/gprpp/global_config_env.cc',
'src/core/lib/gprpp/host_port.cc', 'src/core/lib/gprpp/host_port.cc',

@ -19,6 +19,24 @@ licenses(["notice"]) # Apache v2
grpc_package(name = "test/core/gprpp") grpc_package(name = "test/core/gprpp")
grpc_cc_test(
name = "examine_stack_test",
srcs = ["examine_stack_test.cc"],
external_deps = [
"absl/debugging:stacktrace",
"absl/debugging:symbolize",
"gtest",
],
language = "C++",
# TODO(https://github.com/grpc/grpc/issues/24627): Disable this on Windows
tags = ["no_windows"],
uses_polling = False,
deps = [
"//:gpr",
"//test/core/util:grpc_test_util",
],
)
grpc_cc_test( grpc_cc_test(
name = "fork_test", name = "fork_test",
srcs = ["fork_test.cc"], srcs = ["fork_test.cc"],

@ -0,0 +1,82 @@
/*
*
* Copyright 2020 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.
*
*/
#include "src/core/lib/gprpp/examine_stack.h"
#include <stdio.h>
#include <string.h>
#include <gtest/gtest.h>
#include "absl/debugging/stacktrace.h"
#include "absl/debugging/symbolize.h"
#include <grpc/support/log.h>
namespace {
std::string SimpleCurrentStackTraceProvider() { return "stacktrace"; }
std::string AbseilCurrentStackTraceProvider() {
std::string result = "Stack trace:\n";
constexpr int kNumStackFrames = 10;
void* stack[kNumStackFrames];
int frame_sizes[kNumStackFrames];
int depth = absl::GetStackFrames(stack, frame_sizes, kNumStackFrames, 1);
for (int i = 0; i < depth; i++) {
char tmp[1024];
const char* symbol = "(unknown)";
if (absl::Symbolize(stack[i], tmp, sizeof(tmp))) {
symbol = tmp;
}
result += symbol;
result += +"\n";
}
return result;
}
} // namespace
TEST(ExamineStackTest, NullStackProvider) {
grpc_core::SetCurrentStackTraceProvider(nullptr);
EXPECT_EQ(grpc_core::GetCurrentStackTraceProvider(), nullptr);
EXPECT_EQ(grpc_core::GetCurrentStackTrace(), absl::nullopt);
}
TEST(ExamineStackTest, SimpleStackProvider) {
grpc_core::SetCurrentStackTraceProvider(&SimpleCurrentStackTraceProvider);
EXPECT_NE(grpc_core::GetCurrentStackTraceProvider(), nullptr);
EXPECT_EQ(grpc_core::GetCurrentStackTrace(), "stacktrace");
}
TEST(ExamineStackTest, AbseilStackProvider) {
grpc_core::SetCurrentStackTraceProvider(&AbseilCurrentStackTraceProvider);
EXPECT_NE(grpc_core::GetCurrentStackTraceProvider(), nullptr);
const absl::optional<std::string> stack_trace =
grpc_core::GetCurrentStackTrace();
EXPECT_NE(stack_trace, absl::nullopt);
gpr_log(GPR_INFO, "stack_trace=%s", stack_trace->c_str());
EXPECT_TRUE(stack_trace->find("GetCurrentStackTrace") != -1);
}
int main(int argc, char** argv) {
absl::InitializeSymbolizer(argv[0]);
::testing::InitGoogleTest(&argc, argv);
int ret = RUN_ALL_TESTS();
return ret;
}

@ -39,7 +39,6 @@ grpc_cc_library(
srcs = [ srcs = [
"cmdline.cc", "cmdline.cc",
"eval_args_mock_endpoint.cc", "eval_args_mock_endpoint.cc",
"examine_stack.cc",
"fuzzer_util.cc", "fuzzer_util.cc",
"grpc_profiler.cc", "grpc_profiler.cc",
"histogram.cc", "histogram.cc",
@ -63,7 +62,6 @@ grpc_cc_library(
hdrs = [ hdrs = [
"cmdline.h", "cmdline.h",
"eval_args_mock_endpoint.h", "eval_args_mock_endpoint.h",
"examine_stack.h",
"fuzzer_util.h", "fuzzer_util.h",
"grpc_profiler.h", "grpc_profiler.h",
"histogram.h", "histogram.h",
@ -89,12 +87,12 @@ grpc_cc_library(
], ],
external_deps = [ external_deps = [
"absl/debugging:failure_signal_handler", "absl/debugging:failure_signal_handler",
"absl/debugging:stacktrace",
"absl/debugging:symbolize", "absl/debugging:symbolize",
], ],
language = "C++", language = "C++",
deps = [ deps = [
":grpc_debugger_macros", ":grpc_debugger_macros",
":stack_tracer",
"//:gpr", "//:gpr",
"//:grpc_base_c", "//:grpc_base_c",
"//:grpc_common", "//:grpc_common",
@ -171,6 +169,43 @@ sh_library(
srcs = ["run_with_poller.sh"], srcs = ["run_with_poller.sh"],
) )
grpc_cc_library(
name = "stack_tracer",
srcs = [
"stack_tracer.cc",
],
hdrs = [
"stack_tracer.h",
],
external_deps = [
"absl/debugging:stacktrace",
"absl/debugging:symbolize",
],
language = "C++",
deps = [
"//:grpc_common",
],
)
grpc_cc_test(
name = "stack_tracer_test",
srcs = [
"stack_tracer_test.cc",
],
external_deps = [
"absl/debugging:symbolize",
"gtest",
],
language = "C++",
# TODO(https://github.com/grpc/grpc/issues/24627): Disable this on Windows
tags = ["no_windows"],
uses_polling = False,
deps = [
":grpc_test_util",
":stack_tracer",
],
)
grpc_cc_library( grpc_cc_library(
name = "test_lb_policies", name = "test_lb_policies",
testonly = 1, testonly = 1,

@ -18,7 +18,7 @@
#include <grpc/support/port_platform.h> #include <grpc/support/port_platform.h>
#include "test/core/util/examine_stack.h" #include "test/core/util/stack_tracer.h"
#include <cstdio> #include <cstdio>
#include <string> #include <string>
@ -26,6 +26,8 @@
#include "absl/debugging/stacktrace.h" #include "absl/debugging/stacktrace.h"
#include "absl/debugging/symbolize.h" #include "absl/debugging/symbolize.h"
#include "src/core/lib/gprpp/examine_stack.h"
namespace { namespace {
static constexpr int kPrintfPointerFieldWidth = 2 + 2 * sizeof(void*); static constexpr int kPrintfPointerFieldWidth = 2 + 2 * sizeof(void*);
@ -87,8 +89,9 @@ static void DebugWriteToString(const char* data, void* str) {
} // namespace } // namespace
namespace grpc_core { namespace grpc_core {
namespace testing {
std::string CurrentStackTrace() { std::string GetCurrentStackTrace() {
std::string result = "Stack trace:\n"; std::string result = "Stack trace:\n";
constexpr int kNumStackFrames = 32; constexpr int kNumStackFrames = 32;
void* stack[kNumStackFrames]; void* stack[kNumStackFrames];
@ -99,4 +102,10 @@ std::string CurrentStackTrace() {
return result; return result;
} }
void InitializeStackTracer(const char* argv0) {
absl::InitializeSymbolizer(argv0);
grpc_core::SetCurrentStackTraceProvider(&GetCurrentStackTrace);
}
} // namespace testing
} // namespace grpc_core } // namespace grpc_core

@ -24,11 +24,25 @@
#include <string> #include <string>
namespace grpc_core { namespace grpc_core {
namespace testing {
// Return the current stack trace as a string (on multiple lines, beginning with // Returns the current stack trace as a string. To have symbolized stack-traces,
// "Stack trace:\n") // InitializeStackTracer needs to be called beforehand.
std::string CurrentStackTrace(); //
// Example of stack-trace is
// Stack trace:
// @ 0x405b0f 192 StackTracerTest_Basic_Test::TestBody()
// @ 0x7fbace6baf75 288 testing::internal::RunAllTests()
// @ 0x7fbace6baa93 144 testing::UnitTest::Run()
// @ 0x405d4d 64 main
//
std::string GetCurrentStackTrace();
// Initializes a stack tracer so that GetCurrentStackTrace can work.
// This inits debug symbols and sets this as a gRPC stack-trace provider.
void InitializeStackTracer(const char* argv0);
} // namespace testing
} // namespace grpc_core } // namespace grpc_core
#endif /* GRPC_TEST_CORE_UTIL_EXAMINE_STACK_H */ #endif /* GRPC_TEST_CORE_UTIL_EXAMINE_STACK_H */

@ -0,0 +1,41 @@
/*
*
* Copyright 2020 the 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.
*
*/
#include "test/core/util/stack_tracer.h"
#include <gtest/gtest.h>
#include <string>
#include "absl/debugging/symbolize.h"
#include <grpc/support/log.h>
#include "test/core/util/test_config.h"
TEST(StackTracerTest, Basic) {
std::string stack_trace = grpc_core::testing::GetCurrentStackTrace();
gpr_log(GPR_INFO, "stack_trace=%s", stack_trace.c_str());
EXPECT_TRUE(stack_trace.find("Basic") != -1);
}
int main(int argc, char** argv) {
grpc::testing::TestEnvironment env(argc, argv);
testing::InitGoogleTest(&argc, argv);
int ret = RUN_ALL_TESTS();
return ret;
}

@ -32,7 +32,9 @@
#include "src/core/lib/gpr/string.h" #include "src/core/lib/gpr/string.h"
#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gpr/useful.h"
#include "src/core/lib/gprpp/examine_stack.h"
#include "src/core/lib/surface/init.h" #include "src/core/lib/surface/init.h"
#include "test/core/util/stack_tracer.h"
#include "absl/debugging/failure_signal_handler.h" #include "absl/debugging/failure_signal_handler.h"
#include "absl/debugging/symbolize.h" #include "absl/debugging/symbolize.h"
@ -378,7 +380,7 @@ void grpc_test_init(int argc, char** argv) {
// https://github.com/grpc/grpc/issues/24178 // https://github.com/grpc/grpc/issues/24178
install_crash_handler(); install_crash_handler();
#else #else
absl::InitializeSymbolizer(argv[0]); grpc_core::testing::InitializeStackTracer(argv[0]);
absl::FailureSignalHandlerOptions options; absl::FailureSignalHandlerOptions options;
absl::InstallFailureSignalHandler(options); absl::InstallFailureSignalHandler(options);
#endif #endif

@ -1669,6 +1669,8 @@ src/core/lib/gprpp/arena.h \
src/core/lib/gprpp/atomic.h \ src/core/lib/gprpp/atomic.h \
src/core/lib/gprpp/debug_location.h \ src/core/lib/gprpp/debug_location.h \
src/core/lib/gprpp/dual_ref_counted.h \ src/core/lib/gprpp/dual_ref_counted.h \
src/core/lib/gprpp/examine_stack.cc \
src/core/lib/gprpp/examine_stack.h \
src/core/lib/gprpp/fork.cc \ src/core/lib/gprpp/fork.cc \
src/core/lib/gprpp/fork.h \ src/core/lib/gprpp/fork.h \
src/core/lib/gprpp/global_config.h \ src/core/lib/gprpp/global_config.h \

@ -1510,6 +1510,8 @@ src/core/lib/gprpp/arena.h \
src/core/lib/gprpp/atomic.h \ src/core/lib/gprpp/atomic.h \
src/core/lib/gprpp/debug_location.h \ src/core/lib/gprpp/debug_location.h \
src/core/lib/gprpp/dual_ref_counted.h \ src/core/lib/gprpp/dual_ref_counted.h \
src/core/lib/gprpp/examine_stack.cc \
src/core/lib/gprpp/examine_stack.h \
src/core/lib/gprpp/fork.cc \ src/core/lib/gprpp/fork.cc \
src/core/lib/gprpp/fork.h \ src/core/lib/gprpp/fork.h \
src/core/lib/gprpp/global_config.h \ src/core/lib/gprpp/global_config.h \

@ -4409,6 +4409,28 @@
], ],
"uses_polling": false "uses_polling": false
}, },
{
"args": [],
"benchmark": false,
"ci_platforms": [
"linux",
"mac",
"posix"
],
"cpu_cost": 1.0,
"exclude_configs": [],
"exclude_iomgrs": [],
"flaky": false,
"gtest": true,
"language": "c++",
"name": "examine_stack_test",
"platforms": [
"linux",
"mac",
"posix"
],
"uses_polling": false
},
{ {
"args": [], "args": [],
"benchmark": false, "benchmark": false,
@ -5667,6 +5689,28 @@
], ],
"uses_polling": true "uses_polling": true
}, },
{
"args": [],
"benchmark": false,
"ci_platforms": [
"linux",
"mac",
"posix"
],
"cpu_cost": 1.0,
"exclude_configs": [],
"exclude_iomgrs": [],
"flaky": false,
"gtest": true,
"language": "c++",
"name": "stack_tracer_test",
"platforms": [
"linux",
"mac",
"posix"
],
"uses_polling": false
},
{ {
"args": [], "args": [],
"benchmark": false, "benchmark": false,

Loading…
Cancel
Save