api_trace.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. *
  3. * Copyright 2015 gRPC authors.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. */
  18. #ifndef GRPC_CORE_LIB_SURFACE_API_TRACE_H
  19. #define GRPC_CORE_LIB_SURFACE_API_TRACE_H
  20. #include <grpc/support/port_platform.h>
  21. #include <grpc/support/log.h>
  22. #include "src/core/lib/debug/trace.h"
  23. extern grpc_core::TraceFlag grpc_api_trace;
  24. /* Provide unwrapping macros because we're in C89 and variadic macros weren't
  25. introduced until C99... */
  26. #define GRPC_API_TRACE_UNWRAP0()
  27. #define GRPC_API_TRACE_UNWRAP1(a) , a
  28. #define GRPC_API_TRACE_UNWRAP2(a, b) , a, b
  29. #define GRPC_API_TRACE_UNWRAP3(a, b, c) , a, b, c
  30. #define GRPC_API_TRACE_UNWRAP4(a, b, c, d) , a, b, c, d
  31. #define GRPC_API_TRACE_UNWRAP5(a, b, c, d, e) , a, b, c, d, e
  32. #define GRPC_API_TRACE_UNWRAP6(a, b, c, d, e, f) , a, b, c, d, e, f
  33. #define GRPC_API_TRACE_UNWRAP7(a, b, c, d, e, f, g) , a, b, c, d, e, f, g
  34. #define GRPC_API_TRACE_UNWRAP8(a, b, c, d, e, f, g, h) , a, b, c, d, e, f, g, h
  35. #define GRPC_API_TRACE_UNWRAP9(a, b, c, d, e, f, g, h, i) \
  36. , a, b, c, d, e, f, g, h, i
  37. #define GRPC_API_TRACE_UNWRAP10(a, b, c, d, e, f, g, h, i, j) \
  38. , a, b, c, d, e, f, g, h, i, j
  39. /* Due to the limitations of C89's preprocessor, the arity of the var-arg list
  40. 'nargs' must be specified. */
  41. #define GRPC_API_TRACE(fmt, nargs, args) \
  42. if (GRPC_TRACE_FLAG_ENABLED(grpc_api_trace)) { \
  43. gpr_log(GPR_INFO, fmt GRPC_API_TRACE_UNWRAP##nargs args); \
  44. }
  45. #endif /* GRPC_CORE_LIB_SURFACE_API_TRACE_H */