trace_output.c 20.8 KB
Newer Older
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
/*
 * trace_output.c
 *
 * Copyright (C) 2008 Red Hat Inc, Steven Rostedt <srostedt@redhat.com>
 *
 */

#include <linux/module.h>
#include <linux/mutex.h>
#include <linux/ftrace.h>

#include "trace_output.h"

/* must be a power of 2 */
#define EVENT_HASHSIZE	128

static DEFINE_MUTEX(trace_event_mutex);
static struct hlist_head event_hash[EVENT_HASHSIZE] __read_mostly;

static int next_event_type = __TRACE_LAST_TYPE + 1;

/**
 * trace_seq_printf - sequence printing of trace information
 * @s: trace sequence descriptor
 * @fmt: printf format string
 *
 * The tracer may use either sequence operations or its own
 * copy to user routines. To simplify formating of a trace
 * trace_seq_printf is used to store strings into a special
 * buffer (@s). Then the output may be either used by
 * the sequencer or pulled into another buffer.
 */
int
trace_seq_printf(struct trace_seq *s, const char *fmt, ...)
{
	int len = (PAGE_SIZE - 1) - s->len;
	va_list ap;
	int ret;

	if (!len)
		return 0;

	va_start(ap, fmt);
	ret = vsnprintf(s->buffer + s->len, len, fmt, ap);
	va_end(ap);

	/* If we can't write it all, don't bother writing anything */
	if (ret >= len)
		return 0;

	s->len += ret;

	return len;
}

56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
static int
trace_seq_bprintf(struct trace_seq *s, const char *fmt, const u32 *binary)
{
	int len = (PAGE_SIZE - 1) - s->len;
	int ret;

	if (!len)
		return 0;

	ret = bstr_printf(s->buffer + s->len, len, fmt, binary);

	/* If we can't write it all, don't bother writing anything */
	if (ret >= len)
		return 0;

	s->len += ret;

	return len;
}

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 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308
/**
 * trace_seq_puts - trace sequence printing of simple string
 * @s: trace sequence descriptor
 * @str: simple string to record
 *
 * The tracer may use either the sequence operations or its own
 * copy to user routines. This function records a simple string
 * into a special buffer (@s) for later retrieval by a sequencer
 * or other mechanism.
 */
int trace_seq_puts(struct trace_seq *s, const char *str)
{
	int len = strlen(str);

	if (len > ((PAGE_SIZE - 1) - s->len))
		return 0;

	memcpy(s->buffer + s->len, str, len);
	s->len += len;

	return len;
}

int trace_seq_putc(struct trace_seq *s, unsigned char c)
{
	if (s->len >= (PAGE_SIZE - 1))
		return 0;

	s->buffer[s->len++] = c;

	return 1;
}

int trace_seq_putmem(struct trace_seq *s, void *mem, size_t len)
{
	if (len > ((PAGE_SIZE - 1) - s->len))
		return 0;

	memcpy(s->buffer + s->len, mem, len);
	s->len += len;

	return len;
}

