xref: /aosp_15_r20/external/libtraceevent/Documentation/libtraceevent-field_get_val.txt (revision 436bf2bcd5202612ffffe471bbcc1f277cc8d28e)
1*436bf2bcSAndroid Build Coastguard Workerlibtraceevent(3)
2*436bf2bcSAndroid Build Coastguard Worker================
3*436bf2bcSAndroid Build Coastguard Worker
4*436bf2bcSAndroid Build Coastguard WorkerNAME
5*436bf2bcSAndroid Build Coastguard Worker----
6*436bf2bcSAndroid Build Coastguard Workertep_get_any_field_val, tep_get_common_field_val, tep_get_field_val,
7*436bf2bcSAndroid Build Coastguard Workertep_get_field_raw - Get value of a field.
8*436bf2bcSAndroid Build Coastguard Worker
9*436bf2bcSAndroid Build Coastguard WorkerSYNOPSIS
10*436bf2bcSAndroid Build Coastguard Worker--------
11*436bf2bcSAndroid Build Coastguard Worker[verse]
12*436bf2bcSAndroid Build Coastguard Worker--
13*436bf2bcSAndroid Build Coastguard Worker*#include <event-parse.h>*
14*436bf2bcSAndroid Build Coastguard Worker*#include <trace-seq.h>*
15*436bf2bcSAndroid Build Coastguard Worker
16*436bf2bcSAndroid Build Coastguard Workerint *tep_get_any_field_val*(struct trace_seq pass:[*]_s_, struct tep_event pass:[*]_event_, const char pass:[*]_name_, struct tep_record pass:[*]_record_, unsigned long long pass:[*]_val_, int _err_);
17*436bf2bcSAndroid Build Coastguard Workerint *tep_get_common_field_val*(struct trace_seq pass:[*]_s_, struct tep_event pass:[*]_event_, const char pass:[*]_name_, struct tep_record pass:[*]_record_, unsigned long long pass:[*]_val_, int _err_);
18*436bf2bcSAndroid Build Coastguard Workerint *tep_get_field_val*(struct trace_seq pass:[*]_s_, struct tep_event pass:[*]_event_, const char pass:[*]_name_, struct tep_record pass:[*]_record_, unsigned long long pass:[*]_val_, int _err_);
19*436bf2bcSAndroid Build Coastguard Workervoid pass:[*]*tep_get_field_raw*(struct trace_seq pass:[*]_s_, struct tep_event pass:[*]_event_, const char pass:[*]_name_, struct tep_record pass:[*]_record_, int pass:[*]_len_, int _err_);
20*436bf2bcSAndroid Build Coastguard Worker--
21*436bf2bcSAndroid Build Coastguard Worker
22*436bf2bcSAndroid Build Coastguard WorkerDESCRIPTION
23*436bf2bcSAndroid Build Coastguard Worker-----------
24*436bf2bcSAndroid Build Coastguard WorkerThese functions can be used to find a field and retrieve its value.
25*436bf2bcSAndroid Build Coastguard Worker
26*436bf2bcSAndroid Build Coastguard WorkerThe *tep_get_any_field_val()* function searches in the _record_ for a field
27*436bf2bcSAndroid Build Coastguard Workerwith _name_, part of the _event_. If the field is found, its value is stored in
28*436bf2bcSAndroid Build Coastguard Worker_val_. If there is an error and _err_ is not zero, then an error string is
29*436bf2bcSAndroid Build Coastguard Workerwritten into _s_.
30*436bf2bcSAndroid Build Coastguard Worker
31*436bf2bcSAndroid Build Coastguard WorkerThe *tep_get_common_field_val()* function does the same as
32*436bf2bcSAndroid Build Coastguard Worker*tep_get_any_field_val()*, but searches only in the common fields. This works
33*436bf2bcSAndroid Build Coastguard Workerfor any event as all events include the common fields.
34*436bf2bcSAndroid Build Coastguard Worker
35*436bf2bcSAndroid Build Coastguard WorkerThe *tep_get_field_val()* function does the same as *tep_get_any_field_val()*,
36*436bf2bcSAndroid Build Coastguard Workerbut searches only in the event specific fields.
37*436bf2bcSAndroid Build Coastguard Worker
38*436bf2bcSAndroid Build Coastguard WorkerThe *tep_get_field_raw()* function searches in the _record_ for a field with
39*436bf2bcSAndroid Build Coastguard Worker_name_, part of the _event_. If the field is found, a pointer to where the field
40*436bf2bcSAndroid Build Coastguard Workerexists in the record's raw data is returned. The size of the data is stored in
41*436bf2bcSAndroid Build Coastguard Worker_len_. If there is an error and _err_ is not zero, then an error string is
42*436bf2bcSAndroid Build Coastguard Workerwritten into _s_.
43*436bf2bcSAndroid Build Coastguard Worker
44*436bf2bcSAndroid Build Coastguard WorkerRETURN VALUE
45*436bf2bcSAndroid Build Coastguard Worker------------
46*436bf2bcSAndroid Build Coastguard WorkerThe *tep_get_any_field_val()*, *tep_get_common_field_val()* and
47*436bf2bcSAndroid Build Coastguard Worker*tep_get_field_val()* functions return 0 on success, or -1 in case of an error.
48*436bf2bcSAndroid Build Coastguard Worker
49*436bf2bcSAndroid Build Coastguard WorkerThe *tep_get_field_raw()* function returns a pointer to field's raw data, and
50*436bf2bcSAndroid Build Coastguard Workerplaces the length of this data in _len_. In case of an error NULL is returned.
51*436bf2bcSAndroid Build Coastguard Worker
52*436bf2bcSAndroid Build Coastguard WorkerEXAMPLE
53*436bf2bcSAndroid Build Coastguard Worker-------
54*436bf2bcSAndroid Build Coastguard Worker[source,c]
55*436bf2bcSAndroid Build Coastguard Worker--
56*436bf2bcSAndroid Build Coastguard Worker#include <event-parse.h>
57*436bf2bcSAndroid Build Coastguard Worker#include <trace-seq.h>
58*436bf2bcSAndroid Build Coastguard Worker...
59*436bf2bcSAndroid Build Coastguard Workerstruct tep_handle *tep = tep_alloc();
60*436bf2bcSAndroid Build Coastguard Worker...
61*436bf2bcSAndroid Build Coastguard Workerstruct tep_event *event = tep_find_event_by_name(tep, "kvm", "kvm_exit");
62*436bf2bcSAndroid Build Coastguard Worker...
63*436bf2bcSAndroid Build Coastguard Workervoid process_record(struct tep_record *record)
64*436bf2bcSAndroid Build Coastguard Worker{
65*436bf2bcSAndroid Build Coastguard Worker	int len;
66*436bf2bcSAndroid Build Coastguard Worker	char *comm;
67*436bf2bcSAndroid Build Coastguard Worker	struct tep_event *event;
68*436bf2bcSAndroid Build Coastguard Worker	unsigned long long val;
69*436bf2bcSAndroid Build Coastguard Worker
70*436bf2bcSAndroid Build Coastguard Worker	event = tep_find_event_by_record(tep, record);
71*436bf2bcSAndroid Build Coastguard Worker	if (event != NULL) {
72*436bf2bcSAndroid Build Coastguard Worker		if (tep_get_common_field_val(NULL, event, "common_type",
73*436bf2bcSAndroid Build Coastguard Worker					     record, &val, 0) == 0) {
74*436bf2bcSAndroid Build Coastguard Worker			/* Got the value of common type field */
75*436bf2bcSAndroid Build Coastguard Worker		}
76*436bf2bcSAndroid Build Coastguard Worker		if (tep_get_field_val(NULL, event, "pid", record, &val, 0) == 0) {
77*436bf2bcSAndroid Build Coastguard Worker			/* Got the value of pid specific field */
78*436bf2bcSAndroid Build Coastguard Worker		}
79*436bf2bcSAndroid Build Coastguard Worker		comm = tep_get_field_raw(NULL, event, "comm", record, &len, 0);
80*436bf2bcSAndroid Build Coastguard Worker		if (comm != NULL) {
81*436bf2bcSAndroid Build Coastguard Worker			/* Got a pointer to the comm event specific field */
82*436bf2bcSAndroid Build Coastguard Worker		}
83*436bf2bcSAndroid Build Coastguard Worker	}
84*436bf2bcSAndroid Build Coastguard Worker}
85*436bf2bcSAndroid Build Coastguard Worker--
86*436bf2bcSAndroid Build Coastguard Worker
87*436bf2bcSAndroid Build Coastguard WorkerFILES
88*436bf2bcSAndroid Build Coastguard Worker-----
89*436bf2bcSAndroid Build Coastguard Worker[verse]
90*436bf2bcSAndroid Build Coastguard Worker--
91*436bf2bcSAndroid Build Coastguard Worker*event-parse.h*
92*436bf2bcSAndroid Build Coastguard Worker	Header file to include in order to have access to the library APIs.
93*436bf2bcSAndroid Build Coastguard Worker*trace-seq.h*
94*436bf2bcSAndroid Build Coastguard Worker	Header file to include in order to have access to trace sequences
95*436bf2bcSAndroid Build Coastguard Worker	related APIs. Trace sequences are used to allow a function to call
96*436bf2bcSAndroid Build Coastguard Worker	several other functions to create a string of data to use.
97*436bf2bcSAndroid Build Coastguard Worker*-ltraceevent*
98*436bf2bcSAndroid Build Coastguard Worker	Linker switch to add when building a program that uses the library.
99*436bf2bcSAndroid Build Coastguard Worker--
100*436bf2bcSAndroid Build Coastguard Worker
101*436bf2bcSAndroid Build Coastguard WorkerSEE ALSO
102*436bf2bcSAndroid Build Coastguard Worker--------
103*436bf2bcSAndroid Build Coastguard Worker*libtraceevent*(3), *trace-cmd*(1)
104*436bf2bcSAndroid Build Coastguard Worker
105*436bf2bcSAndroid Build Coastguard WorkerAUTHOR
106*436bf2bcSAndroid Build Coastguard Worker------
107*436bf2bcSAndroid Build Coastguard Worker[verse]
108*436bf2bcSAndroid Build Coastguard Worker--
109*436bf2bcSAndroid Build Coastguard Worker*Steven Rostedt* <[email protected]>, author of *libtraceevent*.
110*436bf2bcSAndroid Build Coastguard Worker*Tzvetomir Stoyanov* <[email protected]>, author of this man page.
111*436bf2bcSAndroid Build Coastguard Worker--
112*436bf2bcSAndroid Build Coastguard WorkerREPORTING BUGS
113*436bf2bcSAndroid Build Coastguard Worker--------------
114*436bf2bcSAndroid Build Coastguard WorkerReport bugs to  <[email protected]>
115*436bf2bcSAndroid Build Coastguard Worker
116*436bf2bcSAndroid Build Coastguard WorkerLICENSE
117*436bf2bcSAndroid Build Coastguard Worker-------
118*436bf2bcSAndroid Build Coastguard Workerlibtraceevent is Free Software licensed under the GNU LGPL 2.1
119*436bf2bcSAndroid Build Coastguard Worker
120*436bf2bcSAndroid Build Coastguard WorkerRESOURCES
121*436bf2bcSAndroid Build Coastguard Worker---------
122*436bf2bcSAndroid Build Coastguard Workerhttps://git.kernel.org/pub/scm/libs/libtrace/libtraceevent.git/
123