xray_interface.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. //===- xray_interface.h -----------------------------------------*- C++ -*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file is a part of XRay, a dynamic runtime instrumentation system.
  11. //
  12. // APIs for controlling XRay functionality explicitly.
  13. //===----------------------------------------------------------------------===//
  14. #ifndef XRAY_XRAY_INTERFACE_H
  15. #define XRAY_XRAY_INTERFACE_H
  16. #include <cstddef>
  17. #include <cstdint>
  18. extern "C" {
  19. /// Synchronize this with AsmPrinter::SledKind in LLVM.
  20. enum XRayEntryType {
  21. ENTRY = 0,
  22. EXIT = 1,
  23. TAIL = 2,
  24. LOG_ARGS_ENTRY = 3,
  25. CUSTOM_EVENT = 4,
  26. };
  27. /// Provide a function to invoke for when instrumentation points are hit. This
  28. /// is a user-visible control surface that overrides the default implementation.
  29. /// The function provided should take the following arguments:
  30. ///
  31. /// - function id: an identifier that indicates the id of a function; this id
  32. /// is generated by xray; the mapping between the function id
  33. /// and the actual function pointer is available through
  34. /// __xray_table.
  35. /// - entry type: identifies what kind of instrumentation point was
  36. /// encountered (function entry, function exit, etc.). See the
  37. /// enum XRayEntryType for more details.
  38. ///
  39. /// The user handler must handle correctly spurious calls after this handler is
  40. /// removed or replaced with another handler, because it would be too costly for
  41. /// XRay runtime to avoid spurious calls.
  42. /// To prevent circular calling, the handler function itself and all its
  43. /// direct&indirect callees must not be instrumented with XRay, which can be
  44. /// achieved by marking them all with: __attribute__((xray_never_instrument))
  45. ///
  46. /// Returns 1 on success, 0 on error.
  47. extern int __xray_set_handler(void (*entry)(int32_t, XRayEntryType));
  48. /// This removes whatever the currently provided handler is. Returns 1 on
  49. /// success, 0 on error.
  50. extern int __xray_remove_handler();
  51. /// Use XRay to log the first argument of each (instrumented) function call.
  52. /// When this function exits, all threads will have observed the effect and
  53. /// start logging their subsequent affected function calls (if patched).
  54. ///
  55. /// Returns 1 on success, 0 on error.
  56. extern int __xray_set_handler_arg1(void (*entry)(int32_t, XRayEntryType,
  57. uint64_t));
  58. /// Disables the XRay handler used to log first arguments of function calls.
  59. /// Returns 1 on success, 0 on error.
  60. extern int __xray_remove_handler_arg1();
  61. /// Provide a function to invoke when XRay encounters a custom event.
  62. extern int __xray_set_customevent_handler(void (*entry)(void*, std::size_t));
  63. /// This removes whatever the currently provided custom event handler is.
  64. /// Returns 1 on success, 0 on error.
  65. extern int __xray_remove_customevent_handler();
  66. enum XRayPatchingStatus {
  67. NOT_INITIALIZED = 0,
  68. SUCCESS = 1,
  69. ONGOING = 2,
  70. FAILED = 3,
  71. };
  72. /// This tells XRay to patch the instrumentation points. See XRayPatchingStatus
  73. /// for possible result values.
  74. extern XRayPatchingStatus __xray_patch();
  75. /// Reverses the effect of __xray_patch(). See XRayPatchingStatus for possible
  76. /// result values.
  77. extern XRayPatchingStatus __xray_unpatch();
  78. /// This patches a specific function id. See XRayPatchingStatus for possible
  79. /// result values.
  80. extern XRayPatchingStatus __xray_patch_function(int32_t FuncId);
  81. /// This unpatches a specific function id. See XRayPatchingStatus for possible
  82. /// result values.
  83. extern XRayPatchingStatus __xray_unpatch_function(int32_t FuncId);
  84. /// This function returns the address of the function provided a valid function
  85. /// id. We return 0 if we encounter any error, even if 0 may be a valid function
  86. /// address.
  87. extern uintptr_t __xray_function_address(int32_t FuncId);
  88. /// This function returns the maximum valid function id. Returns 0 if we
  89. /// encounter errors (when there are no instrumented functions, etc.).
  90. extern size_t __xray_max_function_id();
  91. /// Initialize the required XRay data structures. This is useful in cases where
  92. /// users want to control precisely when the XRay instrumentation data
  93. /// structures are initialized, for example when the XRay library is built with
  94. /// the XRAY_NO_PREINIT preprocessor definition.
  95. ///
  96. /// Calling __xray_init() more than once is safe across multiple threads.
  97. extern void __xray_init();
  98. } // end extern "C"
  99. #endif // XRAY_XRAY_INTERFACE_H