Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 87968f94 authored by Ingo Molnar's avatar Ingo Molnar
Browse files

Merge tag 'perf-core-for-mingo' of...

Merge tag 'perf-core-for-mingo' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux

 into perf/core

Pull perf/core improvements and fixes from Arnaldo Carvalho de Melo:

  * Add new COMM infrastructure, further improving histogram processing, from
    Frédéric Weisbecker, one fix from Namhyung Kim.

  * Enhance option parse error message, showing just the help lines of the
    options affected, from Namhyung Kim.

  * Fixup PERF_SAMPLE_TRANSACTION handling in sample synthesizing and
    'perf test', from Adrian Hunter.

  * Set up output options for in-stream attributes, from Adrian Hunter.

  * Fix 32-bit cross build, from Adrian Hunter.

  * Fix libunwind build and feature detection for 32-bit build, from Adrian Hunter.

  * Always use perf_evsel__set_sample_bit to set sample_type, from Adrian Hunter.
    perf evlist: Add a debug print if event buffer mmap fails

  * Add missing data.h into LIB_H headers, fix from Jiri Olsa.

  * libtraceevent updates from upstream trace-cmd repo, from Steven Rostedt.

Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
parents 2a3ede8c 6d862b8c
Loading
Loading
Loading
Loading
+124 −41
Original line number Diff line number Diff line
@@ -305,6 +305,11 @@ int pevent_register_comm(struct pevent *pevent, const char *comm, int pid)
	return 0;
}

void pevent_register_trace_clock(struct pevent *pevent, char *trace_clock)
{
	pevent->trace_clock = trace_clock;
}

