Update version to 0.16
[ust.git] / ustctl / marker_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 list_markers(int argc, char *argv[])
26 {
27 struct ust_marker_status *cmsf = NULL;
28 int i, sock;
29
30 sock = parse_and_connect_pid(argv[1]);
31
32 if (ustctl_get_cmsf(sock, &cmsf)) {
33 ERR("error while trying to list markers for PID %s\n", argv[1]);
34 return -1;
35 }
36 for (i = 0; cmsf[i].channel; i++) {
37 printf("{PID: %s, channel/marker: %s/%s, "
38 "state: %u, fmt: %s}\n",
39 argv[1],
40 cmsf[i].channel,
41 cmsf[i].ust_marker,
42 cmsf[i].state,
43 cmsf[i].fs);
44 }
45 ustctl_free_cmsf(cmsf);
46 return 0;
47 }
48
49 static int enable_marker(int argc, char *argv[])
50 {
51 int i, sock, result = 0;
52 char *channel, *marker;
53
54 sock = parse_and_connect_pid(argv[1]);
55
56 for (i = 3; i < argc; i++) {
57 channel = NULL;
58 marker = NULL;
59 if (scan_ch_marker(argv[i],
60 &channel, &marker)) {
61 result = -1;
62 fprintf(stderr, "Failed to scan channel and marker from"
63 " %s\n", argv[i]);
64 if (channel)
65 free(channel);
66 if (marker)
67 free(marker);
68 }
69 if (ustctl_set_ust_marker_state(sock, argv[2], channel, marker, 1)) {
70 PERROR("error while trying to enable marker %s with PID %s",
71 argv[i], argv[1]);
72 result = -1;
73 }
74 free(channel);
75 free(marker);
76 }
77
78 return result;
79 }
80
81 static int disable_marker(int argc, char *argv[])
82 {
83 int i, sock, result = 0;
84 char *channel, *marker;
85
86 sock = parse_and_connect_pid(argv[1]);
87
88 for (i = 3; i < argc; i++) {
89 channel = NULL;
90 marker = NULL;
91 if (scan_ch_marker(argv[i],
92 &channel, &marker)) {
93 fprintf(stderr, "Failed to scan channel and marker from"
94 " %s\n", argv[i]);
95 if (channel)
96 free(channel);
97 if (marker)
98 free(marker);
99 return -1;
100 }
101 if (ustctl_set_ust_marker_state(sock, argv[2], channel, marker, 0)) {
102 PERROR("error while trying to disable marker %s with PID %s",
103 argv[i], argv[1]);
104 result = -1;
105 }
106 free(channel);
107 free(marker);
108 }
109
110 return result;
111 }
112
113 struct cli_cmd __cli_cmds ust_marker_cmds[] = {
114 {
115 .name = "list-markers",
116 .description = "List markers for a given pid",
117 .help_text = "list-markers <pid>\n"
118 "List the markers in a process\n",
119 .function = list_markers,
120 .desired_args = 1,
121 .desired_args_op = CLI_EQ,
122 },
123 {
124 .name = "enable-marker",
125 .description = "Enable markers for a given pid",
126 .help_text = "enable-marker <pid> <trace> <channel>/<marker>... \n"
127 "Enable the listed markers for the trace in process pid\n",
128 .function = enable_marker,
129 .desired_args = 3,
130 .desired_args_op = CLI_GE,
131 },
132 {
133 .name = "disable-marker",
134 .description = "Disable markers for a given pid",
135 .help_text = "disable-marker <pid> <trace> <channel>/<marker>... \n"
136 "Disable the listed markers for the trace in process pid\n",
137 .function = disable_marker,
138 .desired_args = 3,
139 .desired_args_op = CLI_GE,
140 }
141 };
This page took 0.032021 seconds and 4 git commands to generate.