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

Commit 11e84acc authored by Frederic Weisbecker's avatar Frederic Weisbecker Committed by Ingo Molnar
Browse files

tracing/function-graph-tracer: display unified style cmdline and pid



Impact: extend function-graph output: let one know which thread called a function

This patch implements a helper function to print the couple cmdline/pid.
Its output is provided during task switching and on each row if the new
"funcgraph-proc" defualt-off option is set through trace_options file.

The output is center aligned and never exceeds 14 characters. The cmdline
is truncated over 7 chars.
But note that if the pid exceeds 6 characters, the column will overflow (but
the situation is abnormal).

Signed-off-by: default avatarFrederic Weisbecker <fweisbec@gmail.com>
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
parent 62679efe
Loading
Loading
Loading
Loading
+99 −14
Original line number Original line Diff line number Diff line
@@ -19,6 +19,7 @@
#define TRACE_GRAPH_PRINT_OVERRUN	0x1
#define TRACE_GRAPH_PRINT_OVERRUN	0x1
#define TRACE_GRAPH_PRINT_CPU		0x2
#define TRACE_GRAPH_PRINT_CPU		0x2
#define TRACE_GRAPH_PRINT_OVERHEAD	0x4
#define TRACE_GRAPH_PRINT_OVERHEAD	0x4
#define TRACE_GRAPH_PRINT_PROC		0x8


static struct tracer_opt trace_opts[] = {
static struct tracer_opt trace_opts[] = {
	/* Display overruns ? */
	/* Display overruns ? */
@@ -27,11 +28,13 @@ static struct tracer_opt trace_opts[] = {
	{ TRACER_OPT(funcgraph-cpu, TRACE_GRAPH_PRINT_CPU) },
	{ TRACER_OPT(funcgraph-cpu, TRACE_GRAPH_PRINT_CPU) },
	/* Display Overhead ? */
	/* Display Overhead ? */
	{ TRACER_OPT(funcgraph-overhead, TRACE_GRAPH_PRINT_OVERHEAD) },
	{ TRACER_OPT(funcgraph-overhead, TRACE_GRAPH_PRINT_OVERHEAD) },
	/* Display proc name/pid */
	{ TRACER_OPT(funcgraph-proc, TRACE_GRAPH_PRINT_PROC) },
	{ } /* Empty entry */
	{ } /* Empty entry */
};
};


static struct tracer_flags tracer_flags = {
static struct tracer_flags tracer_flags = {
	/* Don't display overruns by default */
	/* Don't display overruns and proc by default */
	.val = TRACE_GRAPH_PRINT_CPU | TRACE_GRAPH_PRINT_OVERHEAD,
	.val = TRACE_GRAPH_PRINT_CPU | TRACE_GRAPH_PRINT_OVERHEAD,
	.opts = trace_opts
	.opts = trace_opts
};
};
@@ -104,23 +107,63 @@ print_graph_cpu(struct trace_seq *s, int cpu)
	return TRACE_TYPE_HANDLED;
	return TRACE_TYPE_HANDLED;
}
}


#define TRACE_GRAPH_PROCINFO_LENGTH	14

static enum print_line_t
print_graph_proc(struct trace_seq *s, pid_t pid)
{
	int i;
	int ret;
	int len;
	char comm[8];
	int spaces = 0;
	/* sign + log10(MAX_INT) + '\0' */
	char pid_str[11];

	strncpy(comm, trace_find_cmdline(pid), 7);
	comm[7] = '\0';
	sprintf(pid_str, "%d", pid);

	/* 1 stands for the "-" character */
	len = strlen(comm) + strlen(pid_str) + 1;

	if (len < TRACE_GRAPH_PROCINFO_LENGTH)
		spaces = TRACE_GRAPH_PROCINFO_LENGTH - len;

	/* First spaces to align center */
	for (i = 0; i < spaces / 2; i++) {
		ret = trace_seq_printf(s, " ");
		if (!ret)
			return TRACE_TYPE_PARTIAL_LINE;
	}

	ret = trace_seq_printf(s, "%s-%s", comm, pid_str);
	if (!ret)
		return TRACE_TYPE_PARTIAL_LINE;

	/* Last spaces to align center */
	for (i = 0; i < spaces - (spaces / 2); i++) {
		ret = trace_seq_printf(s, " ");
		if (!ret)
			return TRACE_TYPE_PARTIAL_LINE;
	}
	return TRACE_TYPE_HANDLED;
}



