| 1 | /* Copyright (C) 2011 Ericsson AB, Nils Carlson <nils.carlson@ericsson.com> |
| 2 | * |
| 3 | * This library is free software; you can redistribute it and/or |
| 4 | * modify it under the terms of the GNU Lesser General Public |
| 5 | * License as published by the Free Software Foundation; either |
| 6 | * version 2.1 of the License, or (at your option) any later version. |
| 7 | * |
| 8 | * This library is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 11 | * Lesser General Public License for more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU Lesser General Public |
| 14 | * License along with this library; if not, write to the Free Software |
| 15 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 16 | */ |
| 17 | #include <stdio.h> |
| 18 | #include <sys/types.h> |
| 19 | #include <unistd.h> |
| 20 | #include <ust/ustctl.h> |
| 21 | #include "scanning_functions.h" |
| 22 | #include "usterr.h" |
| 23 | #include "cli.h" |
| 24 | |
| 25 | static int set_subbuf_size(int argc, char *argv[]) |
| 26 | { |
| 27 | int result = 0; |
| 28 | pid_t pid; |
| 29 | char *channel = NULL; |
| 30 | unsigned int size; |
| 31 | |
| 32 | pid = parse_pid(argv[1]); |
| 33 | |
| 34 | if (scan_ch_and_num(argv[3], &channel, &size)) { |
| 35 | fprintf(stderr, "Failed to scan channel and size from" |
| 36 | " %s\n", argv[3]); |
| 37 | if (channel) |
| 38 | free(channel); |
| 39 | return -1; |
| 40 | } |
| 41 | if (ustctl_set_subbuf_size(argv[2], channel, size, pid)) { |
| 42 | ERR("error while trying to set the size of subbuffers " |
| 43 | "for PID %u\n", |
| 44 | pid); |
| 45 | result = -1; |
| 46 | } |
| 47 | |
| 48 | free(channel); |
| 49 | |
| 50 | return result; |
| 51 | } |
| 52 | |
| 53 | static int set_subbuf_num(int argc, char *argv[]) |
| 54 | { |
| 55 | int result = 0; |
| 56 | pid_t pid; |
| 57 | char *channel = NULL; |
| 58 | unsigned int num; |
| 59 | |
| 60 | pid = parse_pid(argv[1]); |
| 61 | |
| 62 | if (scan_ch_and_num(argv[3], &channel, &num)) { |
| 63 | fprintf(stderr, "Failed to scan channel and number from" |
| 64 | " %s\n", argv[3]); |
| 65 | if (channel) |
| 66 | free(channel); |
| 67 | return -1; |
| 68 | } |
| 69 | if (ustctl_set_subbuf_num(argv[2], channel, num, pid)) { |
| 70 | ERR("error while trying to set the number of subbuffers for PID %u\n", |
| 71 | pid); |
| 72 | result = -1; |
| 73 | } |
| 74 | |
| 75 | free(channel); |
| 76 | |
| 77 | return result; |
| 78 | } |
| 79 | |
| 80 | static int get_subbuf_size(int argc, char *argv[]) |
| 81 | { |
| 82 | pid_t pid; |
| 83 | unsigned int size; |
| 84 | |
| 85 | pid = parse_pid(argv[1]); |
| 86 | |
| 87 | if ((size = ustctl_get_subbuf_size(argv[2], argv[3], pid)) < 0) { |
| 88 | ERR("error while trying to get the subbuffer size from PID %u\n", |
| 89 | pid); |
| 90 | return -1; |
| 91 | } |
| 92 | |
| 93 | printf("The subbufer size is %d bytes\n", size); |
| 94 | |
| 95 | return 0; |
| 96 | } |
| 97 | |
| 98 | static int get_subbuf_num(int argc, char *argv[]) |
| 99 | { |
| 100 | pid_t pid; |
| 101 | unsigned int num; |
| 102 | |
| 103 | pid = parse_pid(argv[1]); |
| 104 | |
| 105 | if ((num = ustctl_get_subbuf_num(argv[2], argv[3], pid)) < 0) { |
| 106 | ERR("error while trying to get the subbuffer size from PID %u\n", |
| 107 | pid); |
| 108 | return -1; |
| 109 | } |
| 110 | |
| 111 | printf("There are %u subbufers in each buffer\n", num); |
| 112 | |
| 113 | return 0; |
| 114 | } |
| 115 | |
| 116 | struct cli_cmd __cli_cmds channel_cmds[] = { |
| 117 | { |
| 118 | .name = "set-subbuf-size", |
| 119 | .description = "Set the subbuffer size for a channel", |
| 120 | .help_text = "set-subbuf-size <pid> <trace> <channel>/<size> \n" |
| 121 | "Set the subbuffer size for a channel\n", |
| 122 | .function = set_subbuf_size, |
| 123 | .desired_args = 3, |
| 124 | .desired_args_op = CLI_EQ, |
| 125 | }, |
| 126 | { |
| 127 | .name = "set-subbuf-num", |
| 128 | .description = "Set the number of subbuffers for a channel", |
| 129 | .help_text = "set-subbuf-num <pid> <trace> <channel>/<num> \n" |
| 130 | "Set the number of subbuffers for a channel\n", |
| 131 | .function = set_subbuf_num, |
| 132 | .desired_args = 3, |
| 133 | .desired_args_op = CLI_EQ, |
| 134 | }, |
| 135 | { |
| 136 | .name = "get-subbuf-size", |
| 137 | .description = "Get the subbuffer size for a channel", |
| 138 | .help_text = "get-subbuf-size <pid> <trace> <channel>\n" |
| 139 | "Get the subbuffer size for a channel\n", |
| 140 | .function = get_subbuf_size, |
| 141 | .desired_args = 3, |
| 142 | .desired_args_op = CLI_EQ, |
| 143 | }, |
| 144 | { |
| 145 | .name = "get-subbuf-num", |
| 146 | .description = "Get the number of subbuffers for a channel", |
| 147 | .help_text = "get-subbuf-num <pid> <trace> <channel>\n" |
| 148 | "Get the number of subbuffers for a channel\n", |
| 149 | .function = get_subbuf_num, |
| 150 | .desired_args = 3, |
| 151 | .desired_args_op = CLI_EQ, |
| 152 | }, |
| 153 | }; |