int trace_seq_putmem_hex(struct trace_seq *s, void *mem, size_t len)
{
	unsigned char hex[HEX_CHARS];
	unsigned char *data = mem;
	int i, j;

#ifdef __BIG_ENDIAN
	for (i = 0, j = 0; i < len; i++) {
#else
	for (i = len-1, j = 0; i >= 0; i--) {
#endif
		hex[j++] = hex_asc_hi(data[i]);
		hex[j++] = hex_asc_lo(data[i]);
	}
	hex[j++] = ' ';

	return trace_seq_putmem(s, hex, j);
}

int trace_seq_path(struct trace_seq *s, struct path *path)
{
	unsigned char *p;

	if (s->len >= (PAGE_SIZE - 1))
		return 0;
	p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
	if (!IS_ERR(p)) {
		p = mangle_path(s->buffer + s->len, p, "\n");
		if (p) {
			s->len = p - s->buffer;
			return 1;
		}
	} else {
		s->buffer[s->len++] = '?';
		return 1;
	}

	return 0;
}

#ifdef CONFIG_KRETPROBES
static inline const char *kretprobed(const char *name)
{
	static const char tramp_name[] = "kretprobe_trampoline";
	int size = sizeof(tramp_name);

	if (strncmp(tramp_name, name, size) == 0)
		return "[unknown/kretprobe'd]";
	return name;
}
#else
static inline const char *kretprobed(const char *name)
{
	return name;
}
#endif /* CONFIG_KRETPROBES */

static int
seq_print_sym_short(struct trace_seq *s, const char *fmt, unsigned long address)
{
#ifdef CONFIG_KALLSYMS
	char str[KSYM_SYMBOL_LEN];
	const char *name;

	kallsyms_lookup(address, NULL, NULL, NULL, str);

	name = kretprobed(str);

	return trace_seq_printf(s, fmt, name);
#endif
	return 1;
}

static int
seq_print_sym_offset(struct trace_seq *s, const char *fmt,
		     unsigned long address)
{
#ifdef CONFIG_KALLSYMS
	char str[KSYM_SYMBOL_LEN];
	const char *name;

	sprint_symbol(str, address);
	name = kretprobed(str);

	return trace_seq_printf(s, fmt, name);
#endif
	return 1;
}

#ifndef CONFIG_64BIT
# define IP_FMT "%08lx"
#else
# define IP_FMT "%016lx"
#endif

int seq_print_user_ip(struct trace_seq *s, struct mm_struct *mm,
		      unsigned long ip, unsigned long sym_flags)
{
	struct file *file = NULL;
	unsigned long vmstart = 0;
	int ret = 1;

	if (mm) {
		const struct vm_area_struct *vma;

		down_read(&mm->mmap_sem);
		vma = find_vma(mm, ip);
		if (vma) {
			file = vma->vm_file;
			vmstart = vma->vm_start;
		}
		if (file) {
			ret = trace_seq_path(s, &file->f_path);
			if (ret)
				ret = trace_seq_printf(s, "[+0x%lx]",
						       ip - vmstart);
		}
		up_read(&mm->mmap_sem);
	}
	if (ret && ((sym_flags & TRACE_ITER_SYM_ADDR) || !file))
		ret = trace_seq_printf(s, " <" IP_FMT ">", ip);
	return ret;
}

int
seq_print_userip_objs(const struct userstack_entry *entry, struct trace_seq *s,
		      unsigned long sym_flags)
{
	struct mm_struct *mm = NULL;
	int ret = 1;
	unsigned int i;

	if (trace_flags & TRACE_ITER_SYM_USEROBJ) {
		struct task_struct *task;
		/*
		 * we do the lookup on the thread group leader,
		 * since individual threads might have already quit!
		 */
		rcu_read_lock();
		task = find_task_by_vpid(entry->ent.tgid);
		if (task)
			mm = get_task_mm(task);
		rcu_read_unlock();
	}

	for (i = 0; i < FTRACE_STACK_ENTRIES; i++) {
		unsigned long ip = entry->caller[i];

		if (ip == ULONG_MAX || !ret)
			break;
		if (i && ret)
			ret = trace_seq_puts(s, " <- ");
		if (!ip) {
			if (ret)
				ret = trace_seq_puts(s, "??");
			continue;
		}
		if (!ret)
			break;
		if (ret)
			ret = seq_print_user_ip(s, mm, ip, sym_flags);
	}

	if (mm)
		mmput(mm);
	return ret;
}

int
seq_print_ip_sym(struct trace_seq *s, unsigned long ip, unsigned long sym_flags)
{
	int ret;

	if (!ip)
		return trace_seq_printf(s, "0");

	if (sym_flags & TRACE_ITER_SYM_OFFSET)
		ret = seq_print_sym_offset(s, "%s", ip);
	else
		ret = seq_print_sym_short(s, "%s", ip);

	if (!ret)
		return 0;

	if (sym_flags & TRACE_ITER_SYM_ADDR)
		ret = trace_seq_printf(s, " <" IP_FMT ">", ip);
	return ret;
}

309
static int
310 311 312 313 314 315 316 317
lat_print_generic(struct trace_seq *s, struct trace_entry *entry, int cpu)
{
	int hardirq, softirq;
	char *comm;

	comm = trace_find_cmdline(entry->pid);
	hardirq = entry->flags & TRACE_FLAG_HARDIRQ;
	softirq = entry->flags & TRACE_FLAG_SOFTIRQ;
318 319 320 321 322 323 324 325 326 327 328

	if (!trace_seq_printf(s, "%8.8s-%-5d %3d%c%c%c",
			      comm, entry->pid, cpu,
			      (entry->flags & TRACE_FLAG_IRQS_OFF) ? 'd' :
				(entry->flags & TRACE_FLAG_IRQS_NOSUPPORT) ?
				  'X' : '.',
			      (entry->flags & TRACE_FLAG_NEED_RESCHED) ?
				'N' : '.',
			      (hardirq && softirq) ? 'H' :
				hardirq ? 'h' : softirq ? 's' : '.'))
		return 0;
329 330

	if (entry->preempt_count)
331 332
		return trace_seq_printf(s, "%x", entry->preempt_count);
	return trace_seq_puts(s, ".");
333 334 335 336
}

static unsigned long preempt_mark_thresh = 100;

337
static int
338 339 340
lat_print_timestamp(struct trace_seq *s, u64 abs_usecs,
		    unsigned long rel_usecs)
{
341 342 343
	return trace_seq_printf(s, " %4lldus%c: ", abs_usecs,
				rel_usecs > preempt_mark_thresh ? '!' :
				  rel_usecs > 1 ? '+' : ' ');
344 345 346 347 348 349 350 351 352 353 354
}

int trace_print_context(struct trace_iterator *iter)
{
	struct trace_seq *s = &iter->seq;
	struct trace_entry *entry = iter->ent;
	char *comm = trace_find_cmdline(entry->pid);
	unsigned long long t = ns2usecs(iter->ts);
	unsigned long usec_rem = do_div(t, USEC_PER_SEC);
	unsigned long secs = (unsigned long)t;

355
	return trace_seq_printf(s, "%16s-%-5d [%03d] %5lu.%06lu: ",
356
				comm, entry->pid, iter->cpu, secs, usec_rem);
357 358 359 360 361
}

int trace_print_lat_context(struct trace_iterator *iter)
{
	u64 next_ts;
362
	int ret;
363 364 365 366 367 368 369 370 371 372 373 374 375 376
	struct trace_seq *s = &iter->seq;
	struct trace_entry *entry = iter->ent,
			   *next_entry = trace_find_next_entry(iter, NULL,
							       &next_ts);
	unsigned long verbose = (trace_flags & TRACE_ITER_VERBOSE);
	unsigned long abs_usecs = ns2usecs(iter->ts - iter->tr->time_start);
	unsigned long rel_usecs;

	if (!next_entry)
		next_ts = iter->ts;
	rel_usecs = ns2usecs(next_ts - iter->ts);

	if (verbose) {
		char *comm = trace_find_cmdline(entry->pid);
377 378
		ret = trace_seq_printf(s, "%16s %5d %3d %d %08x %08lx [%08lx]"
				       " %ld.%03ldms (+%ld.%03ldms): ", comm,
379
				       entry->pid, iter->cpu, entry->flags,
380 381 382 383 384 385
				       entry->preempt_count, iter->idx,
				       ns2usecs(iter->ts),
				       abs_usecs / USEC_PER_MSEC,
				       abs_usecs % USEC_PER_MSEC,
				       rel_usecs / USEC_PER_MSEC,
				       rel_usecs % USEC_PER_MSEC);
386
	} else {
387
		ret = lat_print_generic(s, entry, iter->cpu);
388 389
		if (ret)
			ret = lat_print_timestamp(s, abs_usecs, rel_usecs);
390 391
	}

392
	return ret;
393 394
}

395 396 397 398 399 400 401 402 403
static const char state_to_char[] = TASK_STATE_TO_CHAR_STR;

static int task_state_char(unsigned long state)
{
	int bit = state ? __ffs(state) + 1 : 0;

	return bit < sizeof(state_to_char) - 1 ? state_to_char[bit] : '?';
}

404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457
/**
 * ftrace_find_event - find a registered event
 * @type: the type of event to look for
 *
 * Returns an event of type @type otherwise NULL
 */
struct trace_event *ftrace_find_event(int type)
{
	struct trace_event *event;
	struct hlist_node *n;
	unsigned key;

	key = type & (EVENT_HASHSIZE - 1);

	hlist_for_each_entry_rcu(event, n, &event_hash[key], node) {
		if (event->type == type)
			return event;
	}

	return NULL;
}

/**
 * register_ftrace_event - register output for an event type
 * @event: the event type to register
 *
 * Event types are stored in a hash and this hash is used to
 * find a way to print an event. If the @event->type is set
 * then it will use that type, otherwise it will assign a
 * type to use.
 *
 * If you assign your own type, please make sure it is added
 * to the trace_type enum in trace.h, to avoid collisions
 * with the dynamic types.
 *
 * Returns the event type number or zero on error.
 */
int register_ftrace_event(struct trace_event *event)
{
	unsigned key;
	int ret = 0;

	mutex_lock(&trace_event_mutex);

	if (!event->type)
		event->type = next_event_type++;
	else if (event->type > __TRACE_LAST_TYPE) {
		printk(KERN_WARNING "Need to add type to trace.h\n");
		WARN_ON(1);
	}

	if (ftrace_find_event(event->type))
		goto out;

458 459 460 461 462 463 464 465 466
	if (event->trace == NULL)
		event->trace = trace_nop_print;
	if (event->raw == NULL)
		event->raw = trace_nop_print;
	if (event->hex == NULL)
		event->hex = trace_nop_print;
	if (event->binary == NULL)
		event->binary = trace_nop_print;

467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489
	key = event->type & (EVENT_HASHSIZE - 1);

	hlist_add_head_rcu(&event->node, &event_hash[key]);

	ret = event->type;
 out:
	mutex_unlock(&trace_event_mutex);

	return ret;
}

/**
 * unregister_ftrace_event - remove a no longer used event
 * @event: the event to remove
 */
int unregister_ftrace_event(struct trace_event *event)
{
	mutex_lock(&trace_event_mutex);
	hlist_del(&event->node);
	mutex_unlock(&trace_event_mutex);

	return 0;
}
490 491 492 493 494

/*
 * Standard events
 */

495
enum print_line_t trace_nop_print(struct trace_iterator *iter, int flags)
496
{
497
	return TRACE_TYPE_HANDLED;
498 499 500
}

/* TRACE_FN */
501
static enum print_line_t trace_fn_trace(struct trace_iterator *iter, int flags)
502 503
{
	struct ftrace_entry *field;
504
	struct trace_seq *s = &iter->seq;
505

506
	trace_assign_type(field, iter->ent);
507 508 509 510 511 512 513 514 515 516 517 518 519 520 521

	if (!seq_print_ip_sym(s, field->ip, flags))
		goto partial;

	if ((flags & TRACE_ITER_PRINT_PARENT) && field->parent_ip) {
		if (!trace_seq_printf(s, " <-"))
			goto partial;
		if (!seq_print_ip_sym(s,
				      field->parent_ip,
				      flags))
			goto partial;
	}
	if (!trace_seq_printf(s, "\n"))
		goto partial;

522
	return TRACE_TYPE_HANDLED;
523 524 525 526 527

 partial:
	return TRACE_TYPE_PARTIAL_LINE;
}

528
static enum print_line_t trace_fn_raw(struct trace_iterator *iter, int flags)
529 530 531
{
	struct ftrace_entry *field;

532
	trace_assign_type(field, iter->ent);
533

534
	if (!trace_seq_printf(&iter->seq, "%lx %lx\n",
L
Lai Jiangshan 已提交
535 536
			      field->ip,
			      field->parent_ip))
537 538
		return TRACE_TYPE_PARTIAL_LINE;

539
	return TRACE_TYPE_HANDLED;
540 541
}

542
static enum print_line_t trace_fn_hex(struct trace_iterator *iter, int flags)
543 544
{
	struct ftrace_entry *field;
545
	struct trace_seq *s = &iter->seq;
546

547
	trace_assign_type(field, iter->ent);
548 549 550 551

	SEQ_PUT_HEX_FIELD_RET(s, field->ip);
	SEQ_PUT_HEX_FIELD_RET(s, field->parent_ip);

552
	return TRACE_TYPE_HANDLED;
553 554
}

555
static enum print_line_t trace_fn_bin(struct trace_iterator *iter, int flags)
556 557
{
	struct ftrace_entry *field;
558
	struct trace_seq *s = &iter->seq;
559

560
	trace_assign_type(field, iter->ent);
561 562 563 564

	SEQ_PUT_FIELD_RET(s, field->ip);
	SEQ_PUT_FIELD_RET(s, field->parent_ip);

565
	return TRACE_TYPE_HANDLED;
566 567 568 569 570 571 572 573 574 575 576
}

static struct trace_event trace_fn_event = {
	.type	 	= TRACE_FN,
	.trace		= trace_fn_trace,
	.raw		= trace_fn_raw,
	.hex		= trace_fn_hex,
	.binary		= trace_fn_bin,
};

/* TRACE_CTX an TRACE_WAKE */
577 578
static enum print_line_t trace_ctxwake_print(struct trace_iterator *iter,
					     char *delim)
579 580 581 582 583
{
	struct ctx_switch_entry *field;
	char *comm;
	int S, T;

584
	trace_assign_type(field, iter->ent);
585 586 587 588

	T = task_state_char(field->next_state);
	S = task_state_char(field->prev_state);
	comm = trace_find_cmdline(field->next_pid);
589 590
	if (!trace_seq_printf(&iter->seq,
			      " %5d:%3d:%c %s [%03d] %5d:%3d:%c %s\n",
L
Lai Jiangshan 已提交
591 592 593 594 595 596 597
			      field->prev_pid,
			      field->prev_prio,
			      S, delim,
			      field->next_cpu,
			      field->next_pid,
			      field->next_prio,
			      T, comm))
598 599
		return TRACE_TYPE_PARTIAL_LINE;

600
	return TRACE_TYPE_HANDLED;
601 602
}

603
static enum print_line_t trace_ctx_print(struct trace_iterator *iter, int flags)
604
{
605
	return trace_ctxwake_print(iter, "==>");
606 607
}

608 609
static enum print_line_t trace_wake_print(struct trace_iterator *iter,
					  int flags)
610
{
611
	return trace_ctxwake_print(iter, "  +");
612 613
}

614
static int trace_ctxwake_raw(struct trace_iterator *iter, char S)
615 616 617 618
{
	struct ctx_switch_entry *field;
	int T;

619
	trace_assign_type(field, iter->ent);
620 621 622 623

	if (!S)
		task_state_char(field->prev_state);
	T = task_state_char(field->next_state);
624
	if (!trace_seq_printf(&iter->seq, "%d %d %c %d %d %d %c\n",
L
Lai Jiangshan 已提交
625 626 627 628 629 630 631
			      field->prev_pid,
			      field->prev_prio,
			      S,
			      field->next_cpu,
			      field->next_pid,
			      field->next_prio,
			      T))
632 633
		return TRACE_TYPE_PARTIAL_LINE;

634
	return TRACE_TYPE_HANDLED;
635 636
}

637
static enum print_line_t trace_ctx_raw(struct trace_iterator *iter, int flags)
638
{
639
	return trace_ctxwake_raw(iter, 0);
640 641
}

642
static enum print_line_t trace_wake_raw(struct trace_iterator *iter, int flags)
643
{
644
	return trace_ctxwake_raw(iter, '+');
645 646 647
}


648
static int trace_ctxwake_hex(struct trace_iterator *iter, char S)
649 650
{
	struct ctx_switch_entry *field;
651
	struct trace_seq *s = &iter->seq;
652 653
	int T;

654
	trace_assign_type(field, iter->ent);
655 656 657 658 659 660 661 662 663 664 665 666 667

	if (!S)
		task_state_char(field->prev_state);
	T = task_state_char(field->next_state);

	SEQ_PUT_HEX_FIELD_RET(s, field->prev_pid);
	SEQ_PUT_HEX_FIELD_RET(s, field->prev_prio);
	SEQ_PUT_HEX_FIELD_RET(s, S);
	SEQ_PUT_HEX_FIELD_RET(s, field->next_cpu);
	SEQ_PUT_HEX_FIELD_RET(s, field->next_pid);
	SEQ_PUT_HEX_FIELD_RET(s, field->next_prio);
	SEQ_PUT_HEX_FIELD_RET(s, T);

668
	return TRACE_TYPE_HANDLED;
669 670
}

671
static enum print_line_t trace_ctx_hex(struct trace_iterator *iter, int flags)
672
{
673
	return trace_ctxwake_hex(iter, 0);
674 675
}

676
static enum print_line_t trace_wake_hex(struct trace_iterator *iter, int flags)
677
{
678
	return trace_ctxwake_hex(iter, '+');
679 680
}

681 682
static enum print_line_t trace_ctxwake_bin(struct trace_iterator *iter,
					   int flags)
683 684
{
	struct ctx_switch_entry *field;
685
	struct trace_seq *s = &iter->seq;
686

687
	trace_assign_type(field, iter->ent);
688 689 690 691 692 693 694 695

	SEQ_PUT_FIELD_RET(s, field->prev_pid);
	SEQ_PUT_FIELD_RET(s, field->prev_prio);
	SEQ_PUT_FIELD_RET(s, field->prev_state);
	SEQ_PUT_FIELD_RET(s, field->next_pid);
	SEQ_PUT_FIELD_RET(s, field->next_prio);
	SEQ_PUT_FIELD_RET(s, field->next_state);

696
	return TRACE_TYPE_HANDLED;
697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715
}

static struct trace_event trace_ctx_event = {
	.type	 	= TRACE_CTX,
	.trace		= trace_ctx_print,
	.raw		= trace_ctx_raw,
	.hex		= trace_ctx_hex,
	.binary		= trace_ctxwake_bin,
};

static struct trace_event trace_wake_event = {
	.type	 	= TRACE_WAKE,
	.trace		= trace_wake_print,
	.raw		= trace_wake_raw,
	.hex		= trace_wake_hex,
	.binary		= trace_ctxwake_bin,
};

/* TRACE_SPECIAL */
716 717
static enum print_line_t trace_special_print(struct trace_iterator *iter,
					     int flags)
718 719 720
{
	struct special_entry *field;

721
	trace_assign_type(field, iter->ent);
722

723
	if (!trace_seq_printf(&iter->seq, "# %ld %ld %ld\n",
L
Lai Jiangshan 已提交
724 725 726
			      field->arg1,
			      field->arg2,
			      field->arg3))
727 728
		return TRACE_TYPE_PARTIAL_LINE;

729
	return TRACE_TYPE_HANDLED;
730 731
}

732 733
static enum print_line_t trace_special_hex(struct trace_iterator *iter,
					   int flags)
734 735
{
	struct special_entry *field;
736
	struct trace_seq *s = &iter->seq;
737

738
	trace_assign_type(field, iter->ent);
739 740 741 742 743

	SEQ_PUT_HEX_FIELD_RET(s, field->arg1);
	SEQ_PUT_HEX_FIELD_RET(s, field->arg2);
	SEQ_PUT_HEX_FIELD_RET(s, field->arg3);

744
	return TRACE_TYPE_HANDLED;
745 746
}

747 748
static enum print_line_t trace_special_bin(struct trace_iterator *iter,
					   int flags)
749 750
{
	struct special_entry *field;
751
	struct trace_seq *s = &iter->seq;
752

753
	trace_assign_type(field, iter->ent);
754 755 756 757 758

	SEQ_PUT_FIELD_RET(s, field->arg1);
	SEQ_PUT_FIELD_RET(s, field->arg2);
	SEQ_PUT_FIELD_RET(s, field->arg3);

759
	return TRACE_TYPE_HANDLED;
760 761 762 763 764 765 766 767 768 769 770 771
}

static struct trace_event trace_special_event = {
	.type	 	= TRACE_SPECIAL,
	.trace		= trace_special_print,
	.raw		= trace_special_print,
	.hex		= trace_special_hex,
	.binary		= trace_special_bin,
};

/* TRACE_STACK */

772 773
static enum print_line_t trace_stack_print(struct trace_iterator *iter,
					   int flags)
774 775
{
	struct stack_entry *field;
776
	struct trace_seq *s = &iter->seq;
777 778
	int i;

779
	trace_assign_type(field, iter->ent);
780 781 782

	for (i = 0; i < FTRACE_STACK_ENTRIES; i++) {
		if (i) {
L
Lai Jiangshan 已提交
783
			if (!trace_seq_puts(s, " <= "))
784 785
				goto partial;

L
Lai Jiangshan 已提交
786
			if (!seq_print_ip_sym(s, field->caller[i], flags))
787 788
				goto partial;
		}
L
Lai Jiangshan 已提交
789
		if (!trace_seq_puts(s, "\n"))
790 791 792
			goto partial;
	}

793
	return TRACE_TYPE_HANDLED;
794 795 796 797 798 799 800 801 802 803 804 805 806 807

 partial:
	return TRACE_TYPE_PARTIAL_LINE;
}

static struct trace_event trace_stack_event = {
	.type	 	= TRACE_STACK,
	.trace		= trace_stack_print,
	.raw		= trace_special_print,
	.hex		= trace_special_hex,
	.binary		= trace_special_bin,
};

/* TRACE_USER_STACK */
808 809
static enum print_line_t trace_user_stack_print(struct trace_iterator *iter,
						int flags)
810 811
{
	struct userstack_entry *field;
812
	struct trace_seq *s = &iter->seq;
813

814
	trace_assign_type(field, iter->ent);
815

L
Lai Jiangshan 已提交
816
	if (!seq_print_userip_objs(field, s, flags))
817 818
		goto partial;

L
Lai Jiangshan 已提交
819
	if (!trace_seq_putc(s, '\n'))
820 821
		goto partial;

822
	return TRACE_TYPE_HANDLED;
823 824 825 826 827 828 829 830 831 832 833 834 835 836

 partial:
	return TRACE_TYPE_PARTIAL_LINE;
}

static struct trace_event trace_user_stack_event = {
	.type	 	= TRACE_USER_STACK,
	.trace		= trace_user_stack_print,
	.raw		= trace_special_print,
	.hex		= trace_special_hex,
	.binary		= trace_special_bin,
};

/* TRACE_PRINT */
837 838
static enum print_line_t trace_print_print(struct trace_iterator *iter,
					   int flags)
839 840
{
	struct print_entry *field;
841
	struct trace_seq *s = &iter->seq;
842

843
	trace_assign_type(field, iter->ent);
844

L
Lai Jiangshan 已提交
845
	if (!seq_print_ip_sym(s, field->ip, flags))
846 847
		goto partial;

L
Lai Jiangshan 已提交
848
	if (!trace_seq_printf(s, ": %s", field->buf))
849 850
		goto partial;

851
	return TRACE_TYPE_HANDLED;
852 853 854 855 856

 partial:
	return TRACE_TYPE_PARTIAL_LINE;
}

857
static enum print_line_t trace_print_raw(struct trace_iterator *iter, int flags)
858 859 860
{
	struct print_entry *field;

861
	trace_assign_type(field, iter->ent);
862

863
	if (!trace_seq_printf(&iter->seq, "# %lx %s", field->ip, field->buf))
864 865
		goto partial;

866
	return TRACE_TYPE_HANDLED;
867 868 869 870 871 872 873 874 875 876 877

 partial:
	return TRACE_TYPE_PARTIAL_LINE;
}

static struct trace_event trace_print_event = {
	.type	 	= TRACE_PRINT,
	.trace		= trace_print_print,
	.raw		= trace_print_raw,
};

878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931
/* TRACE_BPRINTK */
static enum print_line_t
trace_bprintk_print(struct trace_iterator *iter, int flags)
{
	struct trace_entry *entry = iter->ent;
	struct trace_seq *s = &iter->seq;
	struct bprintk_entry *field;

	trace_assign_type(field, entry);

	if (!seq_print_ip_sym(s, field->ip, flags))
		goto partial;

	if (!trace_seq_puts(s, ": "))
		goto partial;

	if (!trace_seq_bprintf(s, field->fmt, field->buf))
		goto partial;

	return TRACE_TYPE_HANDLED;

 partial:
	return TRACE_TYPE_PARTIAL_LINE;
}

static enum print_line_t
trace_bprintk_raw(struct trace_iterator *iter, int flags)
{
	struct trace_entry *entry = iter->ent;
	struct trace_seq *s = &iter->seq;
	struct bprintk_entry *field;

	trace_assign_type(field, entry);

	if (!trace_seq_printf(s, ": %lx : ", field->ip))
		goto partial;

	if (!trace_seq_bprintf(s, field->fmt, field->buf))
		goto partial;

	return TRACE_TYPE_HANDLED;

 partial:
	return TRACE_TYPE_PARTIAL_LINE;
}

static struct trace_event trace_bprintk_event = {
	.type	 	= TRACE_BPRINTK,
	.trace		= trace_bprintk_print,
	.raw		= trace_bprintk_raw,
	.hex		= trace_nop_print,
	.binary		= trace_nop_print,
};

932 933 934 935 936 937 938 939
static struct trace_event *events[] __initdata = {
	&trace_fn_event,
	&trace_ctx_event,
	&trace_wake_event,
	&trace_special_event,
	&trace_stack_event,
	&trace_user_stack_event,
	&trace_print_event,
940
	&trace_bprintk_event,
941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962
	NULL
};

__init static int init_events(void)
{
	struct trace_event *event;
	int i, ret;

	for (i = 0; events[i]; i++) {
		event = events[i];

		ret = register_ftrace_event(event);
		if (!ret) {
			printk(KERN_WARNING "event %d failed to register\n",
			       event->type);
			WARN_ON_ONCE(1);
		}
	}

	return 0;
}
device_initcall(init_events);