xref: /aosp_15_r20/external/trace-cmd/Documentation/libtracecmd/libtracecmd-record.txt (revision 58e6ee5f017f6a8912852c892d18457e4bafb554)
1libtracecmd(3)
2=============
3
4NAME
5----
6tracecmd_read_cpu_first, tracecmd_read_data, tracecmd_read_at,
7tracecmd_free_record, tracecmd_get_tep - Read recorded events from a trace file.
8
9SYNOPSIS
10--------
11[verse]
12--
13*#include <trace-cmd.h>*
14
15struct tep_record pass:[*]*tracecmd_read_cpu_first*(struct tracecmd_input pass:[*]_handle_, int _cpu_);
16struct tep_record pass:[*]*tracecmd_read_data*(struct tracecmd_input pass:[*]_handle_, int _cpu_);
17struct tep_record pass:[*]*tracecmd_read_at*(struct tracecmd_input pass:[*]_handle_, unsigned long long _offset_, int pass:[*]_cpu_);
18void *tracecmd_free_record*(struct tep_record pass:[*]_record_);
19struct tep_handle pass:[*]*tracecmd_get_tep*(struct tracecmd_input pass:[*]_handle_);
20--
21
22DESCRIPTION
23-----------
24This set of APIs can be used to read tracing data from a trace file opened
25with _tracecmd_open()(3)_, _tracecmd_open_fd()(3)_ or _tracecmd_open_head()(3)_.
26
27The _tracecmd_read_cpu_first()_ function reads the first trace record
28for a given _cpu_ from a trace file associated with _handle_. The returned
29record must be freed with _tracecmd_free_record()_.
30
31The _tracecmd_read_data()_ function reads the next trace record for
32a given _cpu_ from a trace file associated with _handle_ and increments
33the read location pointer, so that the next call to _tracecmd_read_data()_
34will not read the same record again. The returned record must be freed
35with _tracecmd_free_record()_.
36
37The _tracecmd_read_at()_ function reads a trace record from a specific
38_offset_ within the file associated with _handle_. The CPU on which the
39recorded event occurred is stored in the _cpu_. The function does not
40change the current read location pointer. The returned record must be
41freed with _tracecmd_free_record()_.
42
43The _tracecmd_free_record()_ function frees a _record_ returned by any
44of the _tracecmd_read__ APIs.
45
46The _tracecmd_get_tep()_ function returns a tep context for a given
47_handle_.
48
49RETURN VALUE
50------------
51The _tracecmd_read_cpu_first()_, _tracecmd_read_data()_ and
52_tracecmd_read_at()_ functions return a pointer to struct tep_record or
53NULL in case of an error.The returned record must be freed with
54_tracecmd_free_record()_.
55
56The _tracecmd_get_tep()_ function returns a pointer to tep context or
57NULL if there is no tep context for the given _handle_. The returned
58tep pointer must *not* be freed.
59
60EXAMPLE
61-------
62[source,c]
63--
64#include <trace-cmd.h>
65...
66struct tracecmd_input *handle = tracecmd_open("trace.dat");
67	if (!handle) {
68		/* Failed to open trace.dat file */
69	}
70...
71unsigned long long offset = 0;
72struct tep_record *rec;
73int cpu = 0;
74	rec = tracecmd_read_cpu_first(handle, cpu);
75	while (rec) {
76		...
77		if ( /* some interesting record noticed */) {
78			/* store the offset of the interesting record */
79			offset = rec->offset;
80		}
81		...
82		tracecmd_free_record(rec);
83		rec = tracecmd_read_data(handle, cpu);
84	}
85	...
86	if (offset) {
87		rec = tracecmd_read_at(handle, offset, &cpu);
88		if (rec) {
89			/* Got record at offset on cpu */
90			...
91			tracecmd_free_record(rec);
92		}
93	}
94
95...
96	tracecmd_close(hadle);
97
98--
99FILES
100-----
101[verse]
102--
103*trace-cmd.h*
104	Header file to include in order to have access to the library APIs.
105*-ltracecmd*
106	Linker switch to add when building a program that uses the library.
107--
108
109SEE ALSO
110--------
111_libtracefs(3)_,
112_libtraceevent(3)_,
113_trace-cmd(1)_
114_trace-cmd.dat(5)_
115
116AUTHOR
117------
118[verse]
119--
120*Steven Rostedt* <[email protected]>
121*Tzvetomir Stoyanov* <[email protected]>
122--
123REPORTING BUGS
124--------------
125Report bugs to  <[email protected]>
126
127LICENSE
128-------
129libtracecmd is Free Software licensed under the GNU LGPL 2.1
130
131RESOURCES
132---------
133https://git.kernel.org/pub/scm/utils/trace-cmd/trace-cmd.git/
134
135COPYING
136-------
137Copyright \(C) 2020 VMware, Inc. Free use of this software is granted under
138the terms of the GNU Public License (GPL).
139