SoW-2019-0002: Dynamic Snapshot
[lttng-tools.git] / src / bin / lttng / commands / disable_events.c
index 63e5f47418964b876cd2077f6ce1b0833b0aec3c..501c3cf3aa7bc31caecf8792a68a5966c4086594 100644 (file)
@@ -1,21 +1,11 @@
 /*
- * Copyright (C) 2011 David Goulet <david.goulet@polymtl.ca>
+ * Copyright (C) 2011 David Goulet <david.goulet@polymtl.ca>
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2 only,
- * as published by the Free Software Foundation.
+ * SPDX-License-Identifier: GPL-2.0-only
  *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-#define _GNU_SOURCE
+#define _LGPL_SOURCE
 #include <popt.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -36,15 +26,23 @@ static char *opt_session_name;
 static int opt_userspace;
 static int opt_disable_all;
 static int opt_jul;
-#if 0
-/* Not implemented yet */
-static char *opt_cmd_name;
-static pid_t opt_pid;
+static int opt_log4j;
+static int opt_python;
+static int opt_event_type;
+
+#ifdef LTTNG_EMBED_HELP
+static const char help_msg[] =
+#include <lttng-disable-event.1.h>
+;
 #endif
 
 enum {
        OPT_HELP = 1,
-       OPT_USERSPACE,
+       OPT_TYPE_SYSCALL,
+       OPT_TYPE_TRACEPOINT,
+       OPT_TYPE_PROBE,
+       OPT_TYPE_FUNCTION,
+       OPT_TYPE_ALL,
        OPT_LIST_OPTIONS,
 };
 
@@ -58,37 +56,19 @@ static struct poptOption long_options[] = {
        {"all-events",     'a', POPT_ARG_VAL, &opt_disable_all, 1, 0, 0},
        {"channel",        'c', POPT_ARG_STRING, &opt_channel_name, 0, 0, 0},
        {"jul",            'j', POPT_ARG_VAL, &opt_jul, 1, 0, 0},
+       {"log4j",          'l', POPT_ARG_VAL, &opt_log4j, 1, 0, 0},
+       {"python",         'p', POPT_ARG_VAL, &opt_python, 1, 0, 0},
        {"kernel",         'k', POPT_ARG_VAL, &opt_kernel, 1, 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
+       {"userspace",      'u', POPT_ARG_VAL, &opt_userspace, 1, 0, 0},
+       {"syscall",          0, POPT_ARG_NONE, 0, OPT_TYPE_SYSCALL, 0, 0},
+       {"probe",            0, POPT_ARG_NONE, 0, OPT_TYPE_PROBE, 0, 0},
+       {"tracepoint",       0, POPT_ARG_NONE, 0, OPT_TYPE_TRACEPOINT, 0, 0},
+       {"function",         0, POPT_ARG_NONE, 0, OPT_TYPE_FUNCTION, 0, 0},
+       {"all",              0, POPT_ARG_NONE, 0, OPT_TYPE_ALL, 0, 0},
        {"list-options", 0, POPT_ARG_NONE, NULL, OPT_LIST_OPTIONS, NULL, NULL},
        {0, 0, 0, 0, 0, 0, 0}
 };
 
-/*
- * usage
- */
-static void usage(FILE *ofp)
-{
-       fprintf(ofp, "usage: lttng disable-event NAME[,NAME2,...] (-k | -u) [OPTIONS]\n");
-       fprintf(ofp, "\n");
-       fprintf(ofp, "Options:\n");
-       fprintf(ofp, "  -h, --help               Show this help\n");
-       fprintf(ofp, "      --list-options       Simple listing of options\n");
-       fprintf(ofp, "  -s, --session NAME       Apply to session name\n");
-       fprintf(ofp, "  -c, --channel NAME       Apply to this channel\n");
-       fprintf(ofp, "  -a, --all-events         Disable all tracepoints\n");
-       fprintf(ofp, "  -k, --kernel             Apply for the kernel tracer\n");
-       fprintf(ofp, "  -u, --userspace          Apply to the user-space tracer\n");
-       fprintf(ofp, "  -j, --jul                Apply for Java application using JUL\n");
-       fprintf(ofp, "\n");
-}
-
 static
 const char *print_channel_name(const char *name)
 {
@@ -101,11 +81,32 @@ const char *print_raw_channel_name(const char *name)
        return name ? : "<default>";
 }
 
+static
+const char *print_event_type(const enum lttng_event_type ev_type)
+{
+       switch (ev_type) {
+       case LTTNG_EVENT_ALL:
+               return "any";
+       case LTTNG_EVENT_TRACEPOINT:
+               return "tracepoint";
+       case LTTNG_EVENT_PROBE:
+               return "probe";
+       case LTTNG_EVENT_FUNCTION:
+               return "function";
+       case LTTNG_EVENT_FUNCTION_ENTRY:
+               return "function entry";
+       case LTTNG_EVENT_SYSCALL:
+               return "syscall";
+       default:
+               return "";
+       }
+}
+
 /* Mi print a partial event.
  * enabled is 0 or 1
  * success is 0 or 1
  */
-static int mi_print_event(char *event_name, int enabled, int success)
+static int mi_print_event(const char *event_name, int enabled, int success)
 {
        int ret;
 
@@ -156,6 +157,7 @@ static int disable_events(char *session_name)
        int enabled = 1, success = 1;
        char *event_name, *channel_name = NULL;
        struct lttng_domain dom;
+       struct lttng_event event;
 
        memset(&dom, 0, sizeof(dom));
 
@@ -166,10 +168,13 @@ static int disable_events(char *session_name)
                dom.type = LTTNG_DOMAIN_UST;
        } else if (opt_jul) {
                dom.type = LTTNG_DOMAIN_JUL;
+       } else if (opt_log4j) {
+               dom.type = LTTNG_DOMAIN_LOG4J;
+       } else if (opt_python) {
+               dom.type = LTTNG_DOMAIN_PYTHON;
        } else {
-               print_missing_domain();
-               ret = CMD_ERROR;
-               goto error;
+               /* Checked by the caller. */
+               assert(0);
        }
 
        channel_name = opt_channel_name;
@@ -203,8 +208,15 @@ static int disable_events(char *session_name)
                }
        }
 