struct func_map {
	unsigned long long		addr;
	char				*func;
@@ -599,10 +604,11 @@ find_printk(struct pevent *pevent, unsigned long long addr)
 * This registers a string by the address it was stored in the kernel.
 * The @fmt passed in is duplicated.
 */
int pevent_register_print_string(struct pevent *pevent, char *fmt,
int pevent_register_print_string(struct pevent *pevent, const char *fmt,
				 unsigned long long addr)
{
	struct printk_list *item = malloc(sizeof(*item));
	char *p;

	if (!item)
		return -1;
@@ -610,10 +616,21 @@ int pevent_register_print_string(struct pevent *pevent, char *fmt,
	item->next = pevent->printklist;
	item->addr = addr;

	/* Strip off quotes and '\n' from the end */
	if (fmt[0] == '"')
		fmt++;
	item->printk = strdup(fmt);
	if (!item->printk)
		goto out_free;

	p = item->printk + strlen(item->printk) - 1;
	if (*p == '"')
		*p = 0;

	p -= 2;
	if (strcmp(p, "\\n") == 0)
		*p = 0;

	pevent->printklist = item;
	pevent->printk_count++;

@@ -3488,6 +3505,7 @@ static void print_str_arg(struct trace_seq *s, void *data, int size,
	struct pevent *pevent = event->pevent;
	struct print_flag_sym *flag;
	struct format_field *field;
	struct printk_map *printk;
	unsigned long long val, fval;
	unsigned long addr;
	char *str;
@@ -3523,6 +3541,11 @@ static void print_str_arg(struct trace_seq *s, void *data, int size,
		if (!(field->flags & FIELD_IS_ARRAY) &&
		    field->size == pevent->long_size) {
			addr = *(unsigned long *)(data + field->offset);
			/* Check if it matches a print format */
			printk = find_printk(pevent, addr);
			if (printk)
				trace_seq_puts(s, printk->printk);
			else
				trace_seq_printf(s, "%lx", addr);
			break;
		}
@@ -3565,6 +3588,13 @@ static void print_str_arg(struct trace_seq *s, void *data, int size,
		}
		break;
	case PRINT_HEX:
		if (arg->hex.field->type == PRINT_DYNAMIC_ARRAY) {
			unsigned long offset;
			offset = pevent_read_number(pevent,
				data + arg->hex.field->dynarray.field->offset,
				arg->hex.field->dynarray.field->size);
			hex = data + (offset & 0xffff);
		} else {
			field = arg->hex.field->field.field;
			if (!field) {
				str = arg->hex.field->field.name;
@@ -3574,6 +3604,7 @@ static void print_str_arg(struct trace_seq *s, void *data, int size,
				arg->hex.field->field.field = field;
			}
			hex = data + field->offset;
		}
		len = eval_num_arg(data, size, event, arg->hex.size);
		for (i = 0; i < len; i++) {
			if (i)
@@ -3772,7 +3803,7 @@ static struct print_arg *make_bprint_args(char *fmt, void *data, int size, struc
		goto out_free;

	/* skip the first "%pf: " */
	for (ptr = fmt + 6, bptr = data + field->offset;
	for (ptr = fmt + 5, bptr = data + field->offset;
	     bptr < data + size && *ptr; ptr++) {
		int ls = 0;

@@ -3882,7 +3913,6 @@ get_bprint_format(void *data, int size __maybe_unused,
	struct format_field *field;
	struct printk_map *printk;
	char *format;
	char *p;

	field = pevent->bprint_fmt_field;

@@ -3904,20 +3934,8 @@ get_bprint_format(void *data, int size __maybe_unused,
		return format;
	}

	p = printk->printk;
	/* Remove any quotes. */
	if (*p == '"')
		p++;
	if (asprintf(&format, "%s : %s", "%pf", p) < 0)
	if (asprintf(&format, "%s: %s", "%pf", printk->printk) < 0)
		return NULL;
	/* remove ending quotes and new line since we will add one too */
	p = format + strlen(format) - 1;
	if (*p == '"')
		*p = 0;

	p -= 2;
	if (strcmp(p, "\\n") == 0)
		*p = 0;

	return format;
}
@@ -3963,7 +3981,7 @@ static int is_printable_array(char *p, unsigned int len)
	unsigned int i;

	for (i = 0; i < len && p[i]; i++)
		if (!isprint(p[i]))
		if (!isprint(p[i]) && !isspace(p[i]))
		    return 0;
	return 1;
}
@@ -4428,11 +4446,11 @@ void pevent_event_info(struct trace_seq *s, struct event_format *event,
{
	int print_pretty = 1;

	if (event->pevent->print_raw)
	if (event->pevent->print_raw || (event->flags & EVENT_FL_PRINTRAW))
		print_event_fields(s, record->data, record->size, event);
	else {

		if (event->handler)
		if (event->handler && !(event->flags & EVENT_FL_NOHANDLE))
			print_pretty = event->handler(s, record, event,
						      event->context);

@@ -4443,8 +4461,21 @@ void pevent_event_info(struct trace_seq *s, struct event_format *event,
	trace_seq_terminate(s);
}

static bool is_timestamp_in_us(char *trace_clock, bool use_trace_clock)
{
	if (!use_trace_clock)
		return true;

	if (!strcmp(trace_clock, "local") || !strcmp(trace_clock, "global")
	    || !strcmp(trace_clock, "uptime") || !strcmp(trace_clock, "perf"))
		return true;

	/* trace_clock is setting in tsc or counter mode */
	return false;
}

void pevent_print_event(struct pevent *pevent, struct trace_seq *s,
			struct pevent_record *record)
			struct pevent_record *record, bool use_trace_clock)
{
	static const char *spaces = "                    "; /* 20 spaces */
	struct event_format *event;
@@ -4457,9 +4488,14 @@ void pevent_print_event(struct pevent *pevent, struct trace_seq *s,
	int pid;
	int len;
	int p;
	bool use_usec_format;

	use_usec_format = is_timestamp_in_us(pevent->trace_clock,
							use_trace_clock);
	if (use_usec_format) {
		secs = record->ts / NSECS_PER_SEC;
		nsecs = record->ts - secs * NSECS_PER_SEC;
	}

	if (record->size < 0) {
		do_warning("ug! negative record size %d", record->size);
@@ -4484,6 +4520,7 @@ void pevent_print_event(struct pevent *pevent, struct trace_seq *s,
	} else
		trace_seq_printf(s, "%16s-%-5d [%03d]", comm, pid, record->cpu);

	if (use_usec_format) {
		if (pevent->flags & PEVENT_NSEC_OUTPUT) {
			usecs = nsecs;
			p = 9;
@@ -4492,7 +4529,11 @@ void pevent_print_event(struct pevent *pevent, struct trace_seq *s,
			p = 6;
		}

	trace_seq_printf(s, " %5lu.%0*lu: %s: ", secs, p, usecs, event->name);
		trace_seq_printf(s, " %5lu.%0*lu: %s: ",
					secs, p, usecs, event->name);
	} else
		trace_seq_printf(s, " %12llu: %s: ",
					record->ts, event->name);

	/* Space out the event names evenly. */
	len = strlen(event->name);
@@ -5326,6 +5367,48 @@ int pevent_print_num_field(struct trace_seq *s, const char *fmt,
	return -1;
}

/**
 * pevent_print_func_field - print a field and a format for function pointers
 * @s: The seq to print to
 * @fmt: The printf format to print the field with.
 * @event: the event that the field is for
 * @name: The name of the field
 * @record: The record with the field name.
 * @err: print default error if failed.
 *
 * Returns: 0 on success, -1 field not found, or 1 if buffer is full.
 */
int pevent_print_func_field(struct trace_seq *s, const char *fmt,
			    struct event_format *event, const char *name,
			    struct pevent_record *record, int err)
{
	struct format_field *field = pevent_find_field(event, name);
	struct pevent *pevent = event->pevent;
	unsigned long long val;
	struct func_map *func;
	char tmp[128];

	if (!field)
		goto failed;

	if (pevent_read_number_field(field, record->data, &val))
		goto failed;

	func = find_func(pevent, val);

	if (func)
		snprintf(tmp, 128, "%s/0x%llx", func->func, func->addr - val);
	else
		sprintf(tmp, "0x%08llx", val);

	return trace_seq_printf(s, fmt, tmp);

 failed:
	if (err)
		trace_seq_printf(s, "CAN'T FIND FIELD \"%s\"", name);
	return -1;
}

static void free_func_handle(struct pevent_function_handler *func)
{
	struct pevent_func_params *params;
+12 −2
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@
#ifndef _PARSE_EVENTS_H
#define _PARSE_EVENTS_H

#include <stdbool.h>
#include <stdarg.h>
#include <regex.h>

@@ -307,6 +308,8 @@ enum {
	EVENT_FL_ISBPRINT	= 0x04,
	EVENT_FL_ISFUNCENT	= 0x10,
	EVENT_FL_ISFUNCRET	= 0x20,
	EVENT_FL_NOHANDLE	= 0x40,
	EVENT_FL_PRINTRAW	= 0x80,

	EVENT_FL_FAILED		= 0x80000000
};
@@ -450,6 +453,8 @@ struct pevent {

	/* cache */
	struct event_format *last_event;

	char *trace_clock;
};

static inline void pevent_set_flag(struct pevent *pevent, int flag)
@@ -527,14 +532,15 @@ enum trace_flag_type {
};

int pevent_register_comm(struct pevent *pevent, const char *comm, int pid);
void pevent_register_trace_clock(struct pevent *pevent, char *trace_clock);
int pevent_register_function(struct pevent *pevent, char *name,
			     unsigned long long addr, char *mod);
int pevent_register_print_string(struct pevent *pevent, char *fmt,
int pevent_register_print_string(struct pevent *pevent, const char *fmt,
				 unsigned long long addr);
int pevent_pid_is_registered(struct pevent *pevent, int pid);

void pevent_print_event(struct pevent *pevent, struct trace_seq *s,
			struct pevent_record *record);
			struct pevent_record *record, bool use_trace_clock);

int pevent_parse_header_page(struct pevent *pevent, char *buf, unsigned long size,
			     int long_size);
@@ -563,6 +569,10 @@ int pevent_print_num_field(struct trace_seq *s, const char *fmt,
			   struct event_format *event, const char *name,
			   struct pevent_record *record, int err);

int pevent_print_func_field(struct trace_seq *s, const char *fmt,
			   struct event_format *event, const char *name,
			   struct pevent_record *record, int err);

int pevent_register_event_handler(struct pevent *pevent, int id,
				  const char *sys_name, const char *event_name,
				  pevent_event_handler_func func, void *context);
+4 −1
Original line number Diff line number Diff line
@@ -273,6 +273,7 @@ LIB_H += util/color.h
LIB_H += util/values.h
LIB_H += util/sort.h
LIB_H += util/hist.h
LIB_H += util/comm.h
LIB_H += util/thread.h
LIB_H += util/thread_map.h
LIB_H += util/trace-event.h
@@ -295,6 +296,7 @@ LIB_H += ui/helpline.h
LIB_H += ui/progress.h
LIB_H += ui/util.h
LIB_H += ui/ui.h
LIB_H += util/data.h

LIB_OBJS += $(OUTPUT)util/abspath.o
LIB_OBJS += $(OUTPUT)util/alias.o
@@ -340,6 +342,7 @@ LIB_OBJS += $(OUTPUT)util/machine.o
LIB_OBJS += $(OUTPUT)util/map.o
LIB_OBJS += $(OUTPUT)util/pstack.o
LIB_OBJS += $(OUTPUT)util/session.o
LIB_OBJS += $(OUTPUT)util/comm.o
LIB_OBJS += $(OUTPUT)util/thread.o
LIB_OBJS += $(OUTPUT)util/thread_map.o
LIB_OBJS += $(OUTPUT)util/trace-event-parse.o
@@ -708,7 +711,7 @@ $(LIB_FILE): $(LIB_OBJS)
TE_SOURCES = $(wildcard $(TRACE_EVENT_DIR)*.[ch])

$(LIBTRACEEVENT): $(TE_SOURCES)
	$(QUIET_SUBDIR0)$(TRACE_EVENT_DIR) $(QUIET_SUBDIR1) O=$(OUTPUT) libtraceevent.a
	$(QUIET_SUBDIR0)$(TRACE_EVENT_DIR) $(QUIET_SUBDIR1) O=$(OUTPUT) CFLAGS="-g -Wall $(EXTRA_CFLAGS)" libtraceevent.a

$(LIBTRACEEVENT)-clean:
	$(call QUIET_CLEAN, libtraceevent)
+1 −1
Original line number Diff line number Diff line
@@ -315,7 +315,7 @@ static int process_sample_event(struct perf_tool *tool __maybe_unused,
		return -1;
	}

	dump_printf(" ... thread: %s:%d\n", thread->comm, thread->tid);
	dump_printf(" ... thread: %s:%d\n", thread__comm_str(thread), thread->tid);

	if (evsel->handler.func != NULL) {
		tracepoint_handler f = evsel->handler.func;
+1 −1
Original line number Diff line number Diff line
@@ -767,7 +767,7 @@ static void dump_threads(void)
	while (node) {
		st = container_of(node, struct thread_stat, rb);
		t = perf_session__findnew(session, st->tid);
		pr_info("%10d: %s\n", st->tid, t->comm);
		pr_info("%10d: %s\n", st->tid, thread__comm_str(t));
		node = rb_next(node);
	};
}
Loading