/* If the pid changed since the last trace, output this event */
/* If the pid changed since the last trace, output this event */
static int verif_pid(struct trace_seq *s, pid_t pid, int cpu)
static enum print_line_t
verif_pid(struct trace_seq *s, pid_t pid, int cpu)
{
{
	char *comm, *prev_comm;
	pid_t prev_pid;
	pid_t prev_pid;
	int ret;
	int ret;


	if (last_pid[cpu] != -1 && last_pid[cpu] == pid)
	if (last_pid[cpu] != -1 && last_pid[cpu] == pid)
		return 1;
		return TRACE_TYPE_HANDLED;


	prev_pid = last_pid[cpu];
	prev_pid = last_pid[cpu];
	last_pid[cpu] = pid;
	last_pid[cpu] = pid;


	comm = trace_find_cmdline(pid);
	prev_comm = trace_find_cmdline(prev_pid);

/*
/*
 * Context-switch trace line:
 * Context-switch trace line:


@@ -130,11 +173,31 @@ static int verif_pid(struct trace_seq *s, pid_t pid, int cpu)


 */
 */
	ret = trace_seq_printf(s,
	ret = trace_seq_printf(s,
		" ------------------------------------------\n");
		"\n ------------------------------------------\n |");
	ret += trace_seq_printf(s, " | %d)  %s-%d  =>  %s-%d\n",
	if (!ret)
				  cpu, prev_comm, prev_pid, comm, pid);
		TRACE_TYPE_PARTIAL_LINE;
	ret += trace_seq_printf(s,

		" ------------------------------------------\n\n");
	ret = print_graph_cpu(s, cpu);
	if (ret == TRACE_TYPE_PARTIAL_LINE)
		TRACE_TYPE_PARTIAL_LINE;

	ret = print_graph_proc(s, prev_pid);
	if (ret == TRACE_TYPE_PARTIAL_LINE)
		TRACE_TYPE_PARTIAL_LINE;

	ret = trace_seq_printf(s, " => ");
	if (!ret)
		TRACE_TYPE_PARTIAL_LINE;

	ret = print_graph_proc(s, pid);
	if (ret == TRACE_TYPE_PARTIAL_LINE)
		TRACE_TYPE_PARTIAL_LINE;

	ret = trace_seq_printf(s,
		"\n ------------------------------------------\n\n");
	if (!ret)
		TRACE_TYPE_PARTIAL_LINE;

	return ret;
	return ret;
}
}


@@ -288,12 +351,23 @@ print_graph_entry(struct ftrace_graph_ent_entry *field, struct trace_seq *s,
	struct trace_entry *ent = iter->ent;
	struct trace_entry *ent = iter->ent;


	/* Pid */
	/* Pid */
	if (!verif_pid(s, ent->pid, cpu))
	if (verif_pid(s, ent->pid, cpu) == TRACE_TYPE_PARTIAL_LINE)
		return TRACE_TYPE_PARTIAL_LINE;
		return TRACE_TYPE_PARTIAL_LINE;


	/* Cpu */
	/* Cpu */
	if (tracer_flags.val & TRACE_GRAPH_PRINT_CPU) {
	if (tracer_flags.val & TRACE_GRAPH_PRINT_CPU) {
		ret = print_graph_cpu(s, cpu);
		ret = print_graph_cpu(s, cpu);
		if (ret == TRACE_TYPE_PARTIAL_LINE)
			return TRACE_TYPE_PARTIAL_LINE;
	}

	/* Proc */
	if (tracer_flags.val & TRACE_GRAPH_PRINT_PROC) {
		ret = print_graph_proc(s, ent->pid);
		if (ret == TRACE_TYPE_PARTIAL_LINE)
			return TRACE_TYPE_PARTIAL_LINE;

		ret = trace_seq_printf(s, " | ");
		if (!ret)
		if (!ret)
			return TRACE_TYPE_PARTIAL_LINE;
			return TRACE_TYPE_PARTIAL_LINE;
	}
	}
@@ -318,12 +392,23 @@ print_graph_return(struct ftrace_graph_ret *trace, struct trace_seq *s,
		duration = 9999999ULL;
		duration = 9999999ULL;


	/* Pid */
	/* Pid */
	if (!verif_pid(s, ent->pid, cpu))
	if (verif_pid(s, ent->pid, cpu) == TRACE_TYPE_PARTIAL_LINE)
		return TRACE_TYPE_PARTIAL_LINE;
		return TRACE_TYPE_PARTIAL_LINE;


	/* Cpu */
	/* Cpu */
	if (tracer_flags.val & TRACE_GRAPH_PRINT_CPU) {
	if (tracer_flags.val & TRACE_GRAPH_PRINT_CPU) {
		ret = print_graph_cpu(s, cpu);
		ret = print_graph_cpu(s, cpu);
		if (ret == TRACE_TYPE_PARTIAL_LINE)
			return TRACE_TYPE_PARTIAL_LINE;
	}

	/* Proc */
	if (tracer_flags.val & TRACE_GRAPH_PRINT_PROC) {
		ret = print_graph_proc(s, ent->pid);
		if (ret == TRACE_TYPE_PARTIAL_LINE)
			return TRACE_TYPE_PARTIAL_LINE;

		ret = trace_seq_printf(s, " | ");
		if (!ret)
		if (!ret)
			return TRACE_TYPE_PARTIAL_LINE;
			return TRACE_TYPE_PARTIAL_LINE;
	}
	}