+       memset(&event, 0, sizeof(event));
+       /* Set default loglevel to any/unknown */
+       event.loglevel = -1;
+
+       /* opt_event_type contain the event type to disable at this point */
+       event.type = opt_event_type;
+
        if (opt_disable_all) {
-               command_ret = lttng_disable_event(handle, NULL, channel_name);
+               command_ret = lttng_disable_event_ext(handle, &event, channel_name, NULL);
                if (command_ret < 0) {
                        ERR("%s", lttng_strerror(command_ret));
                        enabled = 1;
@@ -213,8 +225,10 @@ static int disable_events(char *session_name)
                } else {
                        enabled = 0;
                        success = 1;
-                       MSG("All %s events are disabled in channel %s",
-                                       get_domain_str(dom.type), print_channel_name(channel_name));
+                       MSG("All %s events of type %s are disabled in channel %s",
+                                       get_domain_str(dom.type),
+                                       print_event_type(opt_event_type),
+                                       print_channel_name(channel_name));
                }
 
                if (lttng_opt_mi) {
@@ -230,9 +244,13 @@ static int disable_events(char *session_name)
                while (event_name != NULL) {
                        DBG("Disabling event %s", event_name);
 
-                       command_ret = lttng_disable_event(handle, event_name, channel_name);
+                       strncpy(event.name, event_name, sizeof(event.name));
+                       event.name[sizeof(event.name) - 1] = '\0';
+                       command_ret = lttng_disable_event_ext(handle, &event, channel_name, NULL);
                        if (command_ret < 0) {
-                               ERR("Event %s: %s (channel %s, session %s)", event_name,
+                               ERR("%s of type %s : %s (channel %s, session %s)",
+                                               event_name,
+                                               print_event_type(opt_event_type),
                                                lttng_strerror(command_ret),
                                                command_ret == -LTTNG_ERR_NEED_CHANNEL_NAME
                                                        ? print_raw_channel_name(channel_name)
@@ -241,13 +259,15 @@ static int disable_events(char *session_name)
                                warn = 1;
                                success = 0;
                                /*
-                                * If an error occurred we assume that
-                                * the event is still enabled.
+                                * If an error occurred we assume that the event is still
+                                * enabled.
                                 */
                                enabled = 1;
                        } else {
-                               MSG("%s event %s disabled in channel %s for session %s",
-                                               get_domain_str(dom.type), event_name,
+                               MSG("%s %s of type %s disabled in channel %s for session %s",
+                                               get_domain_str(dom.type),
+                                               event_name,
+                                               print_event_type(opt_event_type),
                                                print_channel_name(channel_name),
                                                session_name);
                                success = 1;
@@ -298,32 +318,80 @@ int cmd_disable_events(int argc, const char **argv)
        int opt, ret = CMD_SUCCESS, command_ret = CMD_SUCCESS, success = 1;
        static poptContext pc;
        char *session_name = NULL;
+       const char *leftover = NULL;
+       int event_type = -1;
 
        pc = poptGetContext(NULL, argc, argv, long_options, 0);
        poptReadDefaultConfig(pc, 0);
 
+       /* Default event type */
+       opt_event_type = LTTNG_EVENT_ALL;
+
        while ((opt = poptGetNextOpt(pc)) != -1) {
                switch (opt) {
                case OPT_HELP:
-                       usage(stdout);
+                       SHOW_HELP();
                        goto end;
-               case OPT_USERSPACE:
-                       opt_userspace = 1;
+               case OPT_TYPE_SYSCALL:
+                       opt_event_type = LTTNG_EVENT_SYSCALL;
+                       break;
+               case OPT_TYPE_TRACEPOINT:
+                       opt_event_type = LTTNG_EVENT_TRACEPOINT;
+                       break;
+               case OPT_TYPE_PROBE:
+                       opt_event_type = LTTNG_EVENT_PROBE;
+                       break;
+               case OPT_TYPE_FUNCTION:
+                       opt_event_type = LTTNG_EVENT_FUNCTION;
+                       break;
+               case OPT_TYPE_ALL:
+                       opt_event_type = LTTNG_EVENT_ALL;
                        break;
                case OPT_LIST_OPTIONS:
                        list_cmd_options(stdout, long_options);
                        goto end;
                default:
-                       usage(stderr);
                        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;
+                       }
+               }
+       }
+
+       ret = print_missing_or_multiple_domains(
+               opt_kernel + opt_userspace + opt_jul + opt_log4j + opt_python);
+       if (ret) {
+               ret = CMD_ERROR;
+               goto end;
+       }
+
+       /* Ust and agent only support ALL event type */
+       if ((opt_userspace || opt_jul || opt_log4j || opt_python)
+                       && opt_event_type != LTTNG_EVENT_ALL) {
+               ERR("Disabling userspace and agent (-j | -l | -p) event(s) based on instrumentation type is not supported.\n");
+               ret = CMD_ERROR;
+               goto end;
        }
 
        opt_event_list = (char*) poptGetArg(pc);
        if (opt_event_list == NULL && opt_disable_all == 0) {
                ERR("Missing event name(s).\n");
-               usage(stderr);
+               ret = CMD_ERROR;
+               goto end;
+       }
+
+       leftover = poptGetArg(pc);
+       if (leftover) {
+               ERR("Unknown argument: %s", leftover);
                ret = CMD_ERROR;
                goto end;
        }
@@ -403,7 +471,7 @@ end:
                ret = ret ? ret : LTTNG_ERR_MI_IO_FAIL;
        }
 
-       /* Overwrite ret if an error occured in disable_events */
+       /* Overwrite ret if an error occurred in disable_events */
        ret = command_ret ? command_ret : ret;
 
        poptFreeContext(pc);
This page took 0.028495 seconds and 5 git commands to generate.