1 // SPDX-License-Identifier: LGPL-2.1
3 * Copyright (C) 2009, 2010 Red Hat Inc, Steven Rostedt <srostedt@redhat.com>
7 #include "event-parse.h"
8 #include "event-parse-local.h"
9 #include "event-utils.h"
12 * tep_get_event - returns the event with the given index
13 * @tep: a handle to the tep_handle
14 * @index: index of the requested event, in the range 0 .. nr_events
16 * This returns pointer to the element of the events array with the given index
17 * If @tep is NULL, or @index is not in the range 0 .. nr_events, NULL is returned.
19 struct tep_event
*tep_get_event(struct tep_handle
*tep
, int index
)
21 if (tep
&& tep
->events
&& index
< tep
->nr_events
)
22 return tep
->events
[index
];
28 * tep_get_first_event - returns the first event in the events array
29 * @tep: a handle to the tep_handle
31 * This returns pointer to the first element of the events array
32 * If @tep is NULL, NULL is returned.
34 struct tep_event
*tep_get_first_event(struct tep_handle
*tep
)
36 return tep_get_event(tep
, 0);
40 * tep_get_events_count - get the number of defined events
41 * @tep: a handle to the tep_handle
43 * This returns number of elements in event array
44 * If @tep is NULL, 0 is returned.
46 int tep_get_events_count(struct tep_handle
*tep
)
49 return tep
->nr_events
;
54 * tep_set_flag - set event parser flag
55 * @tep: a handle to the tep_handle
56 * @flag: flag, or combination of flags to be set
57 * can be any combination from enum tep_flag
59 * This sets a flag or combination of flags from enum tep_flag
61 void tep_set_flag(struct tep_handle
*tep
, int flag
)
68 * tep_clear_flag - clear event parser flag
69 * @tep: a handle to the tep_handle
70 * @flag: flag to be cleared
72 * This clears a tep flag
74 void tep_clear_flag(struct tep_handle
*tep
, enum tep_flag flag
)
81 * tep_test_flag - check the state of event parser flag
82 * @tep: a handle to the tep_handle
83 * @flag: flag to be checked
85 * This returns the state of the requested tep flag.
86 * Returns: true if the flag is set, false otherwise.
88 bool tep_test_flag(struct tep_handle
*tep
, enum tep_flag flag
)
91 return tep
->flags
& flag
;
95 __hidden
unsigned short data2host2(struct tep_handle
*tep
, unsigned short data
)
99 if (!tep
|| tep
->host_bigendian
== tep
->file_bigendian
)
102 swap
= ((data
& 0xffULL
) << 8) |
103 ((data
& (0xffULL
<< 8)) >> 8);
108 __hidden
unsigned int data2host4(struct tep_handle
*tep
, unsigned int data
)
112 if (!tep
|| tep
->host_bigendian
== tep
->file_bigendian
)
115 swap
= ((data
& 0xffULL
) << 24) |
116 ((data
& (0xffULL
<< 8)) << 8) |
117 ((data
& (0xffULL
<< 16)) >> 8) |
118 ((data
& (0xffULL
<< 24)) >> 24);
123 __hidden
unsigned long long
124 data2host8(struct tep_handle
*tep
, unsigned long long data
)
126 unsigned long long swap
;
128 if (!tep
|| tep
->host_bigendian
== tep
->file_bigendian
)
131 swap
= ((data
& 0xffULL
) << 56) |
132 ((data
& (0xffULL
<< 8)) << 40) |
133 ((data
& (0xffULL
<< 16)) << 24) |
134 ((data
& (0xffULL
<< 24)) << 8) |
135 ((data
& (0xffULL
<< 32)) >> 8) |
136 ((data
& (0xffULL
<< 40)) >> 24) |
137 ((data
& (0xffULL
<< 48)) >> 40) |
138 ((data
& (0xffULL
<< 56)) >> 56);
144 * tep_get_header_page_size - get size of the header page
145 * @tep: a handle to the tep_handle
147 * This returns size of the header page
148 * If @tep is NULL, 0 is returned.
150 int tep_get_header_page_size(struct tep_handle
*tep
)
153 return tep
->header_page_size_size
;
158 * tep_get_header_timestamp_size - get size of the timestamp in the header page
159 * @tep: a handle to the tep_handle
161 * This returns size of the timestamp in the header page
162 * If @tep is NULL, 0 is returned.
164 int tep_get_header_timestamp_size(struct tep_handle
*tep
)
167 return tep
->header_page_ts_size
;
172 * tep_get_cpus - get the number of CPUs
173 * @tep: a handle to the tep_handle
175 * This returns the number of CPUs
176 * If @tep is NULL, 0 is returned.
178 int tep_get_cpus(struct tep_handle
*tep
)
186 * tep_set_cpus - set the number of CPUs
187 * @tep: a handle to the tep_handle
189 * This sets the number of CPUs
191 void tep_set_cpus(struct tep_handle
*tep
, int cpus
)
198 * tep_get_long_size - get the size of a long integer on the traced machine
199 * @tep: a handle to the tep_handle
201 * This returns the size of a long integer on the traced machine
202 * If @tep is NULL, 0 is returned.
204 int tep_get_long_size(struct tep_handle
*tep
)
207 return tep
->long_size
;
212 * tep_set_long_size - set the size of a long integer on the traced machine
213 * @tep: a handle to the tep_handle
214 * @size: size, in bytes, of a long integer
216 * This sets the size of a long integer on the traced machine
218 void tep_set_long_size(struct tep_handle
*tep
, int long_size
)
221 tep
->long_size
= long_size
;
225 * tep_get_page_size - get the size of a memory page on the traced machine
226 * @tep: a handle to the tep_handle
228 * This returns the size of a memory page on the traced machine
229 * If @tep is NULL, 0 is returned.
231 int tep_get_page_size(struct tep_handle
*tep
)
234 return tep
->page_size
;
239 * tep_set_page_size - set the size of a memory page on the traced machine
240 * @tep: a handle to the tep_handle
241 * @_page_size: size of a memory page, in bytes
243 * This sets the size of a memory page on the traced machine
245 void tep_set_page_size(struct tep_handle
*tep
, int _page_size
)
248 tep
->page_size
= _page_size
;
252 * tep_is_file_bigendian - return the endian of the file
253 * @tep: a handle to the tep_handle
255 * This returns true if the file is in big endian order
256 * If @tep is NULL, false is returned.
258 bool tep_is_file_bigendian(struct tep_handle
*tep
)
261 return (tep
->file_bigendian
== TEP_BIG_ENDIAN
);
266 * tep_set_file_bigendian - set if the file is in big endian order
267 * @tep: a handle to the tep_handle
268 * @endian: non zero, if the file is in big endian order
270 * This sets if the file is in big endian order
272 void tep_set_file_bigendian(struct tep_handle
*tep
, enum tep_endian endian
)
275 tep
->file_bigendian
= endian
;
279 * tep_is_local_bigendian - return the endian of the saved local machine
280 * @tep: a handle to the tep_handle
282 * This returns true if the saved local machine in @tep is big endian.
283 * If @tep is NULL, false is returned.
285 bool tep_is_local_bigendian(struct tep_handle
*tep
)
288 return (tep
->host_bigendian
== TEP_BIG_ENDIAN
);
293 * tep_set_local_bigendian - set the stored local machine endian order
294 * @tep: a handle to the tep_handle
295 * @endian: non zero, if the local host has big endian order
297 * This sets the endian order for the local machine.
299 void tep_set_local_bigendian(struct tep_handle
*tep
, enum tep_endian endian
)
302 tep
->host_bigendian
= endian
;
306 * tep_is_old_format - get if an old kernel is used
307 * @tep: a handle to the tep_handle
309 * This returns true, if an old kernel is used to generate the tracing events or
310 * false if a new kernel is used. Old kernels did not have header page info.
311 * If @tep is NULL, false is returned.
313 bool tep_is_old_format(struct tep_handle
*tep
)
316 return tep
->old_format
;
321 * tep_set_test_filters - set a flag to test a filter string
322 * @tep: a handle to the tep_handle
323 * @test_filters: the new value of the test_filters flag
325 * This sets a flag to test a filter string. If this flag is set, when
326 * tep_filter_add_filter_str() API as called,it will print the filter string
327 * instead of adding it.
329 void tep_set_test_filters(struct tep_handle
*tep
, int test_filters
)
332 tep
->test_filters
= test_filters
;