diff options
author | Steven Rostedt <srostedt@redhat.com> | 2010-03-25 17:16:27 -0400 |
---|---|---|
committer | Steven Rostedt <rostedt@goodmis.org> | 2010-03-25 17:16:27 -0400 |
commit | 1b3ec9109f3de45ee3171a20434ee59ff7183c07 (patch) | |
tree | 8187bd065826eb11ff356ffedf0e268a4b7b86e7 | |
parent | 96f72b61aabc6f12d78d5cb8d33d7e2ad4560fa0 (diff) |
trace-cmd: Clean up trace-cmd usage output
The usage just printed all commands and their full descriptions. This is too much
for all the commands that trace-cmd does.
This patch moves the usage out of trace-cmd.c and into a new file called trace-usage.c.
It then makes a structure that holds the name of the command, a short description
and the full usage (from the original usage).
If no command, or the command passed to trace-cmd is not found, then the list
of commands and their short usages are shown.
If a command is passed in, only the usage for that command is shown.
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | trace-cmd.c | 90 | ||||
-rw-r--r-- | trace-usage.c | 166 |
3 files changed, 167 insertions, 91 deletions
@@ -209,7 +209,7 @@ $(obj)/%.o: $(src)/%.c | |||
209 | %.o: $(src)/%.c | 209 | %.o: $(src)/%.c |
210 | $(Q)$(call check_gui) | 210 | $(Q)$(call check_gui) |
211 | 211 | ||
212 | TRACE_CMD_OBJS = trace-cmd.o trace-read.o trace-split.o trace-listen.o | 212 | TRACE_CMD_OBJS = trace-cmd.o trace-usage.o trace-read.o trace-split.o trace-listen.o |
213 | TRACE_VIEW_OBJS = trace-view.o trace-view-store.o trace-filter.o trace-compat.o \ | 213 | TRACE_VIEW_OBJS = trace-view.o trace-view-store.o trace-filter.o trace-compat.o \ |
214 | trace-hash.o | 214 | trace-hash.o |
215 | TRACE_GRAPH_OBJS = trace-graph.o trace-compat.o trace-hash.o trace-filter.o \ | 215 | TRACE_GRAPH_OBJS = trace-graph.o trace-compat.o trace-hash.o trace-filter.o \ |
diff --git a/trace-cmd.c b/trace-cmd.c index 5efb536..1869c1e 100644 --- a/trace-cmd.c +++ b/trace-cmd.c | |||
@@ -37,7 +37,6 @@ | |||
37 | #include <glob.h> | 37 | #include <glob.h> |
38 | 38 | ||
39 | #include "trace-local.h" | 39 | #include "trace-local.h" |
40 | #include "version.h" | ||
41 | 40 | ||
42 | #define _STR(x) #x | 41 | #define _STR(x) #x |
43 | #define STR(x) _STR(x) | 42 | #define STR(x) _STR(x) |
@@ -1287,95 +1286,6 @@ void set_buffer_size(void) | |||
1287 | close(fd); | 1286 | close(fd); |
1288 | } | 1287 | } |
1289 | 1288 | ||
1290 | void usage(char **argv) | ||
1291 | { | ||
1292 | char *arg = argv[0]; | ||
1293 | char *p = arg+strlen(arg); | ||
1294 | |||
1295 | while (p >= arg && *p != '/') | ||
1296 | p--; | ||
1297 | p++; | ||
1298 | |||
1299 | printf("\n" | ||
1300 | "%s version %s\n\n" | ||
1301 | "usage:\n" | ||
1302 | " %s record [-v][-e event [-f filter]][-p plugin][-F][-d][-o file] \\\n" | ||
1303 | " [-s usecs][-O option ][-l func][-g func][-n func]\n" | ||
1304 | " [-P pid][-N host:port][-t][-b size][command ...]\n" | ||
1305 | " -e run command with event enabled\n" | ||
1306 | " -f filter for previous -e event\n" | ||
1307 | " -p run command with plugin enabled\n" | ||
1308 | " -F filter only on the given process\n" | ||
1309 | " -P trace the given pid like -F for the command\n" | ||
1310 | " -l filter function name\n" | ||
1311 | " -g set graph function\n" | ||
1312 | " -n do not trace function\n" | ||
1313 | " -v will negate all -e after it (disable those events)\n" | ||
1314 | " -d disable function tracer when running\n" | ||
1315 | " -o data output file [default trace.dat]\n" | ||
1316 | " -O option to enable (or disable)\n" | ||
1317 | " -s sleep interval between recording (in usecs) [default: 1000]\n" | ||
1318 | " -N host:port to connect to (see listen)\n" | ||
1319 | " -t used with -N, forces use of tcp in live trace\n" | ||
1320 | " -b change kernel buffersize (in kilobytes per CPU)\n" | ||
1321 | "\n" | ||
1322 | " %s start [-e event][-p plugin][-d][-O option ][-P pid]\n" | ||
1323 | " Uses same options as record, but does not run a command.\n" | ||
1324 | " It only enables the tracing and exits\n" | ||
1325 | "\n" | ||
1326 | " %s extract [-p plugin][-O option][-o file]\n" | ||
1327 | " Uses same options as record, but only reads an existing trace.\n" | ||
1328 | "\n" | ||
1329 | " %s stop\n" | ||
1330 | " Stops the tracer from recording more data.\n" | ||
1331 | " Used in conjunction with start\n" | ||
1332 | "\n" | ||
1333 | " %s reset [-b size]\n" | ||
1334 | " Disables the tracer (may reset trace file)\n" | ||
1335 | " Used in conjunction with start\n" | ||
1336 | " -b change the kernel buffer size (in kilobytes per CPU)\n" | ||
1337 | "\n" | ||
1338 | " %s report [-i file] [--cpu cpu] [-e][-f][-l][-P][-E][-F filter][-v][-V]\n" | ||
1339 | " -i input file [default trace.dat]\n" | ||
1340 | " -e show file endianess\n" | ||
1341 | " -f show function list\n" | ||
1342 | " -P show printk list\n" | ||
1343 | " -E show event files stored\n" | ||
1344 | " -F filter to filter output on\n" | ||
1345 | " -v will negate all -F after it (Not show matches)\n" | ||
1346 | " -V verbose (shows plugins being loaded)\n" | ||
1347 | " -w show wakeup latencies\n" | ||
1348 | " -l show latency format (default with latency tracers)\n" | ||
1349 | "\n" | ||
1350 | " %s split [options] -o file [start [end]]\n" | ||
1351 | " -o output file to write to (file.1, file.2, etc)\n" | ||
1352 | " -s n split file up by n seconds\n" | ||
1353 | " -m n split file up by n milliseconds\n" | ||
1354 | " -u n split file up by n microseconds\n" | ||
1355 | " -e n split file up by n events\n" | ||
1356 | " -p n split file up by n pages\n" | ||
1357 | " -r repeat from start to end\n" | ||
1358 | " -c per cpu, that is -p 2 will be 2 pages for each CPU\n" | ||
1359 | " if option is specified, it will split the file\n" | ||
1360 | " up starting at start, and ending at end\n" | ||
1361 | " start - decimal start time in seconds (ex: 75678.923853)\n" | ||
1362 | " if left out, will start at beginning of file\n" | ||
1363 | " end - decimal end time in seconds\n" | ||
1364 | "\n" | ||
1365 | " %s listen -p port[-D][-o file][-d dir]\n" | ||
1366 | " Creates a socket to listen for clients.\n" | ||
1367 | " -D create it in daemon mode.\n" | ||
1368 | " -o file name to use for clients.\n" | ||
1369 | " -d diretory to store client files.\n" | ||
1370 | "\n" | ||
1371 | " %s list [-e][-p]\n" | ||
1372 | " -e list available events\n" | ||
1373 | " -p list available plugins\n" | ||
1374 | " -o list available options\n" | ||
1375 | "\n", p, VERSION_STRING, p, p, p, p, p, p, p, p, p); | ||
1376 | exit(-1); | ||
1377 | } | ||
1378 | |||
1379 | int main (int argc, char **argv) | 1289 | int main (int argc, char **argv) |
1380 | { | 1290 | { |
1381 | const char *plugin = NULL; | 1291 | const char *plugin = NULL; |
diff --git a/trace-usage.c b/trace-usage.c new file mode 100644 index 0000000..bbc4c78 --- /dev/null +++ b/trace-usage.c | |||
@@ -0,0 +1,166 @@ | |||
1 | #include <stdio.h> | ||
2 | #include <stdlib.h> | ||
3 | #include <string.h> | ||
4 | #include <libgen.h> | ||
5 | |||
6 | #include "trace-local.h" | ||
7 | #include "version.h" | ||
8 | |||
9 | struct usage_help { | ||
10 | char *name; | ||
11 | char *short_help; | ||
12 | char *long_help; | ||
13 | }; | ||
14 | |||
15 | static struct usage_help usage_help[] = { | ||
16 | { | ||
17 | "record", | ||
18 | "record a trace into a trace.dat file", | ||
19 | " %s record [-v][-e event [-f filter]][-p plugin][-F][-d][-o file] \\\n" | ||
20 | " [-s usecs][-O option ][-l func][-g func][-n func]\n" | ||
21 | " [-P pid][-N host:port][-t][-b size][command ...]\n" | ||
22 | " -e run command with event enabled\n" | ||
23 | " -f filter for previous -e event\n" | ||
24 | " -p run command with plugin enabled\n" | ||
25 | " -F filter only on the given process\n" | ||
26 | " -P trace the given pid like -F for the command\n" | ||
27 | " -l filter function name\n" | ||
28 | " -g set graph function\n" | ||
29 | " -n do not trace function\n" | ||
30 | " -v will negate all -e after it (disable those events)\n" | ||
31 | " -d disable function tracer when running\n" | ||
32 | " -o data output file [default trace.dat]\n" | ||
33 | " -O option to enable (or disable)\n" | ||
34 | " -s sleep interval between recording (in usecs) [default: 1000]\n" | ||
35 | " -N host:port to connect to (see listen)\n" | ||
36 | " -t used with -N, forces use of tcp in live trace\n" | ||
37 | " -b change kernel buffersize (in kilobytes per CPU)\n" | ||
38 | }, | ||
39 | { | ||
40 | "start", | ||
41 | "start tracing without recording into a file", | ||
42 | " %s start [-e event][-p plugin][-d][-O option ][-P pid]\n" | ||
43 | " Uses same options as record, but does not run a command.\n" | ||
44 | " It only enables the tracing and exits\n" | ||
45 | }, | ||
46 | { | ||
47 | "extract", | ||
48 | "extract a trace from the kernel", | ||
49 | " %s extract [-p plugin][-O option][-o file]\n" | ||
50 | " Uses same options as record, but only reads an existing trace.\n" | ||
51 | }, | ||
52 | { | ||
53 | "stop", | ||
54 | "stop the kernel from recording trace data", | ||
55 | " %s stop\n" | ||
56 | " Stops the tracer from recording more data.\n" | ||
57 | " Used in conjunction with start\n" | ||
58 | }, | ||
59 | { | ||
60 | "reset", | ||
61 | "disable all kernel tracing and clear the trace buffers", | ||
62 | " %s reset [-b size]\n" | ||
63 | " Disables the tracer (may reset trace file)\n" | ||
64 | " Used in conjunction with start\n" | ||
65 | " -b change the kernel buffer size (in kilobytes per CPU)\n" | ||
66 | }, | ||
67 | { | ||
68 | "report", | ||
69 | "read out the trace stored in a trace.dat file", | ||
70 | " %s report [-i file] [--cpu cpu] [-e][-f][-l][-P][-E][-F filter][-v][-V]\n" | ||
71 | " -i input file [default trace.dat]\n" | ||
72 | " -e show file endianess\n" | ||
73 | " -f show function list\n" | ||
74 | " -P show printk list\n" | ||
75 | " -E show event files stored\n" | ||
76 | " -F filter to filter output on\n" | ||
77 | " -v will negate all -F after it (Not show matches)\n" | ||
78 | " -V verbose (shows plugins being loaded)\n" | ||
79 | " -w show wakeup latencies\n" | ||
80 | " -l show latency format (default with latency tracers)\n" | ||
81 | }, | ||
82 | { | ||
83 | "split", | ||
84 | "parse a trace.dat file into smaller file(s)", | ||
85 | " %s split [options] -o file [start [end]]\n" | ||
86 | " -o output file to write to (file.1, file.2, etc)\n" | ||
87 | " -s n split file up by n seconds\n" | ||
88 | " -m n split file up by n milliseconds\n" | ||
89 | " -u n split file up by n microseconds\n" | ||
90 | " -e n split file up by n events\n" | ||
91 | " -p n split file up by n pages\n" | ||
92 | " -r repeat from start to end\n" | ||
93 | " -c per cpu, that is -p 2 will be 2 pages for each CPU\n" | ||
94 | " if option is specified, it will split the file\n" | ||
95 | " up starting at start, and ending at end\n" | ||
96 | " start - decimal start time in seconds (ex: 75678.923853)\n" | ||
97 | " if left out, will start at beginning of file\n" | ||
98 | " end - decimal end time in seconds\n" | ||
99 | }, | ||
100 | { | ||
101 | "listen", | ||
102 | "listen on a network socket for trace clients", | ||
103 | " %s listen -p port[-D][-o file][-d dir]\n" | ||
104 | " Creates a socket to listen for clients.\n" | ||
105 | " -D create it in daemon mode.\n" | ||
106 | " -o file name to use for clients.\n" | ||
107 | " -d diretory to store client files.\n" | ||
108 | }, | ||
109 | { | ||
110 | "list", | ||
111 | "list the available events, plugins or options", | ||
112 | " %s list [-e][-p]\n" | ||
113 | " -e list available events\n" | ||
114 | " -p list available plugins\n" | ||
115 | " -o list available options\n" | ||
116 | }, | ||
117 | { | ||
118 | NULL, NULL, NULL | ||
119 | } | ||
120 | }; | ||
121 | |||
122 | static struct usage_help *find_help(char *cmd) | ||
123 | { | ||
124 | struct usage_help *help; | ||
125 | |||
126 | help = usage_help; | ||
127 | while (help->name) { | ||
128 | if (strcmp(cmd, help->name) == 0) | ||
129 | return help; | ||
130 | help++; | ||
131 | } | ||
132 | return NULL; | ||
133 | } | ||
134 | |||
135 | void usage(char **argv) | ||
136 | { | ||
137 | struct usage_help *help = NULL; | ||
138 | char *arg = argv[0]; | ||
139 | char *p; | ||
140 | |||
141 | p = basename(arg); | ||
142 | |||
143 | printf("\n" | ||
144 | "%s version %s\n\n" | ||
145 | "usage:\n", p, VERSION_STRING); | ||
146 | |||
147 | if (argv[1]) | ||
148 | help = find_help(argv[1]); | ||
149 | |||
150 | if (help) { | ||
151 | printf(help->long_help, p); | ||
152 | goto out; | ||
153 | } | ||
154 | |||
155 | printf(" %s [COMMAND] ...\n\n" | ||
156 | " commands:\n", p); | ||
157 | |||
158 | help = usage_help; | ||
159 | while (help->name) { | ||
160 | printf(" %s - %s\n", help->name, help->short_help); | ||
161 | help++; | ||
162 | } | ||
163 | out: | ||
164 | printf("\n"); | ||
165 | exit(-1); | ||
166 | } | ||