ab5b5360a40ab5f81cc918c7f7d16d1c741cef55
1 /* Copyright (C) 2009 Pierre-Marc Fournier
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.
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.
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
46 char *progname
= NULL
;
50 fprintf(stderr
, "usage: %s COMMAND PIDs...\n", progname
);
51 fprintf(stderr
, "\nControl the tracing of a process that supports LTTng Userspace Tracing.\n\
54 --start-trace\t\t\tStart tracing\n\
55 --stop-trace\t\t\tStop tracing\n\
56 --destroy-trace\t\t\tDestroy the trace\n\
57 --enable-marker \"CHANNEL/MARKER\"\tEnable a marker\n\
58 --disable-marker \"CHANNEL/MARKER\"\tDisable a marker\n\
59 --list-markers\t\t\tList the markers of the process, their\n\t\t\t\t\t state and format string\n\
64 int parse_opts_long(int argc
, char **argv
, struct ust_opts
*opts
)
73 static struct option long_options
[] = {
74 {"start-trace", 0, 0, 1000},
75 {"stop-trace", 0, 0, 1001},
76 {"destroy-trace", 0, 0, 1002},
77 {"list-markers", 0, 0, 1004},
78 {"print-markers", 0, 0, 1005},
80 {"enable-marker", 1, 0, 1007},
81 {"disable-marker", 1, 0, 1008},
82 {"start", 0, 0, 1009},
84 {"version", 0, 0, 1010},
85 {"online-pids", 0, 0, 1011},
89 c
= getopt_long(argc
, argv
, "h", long_options
, &option_index
);
95 printf("option %s", long_options
[option_index
].name
);
97 printf(" with arg %s", optarg
);
102 opts
->cmd
= START_TRACE
;
105 opts
->cmd
= STOP_TRACE
;
114 opts
->cmd
= LIST_MARKERS
;
117 opts
->cmd
= ENABLE_MARKER
;
118 opts
->m_name
= strdup(optarg
);
121 opts
->cmd
= DISABLE_MARKER
;
122 opts
->m_name
= strdup(optarg
);
125 opts
->cmd
= GET_ONLINE_PIDS
;
131 printf("Version 0.1\n");
134 /* unknown option or other error; error is
135 printed by getopt, just return */
141 if(argc
- optind
> 0 && opts
->cmd
!= GET_ONLINE_PIDS
) {
144 opts
->pids
= malloc((argc
-optind
+1) * sizeof(pid_t
));
146 for(i
=optind
; i
<argc
; i
++) {
147 opts
->pids
[pididx
++] = atoi(argv
[i
]);
149 opts
->pids
[pididx
] = -1;
155 int main(int argc
, char *argv
[])
158 //char *msg = argv[2];
159 struct ustcomm_connection conn
;
161 struct ust_opts opts
;
166 fprintf(stderr
, "No operation specified.\n");
171 result
= parse_opts_long(argc
, argv
, &opts
);
177 if(opts
.pids
== NULL
&& opts
.cmd
!= GET_ONLINE_PIDS
) {
178 fprintf(stderr
, "No pid specified.\n");
182 if(opts
.cmd
== UNKNOWN
) {
183 fprintf(stderr
, "No command specified.\n");
188 if (opts
.cmd
== GET_ONLINE_PIDS
) {
189 pid_t
* pp
= ustcmd_get_online_pids();
194 printf("%u\n", (unsigned int) pp
[i
]);
204 struct USTcmd_cmsf
* cmsf
= NULL
;
206 while(*pidit
!= -1) {
209 if (ustcmd_start_trace(*pidit
)) {
211 "error while trying to for trace "
212 "with PID %u\n", (unsigned int) *pidit
);
215 printf("sucessfully started trace for PID %u\n",
216 (unsigned int) *pidit
);
220 if (ustcmd_stop_trace(*pidit
)) {
222 "error while trying to stop trace "
223 "for PID %u\n", (unsigned int) *pidit
);
226 printf("sucessfully stopped trace for PID %u\n",
227 (unsigned int) *pidit
);
231 if (ustcmd_setup_and_start(*pidit
)) {
233 "error while trying to setup/start "
234 "trace for PID %u\n",
235 (unsigned int) *pidit
);
238 printf("sucessfully setup/started trace for PID %u\n",
239 (unsigned int) *pidit
);
243 if (ustcmd_destroy_trace(*pidit
)) {
245 "error while trying to destroy "
246 "trace with PID %u\n",
247 (unsigned int) *pidit
);
250 printf("sucessfully destroyed trace for PID %u\n",
251 (unsigned int) *pidit
);
256 if (ustcmd_get_cmsf(&cmsf
, *pidit
)) {
258 "error while trying to list markers for"
259 " PID %u\n", (unsigned int) *pidit
);
263 while (cmsf
[i
].channel
!= NULL
) {
264 printf("{PID: %u, channel/marker: %s/%s, "
265 "state: %u, fs: %s}\n",
266 (unsigned int) *pidit
,
273 ustcmd_free_cmsf(cmsf
);
277 if (ustcmd_set_marker_state(opts
.m_name
, USTCMD_MS_ON
,
281 "error while trying to enable marker"
282 "\"%s\" for PID %u\n",
284 (unsigned int) *pidit
);
287 printf("sucessfully enabled marker \"%s\" for PID %u\n",
288 opts
.m_name
, (unsigned int) *pidit
);
292 if (ustcmd_set_marker_state(opts
.m_name
, USTCMD_MS_OFF
,
295 "error while trying to disable marker"
296 "\"%s\" for PID %u\n",
298 (unsigned int) *pidit
);
301 printf("sucessfully disabled marker \"%s\" for PID %u\n",
302 opts
.m_name
, (unsigned int) *pidit
);
306 fprintf(stderr
, "error: unknown command...\n");
314 if (opts
.m_name
!= NULL
) {
This page took 0.039388 seconds and 4 git commands to generate.