From: Pierre-Marc Fournier Date: Fri, 15 Jan 2010 22:56:52 +0000 (-0500) Subject: Add --create-trace option to ustctl X-Git-Tag: v0.1~7 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=62ec620f40891af46d0ee4768992275dc7b28433;p=ust.git Add --create-trace option to ustctl --- diff --git a/libust/tracectl.c b/libust/tracectl.c index 80d09ae..873b0f6 100644 --- a/libust/tracectl.c +++ b/libust/tracectl.c @@ -370,6 +370,29 @@ void *listener_main(void *p) return (void *)1; } } + else if(!strcmp(recvbuf, "trace_create")) { + DBG("trace create"); + + result = ltt_trace_setup(trace_name); + if(result < 0) { + ERR("ltt_trace_setup failed"); + return (void *)1; + } + + result = ltt_trace_set_type(trace_name, trace_type); + if(result < 0) { + ERR("ltt_trace_set_type failed"); + return (void *)1; + } + + result = ltt_trace_alloc(trace_name); + if(result < 0) { + ERR("ltt_trace_alloc failed"); + return (void *)1; + } + + inform_consumer_daemon(trace_name); + } else if(!strcmp(recvbuf, "trace_start")) { DBG("trace start"); diff --git a/libustcmd/ustcmd.c b/libustcmd/ustcmd.c index d573a7f..d22fb52 100644 --- a/libustcmd/ustcmd.c +++ b/libustcmd/ustcmd.c @@ -137,6 +137,24 @@ int ustcmd_setup_and_start(pid_t pid) return 0; } +/** + * Creates an UST trace according to a PID. + * + * @param pid Traced process ID + * @return 0 if successful, or error USTCMD_ERR_GEN + */ +int ustcmd_create_trace(pid_t pid) +{ + int result; + + result = ustcmd_send_cmd("trace_create", pid, NULL); + if (result) { + return USTCMD_ERR_GEN; + } + + return 0; +} + /** * Starts an UST trace according to a PID. * diff --git a/libustcmd/ustcmd.h b/libustcmd/ustcmd.h index da4718b..a494bcf 100644 --- a/libustcmd/ustcmd.h +++ b/libustcmd/ustcmd.h @@ -34,6 +34,7 @@ extern int ustcmd_set_marker_state(const char *, int, pid_t); extern int ustcmd_destroy_trace(pid_t); extern int ustcmd_setup_and_start(pid_t); extern int ustcmd_stop_trace(pid_t); +extern int ustcmd_create_trace(pid_t); extern int ustcmd_start_trace(pid_t); extern int ustcmd_free_cmsf(struct marker_status *); extern unsigned int ustcmd_count_nl(const char *); diff --git a/ustctl/ustctl.c b/ustctl/ustctl.c index 789dfe0..3ff2fb7 100644 --- a/ustctl/ustctl.c +++ b/ustctl/ustctl.c @@ -27,6 +27,7 @@ #include "usterr.h" enum command { + CREATE_TRACE, START_TRACE, STOP_TRACE, START, @@ -52,6 +53,7 @@ void usage(void) fprintf(stderr, "\nControl the tracing of a process that supports LTTng Userspace Tracing.\n\ \n\ Commands:\n\ + --create-trace\t\t\tCreate trace\n\ --start-trace\t\t\tStart tracing\n\ --stop-trace\t\t\tStop tracing\n\ --destroy-trace\t\t\tDestroy the trace\n\ @@ -72,6 +74,7 @@ int parse_opts_long(int argc, char **argv, struct ust_opts *opts) while (1) { int option_index = 0; static struct option long_options[] = { + {"create-trace", 0, 0, 1012}, {"start-trace", 0, 0, 1000}, {"stop-trace", 0, 0, 1001}, {"destroy-trace", 0, 0, 1002}, @@ -130,7 +133,10 @@ int parse_opts_long(int argc, char **argv, struct ust_opts *opts) exit(0); case 1010: printf("Version 0.1\n"); - + break; + case 1012: + opts->cmd = CREATE_TRACE; + break; default: /* unknown option or other error; error is printed by getopt, just return */ @@ -212,6 +218,14 @@ int main(int argc, char *argv[]) while(*pidit != -1) { switch (opts.cmd) { + case CREATE_TRACE: + result = ustcmd_create_trace(*pidit); + if (result) { + ERR("error while trying to create trace with PID %u\n", (unsigned int) *pidit); + break; + } + break; + case START_TRACE: result = ustcmd_start_trace(*pidit); if (result) {