event-parse-api.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. // SPDX-License-Identifier: LGPL-2.1
  2. /*
  3. * Copyright (C) 2009, 2010 Red Hat Inc, Steven Rostedt <srostedt@redhat.com>
  4. *
  5. */
  6. #include "event-parse.h"
  7. #include "event-parse-local.h"
  8. #include "event-utils.h"
  9. /**
  10. * tep_get_event - returns the event with the given index
  11. * @tep: a handle to the tep_handle
  12. * @index: index of the requested event, in the range 0 .. nr_events
  13. *
  14. * This returns pointer to the element of the events array with the given index
  15. * If @tep is NULL, or @index is not in the range 0 .. nr_events, NULL is returned.
  16. */
  17. struct tep_event *tep_get_event(struct tep_handle *tep, int index)
  18. {
  19. if (tep && tep->events && index < tep->nr_events)
  20. return tep->events[index];
  21. return NULL;
  22. }
  23. /**
  24. * tep_get_first_event - returns the first event in the events array
  25. * @tep: a handle to the tep_handle
  26. *
  27. * This returns pointer to the first element of the events array
  28. * If @tep is NULL, NULL is returned.
  29. */
  30. struct tep_event *tep_get_first_event(struct tep_handle *tep)
  31. {
  32. return tep_get_event(tep, 0);
  33. }
  34. /**
  35. * tep_get_events_count - get the number of defined events
  36. * @tep: a handle to the tep_handle
  37. *
  38. * This returns number of elements in event array
  39. * If @tep is NULL, 0 is returned.
  40. */
  41. int tep_get_events_count(struct tep_handle *tep)
  42. {
  43. if (tep)
  44. return tep->nr_events;
  45. return 0;
  46. }
  47. /**
  48. * tep_set_flag - set event parser flag
  49. * @tep: a handle to the tep_handle
  50. * @flag: flag, or combination of flags to be set
  51. * can be any combination from enum tep_flag
  52. *
  53. * This sets a flag or combination of flags from enum tep_flag
  54. */
  55. void tep_set_flag(struct tep_handle *tep, int flag)
  56. {
  57. if (tep)
  58. tep->flags |= flag;
  59. }
  60. /**
  61. * tep_clear_flag - clear event parser flag
  62. * @tep: a handle to the tep_handle
  63. * @flag: flag to be cleared
  64. *
  65. * This clears a tep flag
  66. */
  67. void tep_clear_flag(struct tep_handle *tep, enum tep_flag flag)
  68. {
  69. if (tep)
  70. tep->flags &= ~flag;
  71. }
  72. /**
  73. * tep_test_flag - check the state of event parser flag
  74. * @tep: a handle to the tep_handle
  75. * @flag: flag to be checked
  76. *
  77. * This returns the state of the requested tep flag.
  78. * Returns: true if the flag is set, false otherwise.
  79. */
  80. bool tep_test_flag(struct tep_handle *tep, enum tep_flag flag)
  81. {
  82. if (tep)
  83. return tep->flags & flag;
  84. return false;
  85. }
  86. __hidden unsigned short data2host2(struct tep_handle *tep, unsigned short data)
  87. {
  88. unsigned short swap;
  89. if (!tep || tep->host_bigendian == tep->file_bigendian)
  90. return data;
  91. swap = ((data & 0xffULL) << 8) |
  92. ((data & (0xffULL << 8)) >> 8);
  93. return swap;
  94. }
  95. __hidden unsigned int data2host4(struct tep_handle *tep, unsigned int data)
  96. {
  97. unsigned int swap;
  98. if (!tep || tep->host_bigendian == tep->file_bigendian)
  99. return data;
  100. swap = ((data & 0xffULL) << 24) |
  101. ((data & (0xffULL << 8)) << 8) |
  102. ((data & (0xffULL << 16)) >> 8) |
  103. ((data & (0xffULL << 24)) >> 24);
  104. return swap;
  105. }
  106. __hidden unsigned long long
  107. data2host8(struct tep_handle *tep, unsigned long long data)
  108. {
  109. unsigned long long swap;
  110. if (!tep || tep->host_bigendian == tep->file_bigendian)
  111. return data;
  112. swap = ((data & 0xffULL) << 56) |
  113. ((data & (0xffULL << 8)) << 40) |
  114. ((data & (0xffULL << 16)) << 24) |
  115. ((data & (0xffULL << 24)) << 8) |
  116. ((data & (0xffULL << 32)) >> 8) |
  117. ((data & (0xffULL << 40)) >> 24) |
  118. ((data & (0xffULL << 48)) >> 40) |
  119. ((data & (0xffULL << 56)) >> 56);
  120. return swap;
  121. }
  122. /**
  123. * tep_get_header_page_size - get size of the header page
  124. * @tep: a handle to the tep_handle
  125. *
  126. * This returns size of the header page
  127. * If @tep is NULL, 0 is returned.
  128. */
  129. int tep_get_header_page_size(struct tep_handle *tep)
  130. {
  131. if (tep)
  132. return tep->header_page_size_size;
  133. return 0;
  134. }
  135. /**
  136. * tep_get_header_timestamp_size - get size of the timestamp in the header page
  137. * @tep: a handle to the tep_handle
  138. *
  139. * This returns size of the timestamp in the header page
  140. * If @tep is NULL, 0 is returned.
  141. */
  142. int tep_get_header_timestamp_size(struct tep_handle *tep)
  143. {
  144. if (tep)
  145. return tep->header_page_ts_size;
  146. return 0;
  147. }
  148. /**
  149. * tep_get_cpus - get the number of CPUs
  150. * @tep: a handle to the tep_handle
  151. *
  152. * This returns the number of CPUs
  153. * If @tep is NULL, 0 is returned.
  154. */
  155. int tep_get_cpus(struct tep_handle *tep)
  156. {
  157. if (tep)
  158. return tep->cpus;
  159. return 0;
  160. }
  161. /**
  162. * tep_set_cpus - set the number of CPUs
  163. * @tep: a handle to the tep_handle
  164. *
  165. * This sets the number of CPUs
  166. */
  167. void tep_set_cpus(struct tep_handle *tep, int cpus)
  168. {
  169. if (tep)
  170. tep->cpus = cpus;
  171. }
  172. /**
  173. * tep_get_long_size - get the size of a long integer on the traced machine
  174. * @tep: a handle to the tep_handle
  175. *
  176. * This returns the size of a long integer on the traced machine
  177. * If @tep is NULL, 0 is returned.
  178. */
  179. int tep_get_long_size(struct tep_handle *tep)
  180. {
  181. if (tep)
  182. return tep->long_size;
  183. return 0;
  184. }
  185. /**
  186. * tep_set_long_size - set the size of a long integer on the traced machine
  187. * @tep: a handle to the tep_handle
  188. * @size: size, in bytes, of a long integer
  189. *
  190. * This sets the size of a long integer on the traced machine
  191. */
  192. void tep_set_long_size(struct tep_handle *tep, int long_size)
  193. {
  194. if (tep)
  195. tep->long_size = long_size;
  196. }
  197. /**
  198. * tep_get_page_size - get the size of a memory page on the traced machine
  199. * @tep: a handle to the tep_handle
  200. *
  201. * This returns the size of a memory page on the traced machine
  202. * If @tep is NULL, 0 is returned.
  203. */
  204. int tep_get_page_size(struct tep_handle *tep)
  205. {
  206. if (tep)
  207. return tep->page_size;
  208. return 0;
  209. }
  210. /**
  211. * tep_set_page_size - set the size of a memory page on the traced machine
  212. * @tep: a handle to the tep_handle
  213. * @_page_size: size of a memory page, in bytes
  214. *
  215. * This sets the size of a memory page on the traced machine
  216. */
  217. void tep_set_page_size(struct tep_handle *tep, int _page_size)
  218. {
  219. if (tep)
  220. tep->page_size = _page_size;
  221. }
  222. /**
  223. * tep_is_file_bigendian - return the endian of the file
  224. * @tep: a handle to the tep_handle
  225. *
  226. * This returns true if the file is in big endian order
  227. * If @tep is NULL, false is returned.
  228. */
  229. bool tep_is_file_bigendian(struct tep_handle *tep)
  230. {
  231. if (tep)
  232. return (tep->file_bigendian == TEP_BIG_ENDIAN);
  233. return false;
  234. }
  235. /**
  236. * tep_set_file_bigendian - set if the file is in big endian order
  237. * @tep: a handle to the tep_handle
  238. * @endian: non zero, if the file is in big endian order
  239. *
  240. * This sets if the file is in big endian order
  241. */
  242. void tep_set_file_bigendian(struct tep_handle *tep, enum tep_endian endian)
  243. {
  244. if (tep)
  245. tep->file_bigendian = endian;
  246. }
  247. /**
  248. * tep_is_local_bigendian - return the endian of the saved local machine
  249. * @tep: a handle to the tep_handle
  250. *
  251. * This returns true if the saved local machine in @tep is big endian.
  252. * If @tep is NULL, false is returned.
  253. */
  254. bool tep_is_local_bigendian(struct tep_handle *tep)
  255. {
  256. if (tep)
  257. return (tep->host_bigendian == TEP_BIG_ENDIAN);
  258. return 0;
  259. }
  260. /**
  261. * tep_set_local_bigendian - set the stored local machine endian order
  262. * @tep: a handle to the tep_handle
  263. * @endian: non zero, if the local host has big endian order
  264. *
  265. * This sets the endian order for the local machine.
  266. */
  267. void tep_set_local_bigendian(struct tep_handle *tep, enum tep_endian endian)
  268. {
  269. if (tep)
  270. tep->host_bigendian = endian;
  271. }
  272. /**
  273. * tep_is_old_format - get if an old kernel is used
  274. * @tep: a handle to the tep_handle
  275. *
  276. * This returns true, if an old kernel is used to generate the tracing events or
  277. * false if a new kernel is used. Old kernels did not have header page info.
  278. * If @tep is NULL, false is returned.
  279. */
  280. bool tep_is_old_format(struct tep_handle *tep)
  281. {
  282. if (tep)
  283. return tep->old_format;
  284. return false;
  285. }
  286. /**
  287. * tep_set_test_filters - set a flag to test a filter string
  288. * @tep: a handle to the tep_handle
  289. * @test_filters: the new value of the test_filters flag
  290. *
  291. * This sets a flag to test a filter string. If this flag is set, when
  292. * tep_filter_add_filter_str() API as called,it will print the filter string
  293. * instead of adding it.
  294. */
  295. void tep_set_test_filters(struct tep_handle *tep, int test_filters)
  296. {
  297. if (tep)
  298. tep->test_filters = test_filters;
  299. }