Update version to 0.16
[ust.git] / ustctl / channel_cmds.c
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 sock, result = 0;
28 char *channel = NULL;
29 unsigned int size;
30
31 sock = parse_and_connect_pid(argv[1]);
32
33 if (scan_ch_and_num(argv[3], &channel, &size)) {
34 fprintf(stderr, "Failed to scan channel and size from"
35 " %s\n", argv[3]);
36 if (channel)
37 free(channel);
38 return -1;
39 }
40 if (ustctl_set_subbuf_size(sock, argv[2], channel, size)) {
41 ERR("error while trying to set the size of subbuffers "
42 "for PID %s\n",
43 argv[1]);
44 result = -1;
45 }
46
47 free(channel);
48
49 return result;
50 }
51
52 static int set_subbuf_num(int argc, char *argv[])
53 {
54 int sock, result = 0;
55 char *channel = NULL;
56 unsigned int num;
57
58 sock = parse_and_connect_pid(argv[1]);
59
60 if (scan_ch_and_num(argv[3], &channel, &num)) {
61 fprintf(stderr, "Failed to scan channel and number from"
62 " %s\n", argv[3]);
63 if (channel)
64 free(channel);
65 return -1;
66 }
67 if (ustctl_set_subbuf_num(sock, argv[2], channel, num)) {
68 ERR("error while trying to set the number of subbuffers for PID %s\n",
69 argv[1]);
70 result = -1;
71 }
72
73 free(channel);
74
75 return result;
76 }
77
78 static int get_subbuf_size(int argc, char *argv[])
79 {
80 int sock;
81 unsigned int size;
82
83 sock = parse_and_connect_pid(argv[1]);
84
85 if ((size = ustctl_get_subbuf_size(sock, argv[2], argv[3])) < 0) {
86 ERR("error while trying to get the subbuffer size from PID %s\n",
87 argv[1]);
88 return -1;
89 }
90
91 printf("The subbufer size is %d bytes\n", size);
92
93 return 0;
94 }
95
96 static int get_subbuf_num(int argc, char *argv[])
97 {
98 int sock;
99 unsigned int num;
100
101 sock = parse_and_connect_pid(argv[1]);
102
103 if ((num = ustctl_get_subbuf_num(sock, argv[2], argv[3])) < 0) {
104 ERR("error while trying to get the subbuffer size from PID %s\n",
105 argv[1]);
106 return -1;
107 }
108
109 printf("There are %u subbufers in each buffer\n", num);
110
111 return 0;
112 }
113
114 struct cli_cmd __cli_cmds channel_cmds[] = {
115 {
116 .name = "set-subbuf-size",
117 .description = "Set the subbuffer size for a channel",
118 .help_text = "set-subbuf-size <pid> <trace> <channel>/<size> \n"
119 "Set the subbuffer size for a channel\n",
120 .function = set_subbuf_size,
121 .desired_args = 3,
122 .desired_args_op = CLI_EQ,
123 },
124 {
125 .name = "set-subbuf-num",
126 .description = "Set the number of subbuffers for a channel",
127 .help_text = "set-subbuf-num <pid> <trace> <channel>/<num> \n"
128 "Set the number of subbuffers for a channel\n",
129 .function = set_subbuf_num,
130 .desired_args = 3,
131 .desired_args_op = CLI_EQ,
132 },
133 {
134 .name = "get-subbuf-size",
135 .description = "Get the subbuffer size for a channel",
136 .help_text = "get-subbuf-size <pid> <trace> <channel>\n"
137 "Get the subbuffer size for a channel\n",
138 .function = get_subbuf_size,
139 .desired_args = 3,
140 .desired_args_op = CLI_EQ,
141 },
142 {
143 .name = "get-subbuf-num",
144 .description = "Get the number of subbuffers for a channel",
145 .help_text = "get-subbuf-num <pid> <trace> <channel>\n"
146 "Get the number of subbuffers for a channel\n",
147 .function = get_subbuf_num,
148 .desired_args = 3,
149 .desired_args_op = CLI_EQ,
150 },
151 };
This page took 0.03159 seconds and 4 git commands to generate.