#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 = " ";
enum {
OPT_HELP = 1,
OPT_USERSPACE,
+ OPT_LIST_OPTIONS,
};
static struct lttng_handle *handle;
/* 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}
};
*/
static void usage(FILE *ofp)
{
- fprintf(ofp, "usage: lttng list [[-k] [-u] [-p PID] [SESSION [<options>]]]\n");
+ fprintf(ofp, "usage: lttng list [OPTIONS] [SESSION [<OPTIONS>]]\n");
fprintf(ofp, "\n");
fprintf(ofp, "With no arguments, list available tracing session(s)\n");
fprintf(ofp, "\n");
- fprintf(ofp, "With -k alone, list available kernel events\n");
- fprintf(ofp, "With -u alone, list available userspace events\n");
+ fprintf(ofp, "Without a session, -k lists available kernel events\n");
+ fprintf(ofp, "Without a session, -u lists 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, "Session Options:\n");
fprintf(ofp, " -c, --channel NAME List details of a channel\n");
fprintf(ofp, " -d, --domain List available domain(s)\n");
fprintf(ofp, "\n");
}
static
-const char *loglevel_string_pre(const char *loglevel)
+const char *loglevel_string_pre(int loglevel)
{
- if (loglevel[0] == '\0') {
+ if (loglevel == -1) {
return "";
} else {
return " (loglevel: ";
}
static
-const char *loglevel_string_post(const char *loglevel)
+const char *loglevel_string_post(int loglevel)
{
- if (loglevel[0] == '\0') {
+ if (loglevel == -1) {
return "";
} else {
return ")";
}
}
+static const char *loglevel_string(int value)
+{
+ switch (value) {
+ case -1: return "";
+ case 0: return "TRACE_EMERG";
+ case 1: return "TRACE_ALERT";
+ case 2: return "TRACE_CRIT";
+ case 3: return "TRACE_ERR";
+ case 4: return "TRACE_WARNING";
+ case 5: return "TRACE_NOTICE";
+ case 6: return "TRACE_INFO";
+ case 7: return "TRACE_SYSTEM";
+ case 8: return "TRACE_PROGRAM";
+ case 9: return "TRACE_PROCESS";
+ case 10: return "TRACE_MODULE";
+ case 11: return "TRACE_UNIT";
+ case 12: return "TRACE_FUNCTION";
+ case 13: return "TRACE_DEFAULT";
+ case 14: return "TRACE_VERBOSE";
+ case 15: return "TRACE_DEBUG";
+ default: return "<<UNKNOWN>>";
+ }
+}
+
/*
* Pretty print single event.
*/
switch (event->type) {
case LTTNG_EVENT_TRACEPOINT:
{
- char ll_value[LTTNG_SYMBOL_NAME_LEN] = "";
-
- if (event->loglevel[0] != '\0') {
- int ret;
-
- ret = snprintf(ll_value, LTTNG_SYMBOL_NAME_LEN,
- " (%lld)", (long long) event->loglevel_value);
- if (ret < 0)
- ERR("snprintf error");
- }
- MSG("%s%s%s%s%s%s (type: tracepoint)%s", indent6,
+ MSG("%s%s%s%s%s (type: tracepoint)%s", indent6,
event->name,
loglevel_string_pre(event->loglevel),
- event->loglevel,
- ll_value,
+ loglevel_string(event->loglevel),
loglevel_string_post(event->loglevel),
enabled_string(event->enabled));
break;
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);
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) {
}
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;
}
continue;
}
- MSG(" %d) %s (%s)%s", i + 1, sessions[i].name, sessions[i].path, active_string(sessions[i].enabled));
+ MSG(" %d) %s (%s)%s", i + 1, sessions[i].name, sessions[i].path,
+ active_string(sessions[i].enabled));
if (session_found) {
break;
free(sessions);
if (!session_found && session_name != NULL) {
- MSG("Session %s not found", session_name);
+ ERR("Session '%s' not found", session_name);
+ ret = CMD_ERROR;
+ goto error;
}
if (session_name == NULL) {
if (argc < 1) {
usage(stderr);
+ ret = CMD_ERROR;
goto end;
}
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;
}
}
- 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);
handle = lttng_create_handle(session_name, &domain);
if (handle == NULL) {
+ ret = CMD_FATAL;
goto end;
}
if (session_name == NULL) {
if (!opt_kernel && !opt_userspace) {
ret = list_sessions(NULL);
- if (ret < 0) {
+ if (ret != 0) {
goto end;
}
}
} else {
/* List session attributes */
ret = list_sessions(session_name);
- if (ret < 0) {
+ if (ret != 0) {
goto end;
}
handle = lttng_create_handle(session_name, &domains[i]);
if (handle == NULL) {
+ ret = CMD_FATAL;
goto end;
}
}
lttng_destroy_handle(handle);
+ poptFreeContext(pc);
return ret;
}