X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fbin%2Flttng%2Fcommands%2Flist.c;h=4def4e7a2ee3aa050599a661aeb162d5c2d179cb;hp=7698bb6ed12515555ffc3bf72e7541e3d3cf3f85;hb=ae8564917fa3cb3497ec17951d8ac0ee28de9c81;hpb=c399183f4b3257c43915f3d81f44befd23165ad9 diff --git a/src/bin/lttng/commands/list.c b/src/bin/lttng/commands/list.c index 7698bb6ed..4def4e7a2 100644 --- a/src/bin/lttng/commands/list.c +++ b/src/bin/lttng/commands/list.c @@ -26,12 +26,15 @@ #include "../command.h" -static int opt_pid; static int opt_userspace; -static char *opt_cmd_name; static int opt_kernel; static char *opt_channel; static int opt_domain; +#if 0 +/* Not implemented yet */ +static char *opt_cmd_name; +static pid_t opt_pid; +#endif const char *indent4 = " "; const char *indent6 = " "; @@ -40,6 +43,7 @@ const char *indent8 = " "; enum { OPT_HELP = 1, OPT_USERSPACE, + OPT_LIST_OPTIONS, }; static struct lttng_handle *handle; @@ -48,10 +52,16 @@ static struct poptOption long_options[] = { /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */ {"help", 'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0}, {"kernel", 'k', POPT_ARG_VAL, &opt_kernel, 1, 0, 0}, - {"userspace", 'u', POPT_ARG_STRING | POPT_ARGFLAG_OPTIONAL, &opt_cmd_name, OPT_USERSPACE, 0, 0}, - {"pid", 'p', POPT_ARG_INT, &opt_pid, 0, 0, 0}, +#if 0 + /* Not implemented yet */ + {"userspace", 'u', POPT_ARG_STRING | POPT_ARGFLAG_OPTIONAL, &opt_cmd_name, OPT_USERSPACE, 0, 0}, + {"pid", 'p', POPT_ARG_INT, &opt_pid, 0, 0, 0}, +#else + {"userspace", 'u', POPT_ARG_NONE, 0, OPT_USERSPACE, 0, 0}, +#endif {"channel", 'c', POPT_ARG_STRING, &opt_channel, 0, 0, 0}, {"domain", 'd', POPT_ARG_VAL, &opt_domain, 1, 0, 0}, + {"list-options", 0, POPT_ARG_NONE, NULL, OPT_LIST_OPTIONS, NULL, NULL}, {0, 0, 0, 0, 0, 0, 0} }; @@ -60,7 +70,7 @@ static struct poptOption long_options[] = { */ static void usage(FILE *ofp) { - fprintf(ofp, "usage: lttng list [[-k] [-u] [-p PID] [SESSION []]]\n"); + fprintf(ofp, "usage: lttng list [SESSION []]\n"); fprintf(ofp, "\n"); fprintf(ofp, "With no arguments, list available tracing session(s)\n"); fprintf(ofp, "\n"); @@ -68,9 +78,12 @@ static void usage(FILE *ofp) fprintf(ofp, "With -u alone, list available userspace events\n"); fprintf(ofp, "\n"); fprintf(ofp, " -h, --help Show this help\n"); + fprintf(ofp, " --list-options Simple listing of options\n"); fprintf(ofp, " -k, --kernel Select kernel domain\n"); fprintf(ofp, " -u, --userspace Select user-space domain.\n"); +#if 0 fprintf(ofp, " -p, --pid PID List user-space events by PID\n"); +#endif fprintf(ofp, "\n"); fprintf(ofp, "Options:\n"); fprintf(ofp, " -c, --channel NAME List details of a channel\n"); @@ -166,8 +179,9 @@ static void print_events(struct lttng_event *event) ret = snprintf(ll_value, LTTNG_SYMBOL_NAME_LEN, " (%lld)", (long long) event->loglevel_value); - if (ret < 0) + if (ret < 0) { ERR("snprintf error"); + } } MSG("%s%s%s%s%s%s (type: tracepoint)%s", indent6, event->name, @@ -202,11 +216,6 @@ static void print_events(struct lttng_event *event) MSG("%s (type: noop)%s", indent6, enabled_string(event->enabled)); break; - case LTTNG_EVENT_TRACEPOINT_LOGLEVEL: - MSG("%s%s (type: tracepoint loglevel)%s", indent6, - event->name, - enabled_string(event->enabled)); - break; case LTTNG_EVENT_ALL: /* We should never have "all" events in list. */ assert(0); @@ -380,10 +389,10 @@ static int list_channels(const char *channel_name) count = lttng_list_channels(handle, &channels); if (count < 0) { ret = count; - goto error; + goto error_channels; } else if (count == 0) { - MSG("No channel found"); - goto end; + ERR("Channel %s not found", channel_name); + goto error; } if (channel_name == NULL) { @@ -412,14 +421,16 @@ static int list_channels(const char *channel_name) } if (!chan_found && channel_name != NULL) { - MSG("Channel %s not found", channel_name); + ERR("Channel %s not found", channel_name); + goto error; } -end: - free(channels); ret = CMD_SUCCESS; error: + free(channels); + +error_channels: return ret; } @@ -466,7 +477,7 @@ static int list_sessions(const char *session_name) free(sessions); if (!session_found && session_name != NULL) { - MSG("Session %s not found", session_name); + ERR("Session %s not found", session_name); } if (session_name == NULL) { @@ -532,6 +543,7 @@ int cmd_list(int argc, const char **argv) if (argc < 1) { usage(stderr); + ret = CMD_ERROR; goto end; } @@ -541,11 +553,14 @@ int cmd_list(int argc, const char **argv) while ((opt = poptGetNextOpt(pc)) != -1) { switch (opt) { case OPT_HELP: - usage(stderr); + usage(stdout); goto end; case OPT_USERSPACE: opt_userspace = 1; break; + case OPT_LIST_OPTIONS: + list_cmd_options(stdout, long_options); + goto end; default: usage(stderr); ret = CMD_UNDEFINED; @@ -553,10 +568,6 @@ int cmd_list(int argc, const char **argv) } } - if (opt_pid != 0) { - MSG("*** Userspace tracing not implemented for PID ***\n"); - } - /* Get session name (trailing argument) */ session_name = poptGetArg(pc); DBG2("Session name: %s", session_name); @@ -570,6 +581,7 @@ int cmd_list(int argc, const char **argv) handle = lttng_create_handle(session_name, &domain); if (handle == NULL) { + ret = CMD_FATAL; goto end; } @@ -577,18 +589,21 @@ int cmd_list(int argc, const char **argv) if (!opt_kernel && !opt_userspace) { ret = list_sessions(NULL); if (ret < 0) { + ret = CMD_ERROR; goto end; } } if (opt_kernel) { ret = list_kernel_events(); if (ret < 0) { + ret = CMD_ERROR; goto end; } } if (opt_userspace) { ret = list_ust_events(); if (ret < 0) { + ret = CMD_ERROR; goto end; } } @@ -596,12 +611,16 @@ int cmd_list(int argc, const char **argv) /* List session attributes */ ret = list_sessions(session_name); if (ret < 0) { + ret = CMD_ERROR; goto end; } /* Domain listing */ if (opt_domain) { ret = list_domains(session_name); + if (ret < 0) { + ret = CMD_ERROR; + } goto end; } @@ -609,13 +628,14 @@ int cmd_list(int argc, const char **argv) /* Channel listing */ ret = list_channels(opt_channel); if (ret < 0) { + ret = CMD_ERROR; goto end; } } else { /* We want all domain(s) */ nb_domain = lttng_list_domains(session_name, &domains); if (nb_domain < 0) { - ret = nb_domain; + ret = CMD_ERROR; goto end; } @@ -637,11 +657,13 @@ int cmd_list(int argc, const char **argv) handle = lttng_create_handle(session_name, &domains[i]); if (handle == NULL) { + ret = CMD_FATAL; goto end; } ret = list_channels(opt_channel); if (ret < 0) { + ret = CMD_ERROR; goto end; } } @@ -654,5 +676,6 @@ end: } lttng_destroy_handle(handle); + poptFreeContext(pc); return ret; }