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