[lttng-dev] [PATCH] bin/lttng/commands: require exactly one of --kernel and --userspace
Thibault, Daniel
Daniel.Thibault at drdc-rddc.gc.ca
Wed Feb 1 11:46:04 EST 2012
>From 819b327b481ef55c2aaa0a59e7fbb751010eb0f9 Wed, 1 Feb 2012 11:44:31 -0500
From: Daniel U. Thibault <daniel.thibault at drdc-rddc.gc.ca>
Date: Wed, 1 Feb 2012 11:44:08 -0500
Subject: [PATCH] bin/lttng/commands: require exactly one of --kernel and --userspace
Applies to add_context, calibrate, enable/disable_channels/events;
list can have none, one or both.
Signed-off-by: Daniel U. Thibault <daniel.thibault at drdc-rddc.gc.ca>
diff --git a/src/bin/lttng/commands/add_context.c b/src/bin/lttng/commands/add_context.c
index d37ece3..72833b4 100644
--- a/src/bin/lttng/commands/add_context.c
+++ b/src/bin/lttng/commands/add_context.c
@@ -327,7 +327,7 @@
#endif
fprintf(ofp, " -t, --type TYPE Context type. You can repeat that option on\n");
fprintf(ofp, " the command line to specify multiple contexts at once.\n");
- fprintf(ofp, " (--kernel preempts --userspace)\n");
+ fprintf(ofp, " (--kernel and --userspace are mutually exclusive)\n");
fprintf(ofp, " TYPE can be one of the strings below:\n");
print_ctx_type(ofp);
fprintf(ofp, "\n");
@@ -371,15 +371,11 @@
struct ctx_type *type;
char *ptr;
- if (opt_kernel) {
- dom.type = LTTNG_DOMAIN_KERNEL;
- } else if (opt_userspace) {
- dom.type = LTTNG_DOMAIN_UST;
- } else {
- ERR("Please specify a tracer (-k/--kernel or -u/--userspace)");
- ret = CMD_ERROR;
- goto error;
- }
+ /*
+ * cmd_add_context() ensures exactly one
+ * of opt_kernel and opt_userspace is set
+ */
+ dom.type = (opt_kernel ? LTTNG_DOMAIN_KERNEL : LTTNG_DOMAIN_UST);
handle = lttng_create_handle(session_name, &dom);
if (handle == NULL) {
@@ -469,7 +465,6 @@
switch (opt) {
case OPT_HELP:
usage(stdout);
- ret = CMD_SUCCESS;
goto end;
case OPT_TYPE:
/*
@@ -508,7 +503,6 @@
break;
case OPT_LIST_OPTIONS:
list_cmd_options(stdout, long_options);
- ret = CMD_SUCCESS;
goto end;
default:
usage(stderr);
@@ -517,6 +511,16 @@
}
}
+ if (opt_kernel && opt_userspace) {
+ ERR("Can't use -k/--kernel and -u/--userspace together");
+ ret = CMD_FATAL;
+ goto end;
+ } else if (!opt_kernel && !opt_userspace) {
+ ERR("Please specify a tracer (-k/--kernel or -u/--userspace)");
+ ret = CMD_FATAL;
+ goto end;
+ }
+
session_name = (opt_session_name ? opt_session_name : get_session_name() );
if (session_name == NULL) {
ret = CMD_ERROR;
diff --git a/src/bin/lttng/commands/calibrate.c b/src/bin/lttng/commands/calibrate.c
index 591c869..b4c6cb5 100644
--- a/src/bin/lttng/commands/calibrate.c
+++ b/src/bin/lttng/commands/calibrate.c
@@ -93,25 +93,24 @@
#if 0
fprintf(ofp, " -u, --userspace [CMD] Apply to the user-space tracer (domain: UST\n");
fprintf(ofp, " EXEC_NAME). If no CMD, the domain is UST global.\n";
- fprintf(ofp, " (-k preempts -u)\n");
+ fprintf(ofp, " (--kernel and --userspace are mutually exclusive)\n");
fprintf(ofp, " -p, --pid PID If -u, apply to specific PID (domain: UST PID)\n");
#else
fprintf(ofp, " -u, --userspace Apply to the user-space tracer\n");
+ fprintf(ofp, " (--kernel and --userspace are mutually exclusive)\n");
#endif
fprintf(ofp, "\n");
fprintf(ofp, "Calibrate options:\n");
#if 0
- fprintf(ofp, " --tracepoint Tracepoint event (default)\n");
- fprintf(ofp, " --probe\n");
- fprintf(ofp, " Dynamic probe.\n");
+ fprintf(ofp, " --tracepoint Tracepoint event (default)\n");
+ fprintf(ofp, " --probe Dynamic probe.\n");
#if 0
- fprintf(ofp, " --function:entry symbol\n");
- fprintf(ofp, " Function tracer event\n");
+ fprintf(ofp, " --function:entry symbol Function tracer event\n");
#endif
- fprintf(ofp, " --syscall System call eventl\n");
- fprintf(ofp, " --marker User-space marker (deprecated)\n");
+ fprintf(ofp, " --syscall System call eventl\n");
+ fprintf(ofp, " --marker User-space marker (deprecated)\n");
#else
- fprintf(ofp, " --function Dynamic function entry/return probe (default)\n");
+ fprintf(ofp, " --function Dynamic function entry/return probe (default)\n");
#endif
fprintf(ofp, "\n");
}
@@ -128,15 +127,11 @@
struct lttng_calibrate calibrate;
/* Create lttng domain */
- if (opt_kernel) {
- dom.type = LTTNG_DOMAIN_KERNEL;
- } else if (opt_userspace) {
- dom.type = LTTNG_DOMAIN_UST;
- } else {
- ERR("Please specify a tracer (-k/--kernel or -u/--userspace)");
- ret = CMD_ERROR;
- goto error;
- }
+ /*
+ * cmd_calibrate() ensures exactly one
+ * of opt_kernel and opt_userspace is set
+ */
+ dom.type = (opt_kernel ? LTTNG_DOMAIN_KERNEL : LTTNG_DOMAIN_UST);
handle = lttng_create_handle(NULL, &dom);
if (handle == NULL) {
@@ -159,6 +154,7 @@
ret = CMD_ERROR;
goto error;
}
+ ret = CMD_SUCCESS;
MSG("%s calibration done", opt_kernel ? "Kernel" : "UST");
break;
case LTTNG_EVENT_FUNCTION_ENTRY:
@@ -171,8 +167,6 @@
ret = CMD_UNDEFINED;
goto error;
}
-
- ret = CMD_SUCCESS;
error:
lttng_destroy_handle(handle);
@@ -187,7 +181,7 @@
*/
int cmd_calibrate(int argc, const char **argv)
{
- int opt, ret;
+ int opt, ret = CMD_SUCCESS;
static poptContext pc;
pc = poptGetContext(NULL, argc, argv, long_options, 0);
@@ -200,7 +194,6 @@
switch (opt) {
case OPT_HELP:
usage(stdout);
- ret = CMD_SUCCESS;
goto end;
case OPT_TRACEPOINT:
ret = CMD_UNDEFINED;
@@ -225,7 +218,6 @@
break;
case OPT_LIST_OPTIONS:
list_cmd_options(stdout, long_options);
- ret = CMD_SUCCESS;
goto end;
default:
usage(stderr);
@@ -234,6 +226,16 @@
}
}
+ if (opt_kernel && opt_userspace) {
+ ERR("Can't use -k/--kernel and -u/--userspace together");
+ ret = CMD_FATAL;
+ goto end;
+ } else if (!opt_kernel && !opt_userspace) {
+ ERR("Please specify a tracer (-k/--kernel or -u/--userspace)");
+ ret = CMD_FATAL;
+ goto end;
+ }
+
ret = calibrate_lttng();
end:
diff --git a/src/bin/lttng/commands/disable_channels.c b/src/bin/lttng/commands/disable_channels.c
index f6929e6..951fa10 100644
--- a/src/bin/lttng/commands/disable_channels.c
+++ b/src/bin/lttng/commands/disable_channels.c
@@ -76,11 +76,11 @@
fprintf(ofp, " -u, --userspace [CMD] Apply to the user-space tracer\n");
fprintf(ofp, " If no CMD, the domain used is UST global\n");
fprintf(ofp, " otherwise the domain is UST EXEC_NAME\n");
- fprintf(ofp, " (--kernel preempts --userspace)\n");
+ fprintf(ofp, " (--kernel and --userspace are mutually exclusive)\n");
fprintf(ofp, " -p, --pid PID If -u, apply to specific PID (domain: UST PID)\n");
#else
fprintf(ofp, " -u, --userspace Apply to the user-space tracer\n");
- fprintf(ofp, " (--kernel preempts --userspace)\n");
+ fprintf(ofp, " (--kernel and --userspace are mutually exclusive)\n");
#endif
fprintf(ofp, "\n");
}
@@ -99,15 +99,11 @@
struct lttng_domain dom;
/* Create lttng domain */
- if (opt_kernel) {
- dom.type = LTTNG_DOMAIN_KERNEL;
- } else if (opt_userspace) {
- dom.type = LTTNG_DOMAIN_UST;
- } else {
- ERR("Please specify a tracer (-k/--kernel or -u/--userspace)");
- ret = CMD_ERROR;
- goto error;
- }
+ /*
+ * cmd_disable_channels() ensures exactly one
+ * of opt_kernel and opt_userspace is set
+ */
+ dom.type = (opt_kernel ? LTTNG_DOMAIN_KERNEL : LTTNG_DOMAIN_UST);
handle = lttng_create_handle(session_name, &dom);
if (handle == NULL) {
@@ -188,6 +184,16 @@
}
}
+ if (opt_kernel && opt_userspace) {
+ ERR("Can't use -k/--kernel and -u/--userspace together");
+ ret = CMD_FATAL;
+ goto end;
+ } else if (!opt_kernel && !opt_userspace) {
+ ERR("Please specify a tracer (-k/--kernel or -u/--userspace)");
+ ret = CMD_FATAL;
+ goto end;
+ }
+
opt_channels = (char*) poptGetArg(pc);
if (opt_channels == NULL) {
ERR("Missing channel name(s).\n");
diff --git a/src/bin/lttng/commands/disable_events.c b/src/bin/lttng/commands/disable_events.c
index 23f4858..7b2223c 100644
--- a/src/bin/lttng/commands/disable_events.c
+++ b/src/bin/lttng/commands/disable_events.c
@@ -82,11 +82,11 @@
fprintf(ofp, " -u, --userspace [CMD] Apply to the user-space tracer\n");
fprintf(ofp, " If no CMD, the domain used is UST global\n");
fprintf(ofp, " otherwise the domain is UST EXEC_NAME\n");
- fprintf(ofp, " (--kernel preempts --userspace)\n");
+ fprintf(ofp, " (--kernel and --userspace are mutually exclusive)\n");
fprintf(ofp, " -p, --pid PID If -u, apply to specific PID (domain: UST PID)\n");
#else
fprintf(ofp, " -u, --userspace Apply to the user-space tracer\n");
- fprintf(ofp, " (--kernel preempts --userspace)\n");
+ fprintf(ofp, " (--kernel and --userspace are mutually exclusive)\n");
#endif
fprintf(ofp, "\n");
}
@@ -111,23 +111,12 @@
channel_name = opt_channel_name;
}
- /* TODO: Either do this test everywhere or don't do it anywhere */
- if (opt_kernel && opt_userspace) {
- ERR("Can't use -k/--kernel and -u/--userspace together");
- ret = CMD_FATAL;
- goto error;
- }
-
/* Create lttng domain */
- if (opt_kernel) {
- dom.type = LTTNG_DOMAIN_KERNEL;
- } else if (opt_userspace) {
- dom.type = LTTNG_DOMAIN_UST;
- } else {
- ERR("Please specify a tracer (-k/--kernel or -u/--userspace)");
- ret = CMD_ERROR;
- goto error;
- }
+ /*
+ * cmd_disable_events() ensures exactly one
+ * of opt_kernel and opt_userspace is set
+ */
+ dom.type = (opt_kernel ? LTTNG_DOMAIN_KERNEL : LTTNG_DOMAIN_UST);
handle = lttng_create_handle(session_name, &dom);
if (handle == NULL) {
@@ -155,7 +144,7 @@
if (opt_kernel) {
DBG("Disabling kernel event %s in channel %s",
event_name, channel_name);
- } else if (opt_userspace) { /* User-space tracer action */
+ } else { /* User-space tracer action */
#if 0
if (opt_cmd_name != NULL || opt_pid) {
MSG("Only supporting tracing all UST processes (-u) for now.");
@@ -165,10 +154,6 @@
#endif
DBG("Disabling UST event %s in channel %s",
event_name, channel_name);
- } else {
- ERR("Please specify a tracer (-k/--kernel or -u/--userspace)");
- ret = CMD_ERROR;
- goto error;
}
ret = lttng_disable_event(handle, event_name, channel_name);
@@ -231,6 +216,16 @@
}
}
+ if (opt_kernel && opt_userspace) {
+ ERR("Can't use -k/--kernel and -u/--userspace together");
+ ret = CMD_FATAL;
+ goto end;
+ } else if (!opt_kernel && !opt_userspace) {
+ ERR("Please specify a tracer (-k/--kernel or -u/--userspace)");
+ ret = CMD_FATAL;
+ goto end;
+ }
+
opt_event_list = (char*) poptGetArg(pc);
if (opt_event_list == NULL && opt_disable_all == 0) {
ERR("Missing event name(s).\n");
diff --git a/src/bin/lttng/commands/enable_channels.c b/src/bin/lttng/commands/enable_channels.c
index 7bebf76..566e017 100644
--- a/src/bin/lttng/commands/enable_channels.c
+++ b/src/bin/lttng/commands/enable_channels.c
@@ -91,11 +91,11 @@
fprintf(ofp, " -u, --userspace [CMD] Apply to the user-space tracer\n");
fprintf(ofp, " If no CMD, the domain used is UST global\n");
fprintf(ofp, " otherwise the domain is UST EXEC_NAME\n");
- fprintf(ofp, " (--kernel preempts --userspace)\n");
+ fprintf(ofp, " (--kernel and --userspace are mutually exclusive)\n");
fprintf(ofp, " -p, --pid PID If -u, apply to specific PID (domain: UST PID)\n");
#else
fprintf(ofp, " -u, --userspace Apply to the user-space tracer\n");
- fprintf(ofp, " (--kernel preempts --userspace)\n");
+ fprintf(ofp, " (--kernel and --userspace are mutually exclusive)\n");
#endif
fprintf(ofp, "\n");
fprintf(ofp, "Channel options:\n");
@@ -163,15 +163,11 @@
struct lttng_domain dom;
/* Create lttng domain */
- if (opt_kernel) {
- dom.type = LTTNG_DOMAIN_KERNEL;
- } else if (opt_userspace) {
- dom.type = LTTNG_DOMAIN_UST;
- } else {
- ERR("Please specify a tracer (-k/--kernel or -u/--userspace)");
- ret = CMD_ERROR;
- goto error;
- }
+ /*
+ * cmd_enable_channels() ensures exactly one
+ * of opt_kernel and opt_userspace is set
+ */
+ dom.type = (opt_kernel ? LTTNG_DOMAIN_KERNEL : LTTNG_DOMAIN_UST);
set_default_attr(&dom);
@@ -317,6 +313,16 @@
}
}
+ if (opt_kernel && opt_userspace) {
+ ERR("Can't use -k/--kernel and -u/--userspace together");
+ ret = CMD_FATAL;
+ goto end;
+ } else if (!opt_kernel && !opt_userspace) {
+ ERR("Please specify a tracer (-k/--kernel or -u/--userspace)");
+ ret = CMD_FATAL;
+ goto end;
+ }
+
opt_channels = (char*) poptGetArg(pc);
if (opt_channels == NULL) {
ERR("Missing channel name(s).\n");
diff --git a/src/bin/lttng/commands/enable_events.c b/src/bin/lttng/commands/enable_events.c
index 695e374..94b9eb7 100644
--- a/src/bin/lttng/commands/enable_events.c
+++ b/src/bin/lttng/commands/enable_events.c
@@ -110,11 +110,11 @@
fprintf(ofp, " -u, --userspace [CMD] Apply to the user-space tracer\n");
fprintf(ofp, " If no CMD, the domain used is UST global\n");
fprintf(ofp, " otherwise the domain is UST EXEC_NAME\n");
- fprintf(ofp, " (--kernel preempts --userspace)\n");
+ fprintf(ofp, " (--kernel and --userspace are mutually exclusive)\n");
fprintf(ofp, " -p, --pid PID If -u, apply to specific PID (domain: UST PID)\n");
#else
fprintf(ofp, " -u, --userspace Apply to the user-space tracer\n");
- fprintf(ofp, " (--kernel preempts --userspace)\n");
+ fprintf(ofp, " (--kernel and --userspace are mutually exclusive)\n");
#endif
fprintf(ofp, "\n");
fprintf(ofp, "Event options:\n");
@@ -124,10 +124,8 @@
fprintf(ofp, " e.g.:\n");
fprintf(ofp, " \"*\"\n");
fprintf(ofp, " \"app_component:na*\"\n");
- fprintf(ofp, " --loglevel name\n");
- fprintf(ofp, " Tracepoint loglevel (range: 0 to loglevel)\n");
- fprintf(ofp, " --loglevel-only name\n");
- fprintf(ofp, " Tracepoint loglevel (only this loglevel)\n");
+ fprintf(ofp, " --loglevel name Tracepoint loglevel (range: 0 to loglevel)\n");
+ fprintf(ofp, " --loglevel-only name Tracepoint loglevel (only this loglevel)\n");
fprintf(ofp, " --probe [addr | symbol | symbol+offset]\n");
fprintf(ofp, " Dynamic probe.\n");
fprintf(ofp, " Addr and offset can be octal (0NNN...),\n");
@@ -236,23 +234,12 @@
channel_name = opt_channel_name;
}
- /* TODO: Either do this test everywhere or don't do it anywhere */
- if (opt_kernel && opt_userspace) {
- ERR("Can't use -k/--kernel and -u/--userspace together");
- ret = CMD_FATAL;
- goto error;
- }
-
/* Create lttng domain */
- if (opt_kernel) {
- dom.type = LTTNG_DOMAIN_KERNEL;
- } else if (opt_userspace) {
- dom.type = LTTNG_DOMAIN_UST;
- } else {
- ERR("Please specify a tracer (-k/--kernel or -u/--userspace)");
- ret = CMD_ERROR;
- goto error;
- }
+ /*
+ * cmd_enable_events() ensures exactly one
+ * of opt_kernel and opt_userspace is set
+ */
+ dom.type = (opt_kernel ? LTTNG_DOMAIN_KERNEL : LTTNG_DOMAIN_UST);
handle = lttng_create_handle(session_name, &dom);
if (handle == NULL) {
@@ -363,7 +350,7 @@
/* kernel loglevels not implemented */
ev.loglevel_type = opt_loglevel_type;
ev.loglevel[0] = '\0';
- } else if (opt_userspace) { /* User-space tracer action */
+ } else { /* User-space tracer action */
#if 0
if (opt_cmd_name != NULL || opt_pid) {
MSG("Only supporting tracing all UST processes (-u) for now.");
@@ -396,10 +383,6 @@
ev.loglevel_type = opt_loglevel_type;
strncpy(ev.loglevel, opt_loglevel, LTTNG_SYMBOL_NAME_LEN);
ev.loglevel[LTTNG_SYMBOL_NAME_LEN - 1] = '\0';
- } else {
- ERR("Please specify a tracer (-k/--kernel or -u/--userspace)");
- ret = CMD_ERROR;
- goto error;
}
ret = lttng_enable_event(handle, &ev, channel_name);
@@ -482,6 +465,16 @@
}
}
+ if (opt_kernel && opt_userspace) {
+ ERR("Can't use -k/--kernel and -u/--userspace together");
+ ret = CMD_FATAL;
+ goto end;
+ } else if (!opt_kernel && !opt_userspace) {
+ ERR("Please specify a tracer (-k/--kernel or -u/--userspace)");
+ ret = CMD_FATAL;
+ goto end;
+ }
+
opt_event_list = (char*) poptGetArg(pc);
if (opt_event_list == NULL && opt_enable_all == 0) {
ERR("Missing event name(s).\n");
@@ -490,6 +483,7 @@
goto end;
}
+ /* TODO Simplify this if */
if (!opt_session_name) {
session_name = get_session_name();
if (session_name == NULL) {
diff --git a/src/bin/lttng/commands/list.c b/src/bin/lttng/commands/list.c
index 61e1f23..9a91f5c 100644
--- a/src/bin/lttng/commands/list.c
+++ b/src/bin/lttng/commands/list.c
@@ -70,22 +70,23 @@
*/
static void usage(FILE *ofp)
{
- fprintf(ofp, "usage: lttng list [SESSION [<OPTIONS>]]\n");
+ fprintf(ofp, "usage: lttng list [OPTIONS] [SESSION [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, " --list-options Simple listing of options\n");
fprintf(ofp, " -k, --kernel Select kernel domain\n");
fprintf(ofp, " -u, --userspace Select user-space domain.\n");
+ fprintf(ofp, " (You may specify none, one or both of -k and -u)\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");
@@ -529,6 +530,7 @@
/*
* The 'list <options>' first level command
+ * Returns one of the CMD_* result values.
*/
int cmd_list(int argc, const char **argv)
{
@@ -550,14 +552,13 @@
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);
- ret = CMD_SUCCESS;
goto end;
default:
usage(stderr);
------------------------------
Daniel U. Thibault
R & D pour la défense Canada - Valcartier (RDDC Valcartier) / Defence R&D Canada - Valcartier (DRDC Valcartier)
Système de systèmes (SdS) / System of Systems (SoS)
Solutions informatiques et expérimentations (SIE) / Computing Solutions and Experimentations (CSE)
2459 Boul. Pie XI Nord
Québec, QC G3J 1X5
CANADA
Vox : (418) 844-4000 x4245
Fax : (418) 844-4538
NAC: 918V QSDJ
Gouvernement du Canada / Government of Canada
<http://www.valcartier.drdc-rddc.gc.ca/>
More information about the lttng-dev
mailing list