THIS IS A TEST INSTANCE ONLY! REPOSITORIES CAN BE DELETED AT ANY TIME!

Git Source Code Mirror - This is a publish-only repository and all pull requests are ignored. Please follow Documentation/SubmittingPatches procedure for any of your improvements.
git
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
2.3KB

  1. #ifndef TR2_TLS_H
  2. #define TR2_TLS_H
  3. #include "strbuf.h"
  4. /*
  5. * Arbitry limit for thread names for column alignment.
  6. */
  7. #define TR2_MAX_THREAD_NAME (24)
  8. struct tr2tls_thread_ctx {
  9. struct strbuf thread_name;
  10. uint64_t *array_us_start;
  11. int alloc;
  12. int nr_open_regions; /* plays role of "nr" in ALLOC_GROW */
  13. int thread_id;
  14. };
  15. /*
  16. * Create TLS data for the current thread. This gives us a place to
  17. * put per-thread data, such as thread start time, function nesting
  18. * and a per-thread label for our messages.
  19. *
  20. * We assume the first thread is "main". Other threads are given
  21. * non-zero thread-ids to help distinguish messages from concurrent
  22. * threads.
  23. *
  24. * Truncate the thread name if necessary to help with column alignment
  25. * in printf-style messages.
  26. *
  27. * In this and all following functions the term "self" refers to the
  28. * current thread.
  29. */
  30. struct tr2tls_thread_ctx *tr2tls_create_self(const char *thread_name,
  31. uint64_t us_thread_start);
  32. /*
  33. * Get our TLS data.
  34. */
  35. struct tr2tls_thread_ctx *tr2tls_get_self(void);
  36. /*
  37. * return true if the current thread is the main thread.
  38. */
  39. int tr2tls_is_main_thread(void);
  40. /*
  41. * Free our TLS data.
  42. */
  43. void tr2tls_unset_self(void);
  44. /*
  45. * Begin a new nested region and remember the start time.
  46. */
  47. void tr2tls_push_self(uint64_t us_now);
  48. /*
  49. * End the innermost nested region.
  50. */
  51. void tr2tls_pop_self(void);
  52. /*
  53. * Pop any extra (above the first) open regions on the current
  54. * thread and discard. During a thread-exit, we should only
  55. * have region[0] that was pushed in trace2_thread_start() if
  56. * the thread exits normally.
  57. */
  58. void tr2tls_pop_unwind_self(void);
  59. /*
  60. * Compute the elapsed time since the innermost region in the
  61. * current thread started and the given time (usually now).
  62. */
  63. uint64_t tr2tls_region_elasped_self(uint64_t us);
  64. /*
  65. * Compute the elapsed time since the main thread started
  66. * and the given time (usually now). This is assumed to
  67. * be the absolute run time of the process.
  68. */
  69. uint64_t tr2tls_absolute_elapsed(uint64_t us);
  70. /*
  71. * Initialize the tr2 TLS system.
  72. */
  73. void tr2tls_init(void);
  74. /*
  75. * Free all tr2 TLS resources.
  76. */
  77. void tr2tls_release(void);
  78. /*
  79. * Protected increment of an integer.
  80. */
  81. int tr2tls_locked_increment(int *p);
  82. /*
  83. * Capture the process start time and do nothing else.
  84. */
  85. void tr2tls_start_process_clock(void);
  86. #endif /* TR2_TLS_H */