Fix: print lttng strerror on enable event with filter
[lttng-tools.git] / src / bin / lttng / commands / enable_events.c
index 73c9e05209316cb99045a9cc0d744ddd349f83ae..2af85fe476eb74abaf71ea7b456a6ee1723408b1 100644 (file)
@@ -154,8 +154,8 @@ static void usage(FILE *ofp)
        fprintf(ofp, "                               TRACE_DEBUG          = 14\n");
        fprintf(ofp, "                               (shortcuts such as \"system\" are allowed)\n");
        fprintf(ofp, "    --filter \'expression\'\n");
-       fprintf(ofp, "                           Filter expression on event fields,\n");
-       fprintf(ofp, "                           event recording depends on evaluation.\n");
+       fprintf(ofp, "                           Filter expression on event fields and context.\n");
+       fprintf(ofp, "                           Event recording depends on evaluation.\n");
        fprintf(ofp, "                           Only specify on first activation of\n");
        fprintf(ofp, "                           a given event within a session.\n");
        fprintf(ofp, "                           Filter only allowed when enabling\n");
@@ -175,7 +175,20 @@ static void usage(FILE *ofp)
        fprintf(ofp, "                           'seqfield1 == \"te*\"'\n");
        fprintf(ofp, "                           In string literals, the escape character is '\\'.\n");
        fprintf(ofp, "                           Use '\\*' for the '*' character, and '\\\\' for\n");
-       fprintf(ofp, "                           the '\\' character.\n");
+       fprintf(ofp, "                           the '\\' character. Wildcard match any sequence of,\n");
+       fprintf(ofp, "                           characters including an empty sub-string (match 0 or\n");
+       fprintf(ofp, "                           more characters).\n");
+       fprintf(ofp, "\n");
+       fprintf(ofp, "                           Context information can be used for filtering. The\n");
+       fprintf(ofp, "                           examples below show usage of context filtering on\n");
+       fprintf(ofp, "                           process name (with a wildcard), process ID range, and\n");
+       fprintf(ofp, "                           unique thread ID for filtering. The process and\n");
+       fprintf(ofp, "                           thread ID of running applications can be found under\n");
+       fprintf(ofp, "                           columns \"PID\" and \"LWP\" of the \"ps -eLf\" command.\n");
+       fprintf(ofp, "\n");
+       fprintf(ofp, "                           '$ctx.procname == \"demo*\"'\n");
+       fprintf(ofp, "                           '$ctx.vpid >= 4433 && $ctx.vpid < 4455'\n");
+       fprintf(ofp, "                           '$ctx.vtid == 1234'\n");
        fprintf(ofp, "\n");
 }
 
@@ -319,8 +332,11 @@ static int enable_events(char *session_name)
        /* Create lttng domain */
        if (opt_kernel) {
                dom.type = LTTNG_DOMAIN_KERNEL;
+               dom.buf_type = LTTNG_BUFFER_GLOBAL;
        } else if (opt_userspace) {
                dom.type = LTTNG_DOMAIN_UST;
+               /* Default. */
+               dom.buf_type = LTTNG_BUFFER_PER_PID;
        } else {
                ERR("Please specify a tracer (-k/--kernel or -u/--userspace)");
                ret = CMD_ERROR;
@@ -422,7 +438,6 @@ static int enable_events(char *session_name)
                        ret = lttng_enable_event_with_filter(handle, &ev, channel_name,
                                                opt_filter);
                        if (ret < 0) {
-                               fprintf(stderr, "Ret filter: %d\n", ret);
                                switch (-ret) {
                                case LTTNG_ERR_FILTER_EXIST:
                                        WARN("Filter on events is already enabled"
@@ -431,9 +446,8 @@ static int enable_events(char *session_name)
                                        break;
                                case LTTNG_ERR_FILTER_INVAL:
                                case LTTNG_ERR_FILTER_NOMEM:
-                                       ERR("%s", lttng_strerror(ret));
                                default:
-                                       ERR("Setting filter: '%s'", opt_filter);
+                                       ERR("%s", lttng_strerror(ret));
                                        break;
                                }
                                goto error;
@@ -494,7 +508,7 @@ static int enable_events(char *session_name)
 
                        if (opt_loglevel) {
                                MSG("Kernel loglevels are not supported.");
-                               ret = CMD_UNDEFINED;
+                               ret = CMD_UNSUPPORTED;
                                goto error;
                        }
 
@@ -527,7 +541,7 @@ static int enable_events(char *session_name)
                        case LTTNG_EVENT_SYSCALL:
                        default:
                                ERR("Event type not available for user-space tracing");
-                               ret = CMD_UNDEFINED;
+                               ret = CMD_UNSUPPORTED;
                                goto error;
                        }
 
@@ -618,6 +632,7 @@ int cmd_enable_events(int argc, const char **argv)
        int opt, ret = CMD_SUCCESS;
        static poptContext pc;
        char *session_name = NULL;
+       int event_type = -1;
 
        pc = poptGetContext(NULL, argc, argv, long_options, 0);
        poptReadDefaultConfig(pc, 0);
@@ -666,6 +681,17 @@ int cmd_enable_events(int argc, const char **argv)
                        ret = CMD_UNDEFINED;
                        goto end;
                }
+
+               /* Validate event type. Multiple event type are not supported. */
+               if (event_type == -1) {
+                       event_type = opt_event_type;
+               } else {
+                       if (event_type != opt_event_type) {
+                               ERR("Multiple event type not supported.");
+                               ret = CMD_ERROR;
+                               goto end;
+                       }
+               }
        }
 
        opt_event_list = (char*) poptGetArg(pc);
This page took 0.025875 seconds and 4 git commands to generate.