1LIBTRACECMD(3)                 libtracefs Manual                LIBTRACECMD(3)
2
3
4

NAME

6       tracecmd_read_cpu_first, tracecmd_read_data, tracecmd_read_at,
7       tracecmd_free_record, tracecmd_get_tep - Read recorded events from a
8       trace file.
9

SYNOPSIS

11       #include <trace-cmd.h>
12
13       struct tep_record *tracecmd_read_cpu_first(struct tracecmd_input *handle, int cpu);
14       struct tep_record *tracecmd_read_data(struct tracecmd_input *handle, int cpu);
15       struct tep_record *tracecmd_read_at(struct tracecmd_input *handle, unsigned long long offset, int *cpu);
16       void tracecmd_free_record(struct tep_record *record);
17       struct tep_handle *tracecmd_get_tep(struct tracecmd_input *handle);
18

DESCRIPTION

20       This set of APIs can be used to read tracing data from a trace file
21       opened with tracecmd_open()(3), tracecmd_open_fd()(3) or
22       tracecmd_open_head()(3).
23
24       The tracecmd_read_cpu_first() function reads the first trace record for
25       a given cpu from a trace file associated with handle. The returned
26       record must be freed with tracecmd_free_record().
27
28       The tracecmd_read_data() function reads the next trace record for a
29       given cpu from a trace file associated with handle and increments the
30       read location pointer, so that the next call to tracecmd_read_data()
31       will not read the same record again. The returned record must be freed
32       with tracecmd_free_record().
33
34       The tracecmd_read_at() function reads a trace record from a specific
35       offset within the file associated with handle. The CPU on which the
36       recorded event occurred is stored in the cpu. The function does not
37       change the current read location pointer. The returned record must be
38       freed with tracecmd_free_record().
39
40       The tracecmd_free_record() function frees a record returned by any of
41       the tracecmd_read_ APIs.
42
43       The tracecmd_get_tep() function returns a tep context for a given
44       handle.
45

RETURN VALUE

47       The tracecmd_read_cpu_first(), tracecmd_read_data() and
48       tracecmd_read_at() functions return a pointer to struct tep_record or
49       NULL in case of an error.The returned record must be freed with
50       tracecmd_free_record().
51
52       The tracecmd_get_tep() function returns a pointer to tep context or
53       NULL if there is no tep context for the given handle. The returned tep
54       pointer must not be freed.
55

EXAMPLE

57           #include <trace-cmd.h>
58           ...
59           struct tracecmd_input *handle = tracecmd_open("trace.dat");
60                   if (!handle) {
61                           /* Failed to open trace.dat file */
62                   }
63           ...
64           unsigned long long offset = 0;
65           struct tep_record *rec;
66           int cpu = 0;
67                   rec = tracecmd_read_cpu_first(handle, cpu);
68                   while (rec) {
69                           ...
70                           if ( /* some interesting record noticed */) {
71                                   /* store the offset of the interesting record */
72                                   offset = rec->offset;
73                           }
74                           ...
75                           tracecmd_free_record(rec);
76                           rec = tracecmd_read_data(handle, cpu);
77                   }
78                   ...
79                   if (offset) {
80                           rec = tracecmd_read_at(handle, offset, &cpu);
81                           if (rec) {
82                                   /* Got record at offset on cpu */
83                                   ...
84                                   tracecmd_free_record(rec);
85                           }
86                   }
87
88           ...
89                   tracecmd_close(hadle);
90

FILES

92           trace-cmd.h
93                   Header file to include in order to have access to the library APIs.
94           -ltracecmd
95                   Linker switch to add when building a program that uses the library.
96

SEE ALSO

98       libtracefs(3), libtraceevent(3), trace-cmd(1) trace-cmd.dat(5)
99

AUTHOR

101           Steven Rostedt <rostedt@goodmis.org[1]>
102           Tzvetomir Stoyanov <tz.stoyanov@gmail.com[2]>
103

REPORTING BUGS

105       Report bugs to <linux-trace-devel@vger.kernel.org[3]>
106

LICENSE

108       libtracecmd is Free Software licensed under the GNU LGPL 2.1
109

RESOURCES

111       https://git.kernel.org/pub/scm/utils/trace-cmd/trace-cmd.git/
112

COPYING

114       Copyright (C) 2020 VMware, Inc. Free use of this software is granted
115       under the terms of the GNU Public License (GPL).
116

NOTES

118        1. rostedt@goodmis.org
119           mailto:rostedt@goodmis.org
120
121        2. tz.stoyanov@gmail.com
122           mailto:tz.stoyanov@gmail.com
123
124        3. linux-trace-devel@vger.kernel.org
125           mailto:linux-trace-devel@vger.kernel.org
126
127
128
129libtracefs                        04/15/2022                    LIBTRACECMD(3)
Impressum