streamline_annotate.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. /* Copyright (C) 2014-2023 by Arm Limited. All rights reserved.
  2. *
  3. * Redistribution and use in source and binary forms, with or without
  4. * modification, are permitted provided that the following conditions
  5. * are met:
  6. *
  7. * 1. Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. *
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. *
  14. * 3. Neither the name of the copyright holder nor the names of its
  15. * contributors may be used to endorse or promote products derived from
  16. * this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
  21. * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  22. * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
  24. * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  25. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  26. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  27. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. #ifndef STREAMLINE_ANNOTATE_H
  31. #define STREAMLINE_ANNOTATE_H
  32. /*
  33. * ANNOTATE_DEFINE Deprecated and no longer used
  34. *
  35. * ANNOTATE_SETUP Execute at the start of the program before other ANNOTATE macros are called
  36. *
  37. * For defining integer counters where the numeric value is in the range 0...1<<63-1:
  38. *
  39. * ANNOTATE_DELTA_COUNTER Define a delta counter
  40. * ANNOTATE_ABSOLUTE_COUNTER Define an absolute counter
  41. * ANNOTATE_COUNTER_VALUE Emit a counter value
  42. *
  43. * For defining fractional (float/double) counters:
  44. *
  45. * NB: The float value is converted to an integer value in the above range using some fixed multiplier, so for example
  46. * to send a float value in the range 0.000...1.000, with 3-decimal places accuracy, use a modifier value of 1000.
  47. * The float values will be converted to integers between 0 ... 1000.
  48. *
  49. * ANNOTATE_DELTA_COUNTER_SCALE Define a delta counter with scaling
  50. * ANNOTATE_ABSOLUTE_COUNTER_SCALE Define an absolute counter with scaling
  51. * ANNOTATE_COUNTER_VALUE_SCALE Emit a counter value with scaling
  52. *
  53. * For defining CAM views, which visualize multiple linked 'jobs' within a Gantt-like view:
  54. *
  55. * CAM_VIEW_NAME Name the custom activity map view
  56. * CAM_TRACK Create a new custom activity map track
  57. * CAM_JOB Add a new job to a CAM track, use gator_get_time() to obtain the time in nanoseconds
  58. *
  59. * For defining textual annotations:
  60. *
  61. * NB: Channels and groups are defined per thread. This means that if the same
  62. * channel number is used on different threads they are in fact separate
  63. * channels. A channel can belong to only one group per thread. This means
  64. * channel 1 cannot be part of both group 1 and group 2 on the same thread.
  65. *
  66. * ANNOTATE_NAME_GROUP(group, str) Name a group
  67. * ANNOTATE_NAME_CHANNEL(channel, group, str) Name a channel and link it to a group
  68. * ANNOTATE(str) String annotation
  69. * ANNOTATE_CHANNEL(channel, str) String annotation on a channel
  70. * ANNOTATE_COLOR(color, str) String annotation with color
  71. * ANNOTATE_CHANNEL_COLOR(channel, color, str) String annotation on a channel with color
  72. * ANNOTATE_END() Terminate an annotation
  73. * ANNOTATE_CHANNEL_END(channel) Terminate an annotation on a channel
  74. *
  75. * For sending image annotations:
  76. *
  77. * ANNOTATE_VISUAL(data, length, str) Image annotation with optional string
  78. *
  79. * For sending bookmark annotations:
  80. *
  81. * ANNOTATE_MARKER() Marker annotation
  82. * ANNOTATE_MARKER_STR(str) Marker annotation with a string
  83. * ANNOTATE_MARKER_COLOR(color) Marker annotation with a color
  84. * ANNOTATE_MARKER_COLOR_STR(color, str) Marker annotation with a string and color
  85. */
  86. /* ESC character, hex RGB (little endian) */
  87. #define ANNOTATE_RED 0x0000ff1b
  88. #define ANNOTATE_BLUE 0xff00001b
  89. #define ANNOTATE_GREEN 0x00ff001b
  90. #define ANNOTATE_PURPLE 0xff00ff1b
  91. #define ANNOTATE_YELLOW 0x00ffff1b
  92. #define ANNOTATE_CYAN 0xffff001b
  93. #define ANNOTATE_WHITE 0xffffff1b
  94. #define ANNOTATE_LTGRAY 0xbbbbbb1b
  95. #define ANNOTATE_DKGRAY 0x5555551b
  96. #define ANNOTATE_BLACK 0x0000001b
  97. #define ANNOTATE_COLOR_CYCLE 0x00000000
  98. #define ANNOTATE_COLOR_T1 0x00000001
  99. #define ANNOTATE_COLOR_T2 0x00000002
  100. #define ANNOTATE_COLOR_T3 0x00000003
  101. #define ANNOTATE_COLOR_T4 0x00000004
  102. #include <stddef.h>
  103. #include <stdint.h>
  104. #ifdef __cplusplus
  105. extern "C" {
  106. #endif
  107. enum gator_annotate_counter_class { ANNOTATE_DELTA = 1, ANNOTATE_ABSOLUTE, ANNOTATE_ACTIVITY, ANNOTATE_INCIDENT };
  108. enum gator_annotate_display {
  109. ANNOTATE_AVERAGE = 1,
  110. ANNOTATE_ACCUMULATE,
  111. ANNOTATE_HERTZ,
  112. ANNOTATE_MAXIMUM,
  113. ANNOTATE_MINIMUM
  114. };
  115. enum gator_annotate_series_composition { ANNOTATE_STACKED = 1, ANNOTATE_OVERLAY, ANNOTATE_LOG10 };
  116. enum gator_annotate_rendering_type { ANNOTATE_FILL = 1, ANNOTATE_LINE, ANNOTATE_BAR };
  117. void gator_annotate_setup(void);
  118. uint64_t gator_get_time(void);
  119. void gator_annotate_fork_child(void);
  120. void gator_annotate_flush(void);
  121. void gator_annotate_str(uint32_t channel, const char * str);
  122. void gator_annotate_color(uint32_t channel, uint32_t color, const char * str);
  123. void gator_annotate_name_channel(uint32_t channel, uint32_t group, const char * str);
  124. void gator_annotate_name_group(uint32_t group, const char * str);
  125. void gator_annotate_visual(const void * data, uint32_t length, const char * str);
  126. void gator_annotate_marker(const char * str);
  127. void gator_annotate_marker_color(uint32_t color, const char * str);
  128. void gator_annotate_counter(uint32_t id,
  129. const char * title,
  130. const char * name,
  131. int per_cpu,
  132. enum gator_annotate_counter_class counter_class,
  133. enum gator_annotate_display display,
  134. const char * units,
  135. uint32_t modifier,
  136. enum gator_annotate_series_composition series_composition,
  137. enum gator_annotate_rendering_type rendering_type,
  138. int average_selection,
  139. int average_cores,
  140. int percentage,
  141. size_t activity_count,
  142. const char * const * activities,
  143. const uint32_t * activity_colors,
  144. uint32_t cores,
  145. uint32_t color,
  146. const char * description);
  147. void gator_annotate_counter_value(uint32_t core, uint32_t id, int64_t value);
  148. void gator_annotate_counter_time_value(uint32_t core, uint32_t id, uint64_t time, int64_t value);
  149. void gator_annotate_activity_switch(uint32_t core, uint32_t id, uint32_t activity, uint32_t tid);
  150. void gator_cam_track(uint32_t view_uid, uint32_t track_uid, uint32_t parent_track, const char * name);
  151. void gator_cam_job(uint32_t view_uid,
  152. uint32_t job_uid,
  153. const char * name,
  154. uint32_t track,
  155. uint64_t start_time,
  156. uint64_t duration,
  157. uint32_t color,
  158. uint32_t primary_dependency,
  159. size_t dependency_count,
  160. const uint32_t * dependencies);
  161. void gator_cam_job_start(uint32_t view_uid,
  162. uint32_t job_uid,
  163. const char * name,
  164. uint32_t track,
  165. uint64_t time,
  166. uint32_t color);
  167. void gator_cam_job_set_dependencies(uint32_t view_uid,
  168. uint32_t job_uid,
  169. uint64_t time,
  170. uint32_t primary_dependency,
  171. size_t dependency_count,
  172. const uint32_t * dependencies);
  173. void gator_cam_job_stop(uint32_t view_uid, uint32_t job_uid, uint64_t time);
  174. void gator_cam_view_name(uint32_t view_uid, const char * name);
  175. #define ANNOTATE_DEFINE extern int gator_annotate_unused
  176. #define ANNOTATE_SETUP gator_annotate_setup()
  177. #define ANNOTATE(str) gator_annotate_str(0, str)
  178. #define ANNOTATE_CHANNEL(channel, str) gator_annotate_str(channel, str)
  179. #define ANNOTATE_COLOR(color, str) gator_annotate_color(0, color, str)
  180. #define ANNOTATE_CHANNEL_COLOR(channel, color, str) gator_annotate_color(channel, color, str)
  181. #define ANNOTATE_END() gator_annotate_str(0, NULL)
  182. #define ANNOTATE_CHANNEL_END(channel) gator_annotate_str(channel, NULL)
  183. #define ANNOTATE_NAME_CHANNEL(channel, group, str) gator_annotate_name_channel(channel, group, str)
  184. #define ANNOTATE_NAME_GROUP(group, str) gator_annotate_name_group(group, str)
  185. #define ANNOTATE_VISUAL(data, length, str) gator_annotate_visual(data, length, str)
  186. #define ANNOTATE_MARKER() gator_annotate_marker(NULL)
  187. #define ANNOTATE_MARKER_STR(str) gator_annotate_marker(str)
  188. #define ANNOTATE_MARKER_COLOR(color) gator_annotate_marker_color(color, NULL)
  189. #define ANNOTATE_MARKER_COLOR_STR(color, str) gator_annotate_marker_color(color, str)
  190. #define ANNOTATE_DELTA_COUNTER(id, title, name) \
  191. gator_annotate_counter(id, \
  192. title, \
  193. name, \
  194. 0, \
  195. ANNOTATE_DELTA, \
  196. ANNOTATE_ACCUMULATE, \
  197. NULL, \
  198. 1, \
  199. ANNOTATE_STACKED, \
  200. ANNOTATE_FILL, \
  201. 0, \
  202. 0, \
  203. 0, \
  204. 0, \
  205. NULL, \
  206. NULL, \
  207. 0, \
  208. ANNOTATE_COLOR_CYCLE, \
  209. NULL)
  210. #define ANNOTATE_ABSOLUTE_COUNTER(id, title, name) \
  211. gator_annotate_counter(id, \
  212. title, \
  213. name, \
  214. 0, \
  215. ANNOTATE_ABSOLUTE, \
  216. ANNOTATE_MAXIMUM, \
  217. NULL, \
  218. 1, \
  219. ANNOTATE_STACKED, \
  220. ANNOTATE_FILL, \
  221. 0, \
  222. 0, \
  223. 0, \
  224. 0, \
  225. NULL, \
  226. NULL, \
  227. 0, \
  228. ANNOTATE_COLOR_CYCLE, \
  229. NULL)
  230. #define ANNOTATE_COUNTER_VALUE(id, value) gator_annotate_counter_value(0, id, value)
  231. #define ANNOTATE_DELTA_COUNTER_SCALE(id, title, name, modifier) \
  232. gator_annotate_counter(id, \
  233. title, \
  234. name, \
  235. 0, \
  236. ANNOTATE_DELTA, \
  237. ANNOTATE_ACCUMULATE, \
  238. NULL, \
  239. modifier, \
  240. ANNOTATE_STACKED, \
  241. ANNOTATE_FILL, \
  242. 0, \
  243. 0, \
  244. 0, \
  245. 0, \
  246. NULL, \
  247. NULL, \
  248. 0, \
  249. ANNOTATE_COLOR_CYCLE, \
  250. NULL)
  251. #define ANNOTATE_ABSOLUTE_COUNTER_SCALE(id, title, name, modifier) \
  252. gator_annotate_counter(id, \
  253. title, \
  254. name, \
  255. 0, \
  256. ANNOTATE_ABSOLUTE, \
  257. ANNOTATE_MAXIMUM, \
  258. NULL, \
  259. modifier, \
  260. ANNOTATE_STACKED, \
  261. ANNOTATE_FILL, \
  262. 0, \
  263. 0, \
  264. 0, \
  265. 0, \
  266. NULL, \
  267. NULL, \
  268. 0, \
  269. ANNOTATE_COLOR_CYCLE, \
  270. NULL)
  271. #define ANNOTATE_COUNTER_VALUE_SCALE(id, value, modifier) \
  272. do { \
  273. uint64_t __scaledvalue = (uint64_t) ((value) * (modifier) + 0.5f); \
  274. gator_annotate_counter_value(0, id, __scaledvalue); \
  275. } while (0)
  276. #define ANNOTATE_COUNTER_TIME_VALUE_SCALE(id, time, value, modifier) \
  277. do { \
  278. uint64_t __scaledvalue = (uint64_t) ((value) * (modifier) + 0.5f); \
  279. gator_annotate_counter_time_value(0, id, time, __scaledvalue); \
  280. } while (0)
  281. #define CAM_TRACK(view_uid, track_uid, parent_track, name) gator_cam_track(view_uid, track_uid, parent_track, name)
  282. #define CAM_JOB(view_uid, job_uid, name, track, start_time, duration, color) \
  283. gator_cam_job(view_uid, job_uid, name, track, start_time, duration, color, -1, 0, 0)
  284. #define CAM_JOB_DEP(view_uid, job_uid, name, track, start_time, duration, color, dependency) \
  285. { \
  286. uint32_t __dependency = dependency; \
  287. gator_cam_job(view_uid, job_uid, name, track, start_time, duration, color, -1, 1, &__dependency); \
  288. }
  289. #define CAM_JOB_DEPS(view_uid, job_uid, name, track, start_time, duration, color, dependency_count, dependencies) \
  290. gator_cam_job(view_uid, job_uid, name, track, start_time, duration, color, -1, dependency_count, dependencies)
  291. #define CAM_JOB_START(view_uid, job_uid, name, track, time, color) \
  292. gator_cam_job_start(view_uid, job_uid, name, track, time, color)
  293. #define CAM_JOB_SET_DEP(view_uid, job_uid, time, dependency) \
  294. { \
  295. uint32_t __dependency = dependency; \
  296. gator_cam_job_set_dependencies(view_uid, job_uid, time, -1, 1, &__dependency); \
  297. }
  298. #define CAM_JOB_SET_DEPS(view_uid, job_uid, time, dependency_count, dependencies) \
  299. gator_cam_job_set_dependencies(view_uid, job_uid, time, -1, dependency_count, dependencies)
  300. #define CAM_JOB_STOP(view_uid, job_uid, time) gator_cam_job_stop(view_uid, job_uid, time)
  301. #define CAM_VIEW_NAME(view_uid, name) gator_cam_view_name(view_uid, name)
  302. #ifdef __cplusplus
  303. }
  304. #endif
  305. #endif /* STREAMLINE_ANNOTATE_H */