Tzvetomir Stoyanov | bb3dd7e | 2018-10-05 12:22:25 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: LGPL-2.1 |
| 2 | /* |
| 3 | * Copyright (C) 2009, 2010 Red Hat Inc, Steven Rostedt <srostedt@redhat.com> |
| 4 | * |
| 5 | */ |
| 6 | |
| 7 | #include "event-parse.h" |
| 8 | #include "event-parse-local.h" |
| 9 | #include "event-utils.h" |
| 10 | |
| 11 | /** |
| 12 | * tep_get_first_event - returns the first event in the events array |
| 13 | * @tep: a handle to the tep_handle |
| 14 | * |
| 15 | * This returns pointer to the first element of the events array |
| 16 | * If @tep is NULL, NULL is returned. |
| 17 | */ |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 18 | struct tep_event *tep_get_first_event(struct tep_handle *tep) |
Tzvetomir Stoyanov | bb3dd7e | 2018-10-05 12:22:25 -0400 | [diff] [blame] | 19 | { |
| 20 | if (tep && tep->events) |
| 21 | return tep->events[0]; |
| 22 | |
| 23 | return NULL; |
| 24 | } |
| 25 | |
| 26 | /** |
| 27 | * tep_get_events_count - get the number of defined events |
| 28 | * @tep: a handle to the tep_handle |
| 29 | * |
| 30 | * This returns number of elements in event array |
| 31 | * If @tep is NULL, 0 is returned. |
| 32 | */ |
| 33 | int tep_get_events_count(struct tep_handle *tep) |
| 34 | { |
| 35 | if(tep) |
| 36 | return tep->nr_events; |
| 37 | return 0; |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * tep_set_flag - set event parser flag |
| 42 | * @tep: a handle to the tep_handle |
| 43 | * @flag: flag, or combination of flags to be set |
| 44 | * can be any combination from enum tep_flag |
| 45 | * |
| 46 | * This sets a flag or mbination of flags from enum tep_flag |
| 47 | */ |
| 48 | void tep_set_flag(struct tep_handle *tep, int flag) |
| 49 | { |
| 50 | if(tep) |
| 51 | tep->flags |= flag; |
| 52 | } |
| 53 | |
Tzvetomir Stoyanov | 6cd99d2 | 2018-11-30 10:44:10 -0500 | [diff] [blame] | 54 | unsigned short tep_data2host2(struct tep_handle *pevent, unsigned short data) |
Tzvetomir Stoyanov | bb3dd7e | 2018-10-05 12:22:25 -0400 | [diff] [blame] | 55 | { |
| 56 | unsigned short swap; |
| 57 | |
| 58 | if (!pevent || pevent->host_bigendian == pevent->file_bigendian) |
| 59 | return data; |
| 60 | |
| 61 | swap = ((data & 0xffULL) << 8) | |
| 62 | ((data & (0xffULL << 8)) >> 8); |
| 63 | |
| 64 | return swap; |
| 65 | } |
| 66 | |
Tzvetomir Stoyanov | 6cd99d2 | 2018-11-30 10:44:10 -0500 | [diff] [blame] | 67 | unsigned int tep_data2host4(struct tep_handle *pevent, unsigned int data) |
Tzvetomir Stoyanov | bb3dd7e | 2018-10-05 12:22:25 -0400 | [diff] [blame] | 68 | { |
| 69 | unsigned int swap; |
| 70 | |
| 71 | if (!pevent || pevent->host_bigendian == pevent->file_bigendian) |
| 72 | return data; |
| 73 | |
| 74 | swap = ((data & 0xffULL) << 24) | |
| 75 | ((data & (0xffULL << 8)) << 8) | |
| 76 | ((data & (0xffULL << 16)) >> 8) | |
| 77 | ((data & (0xffULL << 24)) >> 24); |
| 78 | |
| 79 | return swap; |
| 80 | } |
| 81 | |
| 82 | unsigned long long |
Tzvetomir Stoyanov | 6cd99d2 | 2018-11-30 10:44:10 -0500 | [diff] [blame] | 83 | tep_data2host8(struct tep_handle *pevent, unsigned long long data) |
Tzvetomir Stoyanov | bb3dd7e | 2018-10-05 12:22:25 -0400 | [diff] [blame] | 84 | { |
| 85 | unsigned long long swap; |
| 86 | |
| 87 | if (!pevent || pevent->host_bigendian == pevent->file_bigendian) |
| 88 | return data; |
| 89 | |
| 90 | swap = ((data & 0xffULL) << 56) | |
| 91 | ((data & (0xffULL << 8)) << 40) | |
| 92 | ((data & (0xffULL << 16)) << 24) | |
| 93 | ((data & (0xffULL << 24)) << 8) | |
| 94 | ((data & (0xffULL << 32)) >> 8) | |
| 95 | ((data & (0xffULL << 40)) >> 24) | |
| 96 | ((data & (0xffULL << 48)) >> 40) | |
| 97 | ((data & (0xffULL << 56)) >> 56); |
| 98 | |
| 99 | return swap; |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * tep_get_header_page_size - get size of the header page |
| 104 | * @pevent: a handle to the tep_handle |
| 105 | * |
| 106 | * This returns size of the header page |
| 107 | * If @pevent is NULL, 0 is returned. |
| 108 | */ |
| 109 | int tep_get_header_page_size(struct tep_handle *pevent) |
| 110 | { |
| 111 | if(pevent) |
| 112 | return pevent->header_page_size_size; |
| 113 | return 0; |
| 114 | } |
| 115 | |
| 116 | /** |
| 117 | * tep_get_cpus - get the number of CPUs |
| 118 | * @pevent: a handle to the tep_handle |
| 119 | * |
| 120 | * This returns the number of CPUs |
| 121 | * If @pevent is NULL, 0 is returned. |
| 122 | */ |
| 123 | int tep_get_cpus(struct tep_handle *pevent) |
| 124 | { |
| 125 | if(pevent) |
| 126 | return pevent->cpus; |
| 127 | return 0; |
| 128 | } |
| 129 | |
| 130 | /** |
| 131 | * tep_set_cpus - set the number of CPUs |
| 132 | * @pevent: a handle to the tep_handle |
| 133 | * |
| 134 | * This sets the number of CPUs |
| 135 | */ |
| 136 | void tep_set_cpus(struct tep_handle *pevent, int cpus) |
| 137 | { |
| 138 | if(pevent) |
| 139 | pevent->cpus = cpus; |
| 140 | } |
| 141 | |
| 142 | /** |
| 143 | * tep_get_long_size - get the size of a long integer on the current machine |
| 144 | * @pevent: a handle to the tep_handle |
| 145 | * |
| 146 | * This returns the size of a long integer on the current machine |
| 147 | * If @pevent is NULL, 0 is returned. |
| 148 | */ |
| 149 | int tep_get_long_size(struct tep_handle *pevent) |
| 150 | { |
| 151 | if(pevent) |
| 152 | return pevent->long_size; |
| 153 | return 0; |
| 154 | } |
| 155 | |
| 156 | /** |
| 157 | * tep_set_long_size - set the size of a long integer on the current machine |
| 158 | * @pevent: a handle to the tep_handle |
| 159 | * @size: size, in bytes, of a long integer |
| 160 | * |
| 161 | * This sets the size of a long integer on the current machine |
| 162 | */ |
| 163 | void tep_set_long_size(struct tep_handle *pevent, int long_size) |
| 164 | { |
| 165 | if(pevent) |
| 166 | pevent->long_size = long_size; |
| 167 | } |
| 168 | |
| 169 | /** |
| 170 | * tep_get_page_size - get the size of a memory page on the current machine |
| 171 | * @pevent: a handle to the tep_handle |
| 172 | * |
| 173 | * This returns the size of a memory page on the current machine |
| 174 | * If @pevent is NULL, 0 is returned. |
| 175 | */ |
| 176 | int tep_get_page_size(struct tep_handle *pevent) |
| 177 | { |
| 178 | if(pevent) |
| 179 | return pevent->page_size; |
| 180 | return 0; |
| 181 | } |
| 182 | |
| 183 | /** |
| 184 | * tep_set_page_size - set the size of a memory page on the current machine |
| 185 | * @pevent: a handle to the tep_handle |
| 186 | * @_page_size: size of a memory page, in bytes |
| 187 | * |
| 188 | * This sets the size of a memory page on the current machine |
| 189 | */ |
| 190 | void tep_set_page_size(struct tep_handle *pevent, int _page_size) |
| 191 | { |
| 192 | if(pevent) |
| 193 | pevent->page_size = _page_size; |
| 194 | } |
| 195 | |
| 196 | /** |
Tzvetomir Stoyanov | 4104e60 | 2018-11-30 23:08:12 -0500 | [diff] [blame] | 197 | * tep_file_bigendian - get if the file is in big endian order |
Tzvetomir Stoyanov | bb3dd7e | 2018-10-05 12:22:25 -0400 | [diff] [blame] | 198 | * @pevent: a handle to the tep_handle |
| 199 | * |
| 200 | * This returns if the file is in big endian order |
| 201 | * If @pevent is NULL, 0 is returned. |
| 202 | */ |
Tzvetomir Stoyanov | 4104e60 | 2018-11-30 23:08:12 -0500 | [diff] [blame] | 203 | int tep_file_bigendian(struct tep_handle *pevent) |
Tzvetomir Stoyanov | bb3dd7e | 2018-10-05 12:22:25 -0400 | [diff] [blame] | 204 | { |
| 205 | if(pevent) |
| 206 | return pevent->file_bigendian; |
| 207 | return 0; |
| 208 | } |
| 209 | |
| 210 | /** |
| 211 | * tep_set_file_bigendian - set if the file is in big endian order |
| 212 | * @pevent: a handle to the tep_handle |
| 213 | * @endian: non zero, if the file is in big endian order |
| 214 | * |
| 215 | * This sets if the file is in big endian order |
| 216 | */ |
| 217 | void tep_set_file_bigendian(struct tep_handle *pevent, enum tep_endian endian) |
| 218 | { |
| 219 | if(pevent) |
| 220 | pevent->file_bigendian = endian; |
| 221 | } |
| 222 | |
| 223 | /** |
| 224 | * tep_is_host_bigendian - get if the order of the current host is big endian |
| 225 | * @pevent: a handle to the tep_handle |
| 226 | * |
| 227 | * This gets if the order of the current host is big endian |
| 228 | * If @pevent is NULL, 0 is returned. |
| 229 | */ |
| 230 | int tep_is_host_bigendian(struct tep_handle *pevent) |
| 231 | { |
| 232 | if(pevent) |
| 233 | return pevent->host_bigendian; |
| 234 | return 0; |
| 235 | } |
| 236 | |
| 237 | /** |
| 238 | * tep_set_host_bigendian - set the order of the local host |
| 239 | * @pevent: a handle to the tep_handle |
| 240 | * @endian: non zero, if the local host has big endian order |
| 241 | * |
| 242 | * This sets the order of the local host |
| 243 | */ |
| 244 | void tep_set_host_bigendian(struct tep_handle *pevent, enum tep_endian endian) |
| 245 | { |
| 246 | if(pevent) |
| 247 | pevent->host_bigendian = endian; |
| 248 | } |
| 249 | |
| 250 | /** |
| 251 | * tep_is_latency_format - get if the latency output format is configured |
| 252 | * @pevent: a handle to the tep_handle |
| 253 | * |
| 254 | * This gets if the latency output format is configured |
| 255 | * If @pevent is NULL, 0 is returned. |
| 256 | */ |
| 257 | int tep_is_latency_format(struct tep_handle *pevent) |
| 258 | { |
| 259 | if(pevent) |
| 260 | return pevent->latency_format; |
| 261 | return 0; |
| 262 | } |
| 263 | |
| 264 | /** |
| 265 | * tep_set_latency_format - set the latency output format |
| 266 | * @pevent: a handle to the tep_handle |
| 267 | * @lat: non zero for latency output format |
| 268 | * |
| 269 | * This sets the latency output format |
| 270 | */ |
| 271 | void tep_set_latency_format(struct tep_handle *pevent, int lat) |
| 272 | { |
| 273 | if(pevent) |
| 274 | pevent->latency_format = lat; |
| 275 | } |