tracing.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // Copyright 2024 The Abseil 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. // https://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. #ifndef ABSL_BASE_INTERNAL_TRACING_H_
  15. #define ABSL_BASE_INTERNAL_TRACING_H_
  16. #include "absl/base/config.h"
  17. namespace absl {
  18. ABSL_NAMESPACE_BEGIN
  19. namespace base_internal {
  20. // Well known Abseil object types that have causality.
  21. enum class ObjectKind { kUnknown, kBlockingCounter, kNotification };
  22. // `TraceWait` and `TraceContinue` record the start and end of a potentially
  23. // blocking wait operation on `object`. `object` typically represents a higher
  24. // level synchronization object such as `absl::Notification`.
  25. void TraceWait(const void* object, ObjectKind kind);
  26. void TraceContinue(const void* object, ObjectKind kind);
  27. // `TraceSignal` records a signal on `object`.
  28. void TraceSignal(const void* object, ObjectKind kind);
  29. // `TraceObserved` records the non-blocking observation of a signaled object.
  30. void TraceObserved(const void* object, ObjectKind kind);
  31. // ---------------------------------------------------------------------------
  32. // Weak implementation detail:
  33. //
  34. // We define the weak API as extern "C": in some build configurations we pass
  35. // `--detect-odr-violations` to the gold linker. This causes it to flag weak
  36. // symbol overrides as ODR violations. Because ODR only applies to C++ and not
  37. // C, `--detect-odr-violations` ignores symbols not mangled with C++ names.
  38. // By changing our extension points to be extern "C", we dodge this check.
  39. // ---------------------------------------------------------------------------
  40. extern "C" {
  41. void ABSL_INTERNAL_C_SYMBOL(AbslInternalTraceWait)(const void* object,
  42. ObjectKind kind);
  43. void ABSL_INTERNAL_C_SYMBOL(AbslInternalTraceContinue)(const void* object,
  44. ObjectKind kind);
  45. void ABSL_INTERNAL_C_SYMBOL(AbslInternalTraceSignal)(const void* object,
  46. ObjectKind kind);
  47. void ABSL_INTERNAL_C_SYMBOL(AbslInternalTraceObserved)(const void* object,
  48. ObjectKind kind);
  49. } // extern "C"
  50. inline void TraceWait(const void* object, ObjectKind kind) {
  51. ABSL_INTERNAL_C_SYMBOL(AbslInternalTraceWait)(object, kind);
  52. }
  53. inline void TraceContinue(const void* object, ObjectKind kind) {
  54. ABSL_INTERNAL_C_SYMBOL(AbslInternalTraceContinue)(object, kind);
  55. }
  56. inline void TraceSignal(const void* object, ObjectKind kind) {
  57. ABSL_INTERNAL_C_SYMBOL(AbslInternalTraceSignal)(object, kind);
  58. }
  59. inline void TraceObserved(const void* object, ObjectKind kind) {
  60. ABSL_INTERNAL_C_SYMBOL(AbslInternalTraceObserved)(object, kind);
  61. }
  62. } // namespace base_internal
  63. ABSL_NAMESPACE_END
  64. } // namespace absl
  65. #endif // ABSL_BASE_INTERNAL_TRACING_H_