diff options
author | Steven Rostedt (Red Hat) <rostedt@goodmis.org> | 2014-06-20 13:38:54 -0400 |
---|---|---|
committer | Steven Rostedt <rostedt@goodmis.org> | 2014-07-01 07:13:35 -0400 |
commit | 12306276fabcb746a14979e96f43a13c724dec49 (patch) | |
tree | 566588d71d1f32c4cc07dd600892ed75214eb463 /kernel/trace/trace_output.c | |
parent | 5c27c775d5e698d5b754d213747e9fb85290e3b8 (diff) |
tracing: Move the trace_seq_* functions into its own trace_seq.c file
The trace_seq_*() functions are a nice utility that allows users to manipulate
buffers with printf() like formats. It has its own trace_seq.h header in
include/linux and should be in its own file. Being tied with trace_output.c
is rather awkward.
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Diffstat (limited to 'kernel/trace/trace_output.c')
-rw-r--r-- | kernel/trace/trace_output.c | 268 |
1 files changed, 0 insertions, 268 deletions
diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c index f3dad80c20b2..b8930f79a04b 100644 --- a/kernel/trace/trace_output.c +++ b/kernel/trace/trace_output.c | |||
@@ -20,23 +20,6 @@ static struct hlist_head event_hash[EVENT_HASHSIZE] __read_mostly; | |||
20 | 20 | ||
21 | static int next_event_type = __TRACE_LAST_TYPE + 1; | 21 | static int next_event_type = __TRACE_LAST_TYPE + 1; |
22 | 22 | ||
23 | int trace_print_seq(struct seq_file *m, struct trace_seq *s) | ||
24 | { | ||
25 | int len = s->len >= PAGE_SIZE ? PAGE_SIZE - 1 : s->len; | ||
26 | int ret; | ||
27 | |||
28 | ret = seq_write(m, s->buffer, len); | ||
29 | |||
30 | /* | ||
31 | * Only reset this buffer if we successfully wrote to the | ||
32 | * seq_file buffer. | ||
33 | */ | ||
34 | if (!ret) | ||
35 | trace_seq_init(s); | ||
36 | |||
37 | return ret; | ||
38 | } | ||
39 | |||
40 | enum print_line_t trace_print_bputs_msg_only(struct trace_iterator *iter) | 23 | enum print_line_t trace_print_bputs_msg_only(struct trace_iterator *iter) |
41 | { | 24 | { |
42 | struct trace_seq *s = &iter->seq; | 25 | struct trace_seq *s = &iter->seq; |
@@ -85,257 +68,6 @@ enum print_line_t trace_print_printk_msg_only(struct trace_iterator *iter) | |||
85 | return TRACE_TYPE_HANDLED; | 68 | return TRACE_TYPE_HANDLED; |
86 | } | 69 | } |
87 | 70 | ||
88 | /** | ||
89 | * trace_seq_printf - sequence printing of trace information | ||
90 | * @s: trace sequence descriptor | ||
91 | * @fmt: printf format string | ||
92 | * | ||
93 | * It returns 0 if the trace oversizes the buffer's free | ||
94 | * space, 1 otherwise. | ||
95 | * | ||
96 | * The tracer may use either sequence operations or its own | ||
97 | * copy to user routines. To simplify formating of a trace | ||
98 | * trace_seq_printf is used to store strings into a special | ||
99 | * buffer (@s). Then the output may be either used by | ||
100 | * the sequencer or pulled into another buffer. | ||
101 | */ | ||
102 | int | ||
103 | trace_seq_printf(struct trace_seq *s, const char *fmt, ...) | ||
104 | { | ||
105 | int len = (PAGE_SIZE - 1) - s->len; | ||
106 | va_list ap; | ||
107 | int ret; | ||
108 | |||
109 | if (s->full || !len) | ||
110 | return 0; | ||
111 | |||
112 | va_start(ap, fmt); | ||
113 | ret = vsnprintf(s->buffer + s->len, len, fmt, ap); | ||
114 | va_end(ap); | ||
115 | |||
116 | /* If we can't write it all, don't bother writing anything */ | ||
117 | if (ret >= len) { | ||
118 | s->full = 1; | ||
119 | return 0; | ||
120 | } | ||
121 | |||
122 | s->len += ret; | ||
123 | |||
124 | return 1; | ||
125 | } | ||
126 | EXPORT_SYMBOL_GPL(trace_seq_printf); | ||
127 | |||
128 | /** | ||
129 | * trace_seq_bitmask - put a list of longs as a bitmask print output | ||
130 | * @s: trace sequence descriptor | ||
131 | * @maskp: points to an array of unsigned longs that represent a bitmask | ||
132 | * @nmaskbits: The number of bits that are valid in @maskp | ||
133 | * | ||
134 | * It returns 0 if the trace oversizes the buffer's free | ||
135 | * space, 1 otherwise. | ||
136 | * | ||
137 | * Writes a ASCII representation of a bitmask string into @s. | ||
138 | */ | ||
139 | int | ||
140 | trace_seq_bitmask(struct trace_seq *s, const unsigned long *maskp, | ||
141 | int nmaskbits) | ||
142 | { | ||
143 | int len = (PAGE_SIZE - 1) - s->len; | ||
144 | int ret; | ||
145 | |||
146 | if (s->full || !len) | ||
147 | return 0; | ||
148 | |||
149 | ret = bitmap_scnprintf(s->buffer, len, maskp, nmaskbits); | ||
150 | s->len += ret; | ||
151 | |||
152 | return 1; | ||
153 | } | ||
154 | EXPORT_SYMBOL_GPL(trace_seq_bitmask); | ||
155 | |||
156 | /** | ||
157 | * trace_seq_vprintf - sequence printing of trace information | ||
158 | * @s: trace sequence descriptor | ||
159 | * @fmt: printf format string | ||
160 | * | ||
161 | * The tracer may use either sequence operations or its own | ||
162 | * copy to user routines. To simplify formating of a trace | ||
163 | * trace_seq_printf is used to store strings into a special | ||
164 | * buffer (@s). Then the output may be either used by | ||
165 | * the sequencer or pulled into another buffer. | ||
166 | */ | ||
167 | int | ||
168 | trace_seq_vprintf(struct trace_seq *s, const char *fmt, va_list args) | ||
169 | { | ||
170 | int len = (PAGE_SIZE - 1) - s->len; | ||
171 | int ret; | ||
172 | |||
173 | if (s->full || !len) | ||
174 | return 0; | ||
175 | |||
176 | ret = vsnprintf(s->buffer + s->len, len, fmt, args); | ||
177 | |||
178 | /* If we can't write it all, don't bother writing anything */ | ||
179 | if (ret >= len) { | ||
180 | s->full = 1; | ||
181 | return 0; | ||
182 | } | ||
183 | |||
184 | s->len += ret; | ||
185 | |||
186 | return len; | ||
187 | } | ||
188 | EXPORT_SYMBOL_GPL(trace_seq_vprintf); | ||
189 | |||
190 | int trace_seq_bprintf(struct trace_seq *s, const char *fmt, const u32 *binary) | ||
191 | { | ||
192 | int len = (PAGE_SIZE - 1) - s->len; | ||
193 | int ret; | ||
194 | |||
195 | if (s->full || !len) | ||
196 | return 0; | ||
197 | |||
198 | ret = bstr_printf(s->buffer + s->len, len, fmt, binary); | ||
199 | |||
200 | /* If we can't write it all, don't bother writing anything */ | ||
201 | if (ret >= len) { | ||
202 | s->full = 1; | ||
203 | return 0; | ||
204 | } | ||
205 | |||
206 | s->len += ret; | ||
207 | |||
208 | return len; | ||
209 | } | ||
210 | |||
211 | /** | ||
212 | * trace_seq_puts - trace sequence printing of simple string | ||
213 | * @s: trace sequence descriptor | ||
214 | * @str: simple string to record | ||
215 | * | ||
216 | * The tracer may use either the sequence operations or its own | ||
217 | * copy to user routines. This function records a simple string | ||
218 | * into a special buffer (@s) for later retrieval by a sequencer | ||
219 | * or other mechanism. | ||
220 | */ | ||
221 | int trace_seq_puts(struct trace_seq *s, const char *str) | ||
222 | { | ||
223 | int len = strlen(str); | ||
224 | |||
225 | if (s->full) | ||
226 | return 0; | ||
227 | |||
228 | if (len > ((PAGE_SIZE - 1) - s->len)) { | ||
229 | s->full = 1; | ||
230 | return 0; | ||
231 | } | ||
232 | |||
233 | memcpy(s->buffer + s->len, str, len); | ||
234 | s->len += len; | ||
235 | |||
236 | return len; | ||
237 | } | ||
238 | |||
239 | int trace_seq_putc(struct trace_seq *s, unsigned char c) | ||
240 | { | ||
241 | if (s->full) | ||
242 | return 0; | ||
243 | |||
244 | if (s->len >= (PAGE_SIZE - 1)) { | ||
245 | s->full = 1; | ||
246 | return 0; | ||
247 | } | ||
248 | |||
249 | s->buffer[s->len++] = c; | ||
250 | |||
251 | return 1; | ||
252 | } | ||
253 | EXPORT_SYMBOL(trace_seq_putc); | ||
254 | |||
255 | int trace_seq_putmem(struct trace_seq *s, const void *mem, size_t len) | ||
256 | { | ||
257 | if (s->full) | ||
258 | return 0; | ||
259 | |||
260 | if (len > ((PAGE_SIZE - 1) - s->len)) { | ||
261 | s->full = 1; | ||
262 | return 0; | ||
263 | } | ||
264 | |||
265 | memcpy(s->buffer + s->len, mem, len); | ||
266 | s->len += len; | ||
267 | |||
268 | return len; | ||
269 | } | ||
270 | |||
271 | int trace_seq_putmem_hex(struct trace_seq *s, const void *mem, size_t len) | ||
272 | { | ||
273 | unsigned char hex[HEX_CHARS]; | ||
274 | const unsigned char *data = mem; | ||
275 | int i, j; | ||
276 | |||
277 | if (s->full) | ||
278 | return 0; | ||
279 | |||
280 | #ifdef __BIG_ENDIAN | ||
281 | for (i = 0, j = 0; i < len; i++) { | ||
282 | #else | ||
283 | for (i = len-1, j = 0; i >= 0; i--) { | ||
284 | #endif | ||
285 | hex[j++] = hex_asc_hi(data[i]); | ||
286 | hex[j++] = hex_asc_lo(data[i]); | ||
287 | } | ||
288 | hex[j++] = ' '; | ||
289 | |||
290 | return trace_seq_putmem(s, hex, j); | ||
291 | } | ||
292 | |||
293 | void *trace_seq_reserve(struct trace_seq *s, size_t len) | ||
294 | { | ||
295 | void *ret; | ||
296 | |||
297 | if (s->full) | ||
298 | return NULL; | ||
299 | |||
300 | if (len > ((PAGE_SIZE - 1) - s->len)) { | ||
301 | s->full = 1; | ||
302 | return NULL; | ||
303 | } | ||
304 | |||
305 | ret = s->buffer + s->len; | ||
306 | s->len += len; | ||
307 | |||
308 | return ret; | ||
309 | } | ||
310 | |||
311 | int trace_seq_path(struct trace_seq *s, const struct path *path) | ||
312 | { | ||
313 | unsigned char *p; | ||
314 | |||
315 | if (s->full) | ||
316 | return 0; | ||
317 | |||
318 | if (s->len >= (PAGE_SIZE - 1)) { | ||
319 | s->full = 1; | ||
320 | return 0; | ||
321 | } | ||
322 | |||
323 | p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len); | ||
324 | if (!IS_ERR(p)) { | ||
325 | p = mangle_path(s->buffer + s->len, p, "\n"); | ||
326 | if (p) { | ||
327 | s->len = p - s->buffer; | ||
328 | return 1; | ||
329 | } | ||
330 | } else { | ||
331 | s->buffer[s->len++] = '?'; | ||
332 | return 1; | ||
333 | } | ||
334 | |||
335 | s->full = 1; | ||
336 | return 0; | ||
337 | } | ||
338 | |||
339 | const char * | 71 | const char * |
340 | ftrace_print_flags_seq(struct trace_seq *p, const char *delim, | 72 | ftrace_print_flags_seq(struct trace_seq *p, const char *delim, |
341 | unsigned long flags, | 73 | unsigned long flags, |