1
0

profiler.h 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #pragma once
  2. #include "base.h"
  3. #include "darray.h"
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7. typedef struct profiler_snapshot profiler_snapshot_t;
  8. typedef struct profiler_snapshot_entry profiler_snapshot_entry_t;
  9. typedef struct profiler_time_entry profiler_time_entry_t;
  10. /* ------------------------------------------------------------------------- */
  11. /* Profiling */
  12. EXPORT void profile_register_root(const char *name, uint64_t expected_time_between_calls);
  13. EXPORT void profile_start(const char *name);
  14. EXPORT void profile_end(const char *name);
  15. EXPORT void profile_reenable_thread(void);
  16. /* ------------------------------------------------------------------------- */
  17. /* Profiler control */
  18. EXPORT void profiler_start(void);
  19. EXPORT void profiler_stop(void);
  20. EXPORT void profiler_print(profiler_snapshot_t *snap);
  21. EXPORT void profiler_print_time_between_calls(profiler_snapshot_t *snap);
  22. EXPORT void profiler_free(void);
  23. /* ------------------------------------------------------------------------- */
  24. /* Profiler name storage */
  25. typedef struct profiler_name_store profiler_name_store_t;
  26. EXPORT profiler_name_store_t *profiler_name_store_create(void);
  27. EXPORT void profiler_name_store_free(profiler_name_store_t *store);
  28. #ifndef _MSC_VER
  29. #define PRINTFATTR(f, a) __attribute__((__format__(__printf__, f, a)))
  30. #else
  31. #define PRINTFATTR(f, a)
  32. #endif
  33. PRINTFATTR(2, 3)
  34. EXPORT const char *profile_store_name(profiler_name_store_t *store, const char *format, ...);
  35. #undef PRINTFATTR
  36. /* ------------------------------------------------------------------------- */
  37. /* Profiler data access */
  38. struct profiler_time_entry {
  39. uint64_t time_delta;
  40. uint64_t count;
  41. };
  42. typedef DARRAY(profiler_time_entry_t) profiler_time_entries_t;
  43. typedef bool (*profiler_entry_enum_func)(void *context, profiler_snapshot_entry_t *entry);
  44. EXPORT profiler_snapshot_t *profile_snapshot_create(void);
  45. EXPORT void profile_snapshot_free(profiler_snapshot_t *snap);
  46. EXPORT bool profiler_snapshot_dump_csv(const profiler_snapshot_t *snap, const char *filename);
  47. EXPORT bool profiler_snapshot_dump_csv_gz(const profiler_snapshot_t *snap, const char *filename);
  48. EXPORT size_t profiler_snapshot_num_roots(profiler_snapshot_t *snap);
  49. EXPORT void profiler_snapshot_enumerate_roots(profiler_snapshot_t *snap, profiler_entry_enum_func func, void *context);
  50. typedef bool (*profiler_name_filter_func)(void *data, const char *name, bool *remove);
  51. EXPORT void profiler_snapshot_filter_roots(profiler_snapshot_t *snap, profiler_name_filter_func func, void *data);
  52. EXPORT size_t profiler_snapshot_num_children(profiler_snapshot_entry_t *entry);
  53. EXPORT void profiler_snapshot_enumerate_children(profiler_snapshot_entry_t *entry, profiler_entry_enum_func func,
  54. void *context);
  55. EXPORT const char *profiler_snapshot_entry_name(profiler_snapshot_entry_t *entry);
  56. EXPORT profiler_time_entries_t *profiler_snapshot_entry_times(profiler_snapshot_entry_t *entry);
  57. EXPORT uint64_t profiler_snapshot_entry_min_time(profiler_snapshot_entry_t *entry);
  58. EXPORT uint64_t profiler_snapshot_entry_max_time(profiler_snapshot_entry_t *entry);
  59. EXPORT uint64_t profiler_snapshot_entry_overall_count(profiler_snapshot_entry_t *entry);
  60. EXPORT profiler_time_entries_t *profiler_snapshot_entry_times_between_calls(profiler_snapshot_entry_t *entry);
  61. EXPORT uint64_t profiler_snapshot_entry_expected_time_between_calls(profiler_snapshot_entry_t *entry);
  62. EXPORT uint64_t profiler_snapshot_entry_min_time_between_calls(profiler_snapshot_entry_t *entry);
  63. EXPORT uint64_t profiler_snapshot_entry_max_time_between_calls(profiler_snapshot_entry_t *entry);
  64. EXPORT uint64_t profiler_snapshot_entry_overall_between_calls_count(profiler_snapshot_entry_t *entry);
  65. #ifdef __cplusplus
  66. }
  67. #endif