-
Notifications
You must be signed in to change notification settings - Fork 1
/
trace-usage.c
208 lines (196 loc) · 6.55 KB
/
trace-usage.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <libgen.h>
#include "trace-local.h"
#include "version.h"
struct usage_help {
char *name;
char *short_help;
char *long_help;
};
static struct usage_help usage_help[] = {
{
"record",
"record a trace into a trace.dat file",
" %s record [-v][-e event [-f filter]][-p plugin][-F][-d][-o file] \\\n"
" [-s usecs][-O option ][-l func][-g func][-n func] \\\n"
" [-P pid][-N host:port][-t][-r prio][-b size][command ...]\n"
" -e run command with event enabled\n"
" -f filter for previous -e event\n"
" -p run command with plugin enabled\n"
" -F filter only on the given process\n"
" -P trace the given pid like -F for the command\n"
" -c also trace the childen of -F or -P\n"
" -T do a stacktrace on all events\n"
" -l filter function name\n"
" -g set graph function\n"
" -n do not trace function\n"
" -v will negate all -e after it (disable those events)\n"
" -d disable function tracer when running\n"
" -o data output file [default trace.dat]\n"
" -O option to enable (or disable)\n"
" -r real time priority to run the capture threads\n"
" -s sleep interval between recording (in usecs) [default: 1000]\n"
" -N host:port to connect to (see listen)\n"
" -t used with -N, forces use of tcp in live trace\n"
" -b change kernel buffersize (in kilobytes per CPU)\n"
" -k do not reset the buffers after tracing.\n"
" -i do not fail if an event is not found\n"
" --func-stack perform a stack trace for function tracer\n"
" (use with caution)\n"
},
{
"start",
"start tracing without recording into a file",
" %s start [-e event][-p plugin][-d][-O option ][-P pid]\n"
" Uses same options as record, but does not run a command.\n"
" It only enables the tracing and exits\n"
},
{
"extract",
"extract a trace from the kernel",
" %s extract [-p plugin][-O option][-o file]\n"
" Uses same options as record, but only reads an existing trace.\n"
},
{
"stop",
"stop the kernel from recording trace data",
" %s stop\n"
" Stops the tracer from recording more data.\n"
" Used in conjunction with start\n"
},
{
"reset",
"disable all kernel tracing and clear the trace buffers",
" %s reset [-b size]\n"
" Disables the tracer (may reset trace file)\n"
" Used in conjunction with start\n"
" -b change the kernel buffer size (in kilobytes per CPU)\n"
},
{
"report",
"read out the trace stored in a trace.dat file",
" %s report [-i file] [--cpu cpu] [-e][-f][-l][-P][-L][-N][-r][-E]\\\n"
" [-F filter][-v][-V][-T][-O option]\n"
" -i input file [default trace.dat]\n"
" -e show file endianess\n"
" -f show function list\n"
" -P show printk list\n"
" -E show event files stored\n"
" -F filter to filter output on\n"
" -r raw format: ignore print format and only show field data\n"
" -v will negate all -F after it (Not show matches)\n"
" -T print out the filter strings created and exit\n"
" -V verbose (shows plugins being loaded)\n"
" -L load only local (~/.trace-cmd/plugins) plugins\n"
" -N do not load any plugins\n"
" -w show wakeup latencies\n"
" -l show latency format (default with latency tracers)\n"
" -O plugin option -O [plugin:]var[=val]\n"
" --check-events return whether all event formats can be parsed\n"
},
{
"split",
"parse a trace.dat file into smaller file(s)",
" %s split [options] -o file [start [end]]\n"
" -o output file to write to (file.1, file.2, etc)\n"
" -s n split file up by n seconds\n"
" -m n split file up by n milliseconds\n"
" -u n split file up by n microseconds\n"
" -e n split file up by n events\n"
" -p n split file up by n pages\n"
" -r repeat from start to end\n"
" -c per cpu, that is -p 2 will be 2 pages for each CPU\n"
" if option is specified, it will split the file\n"
" up starting at start, and ending at end\n"
" start - decimal start time in seconds (ex: 75678.923853)\n"
" if left out, will start at beginning of file\n"
" end - decimal end time in seconds\n"
},
{
"options",
"list the plugin options available for trace-cmd report",
" %s options\n"
},
{
"listen",
"listen on a network socket for trace clients",
" %s listen -p port[-D][-o file][-d dir][-l logfile]\n"
" Creates a socket to listen for clients.\n"
" -D create it in daemon mode.\n"
" -o file name to use for clients.\n"
" -d diretory to store client files.\n"
" -l logfile to write messages to.\n"
},
{
"list",
"list the available events, plugins or options",
" %s list [-e][-p]\n"
" -e list available events\n"
" -p list available plugins\n"
" -o list available options\n"
},
{
"restore",
"restore a crashed record",
" %s restore [-c][-o file][-i file] cpu-file [cpu-file ...]\n"
" -c create a partial trace.dat file only\n"
" -o output file\n"
" -i parital trace.dat file for input\n"
},
{
"stack",
"output, enable or disable kernel stack tracing",
" %s stack [--start][--stop][--reset]\n"
" --start enable the stack tracer\n"
" --stop disable the stack tracer\n"
" --reset reset the maximum stack found\n"
},
{
"check-events",
"parse trace event formats",
" %s check-format [-N]\n"
" -N do not load any plugins\n"
},
{
NULL, NULL, NULL
}
};
static struct usage_help *find_help(char *cmd)
{
struct usage_help *help;
help = usage_help;
while (help->name) {
if (strcmp(cmd, help->name) == 0)
return help;
help++;
}
return NULL;
}
void usage(char **argv)
{
struct usage_help *help = NULL;
char *arg = argv[0];
char *p;
p = basename(arg);
printf("\n"
"%s version %s\n\n"
"usage:\n", p, VERSION_STRING);
if (argv[1])
help = find_help(argv[1]);
if (help) {
printf(help->long_help, p);
goto out;
}
printf(" %s [COMMAND] ...\n\n"
" commands:\n", p);
help = usage_help;
while (help->name) {
printf(" %s - %s\n", help->name, help->short_help);
help++;
}
out:
printf("\n");
exit(-1);
}