reference-libobs-util-profiler.rst 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. Profiler
  2. ========
  3. The profiler is used to get information about program performance and
  4. efficiency.
  5. .. type:: struct profiler_snapshot profiler_snapshot_t
  6. .. type:: struct profiler_snapshot_entry profiler_snapshot_entry_t
  7. .. type:: struct profiler_name_store profiler_name_store_t
  8. .. type:: struct profiler_time_entry profiler_time_entry_t
  9. .. code:: cpp
  10. #include <util/profiler.h>
  11. Profiler Structures
  12. -------------------
  13. .. struct:: profiler_time_entry
  14. .. member:: uint64_t profiler_time_entry.time_delta
  15. .. member:: uint64_t profiler_time_entry.count
  16. Profiler Control Functions
  17. --------------------------
  18. .. function:: void profiler_start(void)
  19. Starts the profiler.
  20. ----------------------
  21. .. function:: void profiler_stop(void)
  22. Stops the profiler.
  23. ----------------------
  24. .. function:: void profiler_print(profiler_snapshot_t *snap)
  25. Creates a profiler snapshot and saves it within *snap*.
  26. :param snap: A profiler snapshot object
  27. ----------------------
  28. .. function:: void profiler_print_time_between_calls(profiler_snapshot_t *snap)
  29. Creates a profiler snapshot of time between calls and saves it within
  30. *snap*.
  31. :param snap: A profiler snapshot object
  32. ----------------------
  33. .. function:: void profiler_free(void)
  34. Frees the profiler.
  35. ----------------------
  36. Profiling Functions
  37. -------------------
  38. .. function:: void profile_register_root(const char *name, uint64_t expected_time_between_calls)
  39. Registers a root profile node.
  40. :param name: Name of the root profile node
  41. :param expected_time_between_calls: The expected time between calls
  42. of the profile root node, or 0 if
  43. none.
  44. ----------------------
  45. .. function:: void profile_start(const char *name)
  46. Starts a profile node. This profile node will be a child of the last
  47. node that was started.
  48. :param name: Name of the profile node
  49. ----------------------
  50. .. function:: void profile_end(const char *name)
  51. :param name: Name of the profile node
  52. ----------------------
  53. .. function:: void profile_reenable_thread(void)
  54. Because :c:func:`profiler_start()` can be called in a different
  55. thread than the current thread, this is used to specify a point where
  56. it's safe to re-enable profiling in the calling thread. Call this
  57. when you have looped root profile nodes and need to specify a safe
  58. point where the root profile node isn't active and the profiler can
  59. start up in the current thread again.
  60. ----------------------
  61. Profiler Name Storage Functions
  62. -------------------------------
  63. .. function:: profiler_name_store_t *profiler_name_store_create(void)
  64. Creates a profiler name storage object.
  65. :return: Profiler name store object
  66. ----------------------
  67. .. function:: void profiler_name_store_free(profiler_name_store_t *store)
  68. Frees a profiler name storage object.
  69. :param store: Profiler name storage object
  70. ----------------------
  71. .. function:: const char *profile_store_name(profiler_name_store_t *store, const char *format, ...)
  72. Creates a formatted string and stores it within a profiler name
  73. storage object.
  74. :param store: Profiler name storage object
  75. :param format: Formatted string
  76. :return: The string created from format specifications
  77. ----------------------
  78. Profiler Data Access Functions
  79. ------------------------------
  80. .. function:: profiler_snapshot_t *profile_snapshot_create(void)
  81. Creates a profile snapshot. Profiler snapshots are used to obtain
  82. data about how the active profiles performed.
  83. :return: A profiler snapshot object
  84. ----------------------
  85. .. function:: void profile_snapshot_free(profiler_snapshot_t *snap)
  86. Frees a profiler snapshot object.
  87. :param snap: A profiler snapshot
  88. ----------------------
  89. .. function:: bool profiler_snapshot_dump_csv(const profiler_snapshot_t *snap, const char *filename)
  90. Creates a CSV file of the profiler snapshot.
  91. :param snap: A profiler snapshot
  92. :param filename: The path to the CSV file to save
  93. :return: *true* if successfully written, *false* otherwise
  94. ----------------------
  95. .. function:: bool profiler_snapshot_dump_csv_gz(const profiler_snapshot_t *snap, const char *filename)
  96. Creates a gzipped CSV file of the profiler snapshot.
  97. :param snap: A profiler snapshot
  98. :param filename: The path to the gzipped CSV file to save
  99. :return: *true* if successfully written, *false* otherwise
  100. ----------------------
  101. .. function:: size_t profiler_snapshot_num_roots(profiler_snapshot_t *snap)
  102. :param snap: A profiler snapshot
  103. :return: Number of root profiler nodes in the snapshot
  104. ----------------------
  105. .. type:: bool (*profiler_entry_enum_func)(void *context, profiler_snapshot_entry_t *entry)
  106. Profiler snapshot entry numeration callback
  107. :param context: Private data passed to this callback
  108. :param entry: Profiler snapshot entry
  109. :return: *true* to continue enumeration, *false* otherwise
  110. ----------------------
  111. .. function:: void profiler_snapshot_enumerate_roots(profiler_snapshot_t *snap, profiler_entry_enum_func func, void *context)
  112. Enumerates root profile nodes.
  113. :param snap: A profiler snapshot
  114. :param func: Enumeration callback
  115. :param context: Private data to pass to the callback
  116. ----------------------
  117. .. type:: bool (*profiler_name_filter_func)(void *data, const char *name, bool *remove)
  118. Callback used to determine what profile nodes are removed/filtered.
  119. :param data: Private data passed to this callback
  120. :param name: Profile node name to be filtered
  121. :param remove: Used to determined whether the node should be removed
  122. or not
  123. :return: *true* to continue enumeration, *false* otherwise
  124. ----------------------
  125. .. function:: void profiler_snapshot_filter_roots(profiler_snapshot_t *snap, profiler_name_filter_func func, void *data)
  126. Removes/filters profile roots based upon their names.
  127. :param snap: A profiler snapshot
  128. :param func: Enumeration callback to filter with
  129. :param data: Private data to pass to the callback
  130. ----------------------
  131. .. function:: size_t profiler_snapshot_num_children(profiler_snapshot_entry_t *entry)
  132. :param entry: A profiler snapshot entry
  133. :return: Number of children for the entry
  134. ----------------------
  135. .. function:: void profiler_snapshot_enumerate_children(profiler_snapshot_entry_t *entry, profiler_entry_enum_func func, void *context)
  136. Enumerates child entries of a profiler snapshot entry.
  137. :param entry: A profiler snapshot entry
  138. :param func: Enumeration callback
  139. :param context: Private data passed to the callback
  140. ----------------------
  141. .. function:: const char *profiler_snapshot_entry_name(profiler_snapshot_entry_t *entry)
  142. :param entry: A profiler snapshot entry
  143. :return: The name of the profiler snapshot entry
  144. ----------------------
  145. .. function:: profiler_time_entries_t *profiler_snapshot_entry_times(profiler_snapshot_entry_t *entry)
  146. Gets the time entries for a snapshot entry.
  147. :param entry: A profiler snapshot entry
  148. :return: An array of profiler time entries
  149. ----------------------
  150. .. function:: uint64_t profiler_snapshot_entry_min_time(profiler_snapshot_entry_t *entry)
  151. Gets the minimum time for a profiler snapshot entry.
  152. :param entry: A profiler snapshot entry
  153. :return: The minimum time value for the snapshot entry
  154. ----------------------
  155. .. function:: uint64_t profiler_snapshot_entry_max_time(profiler_snapshot_entry_t *entry)
  156. Gets the maximum time for a profiler snapshot entry.
  157. :param entry: A profiler snapshot entry
  158. :return: The maximum time value for the snapshot entry
  159. ----------------------
  160. .. function:: uint64_t profiler_snapshot_entry_overall_count(profiler_snapshot_entry_t *entry)
  161. Gets the overall count for a profiler snapshot entry.
  162. :param entry: A profiler snapshot entry
  163. :return: The overall count value for the snapshot entry
  164. ----------------------
  165. .. function:: profiler_time_entries_t *profiler_snapshot_entry_times_between_calls(profiler_snapshot_entry_t *entry)
  166. Gets an array of time between calls for a profiler snapshot entry.
  167. :param entry: A profiler snapshot entry
  168. :return: An array of profiler time entries
  169. ----------------------
  170. .. function:: uint64_t profiler_snapshot_entry_expected_time_between_calls(profiler_snapshot_entry_t *entry)
  171. Gets the expected time between calls for a profiler snapshot entry.
  172. :param entry: A profiler snapshot entry
  173. :return: The expected time between calls for the snapshot entry,
  174. or 0 if not set
  175. ----------------------
  176. .. function:: uint64_t profiler_snapshot_entry_min_time_between_calls(profiler_snapshot_entry_t *entry)
  177. Gets the minimum time seen between calls for a profiler snapshot entry.
  178. :param entry: A profiler snapshot entry
  179. :return: The minimum time seen between calls for the snapshot entry
  180. ----------------------
  181. .. function:: uint64_t profiler_snapshot_entry_max_time_between_calls(profiler_snapshot_entry_t *entry)
  182. Gets the maximum time seen between calls for a profiler snapshot entry.
  183. :param entry: A profiler snapshot entry
  184. :return: The maximum time seen between calls for the snapshot entry
  185. ----------------------
  186. .. function:: uint64_t profiler_snapshot_entry_overall_between_calls_count(profiler_snapshot_entry_t *entry)
  187. Gets the overall time between calls for a profiler snapshot entry.
  188. :param entry: A profiler snapshot entry
  189. :return: The overall time between calls for the snapshot entry