Add calibrate command
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Sat, 6 Aug 2011 06:33:48 +0000 (02:33 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Sat, 6 Aug 2011 06:33:48 +0000 (02:33 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
15 files changed:
include/lttng-kernel.h
include/lttng/lttng.h
libkernelctl/kernel-ioctl.h
libkernelctl/libkernelctl.c
libkernelctl/libkernelctl.h
liblttngctl/liblttngctl.c
liblttsessiondcomm/liblttsessiondcomm.h
ltt-sessiond/kernel-ctl.c
ltt-sessiond/kernel-ctl.h
ltt-sessiond/ltt-sessiond.h
ltt-sessiond/main.c
lttng/Makefile.am
lttng/cmd.h
lttng/commands/calibrate.c [new file with mode: 0644]
lttng/lttng.c

index 9eb207bb2fd4e255cf88bccc8de61f27ce99deec..95f003f2df2391423dff548e6bc90f3ce25c41e0 100644 (file)
@@ -105,4 +105,12 @@ struct lttng_kernel_tracer_version {
        uint32_t sublevel;
 };
 
+enum lttng_kernel_calibrate_type {
+       LTTNG_KERNEL_CALIBRATE_KRETPROBE,
+};
+
+struct lttng_kernel_calibrate {
+       enum lttng_kernel_calibrate_type type;  /* type (input) */
+};
+
 #endif /* _LTTNG_KERNEL_H */
index eb34a73490615593ce8b7a4a0b0c0b82bd5ed0fe..c08580ac2fc70d076e1ddedbd294a6751f10c76e 100644 (file)
@@ -90,6 +90,10 @@ enum lttng_event_context_type {
        LTTNG_EVENT_CONTEXT_VPPID              = 9,
 };
 
+enum lttng_calibrate_type {
+       LTTNG_CALIBRATE_FUNCTION               = 0,
+};
+
 struct lttng_domain {
        enum lttng_domain_type type;
        union {
@@ -167,6 +171,10 @@ struct lttng_channel {
        struct lttng_channel_attr attr;
 };
 
+struct lttng_calibrate {
+       enum lttng_calibrate_type type;
+};
+
 /*
  * Basic session information.
  *
@@ -333,4 +341,10 @@ extern int lttng_disable_event(struct lttng_domain *domain, const char *name,
 extern int lttng_disable_channel(struct lttng_domain *domain,
                const char *name);
 
+/*
+ * Calibrate LTTng overhead.
+ */
+extern int lttng_calibrate(struct lttng_domain *domain,
+               struct lttng_calibrate *calibrate);
+
 #endif /* _LTTNG_H */
index 848ecbc46fe84ba81c425ba866864bd5ae7a5acc..408535d431a7578702cc4544f38f69dada71ae78 100644 (file)
@@ -54,6 +54,8 @@
                _IOR(0xF6, 0x41, struct lttng_kernel_tracer_version)
 #define LTTNG_KERNEL_TRACEPOINT_LIST        _IO(0xF6, 0x42)
 #define LTTNG_KERNEL_WAIT_QUIESCENT         _IO(0xF6, 0x43)
+#define LTTNG_KERNEL_CALIBRATE                 \
+       _IOWR(0xF6, 0x44, struct lttng_kernel_calibrate)
 
 /* Session FD ioctl */
 #define LTTNG_KERNEL_METADATA               \
index 1f30c77c0bb42e9502d6899557dae183362ddf36..78b2563473fd370be92dc116dc57875af59c45e3 100644 (file)
@@ -166,3 +166,8 @@ int kernctl_wait_quiescent(int fd)
 {
        return ioctl(fd, LTTNG_KERNEL_WAIT_QUIESCENT);
 }
+
+int kernctl_calibrate(int fd, struct lttng_kernel_calibrate *calibrate)
+{
+       return ioctl(fd, LTTNG_KERNEL_CALIBRATE, calibrate);
+}
index 25e5d0c1b2e2a13a91fd6da620d7ad3023a9d1c7..026f58d21df89de12faf9b552cd6672d4a7cba47 100644 (file)
@@ -50,5 +50,6 @@ int kernctl_stop_session(int fd);
 int kernctl_tracepoint_list(int fd);
 int kernctl_tracer_version(int fd, struct lttng_kernel_tracer_version *v);
 int kernctl_wait_quiescent(int fd);
+int kernctl_calibrate(int fd, struct lttng_kernel_calibrate *calibrate);
 
 #endif /* _LTT_LIBKERNELCTL_H */
index 37e202f2c35f7f1a099a50d7f9b4fa91524bf79d..4faf8414f7cf5d7deb31f2658ee0a7a850a1fe00 100644 (file)
@@ -575,6 +575,22 @@ int lttng_set_tracing_group(const char *name)
        return 0;
 }
 
+/*
+ *  lttng_calibrate
+ */
+int lttng_calibrate(struct lttng_domain *domain,
+               struct lttng_calibrate *calibrate)
+{
+       int ret;
+
+       copy_lttng_domain(domain);
+
+       memcpy(&lsm.u.calibrate, calibrate, sizeof(struct lttng_calibrate));
+       ret = ask_sessiond(LTTNG_CALIBRATE, NULL);
+
+       return ret;
+}
+
 /*
  *  lttng_check_session_daemon
  *
index fa178aae1c396c75ab042b493565333b14a34c6f..a06bb91757405fe4ad3a3ff56a36613f840577fe 100644 (file)
@@ -59,6 +59,7 @@ enum lttcomm_sessiond_command {
        LTTNG_LIST_TRACEPOINTS,
        LTTNG_START_TRACE,
        LTTNG_STOP_TRACE,
+       LTTNG_CALIBRATE,
 };
 
 /*
@@ -152,6 +153,7 @@ struct lttcomm_session_msg {
                struct {
                        char channel_name[NAME_MAX];
                } list;
+               struct lttng_calibrate calibrate;
        } u;
 };
 
index 27210708e64f1f791b9322d78e01fe7d3258d5e9..3dd146dd4b9792fe6754ef1136a49aef6b111c53 100644 (file)
@@ -408,6 +408,23 @@ void kernel_wait_quiescent(int fd)
        }
 }
 
+/*
+ *  kernel_calibrate
+ */
+int kernel_calibrate(int fd, struct lttng_kernel_calibrate *calibrate)
+{
+       int ret;
+
+       ret = kernctl_calibrate(fd, calibrate);
+       if (ret < 0) {
+               perror("calibrate ioctl");
+               return -1;
+       }
+
+       return 0;
+}
+
+
 /*
  *  kernel_metadata_flush_buffer
  *
index 22250417db7883b496efa8d9211525add09a642c..df0cca2af08e896ca852b7c5cdf1670c721802bb 100644 (file)
@@ -51,5 +51,6 @@ int kernel_start_session(struct ltt_kernel_session *session);
 int kernel_stop_session(struct ltt_kernel_session *session);
 ssize_t kernel_list_events(int tracer_fd, struct lttng_event **event_list);
 void kernel_wait_quiescent(int fd);
+int kernel_calibrate(int fd, struct lttng_kernel_calibrate *calibrate);
 
 #endif /* _LTT_KERNEL_CTL_H */
index febc4eb121c23ecf67422345b87b7d92212e0eab..acdc9724b185d1c05906674ff20ff9de91fb268a 100644 (file)
@@ -31,11 +31,11 @@ struct module_param {
 
 /* LTTng kernel tracer modules list */
 const struct module_param kernel_modules_list[] = {
-       { "ltt-relay", 1 },
        { "lttng-ftrace", 0 },
        { "lttng-kprobes", 0 },
        { "lttng-kretprobes", 0 },
        { "lib-ring-buffer", 1 },
+       { "ltt-relay", 1 },
        { "ltt-ring-buffer-client-discard", 1 },
        { "ltt-ring-buffer-client-overwrite", 1 },
        { "ltt-ring-buffer-metadata-client", 1 },
index b3dc0e3a6f08ee397935c8a672e2470179633980..5636700d8fad1cd3127c9c6571b03a648782261d 100644 (file)
@@ -1321,6 +1321,7 @@ static int process_client_msg(struct command_ctx *cmd_ctx)
        case LTTNG_CREATE_SESSION:
        case LTTNG_LIST_SESSIONS:
        case LTTNG_LIST_TRACEPOINTS:
+       case LTTNG_CALIBRATE:
                break;
        default:
                DBG("Getting session %s by name", cmd_ctx->lsm->session.name);
@@ -1341,7 +1342,7 @@ static int process_client_msg(struct command_ctx *cmd_ctx)
        }
 
        /*
-        * Check domain type for specifif "pre-action".
+        * Check domain type for specific "pre-action".
         */
        switch (cmd_ctx->lsm->domain.type) {
        case LTTNG_DOMAIN_KERNEL:
@@ -1355,21 +1356,27 @@ static int process_client_msg(struct command_ctx *cmd_ctx)
                }
 
                /* Need a session for kernel command */
-               if (cmd_ctx->lsm->cmd_type != LTTNG_LIST_TRACEPOINTS &&
-                               cmd_ctx->session->kernel_session == NULL) {
-
-                       ret = create_kernel_session(cmd_ctx->session);
-                       if (ret < 0) {
-                               ret = LTTCOMM_KERN_SESS_FAIL;
-                               goto error;
-                       }
-
-                       /* Start the kernel consumer daemon */
-                       if (kconsumerd_pid == 0) {
-                               ret = start_kconsumerd();
+               switch (cmd_ctx->lsm->cmd_type) {
+               case LTTNG_CREATE_SESSION:
+               case LTTNG_LIST_SESSIONS:
+               case LTTNG_LIST_TRACEPOINTS:
+               case LTTNG_CALIBRATE:
+                       break;
+               default:
+                       if (cmd_ctx->session->kernel_session == NULL) {
+                               ret = create_kernel_session(cmd_ctx->session);
                                if (ret < 0) {
+                                       ret = LTTCOMM_KERN_SESS_FAIL;
                                        goto error;
                                }
+
+                               /* Start the kernel consumer daemon */
+                               if (kconsumerd_pid == 0) {
+                                       ret = start_kconsumerd();
+                                       if (ret < 0) {
+                                               goto error;
+                                       }
+                               }
                        }
                }
                break;
@@ -2049,6 +2056,37 @@ static int process_client_msg(struct command_ctx *cmd_ctx)
                ret = LTTCOMM_OK;
                break;
        }
+
+       case LTTNG_CALIBRATE:
+       {
+               /* Setup lttng message with no payload */
+               ret = setup_lttng_msg(cmd_ctx, 0);
+               if (ret < 0) {
+                       goto setup_error;
+               }
+
+               switch (cmd_ctx->lsm->domain.type) {
+               case LTTNG_DOMAIN_KERNEL:
+               {
+                       struct lttng_kernel_calibrate kcalibrate;
+
+                       kcalibrate.type = cmd_ctx->lsm->u.calibrate.type;
+                       ret = kernel_calibrate(kernel_tracer_fd, &kcalibrate);
+                       if (ret < 0) {
+                               ret = LTTCOMM_KERN_ENABLE_FAIL;
+                               goto error;
+                       }
+                       break;
+               }
+               default:
+                       /* TODO: Userspace tracing */
+                       ret = LTTCOMM_NOT_IMPLEMENTED;
+                       goto error;
+               }
+               ret = LTTCOMM_OK;
+               break;
+       }
+
        default:
                /* Undefined command */
                ret = setup_lttng_msg(cmd_ctx, 0);
index 9d696aa01f360232f2b67ba985c4590618d78871..8dc68e45b7e89c97a8aaeef9436b99d9b21e51c3 100644 (file)
@@ -8,7 +8,7 @@ lttng_SOURCES = cmd.h conf.c conf.h commands/start.c \
                                commands/disable_events.c commands/enable_channels.c \
                                commands/disable_channels.c commands/add_context.c \
                                commands/set_session.c commands/version.c \
-                               utils.c utils.h lttng.c
+                               commands/calibrate.c utils.c utils.h lttng.c
 
 lttng_LDADD = \
                $(top_builddir)/liblttngctl/liblttngctl.la
index 85efd734a6ec4735465c07b4b125bfd2c6e8f144..257d0a1c490fa33d9f3ba761690fe8ba4da53bb3 100644 (file)
@@ -49,5 +49,6 @@ extern int cmd_disable_channels(int argc, const char **argv);
 extern int cmd_add_context(int argc, const char **argv);
 extern int cmd_set_session(int argc, const char **argv);
 extern int cmd_version(int argc, const char **argv);
+extern int cmd_calibrate(int argc, const char **argv);
 
 #endif /* _LTTNG_CMD_H */
diff --git a/lttng/commands/calibrate.c b/lttng/commands/calibrate.c
new file mode 100644 (file)
index 0000000..40d1c45
--- /dev/null
@@ -0,0 +1,198 @@
+/*
+ * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
+ * Copyright (C) 2011 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; only version 2
+ * of the License.
+ *
+ * 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+
+#define _GNU_SOURCE
+#include <popt.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <inttypes.h>
+#include <ctype.h>
+
+#include "../cmd.h"
+#include "../conf.h"
+#include "../utils.h"
+
+static int opt_event_type;
+static char *opt_kernel;
+static char *opt_cmd_name;
+static int opt_pid_all;
+static int opt_userspace;
+static pid_t opt_pid;
+
+enum {
+       OPT_HELP = 1,
+       OPT_USERSPACE,
+       OPT_TRACEPOINT,
+       OPT_MARKER,
+       OPT_PROBE,
+       OPT_FUNCTION,
+       OPT_FUNCTION_ENTRY,
+};
+
+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, 0, OPT_USERSPACE, 0, 0},
+       {"all",            0,   POPT_ARG_VAL, &opt_pid_all, 1, 0, 0},
+       {"pid",            'p', POPT_ARG_INT, &opt_pid, 0, 0, 0},
+       {"tracepoint",     0,   POPT_ARG_NONE, 0, OPT_TRACEPOINT, 0, 0},
+       {"marker",         0,   POPT_ARG_NONE, 0, OPT_MARKER, 0, 0},
+       {"probe",          0,   POPT_ARG_NONE, 0, OPT_PROBE, 0, 0},
+       {"function",       0,   POPT_ARG_NONE, 0, OPT_FUNCTION, 0, 0},
+       {"function:entry", 0,   POPT_ARG_NONE, 0, OPT_FUNCTION_ENTRY, 0, 0},
+       {0, 0, 0, 0, 0, 0, 0}
+};
+
+/*
+ * usage
+ */
+static void usage(FILE *ofp)
+{
+       fprintf(ofp, "usage: lttng calibrate [options] [calibrate_options]\n");
+       fprintf(ofp, "\n");
+       fprintf(ofp, "  -h, --help               Show this help\n");
+       fprintf(ofp, "  -k, --kernel             Apply for the kernel tracer\n");
+       fprintf(ofp, "  -u, --userspace [CMD]    Apply for the user-space tracer\n");
+       fprintf(ofp, "      --all                If -u, apply on all traceable apps\n");
+       fprintf(ofp, "  -p, --pid PID            If -u, apply on a specific PID\n");
+       fprintf(ofp, "\n");
+       fprintf(ofp, "Calibrate options:\n");
+       fprintf(ofp, "    --tracepoint           Tracepoint event (default)\n");
+       fprintf(ofp, "    --probe\n");
+       fprintf(ofp, "                           Dynamic probe.\n");
+       fprintf(ofp, "    --function\n");
+       fprintf(ofp, "                           Dynamic function entry/return probe.\n");
+       fprintf(ofp, "    --function:entry symbol\n");
+       fprintf(ofp, "                           Function tracer event\n");
+       fprintf(ofp, "    --marker               User-space marker (deprecated)\n");
+       fprintf(ofp, "\n");
+}
+
+/*
+ *  calibrate_lttng
+ *
+ *  Calibrate LTTng.
+ */
+static int calibrate_lttng(void)
+{
+       int ret = CMD_SUCCESS;
+       struct lttng_domain dom;
+       struct lttng_calibrate calibrate;
+
+       /* Create lttng domain */
+       if (opt_kernel) {
+               dom.type = LTTNG_DOMAIN_KERNEL;
+       }
+
+       /* Kernel tracer action */
+       if (opt_kernel) {
+               switch (opt_event_type) {
+               case LTTNG_EVENT_TRACEPOINT:
+                       DBG("Calibrating kernel tracepoints");
+                       break;
+               case LTTNG_EVENT_PROBE:
+                       DBG("Calibrating kernel probes");
+                       break;
+               case LTTNG_EVENT_FUNCTION:
+                       DBG("Calibrating kernel functions");
+                       calibrate.type = LTTNG_CALIBRATE_FUNCTION;
+                       ret = lttng_calibrate(&dom, &calibrate);
+                       break;
+               case LTTNG_EVENT_FUNCTION_ENTRY:
+                       DBG("Calibrating kernel function entry");
+                       break;
+               default:
+                       ret = CMD_NOT_IMPLEMENTED;
+                       goto end;
+               }
+       } else if (opt_userspace) {             /* User-space tracer action */
+               /*
+                * TODO: Waiting on lttng UST 2.0
+                */
+               if (opt_pid_all) {
+               } else if (opt_pid != 0) {
+               }
+               ret = CMD_NOT_IMPLEMENTED;
+               goto end;
+       } else {
+               ERR("Please specify a tracer (kernel or user-space)");
+               goto end;
+       }
+end:
+       return ret;
+}
+
+/*
+ *  cmd_calibrate
+ *
+ *  Calibrate LTTng tracer.
+ */
+int cmd_calibrate(int argc, const char **argv)
+{
+       int opt, ret;
+       static poptContext pc;
+
+       pc = poptGetContext(NULL, argc, argv, long_options, 0);
+       poptReadDefaultConfig(pc, 0);
+
+       /* Default event type */
+       opt_event_type = LTTNG_EVENT_TRACEPOINT;
+
+       while ((opt = poptGetNextOpt(pc)) != -1) {
+               switch (opt) {
+               case OPT_HELP:
+                       usage(stderr);
+                       ret = CMD_SUCCESS;
+                       goto end;
+               case OPT_USERSPACE:
+                       opt_userspace = 1;
+                       opt_cmd_name = poptGetOptArg(pc);
+                       break;
+               case OPT_TRACEPOINT:
+                       ret = CMD_NOT_IMPLEMENTED;
+                       break;
+               case OPT_MARKER:
+                       ret = CMD_NOT_IMPLEMENTED;
+                       goto end;
+               case OPT_PROBE:
+                       ret = CMD_NOT_IMPLEMENTED;
+                       break;
+               case OPT_FUNCTION:
+                       opt_event_type = LTTNG_EVENT_FUNCTION;
+                       break;
+               case OPT_FUNCTION_ENTRY:
+                       ret = CMD_NOT_IMPLEMENTED;
+                       break;
+               default:
+                       usage(stderr);
+                       ret = CMD_UNDEFINED;
+                       goto end;
+               }
+       }
+
+       ret = calibrate_lttng();
+
+end:
+       return ret;
+}
index 3e5f1b187f238049bc8c81a01fafbd161083888f..4d81d2a1d4d9fe7914cd84bec9132207fed65f0c 100644 (file)
@@ -71,6 +71,7 @@ static struct cmd_struct commands[] =  {
        { "add-context", cmd_add_context},
        { "set-session", cmd_set_session},
        { "version", cmd_version},
+       { "calibrate", cmd_calibrate},
        { NULL, NULL}   /* Array closure */
 };
 
@@ -91,6 +92,7 @@ static void usage(FILE *ofp)
        fprintf(ofp, "\n");
        fprintf(ofp, "Commands:\n");
        fprintf(ofp, "    add-context     Add context to event or/and channel\n");
+       fprintf(ofp, "    calibrate       Quantify LTTng overhead\n");
        fprintf(ofp, "    create          Create tracing session\n");
        fprintf(ofp, "    destroy         Teardown tracing session\n");
        fprintf(ofp, "    enable-channel  Enable tracing channel\n");
This page took 0.037897 seconds and 5 git commands to generate.