X-Git-Url: http://git.lttng.org/?a=blobdiff_plain;f=ustctl%2Fmarker_cmds.c;fp=ustctl%2Fmarker_cmds.c;h=20222dd1cdb3678c7d2a2f792888431baf7c0c8c;hb=0c89df6cb75f1d967003137e7fc334af1128a42f;hp=0000000000000000000000000000000000000000;hpb=91594b712729c0d855efeab849c2093706336941;p=ust.git diff --git a/ustctl/marker_cmds.c b/ustctl/marker_cmds.c new file mode 100644 index 0000000..20222dd --- /dev/null +++ b/ustctl/marker_cmds.c @@ -0,0 +1,144 @@ +/* Copyright (C) 2011 Ericsson AB, Nils Carlson + * + * 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 + */ +#include +#include +#include +#include +#include "scanning_functions.h" +#include "usterr.h" +#include "cli.h" + +static int list_markers(int argc, char *argv[]) +{ + struct marker_status *cmsf = NULL; + int i; + pid_t pid; + + pid = parse_pid(argv[1]); + + if (ustcmd_get_cmsf(&cmsf, pid)) { + ERR("error while trying to list markers for PID %u\n", pid); + return -1; + } + for (i = 0; cmsf[i].channel; i++) { + printf("{PID: %u, channel/marker: %s/%s, " + "state: %u, fmt: %s}\n", + (unsigned int) pid, + cmsf[i].channel, + cmsf[i].marker, + cmsf[i].state, + cmsf[i].fs); + } + ustcmd_free_cmsf(cmsf); + return 0; +} + +static int enable_marker(int argc, char *argv[]) +{ + int i, result = 0; + pid_t pid; + char *channel, *marker; + + pid = parse_pid(argv[1]); + + for (i = 3; i < argc; i++) { + channel = NULL; + marker = NULL; + if (scan_ch_marker(argv[i], + &channel, &marker)) { + result = -1; + fprintf(stderr, "Failed to scan channel and marker from" + " %s\n", argv[i]); + if (channel) + free(channel); + if (marker) + free(marker); + } + if (ustcmd_set_marker_state(argv[2], channel, marker, 1, pid)) { + PERROR("error while trying to enable marker %s with PID %u", + argv[i], pid); + result = -1; + } + free(channel); + free(marker); + } + + return result; +} + +static int disable_marker(int argc, char *argv[]) +{ + int i, result = 0; + pid_t pid; + char *channel, *marker; + + pid = parse_pid(argv[1]); + + for (i = 3; i < argc; i++) { + channel = NULL; + marker = NULL; + if (scan_ch_marker(argv[i], + &channel, &marker)) { + fprintf(stderr, "Failed to scan channel and marker from" + " %s\n", argv[i]); + if (channel) + free(channel); + if (marker) + free(marker); + return -1; + } + if (ustcmd_set_marker_state(argv[2], channel, marker, 0, pid)) { + PERROR("error while trying to disable marker %s with PID %u", + argv[i], pid); + result = -1; + } + free(channel); + free(marker); + } + + return result; +} + +struct cli_cmd __cli_cmds marker_cmds[] = { + { + .name = "list-markers", + .description = "List markers for a given pid", + .help_text = "list-markers \n" + "List the markers in a process\n", + .function = list_markers, + .desired_args = 1, + .desired_args_op = CLI_EQ, + }, + { + .name = "enable-marker", + .description = "Enable markers for a given pid", + .help_text = "enable-marker /... \n" + "Enable the listed markers for the trace in process pid\n", + .function = enable_marker, + .desired_args = 3, + .desired_args_op = CLI_GE, + }, + { + .name = "disable-marker", + .description = "Disable markers for a given pid", + .help_text = "disable-marker /... \n" + "Disable the listed markers for the trace in process pid\n", + .function = disable_marker, + .desired_args = 3, + .desired_args_op = CLI_GE, + } +};