Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: LGPL-2.1
0002 /*
0003  * Copyright (C) 2009, 2010 Red Hat Inc, Steven Rostedt <srostedt@redhat.com>
0004  *
0005  */
0006 
0007 #include "event-parse.h"
0008 #include "event-parse-local.h"
0009 #include "event-utils.h"
0010 
0011 /**
0012  * tep_get_event - returns the event with the given index
0013  * @tep: a handle to the tep_handle
0014  * @index: index of the requested event, in the range 0 .. nr_events
0015  *
0016  * This returns pointer to the element of the events array with the given index
0017  * If @tep is NULL, or @index is not in the range 0 .. nr_events, NULL is returned.
0018  */
0019 struct tep_event *tep_get_event(struct tep_handle *tep, int index)
0020 {
0021     if (tep && tep->events && index < tep->nr_events)
0022         return tep->events[index];
0023 
0024     return NULL;
0025 }
0026 
0027 /**
0028  * tep_get_first_event - returns the first event in the events array
0029  * @tep: a handle to the tep_handle
0030  *
0031  * This returns pointer to the first element of the events array
0032  * If @tep is NULL, NULL is returned.
0033  */
0034 struct tep_event *tep_get_first_event(struct tep_handle *tep)
0035 {
0036     return tep_get_event(tep, 0);
0037 }
0038 
0039 /**
0040  * tep_get_events_count - get the number of defined events
0041  * @tep: a handle to the tep_handle
0042  *
0043  * This returns number of elements in event array
0044  * If @tep is NULL, 0 is returned.
0045  */
0046 int tep_get_events_count(struct tep_handle *tep)
0047 {
0048     if (tep)
0049         return tep->nr_events;
0050     return 0;
0051 }
0052 
0053 /**
0054  * tep_set_flag - set event parser flag
0055  * @tep: a handle to the tep_handle
0056  * @flag: flag, or combination of flags to be set
0057  * can be any combination from enum tep_flag
0058  *
0059  * This sets a flag or combination of flags from enum tep_flag
0060  */
0061 void tep_set_flag(struct tep_handle *tep, int flag)
0062 {
0063     if (tep)
0064         tep->flags |= flag;
0065 }
0066 
0067 /**
0068  * tep_clear_flag - clear event parser flag
0069  * @tep: a handle to the tep_handle
0070  * @flag: flag to be cleared
0071  *
0072  * This clears a tep flag
0073  */
0074 void tep_clear_flag(struct tep_handle *tep, enum tep_flag flag)
0075 {
0076     if (tep)
0077         tep->flags &= ~flag;
0078 }
0079 
0080 /**
0081  * tep_test_flag - check the state of event parser flag
0082  * @tep: a handle to the tep_handle
0083  * @flag: flag to be checked
0084  *
0085  * This returns the state of the requested tep flag.
0086  * Returns: true if the flag is set, false otherwise.
0087  */
0088 bool tep_test_flag(struct tep_handle *tep, enum tep_flag flag)
0089 {
0090     if (tep)
0091         return tep->flags & flag;
0092     return false;
0093 }
0094 
0095 __hidden unsigned short data2host2(struct tep_handle *tep, unsigned short data)
0096 {
0097     unsigned short swap;
0098 
0099     if (!tep || tep->host_bigendian == tep->file_bigendian)
0100         return data;
0101 
0102     swap = ((data & 0xffULL) << 8) |
0103         ((data & (0xffULL << 8)) >> 8);
0104 
0105     return swap;
0106 }
0107 
0108 __hidden unsigned int data2host4(struct tep_handle *tep, unsigned int data)
0109 {
0110     unsigned int swap;
0111 
0112     if (!tep || tep->host_bigendian == tep->file_bigendian)
0113         return data;
0114 
0115     swap = ((data & 0xffULL) << 24) |
0116         ((data & (0xffULL << 8)) << 8) |
0117         ((data & (0xffULL << 16)) >> 8) |
0118         ((data & (0xffULL << 24)) >> 24);
0119 
0120     return swap;
0121 }
0122 
0123 __hidden  unsigned long long
0124 data2host8(struct tep_handle *tep, unsigned long long data)
0125 {
0126     unsigned long long swap;
0127 
0128     if (!tep || tep->host_bigendian == tep->file_bigendian)
0129         return data;
0130 
0131     swap = ((data & 0xffULL) << 56) |
0132         ((data & (0xffULL << 8)) << 40) |
0133         ((data & (0xffULL << 16)) << 24) |
0134         ((data & (0xffULL << 24)) << 8) |
0135         ((data & (0xffULL << 32)) >> 8) |
0136         ((data & (0xffULL << 40)) >> 24) |
0137         ((data & (0xffULL << 48)) >> 40) |
0138         ((data & (0xffULL << 56)) >> 56);
0139 
0140     return swap;
0141 }
0142 
0143 /**
0144  * tep_get_header_page_size - get size of the header page
0145  * @tep: a handle to the tep_handle
0146  *
0147  * This returns size of the header page
0148  * If @tep is NULL, 0 is returned.
0149  */
0150 int tep_get_header_page_size(struct tep_handle *tep)
0151 {
0152     if (tep)
0153         return tep->header_page_size_size;
0154     return 0;
0155 }
0156 
0157 /**
0158  * tep_get_header_timestamp_size - get size of the timestamp in the header page
0159  * @tep: a handle to the tep_handle
0160  *
0161  * This returns size of the timestamp in the header page
0162  * If @tep is NULL, 0 is returned.
0163  */
0164 int tep_get_header_timestamp_size(struct tep_handle *tep)
0165 {
0166     if (tep)
0167         return tep->header_page_ts_size;
0168     return 0;
0169 }
0170 
0171 /**
0172  * tep_get_cpus - get the number of CPUs
0173  * @tep: a handle to the tep_handle
0174  *
0175  * This returns the number of CPUs
0176  * If @tep is NULL, 0 is returned.
0177  */
0178 int tep_get_cpus(struct tep_handle *tep)
0179 {
0180     if (tep)
0181         return tep->cpus;
0182     return 0;
0183 }
0184 
0185 /**
0186  * tep_set_cpus - set the number of CPUs
0187  * @tep: a handle to the tep_handle
0188  *
0189  * This sets the number of CPUs
0190  */
0191 void tep_set_cpus(struct tep_handle *tep, int cpus)
0192 {
0193     if (tep)
0194         tep->cpus = cpus;
0195 }
0196 
0197 /**
0198  * tep_get_long_size - get the size of a long integer on the traced machine
0199  * @tep: a handle to the tep_handle
0200  *
0201  * This returns the size of a long integer on the traced machine
0202  * If @tep is NULL, 0 is returned.
0203  */
0204 int tep_get_long_size(struct tep_handle *tep)
0205 {
0206     if (tep)
0207         return tep->long_size;
0208     return 0;
0209 }
0210 
0211 /**
0212  * tep_set_long_size - set the size of a long integer on the traced machine
0213  * @tep: a handle to the tep_handle
0214  * @size: size, in bytes, of a long integer
0215  *
0216  * This sets the size of a long integer on the traced machine
0217  */
0218 void tep_set_long_size(struct tep_handle *tep, int long_size)
0219 {
0220     if (tep)
0221         tep->long_size = long_size;
0222 }
0223 
0224 /**
0225  * tep_get_page_size - get the size of a memory page on the traced machine
0226  * @tep: a handle to the tep_handle
0227  *
0228  * This returns the size of a memory page on the traced machine
0229  * If @tep is NULL, 0 is returned.
0230  */
0231 int tep_get_page_size(struct tep_handle *tep)
0232 {
0233     if (tep)
0234         return tep->page_size;
0235     return 0;
0236 }
0237 
0238 /**
0239  * tep_set_page_size - set the size of a memory page on the traced machine
0240  * @tep: a handle to the tep_handle
0241  * @_page_size: size of a memory page, in bytes
0242  *
0243  * This sets the size of a memory page on the traced machine
0244  */
0245 void tep_set_page_size(struct tep_handle *tep, int _page_size)
0246 {
0247     if (tep)
0248         tep->page_size = _page_size;
0249 }
0250 
0251 /**
0252  * tep_is_file_bigendian - return the endian of the file
0253  * @tep: a handle to the tep_handle
0254  *
0255  * This returns true if the file is in big endian order
0256  * If @tep is NULL, false is returned.
0257  */
0258 bool tep_is_file_bigendian(struct tep_handle *tep)
0259 {
0260     if (tep)
0261         return (tep->file_bigendian == TEP_BIG_ENDIAN);
0262     return false;
0263 }
0264 
0265 /**
0266  * tep_set_file_bigendian - set if the file is in big endian order
0267  * @tep: a handle to the tep_handle
0268  * @endian: non zero, if the file is in big endian order
0269  *
0270  * This sets if the file is in big endian order
0271  */
0272 void tep_set_file_bigendian(struct tep_handle *tep, enum tep_endian endian)
0273 {
0274     if (tep)
0275         tep->file_bigendian = endian;
0276 }
0277 
0278 /**
0279  * tep_is_local_bigendian - return the endian of the saved local machine
0280  * @tep: a handle to the tep_handle
0281  *
0282  * This returns true if the saved local machine in @tep is big endian.
0283  * If @tep is NULL, false is returned.
0284  */
0285 bool tep_is_local_bigendian(struct tep_handle *tep)
0286 {
0287     if (tep)
0288         return (tep->host_bigendian == TEP_BIG_ENDIAN);
0289     return 0;
0290 }
0291 
0292 /**
0293  * tep_set_local_bigendian - set the stored local machine endian order
0294  * @tep: a handle to the tep_handle
0295  * @endian: non zero, if the local host has big endian order
0296  *
0297  * This sets the endian order for the local machine.
0298  */
0299 void tep_set_local_bigendian(struct tep_handle *tep, enum tep_endian endian)
0300 {
0301     if (tep)
0302         tep->host_bigendian = endian;
0303 }
0304 
0305 /**
0306  * tep_is_old_format - get if an old kernel is used
0307  * @tep: a handle to the tep_handle
0308  *
0309  * This returns true, if an old kernel is used to generate the tracing events or
0310  * false if a new kernel is used. Old kernels did not have header page info.
0311  * If @tep is NULL, false is returned.
0312  */
0313 bool tep_is_old_format(struct tep_handle *tep)
0314 {
0315     if (tep)
0316         return tep->old_format;
0317     return false;
0318 }
0319 
0320 /**
0321  * tep_set_test_filters - set a flag to test a filter string
0322  * @tep: a handle to the tep_handle
0323  * @test_filters: the new value of the test_filters flag
0324  *
0325  * This sets a flag to test a filter string. If this flag is set, when
0326  * tep_filter_add_filter_str() API as called,it will print the filter string
0327  * instead of adding it.
0328  */
0329 void tep_set_test_filters(struct tep_handle *tep, int test_filters)
0330 {
0331     if (tep)
0332         tep->test_filters = test_filters;
0333 }