instr_prof_interface.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*===---- instr_prof_interface.h - Instrumentation PGO User Program API ----===
  2. *
  3. * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. * See https://llvm.org/LICENSE.txt for license information.
  5. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. *
  7. *===-----------------------------------------------------------------------===
  8. *
  9. * This header provides a public interface for fine-grained control of counter
  10. * reset and profile dumping. These interface functions can be directly called
  11. * in user programs.
  12. *
  13. \*===---------------------------------------------------------------------===*/
  14. #ifndef COMPILER_RT_INSTR_PROFILING
  15. #define COMPILER_RT_INSTR_PROFILING
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. #ifdef __LLVM_INSTR_PROFILE_GENERATE
  20. // Profile file reset and dump interfaces.
  21. // When `-fprofile[-instr]-generate`/`-fcs-profile-generate` is in effect,
  22. // clang defines __LLVM_INSTR_PROFILE_GENERATE to pick up the API calls.
  23. /*!
  24. * \brief Set the filename for writing instrumentation data.
  25. *
  26. * Sets the filename to be used for subsequent calls to
  27. * \a __llvm_profile_write_file().
  28. *
  29. * \c Name is not copied, so it must remain valid. Passing NULL resets the
  30. * filename logic to the default behaviour.
  31. *
  32. * Note: There may be multiple copies of the profile runtime (one for each
  33. * instrumented image/DSO). This API only modifies the filename within the
  34. * copy of the runtime available to the calling image.
  35. *
  36. * Warning: This is a no-op if continuous mode (\ref
  37. * __llvm_profile_is_continuous_mode_enabled) is on. The reason for this is
  38. * that in continuous mode, profile counters are mmap()'d to the profile at
  39. * program initialization time. Support for transferring the mmap'd profile
  40. * counts to a new file has not been implemented.
  41. */
  42. void __llvm_profile_set_filename(const char *Name);
  43. /*!
  44. * \brief Interface to set all PGO counters to zero for the current process.
  45. *
  46. */
  47. void __llvm_profile_reset_counters(void);
  48. /*!
  49. * \brief this is a wrapper interface to \c __llvm_profile_write_file.
  50. * After this interface is invoked, an already dumped flag will be set
  51. * so that profile won't be dumped again during program exit.
  52. * Invocation of interface __llvm_profile_reset_counters will clear
  53. * the flag. This interface is designed to be used to collect profile
  54. * data from user selected hot regions. The use model is
  55. * __llvm_profile_reset_counters();
  56. * ... hot region 1
  57. * __llvm_profile_dump();
  58. * .. some other code
  59. * __llvm_profile_reset_counters();
  60. * ... hot region 2
  61. * __llvm_profile_dump();
  62. *
  63. * It is expected that on-line profile merging is on with \c %m specifier
  64. * used in profile filename . If merging is not turned on, user is expected
  65. * to invoke __llvm_profile_set_filename to specify different profile names
  66. * for different regions before dumping to avoid profile write clobbering.
  67. */
  68. int __llvm_profile_dump(void);
  69. // Interface to dump the current process' order file to disk.
  70. int __llvm_orderfile_dump(void);
  71. #else
  72. #define __llvm_profile_set_filename(Name)
  73. #define __llvm_profile_reset_counters()
  74. #define __llvm_profile_dump() (0)
  75. #define __llvm_orderfile_dump() (0)
  76. #endif
  77. #ifdef __cplusplus
  78. } // extern "C"
  79. #endif
  80. #endif