From: Pierre-Marc Fournier Date: Mon, 5 Oct 2009 20:15:32 +0000 (-0400) Subject: rename ust -> ustctl X-Git-Tag: v0.1~101 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=55ad629d916dc8a9e0e8859bd469815dc9ec6ceb;p=ust.git rename ust -> ustctl --- diff --git a/Makefile.am b/Makefile.am index 2d6c23b..33be5b4 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,5 +1,5 @@ ACLOCAL_AMFLAGS = -I m4 -SUBDIRS = libust tests libmallocwrap ustd ust libinterfork +SUBDIRS = libust tests libmallocwrap ustd ustctl libinterfork EXTRA_DIST = share/kernelcompat.h doc bin_SCRIPTS = usttrace diff --git a/README b/README index 71ad996..1b86fb2 100644 --- a/README +++ b/README @@ -28,7 +28,7 @@ Package contents: The actual userspace tracing library that must be linked to the instrumented programs. -- ust +- ustctl A program to control the tracing of userspace applications. It can list markers, start the tracing, stop the tracing, enable/disable markers, etc. diff --git a/configure.ac b/configure.ac index 9bf9c2c..bc8c325 100644 --- a/configure.ac +++ b/configure.ac @@ -6,7 +6,7 @@ AC_INIT([ust], [0.0], [pierre-marc dot fournier at polymtl dot ca]) AC_CONFIG_AUX_DIR([config]) AC_CONFIG_MACRO_DIR([m4]) AM_INIT_AUTOMAKE([0.0 foreign dist-bzip2 no-dist-gzip]) -AC_CONFIG_SRCDIR([ust/ust.c]) +AC_CONFIG_SRCDIR([ustctl/ustctl.c]) AC_CONFIG_HEADERS([config.h]) # Checks for programs. @@ -87,7 +87,7 @@ AC_CONFIG_FILES([ libmallocwrap/Makefile libinterfork/Makefile ustd/Makefile - ust/Makefile + ustctl/Makefile java/Makefile ]) AC_OUTPUT diff --git a/ust/Makefile.am b/ust/Makefile.am deleted file mode 100644 index dcd23a8..0000000 --- a/ust/Makefile.am +++ /dev/null @@ -1,8 +0,0 @@ -bin_PROGRAMS = ust -ust_SOURCES = ust.c $(top_builddir)/libustcomm/ustcomm.c $(top_builddir)/libustcomm/ustcomm.h $(top_builddir)/libustcmd/ustcmd.c $(top_builddir)/libustcmd/ustcmd.h $(top_builddir)/share/usterr.h -ust_CFLAGS = -DUST_COMPONENT=ust - -INCLUDES = $(KCOMPAT_CFLAGS) -INCLUDES += -I$(top_builddir)/libustcomm -INCLUDES += -I$(top_builddir)/libustcmd -INCLUDES += -I$(top_builddir)/share diff --git a/ust/README b/ust/README deleted file mode 100644 index 69e513b..0000000 --- a/ust/README +++ /dev/null @@ -1,3 +0,0 @@ -ust is a helper application used to control tracing on programs that support tracing. - -It can list markers, enable/disable markers, start tracing and stop tracing. diff --git a/ust/ust.c b/ust/ust.c deleted file mode 100644 index 789dfe0..0000000 --- a/ust/ust.c +++ /dev/null @@ -1,299 +0,0 @@ -/* Copyright (C) 2009 Pierre-Marc Fournier - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#define _GNU_SOURCE -#include -#include -#include -#include -#include - -#include "ustcomm.h" -#include "ustcmd.h" -#include "usterr.h" - -enum command { - START_TRACE, - STOP_TRACE, - START, - DESTROY, - LIST_MARKERS, - ENABLE_MARKER, - DISABLE_MARKER, - GET_ONLINE_PIDS, - UNKNOWN -}; - -struct ust_opts { - enum command cmd; - pid_t *pids; - char *regex; -}; - -char *progname = NULL; - -void usage(void) -{ - fprintf(stderr, "usage: %s COMMAND PIDs...\n", progname); - fprintf(stderr, "\nControl the tracing of a process that supports LTTng Userspace Tracing.\n\ -\n\ -Commands:\n\ - --start-trace\t\t\tStart tracing\n\ - --stop-trace\t\t\tStop tracing\n\ - --destroy-trace\t\t\tDestroy the trace\n\ - --enable-marker \"CHANNEL/MARKER\"\tEnable a marker\n\ - --disable-marker \"CHANNEL/MARKER\"\tDisable a marker\n\ - --list-markers\t\t\tList the markers of the process, their\n\t\t\t\t\t state and format string\n\ -\ -"); -} - -int parse_opts_long(int argc, char **argv, struct ust_opts *opts) -{ - int c; - - opts->pids = NULL; - opts->regex = NULL; - - while (1) { - int option_index = 0; - static struct option long_options[] = { - {"start-trace", 0, 0, 1000}, - {"stop-trace", 0, 0, 1001}, - {"destroy-trace", 0, 0, 1002}, - {"list-markers", 0, 0, 1004}, - {"print-markers", 0, 0, 1005}, - {"pid", 1, 0, 1006}, - {"enable-marker", 1, 0, 1007}, - {"disable-marker", 1, 0, 1008}, - {"start", 0, 0, 1009}, - {"help", 0, 0, 'h'}, - {"version", 0, 0, 1010}, - {"online-pids", 0, 0, 1011}, - {0, 0, 0, 0} - }; - - c = getopt_long(argc, argv, "h", long_options, &option_index); - if (c == -1) - break; - - switch (c) { - case 0: - printf("option %s", long_options[option_index].name); - if (optarg) - printf(" with arg %s", optarg); - printf("\n"); - break; - - case 1000: - opts->cmd = START_TRACE; - break; - case 1001: - opts->cmd = STOP_TRACE; - break; - case 1009: - opts->cmd = START; - break; - case 1002: - opts->cmd = DESTROY; - break; - case 1004: - opts->cmd = LIST_MARKERS; - break; - case 1007: - opts->cmd = ENABLE_MARKER; - opts->regex = strdup(optarg); - break; - case 1008: - opts->cmd = DISABLE_MARKER; - opts->regex = strdup(optarg); - break; - case 1011: - opts->cmd = GET_ONLINE_PIDS; - break; - case 'h': - usage(); - exit(0); - case 1010: - printf("Version 0.1\n"); - - default: - /* unknown option or other error; error is - printed by getopt, just return */ - opts->cmd = UNKNOWN; - return 1; - } - } - - if (argc - optind > 0 && opts->cmd != GET_ONLINE_PIDS) { - int i; - int pididx=0; - opts->pids = malloc((argc-optind+1) * sizeof(pid_t)); - - for(i=optind; ipids[pididx++] = (pid_t) tmp; - } - opts->pids[pididx] = -1; - } - - return 0; -} - -int main(int argc, char *argv[]) -{ - pid_t *pidit; - int result; - struct ust_opts opts; - - progname = argv[0]; - - if(argc <= 1) { - fprintf(stderr, "No operation specified.\n"); - usage(); - exit(EXIT_FAILURE); - } - - result = parse_opts_long(argc, argv, &opts); - if(result) { - fprintf(stderr, "\n"); - usage(); - exit(EXIT_FAILURE); - } - - if(opts.pids == NULL && opts.cmd != GET_ONLINE_PIDS) { - fprintf(stderr, "No pid specified.\n"); - usage(); - exit(EXIT_FAILURE); - } - if(opts.cmd == UNKNOWN) { - fprintf(stderr, "No command specified.\n"); - usage(); - exit(EXIT_FAILURE); - } - if (opts.cmd == GET_ONLINE_PIDS) { - pid_t *pp = ustcmd_get_online_pids(); - unsigned int i = 0; - - if (pp) { - while (pp[i] != 0) { - printf("%u\n", (unsigned int) pp[i]); - ++i; - } - free(pp); - } - - exit(EXIT_SUCCESS); - } - - pidit = opts.pids; - struct marker_status *cmsf = NULL; - - while(*pidit != -1) { - switch (opts.cmd) { - case START_TRACE: - result = ustcmd_start_trace(*pidit); - if (result) { - ERR("error while trying to for trace with PID %u\n", (unsigned int) *pidit); - break; - } - //printf("sucessfully started trace for PID %u\n", (unsigned int) *pidit); - break; - - case STOP_TRACE: - result = ustcmd_stop_trace(*pidit); - if (result) { - ERR("error while trying to stop trace for PID %u\n", (unsigned int) *pidit); - break; - } - //printf("sucessfully stopped trace for PID %u\n", (unsigned int) *pidit); - break; - - case START: - result = ustcmd_setup_and_start(*pidit); - if (result) { - ERR("error while trying to setup/start trace for PID %u\n", (unsigned int) *pidit); - break; - } - //printf("sucessfully setup/started trace for PID %u\n", (unsigned int) *pidit); - break; - - case DESTROY: - result = ustcmd_destroy_trace(*pidit); - if (result) { - ERR("error while trying to destroy trace with PID %u\n", (unsigned int) *pidit); - break; - } - //printf("sucessfully destroyed trace for PID %u\n", (unsigned int) *pidit); - break; - - case LIST_MARKERS: - cmsf = NULL; - if (ustcmd_get_cmsf(&cmsf, *pidit)) { - fprintf(stderr, - "error while trying to list markers for" - " PID %u\n", (unsigned int) *pidit); - break; - } - unsigned int i = 0; - while (cmsf[i].channel != NULL) { - printf("{PID: %u, channel/marker: %s/%s, " - "state: %u, fmt: %s}\n", - (unsigned int) *pidit, - cmsf[i].channel, - cmsf[i].marker, - cmsf[i].state, - cmsf[i].fs); - ++i; - } - ustcmd_free_cmsf(cmsf); - break; - - case ENABLE_MARKER: - if(opts.regex) - ustcmd_set_marker_state(opts.regex, 1, *pidit); - break; - case DISABLE_MARKER: - if(opts.regex) - ustcmd_set_marker_state(opts.regex, 0, *pidit); - break; - - default: - ERR("unknown command\n"); - break; - } - - pidit++; - } - - if (opts.pids != NULL) { - free(opts.pids); - } - if (opts.regex != NULL) { - free(opts.regex); - } - - return 0; -} - diff --git a/ustctl/Makefile.am b/ustctl/Makefile.am new file mode 100644 index 0000000..7ceca54 --- /dev/null +++ b/ustctl/Makefile.am @@ -0,0 +1,8 @@ +bin_PROGRAMS = ustctl +ustctl_SOURCES = ustctl.c $(top_builddir)/libustcomm/ustcomm.c $(top_builddir)/libustcomm/ustcomm.h $(top_builddir)/libustcmd/ustcmd.c $(top_builddir)/libustcmd/ustcmd.h $(top_builddir)/share/usterr.h +ustctl_CFLAGS = -DUST_COMPONENT=ust + +INCLUDES = $(KCOMPAT_CFLAGS) +INCLUDES += -I$(top_builddir)/libustcomm +INCLUDES += -I$(top_builddir)/libustcmd +INCLUDES += -I$(top_builddir)/share diff --git a/ustctl/README b/ustctl/README new file mode 100644 index 0000000..3fdfbbd --- /dev/null +++ b/ustctl/README @@ -0,0 +1,3 @@ +ustctl is a helper application used to control tracing on programs that support tracing. + +It can list markers, enable/disable markers, start tracing and stop tracing. diff --git a/ustctl/ustctl.c b/ustctl/ustctl.c new file mode 100644 index 0000000..789dfe0 --- /dev/null +++ b/ustctl/ustctl.c @@ -0,0 +1,299 @@ +/* Copyright (C) 2009 Pierre-Marc Fournier + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#define _GNU_SOURCE +#include +#include +#include +#include +#include + +#include "ustcomm.h" +#include "ustcmd.h" +#include "usterr.h" + +enum command { + START_TRACE, + STOP_TRACE, + START, + DESTROY, + LIST_MARKERS, + ENABLE_MARKER, + DISABLE_MARKER, + GET_ONLINE_PIDS, + UNKNOWN +}; + +struct ust_opts { + enum command cmd; + pid_t *pids; + char *regex; +}; + +char *progname = NULL; + +void usage(void) +{ + fprintf(stderr, "usage: %s COMMAND PIDs...\n", progname); + fprintf(stderr, "\nControl the tracing of a process that supports LTTng Userspace Tracing.\n\ +\n\ +Commands:\n\ + --start-trace\t\t\tStart tracing\n\ + --stop-trace\t\t\tStop tracing\n\ + --destroy-trace\t\t\tDestroy the trace\n\ + --enable-marker \"CHANNEL/MARKER\"\tEnable a marker\n\ + --disable-marker \"CHANNEL/MARKER\"\tDisable a marker\n\ + --list-markers\t\t\tList the markers of the process, their\n\t\t\t\t\t state and format string\n\ +\ +"); +} + +int parse_opts_long(int argc, char **argv, struct ust_opts *opts) +{ + int c; + + opts->pids = NULL; + opts->regex = NULL; + + while (1) { + int option_index = 0; + static struct option long_options[] = { + {"start-trace", 0, 0, 1000}, + {"stop-trace", 0, 0, 1001}, + {"destroy-trace", 0, 0, 1002}, + {"list-markers", 0, 0, 1004}, + {"print-markers", 0, 0, 1005}, + {"pid", 1, 0, 1006}, + {"enable-marker", 1, 0, 1007}, + {"disable-marker", 1, 0, 1008}, + {"start", 0, 0, 1009}, + {"help", 0, 0, 'h'}, + {"version", 0, 0, 1010}, + {"online-pids", 0, 0, 1011}, + {0, 0, 0, 0} + }; + + c = getopt_long(argc, argv, "h", long_options, &option_index); + if (c == -1) + break; + + switch (c) { + case 0: + printf("option %s", long_options[option_index].name); + if (optarg) + printf(" with arg %s", optarg); + printf("\n"); + break; + + case 1000: + opts->cmd = START_TRACE; + break; + case 1001: + opts->cmd = STOP_TRACE; + break; + case 1009: + opts->cmd = START; + break; + case 1002: + opts->cmd = DESTROY; + break; + case 1004: + opts->cmd = LIST_MARKERS; + break; + case 1007: + opts->cmd = ENABLE_MARKER; + opts->regex = strdup(optarg); + break; + case 1008: + opts->cmd = DISABLE_MARKER; + opts->regex = strdup(optarg); + break; + case 1011: + opts->cmd = GET_ONLINE_PIDS; + break; + case 'h': + usage(); + exit(0); + case 1010: + printf("Version 0.1\n"); + + default: + /* unknown option or other error; error is + printed by getopt, just return */ + opts->cmd = UNKNOWN; + return 1; + } + } + + if (argc - optind > 0 && opts->cmd != GET_ONLINE_PIDS) { + int i; + int pididx=0; + opts->pids = malloc((argc-optind+1) * sizeof(pid_t)); + + for(i=optind; ipids[pididx++] = (pid_t) tmp; + } + opts->pids[pididx] = -1; + } + + return 0; +} + +int main(int argc, char *argv[]) +{ + pid_t *pidit; + int result; + struct ust_opts opts; + + progname = argv[0]; + + if(argc <= 1) { + fprintf(stderr, "No operation specified.\n"); + usage(); + exit(EXIT_FAILURE); + } + + result = parse_opts_long(argc, argv, &opts); + if(result) { + fprintf(stderr, "\n"); + usage(); + exit(EXIT_FAILURE); + } + + if(opts.pids == NULL && opts.cmd != GET_ONLINE_PIDS) { + fprintf(stderr, "No pid specified.\n"); + usage(); + exit(EXIT_FAILURE); + } + if(opts.cmd == UNKNOWN) { + fprintf(stderr, "No command specified.\n"); + usage(); + exit(EXIT_FAILURE); + } + if (opts.cmd == GET_ONLINE_PIDS) { + pid_t *pp = ustcmd_get_online_pids(); + unsigned int i = 0; + + if (pp) { + while (pp[i] != 0) { + printf("%u\n", (unsigned int) pp[i]); + ++i; + } + free(pp); + } + + exit(EXIT_SUCCESS); + } + + pidit = opts.pids; + struct marker_status *cmsf = NULL; + + while(*pidit != -1) { + switch (opts.cmd) { + case START_TRACE: + result = ustcmd_start_trace(*pidit); + if (result) { + ERR("error while trying to for trace with PID %u\n", (unsigned int) *pidit); + break; + } + //printf("sucessfully started trace for PID %u\n", (unsigned int) *pidit); + break; + + case STOP_TRACE: + result = ustcmd_stop_trace(*pidit); + if (result) { + ERR("error while trying to stop trace for PID %u\n", (unsigned int) *pidit); + break; + } + //printf("sucessfully stopped trace for PID %u\n", (unsigned int) *pidit); + break; + + case START: + result = ustcmd_setup_and_start(*pidit); + if (result) { + ERR("error while trying to setup/start trace for PID %u\n", (unsigned int) *pidit); + break; + } + //printf("sucessfully setup/started trace for PID %u\n", (unsigned int) *pidit); + break; + + case DESTROY: + result = ustcmd_destroy_trace(*pidit); + if (result) { + ERR("error while trying to destroy trace with PID %u\n", (unsigned int) *pidit); + break; + } + //printf("sucessfully destroyed trace for PID %u\n", (unsigned int) *pidit); + break; + + case LIST_MARKERS: + cmsf = NULL; + if (ustcmd_get_cmsf(&cmsf, *pidit)) { + fprintf(stderr, + "error while trying to list markers for" + " PID %u\n", (unsigned int) *pidit); + break; + } + unsigned int i = 0; + while (cmsf[i].channel != NULL) { + printf("{PID: %u, channel/marker: %s/%s, " + "state: %u, fmt: %s}\n", + (unsigned int) *pidit, + cmsf[i].channel, + cmsf[i].marker, + cmsf[i].state, + cmsf[i].fs); + ++i; + } + ustcmd_free_cmsf(cmsf); + break; + + case ENABLE_MARKER: + if(opts.regex) + ustcmd_set_marker_state(opts.regex, 1, *pidit); + break; + case DISABLE_MARKER: + if(opts.regex) + ustcmd_set_marker_state(opts.regex, 0, *pidit); + break; + + default: + ERR("unknown command\n"); + break; + } + + pidit++; + } + + if (opts.pids != NULL) { + free(opts.pids); + } + if (opts.regex != NULL) { + free(opts.regex); + } + + return 0; +} +