• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1libtracecmd(3)
2=============
3
4NAME
5----
6tracecmd_map_vcpus, tracecmd_get_cpu_map, tracecmd_map_find_by_host_pid, tracecmd_map_get_host_pid,
7tracecmd_map_get_guest, tracecmd_map_set_private, tracecmd_map_get_private - Mapping host and guest data
8
9SYNOPSIS
10--------
11[verse]
12--
13*#include <trace-cmd.h>*
14
15int *tracecmd_map_vcpus*(struct tracecmd_input pass:[**]handles, int nr_handles);
16struct tracecmd_cpu_map pass:[*]*tracecmd_get_cpu_map*(struct tracecmd_input pass:[*]handle, int cpu);
17struct tracecmd_cpu_map pass:[*]*tracecmd_map_find_by_host_pid*(struct tracecmd_input pass:[*]handle,
18						      int host_pid);
19int *tracecmd_map_get_host_pid*(struct tracecmd_cpu_map pass:[*]map);
20struct tracecmd_input pass:[*]*tracecmd_map_get_guest*(struct tracecmd_cpu_map pass:[*]map);
21void *tracecmd_map_set_private*(struct tracecmd_cpu_map pass:[*]map, void pass:[*]priv);
22void pass:[*]*tracecmd_map_get_private*(struct tracecmd_cpu_map pass:[*]map);
23--
24
25DESCRIPTION
26-----------
27This set of APIs is used to map host and guest trace files for to facilitate
28further tracing analysis.
29
30The *tracecmd_map_vcpus()* takes an array of _handles_ where each item in that
31array was created by one of the *tracecmd_open(3)* functions, and the number
32of handles as _nr_handles_. The first handle in the array of _handles_ is expected
33to be the descriptor for the host tracing file, and the rest are guest trace
34files that run on the host, and were created by the *trace-cmd record(1)* and
35*trace-cmd agent(1)* interactions. It returns the number of guests found in
36_handles_ that were associated with the host, or negative on error.
37
38The *tracecmd_get_cpu_map()* returns a descriptor for a given CPU for a handle.
39If the _handle_ was a guest defined from *tracecmd_map_vcpus()* then the mapping
40created from that function that is associated to this particular vCPU (denoted by
41_cpu_) from _handle_. This destriptor can be used by *tarcecmd_map_get_guest()*,
42*tracecmd_map_set_private()* and *tracecmd_map_get_private()* functions.
43
44The *tracecmd_map_find_by_host_pid()* will return a mapping for a guest virtual
45CPU that is handled by the given _host_pid_. Note, the _handle_ passed in can be
46either the host handle or one of the guest's handles for that host that was
47mapped by *tracecmd_map_vcpus()*, even if the guest handle does not have the vCPU
48that the _host_pid_ represents.
49
50The *tracecmd_map_get_host_pid()* will recturn the host_pid for a given _map_
51that was retrieved by one of the above functions.
52
53The *tracecmd_map_get_guest()* will recturn the guest_handle for a given _map_
54that was retrieved by one of the above functions.
55
56The *tracecmd_map_set_private()* allows the application to assign private data
57for a given guest vCPU to host thread mapping defined by _map_.
58
59The *tracecmd_map_get_private()* retrieves the _priv_ data from _map_ that was
60set by *tracecmd_map_set_private()*.
61
62RETURN VALUE
63------------
64*tracecmd_map_vcpus()* returns the number of guests in the _handles_ array that
65were mapped to the host handle that is the first entry in _handles_. It returns
66-1 on error.
67
68*tracecmd_get_cpu_map()* returns a map created by *tracecmd_map_vcpus()* for
69a given _cpu_ for a given _handle_, or NULL if it is not found.
70
71*tracecmd_map_find_by_host_pid()* returns a map that is associated by the host
72task with _host_pid_ as its process ID. _handle_ can be either a the host
73handle, or one of the guest handles that were mapped to the host via
74*tracecmd_map_vcpus()*, even if the guest handle is another guest than
75the one that the mapping is for. It returns NULL if not found.
76
77*tracecmd_map_get_host_pid()* returns the host process ID for an associated
78mapping defined by _map_.
79
80*tracecmd_map_get_guest()* returns the guest handle for an associated
81mapping defined by _map_.
82
83*tracecmd_map_get_private()* returns the private data of a mapping defined
84by _map_ that was set by *tracecmd_map_set_private()*.
85
86EXAMPLE
87-------
88[source,c]
89--
90#include <stdlib.h>
91#include <errno.h>
92#include <trace-cmd.h>
93
94int main(int argc, char **argv)
95{
96	struct tracecmd_input **handles = NULL;
97	int nr_handles;
98	int i;
99
100	if (argc < 2) {
101		printf("usage: host_trace.dat guest1_trace.dat [guest2_trace.dat ...]\n");
102		exit(-1);
103	}
104
105	for (i = 1; i < argc; i++) {
106		handles = realloc(handles, sizeof(*handles) * (nr_handles + 1));
107		if (!handles)
108			exit(-1);
109		handles[nr_handles] = tracecmd_open(argv[i], 0);
110		if (!handles[nr_handles]) {
111			perror(argv[1]);
112			exit(-1);
113		}
114		tracecmd_set_private(handles[nr_handles], argv[i]);
115		nr_handles++;
116	}
117
118	tracecmd_map_vcpus(handles, nr_handles);
119
120	for (i = 1; i < nr_handles; i++) {
121		struct tracecmd_cpu_map *map;
122		struct tep_handle *tep;
123		const char *file = tracecmd_get_private(handles[i]);
124		int cpus, cpu;
125
126		printf("Mappings for guest %s:\n", file);
127		tep = tracecmd_get_tep(handles[i]);
128		cpus = tep_get_cpus(tep);
129		for (cpu = 0; cpu < cpus; cpu++) {
130			printf("  [%03d] ", cpu);
131			map = tracecmd_get_cpu_map(handles[i], cpu);
132			if (!map) {
133				printf("Has no mapping!\n");
134				continue;
135			}
136			printf("host_pid: %d\n", tracecmd_map_get_host_pid(map));
137		}
138	}
139	for (i = 0; i < nr_handles; i++)
140		tracecmd_close(handles[i]);
141	free(handles);
142	exit(0);
143}
144--
145FILES
146-----
147[verse]
148--
149*trace-cmd.h*
150	Header file to include in order to have access to the library APIs.
151*-ltracecmd*
152	Linker switch to add when building a program that uses the library.
153--
154
155SEE ALSO
156--------
157*libtracefs(3)*,
158*libtraceevent(3)*,
159*trace-cmd(1)*
160*trace-cmd.dat(5)*
161
162REPORTING BUGS
163--------------
164Report bugs to  <linux-trace-devel@vger.kernel.org>
165
166LICENSE
167-------
168libtracecmd is Free Software licensed under the GNU LGPL 2.1
169
170RESOURCES
171---------
172https://git.kernel.org/pub/scm/utils/trace-cmd/trace-cmd.git/
173
174COPYING
175-------
176Copyright \(C) 2020 VMware, Inc. Free use of this software is granted under
177the terms of the GNU Public License (GPL).
178