@@ -370,16 +370,20 @@ bool tracecmd_msg_done(struct tracecmd_msg_handle *msg_handle);
void tracecmd_msg_set_done(struct tracecmd_msg_handle *msg_handle);
int tracecmd_msg_send_trace_req(struct tracecmd_msg_handle *msg_handle,
- int argc, char **argv, bool use_fifos);
+ int argc, char **argv, bool use_fifos,
+ unsigned long long trace_id);
int tracecmd_msg_recv_trace_req(struct tracecmd_msg_handle *msg_handle,
- int *argc, char ***argv, bool *use_fifos);
+ int *argc, char ***argv, bool *use_fifos,
+ unsigned long long *trace_id);
int tracecmd_msg_send_trace_resp(struct tracecmd_msg_handle *msg_handle,
int nr_cpus, int page_size,
- unsigned int *ports, bool use_fifos);
+ unsigned int *ports, bool use_fifos,
+ unsigned long long trace_id);
int tracecmd_msg_recv_trace_resp(struct tracecmd_msg_handle *msg_handle,
int *nr_cpus, int *page_size,
- unsigned int **ports, bool *use_fifos);
+ unsigned int **ports, bool *use_fifos,
+ unsigned long long *trace_id);
/* --- Plugin handling --- */
extern struct tep_plugin_option trace_ftrace_options[];
@@ -23,6 +23,7 @@
#include <linux/types.h>
#include "trace-write-local.h"
+#include "trace-cmd-local.h"
#include "trace-local.h"
#include "trace-msg.h"
@@ -63,12 +64,14 @@ struct tracecmd_msg_rinit {
struct tracecmd_msg_trace_req {
be32 flags;
be32 argc;
+ u64 trace_id;
} __attribute__((packed));
struct tracecmd_msg_trace_resp {
be32 flags;
be32 cpus;
be32 page_size;
+ u64 trace_id;
} __attribute__((packed));
struct tracecmd_msg_header {
@@ -811,7 +814,8 @@ int tracecmd_msg_wait_close_resp(struct tracecmd_msg_handle *msg_handle)
return tracecmd_msg_wait_for_cmd(msg_handle, MSG_CLOSE_RESP);
}
-static int make_trace_req(struct tracecmd_msg *msg, int argc, char **argv, bool use_fifos)
+static int make_trace_req(struct tracecmd_msg *msg, int argc, char **argv,
+ bool use_fifos, unsigned long long trace_id)
{
size_t args_size = 0;
char *p;
@@ -823,6 +827,7 @@ static int make_trace_req(struct tracecmd_msg *msg, int argc, char **argv, bool
msg->hdr.size = htonl(ntohl(msg->hdr.size) + args_size);
msg->trace_req.flags = use_fifos ? htonl(MSG_TRACE_USE_FIFOS) : htonl(0);
msg->trace_req.argc = htonl(argc);
+ msg->trace_req.trace_id = htonll(trace_id);
msg->buf = calloc(args_size, 1);
if (!msg->buf)
return -ENOMEM;
@@ -835,13 +840,14 @@ static int make_trace_req(struct tracecmd_msg *msg, int argc, char **argv, bool
}
int tracecmd_msg_send_trace_req(struct tracecmd_msg_handle *msg_handle,
- int argc, char **argv, bool use_fifos)
+ int argc, char **argv, bool use_fifos,
+ unsigned long long trace_id)
{
struct tracecmd_msg msg;
int ret;
tracecmd_msg_init(MSG_TRACE_REQ, &msg);
- ret = make_trace_req(&msg, argc, argv, use_fifos);
+ ret = make_trace_req(&msg, argc, argv, use_fifos, trace_id);
if (ret < 0)
return ret;
@@ -854,7 +860,8 @@ int tracecmd_msg_send_trace_req(struct tracecmd_msg_handle *msg_handle,
* free(argv);
*/
int tracecmd_msg_recv_trace_req(struct tracecmd_msg_handle *msg_handle,
- int *argc, char ***argv, bool *use_fifos)
+ int *argc, char ***argv, bool *use_fifos,
+ unsigned long long *trace_id)
{
struct tracecmd_msg msg;
char *p, *buf_end, **args;
@@ -901,7 +908,7 @@ int tracecmd_msg_recv_trace_req(struct tracecmd_msg_handle *msg_handle,
*argc = nr_args;
*argv = args;
*use_fifos = ntohl(msg.trace_req.flags) & MSG_TRACE_USE_FIFOS;
-
+ *trace_id = ntohll(msg.trace_req.trace_id);
/*
* On success we're passing msg.buf to the caller through argv[0] so we
* reset it here before calling msg_free().
@@ -921,7 +928,8 @@ out:
}
static int make_trace_resp(struct tracecmd_msg *msg, int page_size, int nr_cpus,
- unsigned int *ports, bool use_fifos)
+ unsigned int *ports, bool use_fifos,
+ unsigned long long trace_id)
{
int data_size;
@@ -935,19 +943,22 @@ static int make_trace_resp(struct tracecmd_msg *msg, int page_size, int nr_cpus,
msg->trace_resp.flags = use_fifos ? htonl(MSG_TRACE_USE_FIFOS) : htonl(0);
msg->trace_resp.cpus = htonl(nr_cpus);
msg->trace_resp.page_size = htonl(page_size);
+ msg->trace_resp.trace_id = htonll(trace_id);
return 0;
}
int tracecmd_msg_send_trace_resp(struct tracecmd_msg_handle *msg_handle,
int nr_cpus, int page_size,
- unsigned int *ports, bool use_fifos)
+ unsigned int *ports, bool use_fifos,
+ unsigned long long trace_id)
{
struct tracecmd_msg msg;
int ret;
tracecmd_msg_init(MSG_TRACE_RESP, &msg);
- ret = make_trace_resp(&msg, page_size, nr_cpus, ports, use_fifos);
+ ret = make_trace_resp(&msg, page_size, nr_cpus, ports,
+ use_fifos, trace_id);
if (ret < 0)
return ret;
@@ -956,7 +967,8 @@ int tracecmd_msg_send_trace_resp(struct tracecmd_msg_handle *msg_handle,
int tracecmd_msg_recv_trace_resp(struct tracecmd_msg_handle *msg_handle,
int *nr_cpus, int *page_size,
- unsigned int **ports, bool *use_fifos)
+ unsigned int **ports, bool *use_fifos,
+ unsigned long long *trace_id)
{
struct tracecmd_msg msg;
char *p, *buf_end;
@@ -981,6 +993,7 @@ int tracecmd_msg_recv_trace_resp(struct tracecmd_msg_handle *msg_handle,
*use_fifos = ntohl(msg.trace_resp.flags) & MSG_TRACE_USE_FIFOS;
*nr_cpus = ntohl(msg.trace_resp.cpus);
*page_size = ntohl(msg.trace_resp.page_size);
+ *trace_id = ntohll(msg.trace_resp.trace_id);
*ports = calloc(*nr_cpus, sizeof(**ports));
if (!*ports) {
ret = -ENOMEM;
@@ -101,7 +101,8 @@ void trace_dump(int argc, char **argv);
int trace_record_agent(struct tracecmd_msg_handle *msg_handle,
int cpus, int *fds,
- int argc, char **argv, bool use_fifos);
+ int argc, char **argv, bool use_fifos,
+ unsigned long long trace_id);
struct hook_list;
@@ -128,6 +128,7 @@ cleanup:
static void agent_handle(int sd, int nr_cpus, int page_size)
{
struct tracecmd_msg_handle *msg_handle;
+ unsigned long long trace_id;
unsigned int *ports;
char **argv = NULL;
int argc = 0;
@@ -144,7 +145,8 @@ static void agent_handle(int sd, int nr_cpus, int page_size)
if (!msg_handle)
die("Failed to allocate message handle");
- ret = tracecmd_msg_recv_trace_req(msg_handle, &argc, &argv, &use_fifos);
+ ret = tracecmd_msg_recv_trace_req(msg_handle, &argc, &argv,
+ &use_fifos, &trace_id);
if (ret < 0)
die("Failed to receive trace request");
@@ -154,12 +156,14 @@ static void agent_handle(int sd, int nr_cpus, int page_size)
if (!use_fifos)
make_vsocks(nr_cpus, fds, ports);
+ trace_id = tracecmd_generate_traceid();
ret = tracecmd_msg_send_trace_resp(msg_handle, nr_cpus, page_size,
- ports, use_fifos);
+ ports, use_fifos, trace_id);
if (ret < 0)
die("Failed to send trace response");
- trace_record_agent(msg_handle, nr_cpus, fds, argc, argv, use_fifos);
+ trace_record_agent(msg_handle, nr_cpus, fds, argc, argv,
+ use_fifos, trace_id);
free(argv[0]);
free(argv);
@@ -3686,12 +3686,14 @@ static void connect_to_agent(struct buffer_instance *instance)
die("Failed to allocate message handle");
ret = tracecmd_msg_send_trace_req(msg_handle, instance->argc,
- instance->argv, use_fifos);
+ instance->argv, use_fifos,
+ top_instance.trace_id);
if (ret < 0)
die("Failed to send trace request");
ret = tracecmd_msg_recv_trace_resp(msg_handle, &nr_cpus, &page_size,
- &ports, &use_fifos);
+ &ports, &use_fifos,
+ &instance->trace_id);
if (ret < 0)
die("Failed to receive trace response");
@@ -6237,7 +6239,8 @@ void trace_record(int argc, char **argv)
int trace_record_agent(struct tracecmd_msg_handle *msg_handle,
int cpus, int *fds,
int argc, char **argv,
- bool use_fifos)
+ bool use_fifos,
+ unsigned long long trace_id)
{
struct common_record_context ctx;
char **argv_plus;
@@ -6267,6 +6270,7 @@ int trace_record_agent(struct tracecmd_msg_handle *msg_handle,
ctx.instance->flags |= BUFFER_FL_AGENT;
ctx.instance->msg_handle = msg_handle;
msg_handle->version = V3_PROTOCOL;
+ top_instance.trace_id = trace_id;
record_trace(argc, argv, &ctx);
free(argv_plus);
Extend the trace request and trace reply messages, to include also the IDs of host and guest tracing sessions. Those IDs are used to unambiguously match the tracing sessions, when reading trace.dat files. Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com> --- include/trace-cmd/trace-cmd.h | 12 ++++++++---- lib/trace-cmd/trace-msg.c | 31 ++++++++++++++++++++++--------- tracecmd/include/trace-local.h | 3 ++- tracecmd/trace-agent.c | 10 +++++++--- tracecmd/trace-record.c | 10 +++++++--- 5 files changed, 46 insertions(+), 20 deletions(-)