libustctl: use direct socket communication
[ust.git] / ustctl / marker_cmds.c
CommitLineData
0c89df6c
NC
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>
2298f329 20#include <ust/ustctl.h>
0c89df6c
NC
21#include "scanning_functions.h"
22#include "usterr.h"
23#include "cli.h"
24
25static int list_markers(int argc, char *argv[])
26{
27 struct marker_status *cmsf = NULL;
8b26d56b 28 int i, sock;
0c89df6c 29
8b26d56b 30 sock = parse_and_connect_pid(argv[1]);
0c89df6c 31
8b26d56b
NC
32 if (ustctl_get_cmsf(sock, &cmsf)) {
33 ERR("error while trying to list markers for PID %s\n", argv[1]);
0c89df6c
NC
34 return -1;
35 }
36 for (i = 0; cmsf[i].channel; i++) {
8b26d56b 37 printf("{PID: %s, channel/marker: %s/%s, "
0c89df6c 38 "state: %u, fmt: %s}\n",
8b26d56b 39 argv[1],
0c89df6c
NC
40 cmsf[i].channel,
41 cmsf[i].marker,
42 cmsf[i].state,
43 cmsf[i].fs);
44 }
2298f329 45 ustctl_free_cmsf(cmsf);
0c89df6c
NC
46 return 0;
47}
48
49static int enable_marker(int argc, char *argv[])
50{
8b26d56b 51 int i, sock, result = 0;
0c89df6c
NC
52 char *channel, *marker;
53
8b26d56b 54 sock = parse_and_connect_pid(argv[1]);
0c89df6c
NC
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 }
8b26d56b
NC
69 if (ustctl_set_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]);
0c89df6c
NC
72 result = -1;
73 }
74 free(channel);
75 free(marker);
76 }
77
78 return result;
79}
80
81static int disable_marker(int argc, char *argv[])
82{
8b26d56b 83 int i, sock, result = 0;
0c89df6c
NC
84 char *channel, *marker;
85
8b26d56b 86 sock = parse_and_connect_pid(argv[1]);
0c89df6c
NC
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 }
8b26d56b
NC
101 if (ustctl_set_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]);
0c89df6c
NC
104 result = -1;
105 }
106 free(channel);
107 free(marker);
108 }
109
110 return result;
111}
112
113struct cli_cmd __cli_cmds 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.027287 seconds and 4 git commands to generate.