event-parse-api.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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_first_event - returns the first event in the events array
  11. * @tep: a handle to the tep_handle
  12. *
  13. * This returns pointer to the first element of the events array
  14. * If @tep is NULL, NULL is returned.
  15. */
  16. struct tep_event_format *tep_get_first_event(struct tep_handle *tep)
  17. {
  18. if (tep && tep->events)
  19. return tep->events[0];
  20. return NULL;
  21. }
  22. /**
  23. * tep_get_events_count - get the number of defined events
  24. * @tep: a handle to the tep_handle
  25. *
  26. * This returns number of elements in event array
  27. * If @tep is NULL, 0 is returned.
  28. */
  29. int tep_get_events_count(struct tep_handle *tep)
  30. {
  31. if(tep)
  32. return tep->nr_events;
  33. return 0;
  34. }
  35. /**
  36. * tep_set_flag - set event parser flag
  37. * @tep: a handle to the tep_handle
  38. * @flag: flag, or combination of flags to be set
  39. * can be any combination from enum tep_flag
  40. *
  41. * This sets a flag or mbination of flags from enum tep_flag
  42. */
  43. void tep_set_flag(struct tep_handle *tep, int flag)
  44. {
  45. if(tep)
  46. tep->flags |= flag;
  47. }
  48. unsigned short __tep_data2host2(struct tep_handle *pevent, unsigned short data)
  49. {
  50. unsigned short swap;
  51. if (!pevent || pevent->host_bigendian == pevent->file_bigendian)
  52. return data;
  53. swap = ((data & 0xffULL) << 8) |
  54. ((data & (0xffULL << 8)) >> 8);
  55. return swap;
  56. }
  57. unsigned int __tep_data2host4(struct tep_handle *pevent, unsigned int data)
  58. {
  59. unsigned int swap;
  60. if (!pevent || pevent->host_bigendian == pevent->file_bigendian)
  61. return data;
  62. swap = ((data & 0xffULL) << 24) |
  63. ((data & (0xffULL << 8)) << 8) |
  64. ((data & (0xffULL << 16)) >> 8) |
  65. ((data & (0xffULL << 24)) >> 24);
  66. return swap;
  67. }
  68. unsigned long long
  69. __tep_data2host8(struct tep_handle *pevent, unsigned long long data)
  70. {
  71. unsigned long long swap;
  72. if (!pevent || pevent->host_bigendian == pevent->file_bigendian)
  73. return data;
  74. swap = ((data & 0xffULL) << 56) |
  75. ((data & (0xffULL << 8)) << 40) |
  76. ((data & (0xffULL << 16)) << 24) |
  77. ((data & (0xffULL << 24)) << 8) |
  78. ((data & (0xffULL << 32)) >> 8) |
  79. ((data & (0xffULL << 40)) >> 24) |
  80. ((data & (0xffULL << 48)) >> 40) |
  81. ((data & (0xffULL << 56)) >> 56);
  82. return swap;
  83. }
  84. /**
  85. * tep_get_header_page_size - get size of the header page
  86. * @pevent: a handle to the tep_handle
  87. *
  88. * This returns size of the header page
  89. * If @pevent is NULL, 0 is returned.
  90. */
  91. int tep_get_header_page_size(struct tep_handle *pevent)
  92. {
  93. if(pevent)
  94. return pevent->header_page_size_size;
  95. return 0;
  96. }
  97. /**
  98. * tep_get_cpus - get the number of CPUs
  99. * @pevent: a handle to the tep_handle
  100. *
  101. * This returns the number of CPUs
  102. * If @pevent is NULL, 0 is returned.
  103. */
  104. int tep_get_cpus(struct tep_handle *pevent)
  105. {
  106. if(pevent)
  107. return pevent->cpus;
  108. return 0;
  109. }
  110. /**
  111. * tep_set_cpus - set the number of CPUs
  112. * @pevent: a handle to the tep_handle
  113. *
  114. * This sets the number of CPUs
  115. */
  116. void tep_set_cpus(struct tep_handle *pevent, int cpus)
  117. {
  118. if(pevent)
  119. pevent->cpus = cpus;
  120. }
  121. /**
  122. * tep_get_long_size - get the size of a long integer on the current machine
  123. * @pevent: a handle to the tep_handle
  124. *
  125. * This returns the size of a long integer on the current machine
  126. * If @pevent is NULL, 0 is returned.
  127. */
  128. int tep_get_long_size(struct tep_handle *pevent)
  129. {
  130. if(pevent)
  131. return pevent->long_size;
  132. return 0;
  133. }
  134. /**
  135. * tep_set_long_size - set the size of a long integer on the current machine
  136. * @pevent: a handle to the tep_handle
  137. * @size: size, in bytes, of a long integer
  138. *
  139. * This sets the size of a long integer on the current machine
  140. */
  141. void tep_set_long_size(struct tep_handle *pevent, int long_size)
  142. {
  143. if(pevent)
  144. pevent->long_size = long_size;
  145. }
  146. /**
  147. * tep_get_page_size - get the size of a memory page on the current machine
  148. * @pevent: a handle to the tep_handle
  149. *
  150. * This returns the size of a memory page on the current machine
  151. * If @pevent is NULL, 0 is returned.
  152. */
  153. int tep_get_page_size(struct tep_handle *pevent)
  154. {
  155. if(pevent)
  156. return pevent->page_size;
  157. return 0;
  158. }
  159. /**
  160. * tep_set_page_size - set the size of a memory page on the current machine
  161. * @pevent: a handle to the tep_handle
  162. * @_page_size: size of a memory page, in bytes
  163. *
  164. * This sets the size of a memory page on the current machine
  165. */
  166. void tep_set_page_size(struct tep_handle *pevent, int _page_size)
  167. {
  168. if(pevent)
  169. pevent->page_size = _page_size;
  170. }
  171. /**
  172. * tep_is_file_bigendian - get if the file is in big endian order
  173. * @pevent: a handle to the tep_handle
  174. *
  175. * This returns if the file is in big endian order
  176. * If @pevent is NULL, 0 is returned.
  177. */
  178. int tep_is_file_bigendian(struct tep_handle *pevent)
  179. {
  180. if(pevent)
  181. return pevent->file_bigendian;
  182. return 0;
  183. }
  184. /**
  185. * tep_set_file_bigendian - set if the file is in big endian order
  186. * @pevent: a handle to the tep_handle
  187. * @endian: non zero, if the file is in big endian order
  188. *
  189. * This sets if the file is in big endian order
  190. */
  191. void tep_set_file_bigendian(struct tep_handle *pevent, enum tep_endian endian)
  192. {
  193. if(pevent)
  194. pevent->file_bigendian = endian;
  195. }
  196. /**
  197. * tep_is_host_bigendian - get if the order of the current host is big endian
  198. * @pevent: a handle to the tep_handle
  199. *
  200. * This gets if the order of the current host is big endian
  201. * If @pevent is NULL, 0 is returned.
  202. */
  203. int tep_is_host_bigendian(struct tep_handle *pevent)
  204. {
  205. if(pevent)
  206. return pevent->host_bigendian;
  207. return 0;
  208. }
  209. /**
  210. * tep_set_host_bigendian - set the order of the local host
  211. * @pevent: a handle to the tep_handle
  212. * @endian: non zero, if the local host has big endian order
  213. *
  214. * This sets the order of the local host
  215. */
  216. void tep_set_host_bigendian(struct tep_handle *pevent, enum tep_endian endian)
  217. {
  218. if(pevent)
  219. pevent->host_bigendian = endian;
  220. }
  221. /**
  222. * tep_is_latency_format - get if the latency output format is configured
  223. * @pevent: a handle to the tep_handle
  224. *
  225. * This gets if the latency output format is configured
  226. * If @pevent is NULL, 0 is returned.
  227. */
  228. int tep_is_latency_format(struct tep_handle *pevent)
  229. {
  230. if(pevent)
  231. return pevent->latency_format;
  232. return 0;
  233. }
  234. /**
  235. * tep_set_latency_format - set the latency output format
  236. * @pevent: a handle to the tep_handle
  237. * @lat: non zero for latency output format
  238. *
  239. * This sets the latency output format
  240. */
  241. void tep_set_latency_format(struct tep_handle *pevent, int lat)
  242. {
  243. if(pevent)
  244. pevent->latency_format = lat;
  245. }