Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 140606
b: refs/heads/master
c: e302cf3
h: refs/heads/master
v: v3
  • Loading branch information
Frederic Weisbecker authored and Ingo Molnar committed Dec 29, 2008
1 parent d2e2513 commit d70bb2c
Show file tree
Hide file tree
Showing 2 changed files with 143 additions and 127 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: dbd0b4b33074aa6b7832a9d9a5bd985eca5c1aa2
refs/heads/master: e302cf3f961ceb54c1dd0aff7ba8531df83be07a
268 changes: 142 additions & 126 deletions trunk/kernel/trace/trace_branch.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@
#include "trace.h"
#include "trace_output.h"

static struct tracer branch_trace;

#ifdef CONFIG_BRANCH_TRACER

static int branch_tracing_enabled __read_mostly;
static DEFINE_MUTEX(branch_tracing_mutex);

static struct trace_array *branch_tracer;

static void
Expand Down Expand Up @@ -178,6 +181,7 @@ trace_branch_print(struct trace_seq *s, struct trace_entry *entry, int flags)
return 0;
}


static struct trace_event trace_branch_event = {
.type = TRACE_BRANCH,
.trace = trace_branch_print,
Expand All @@ -187,30 +191,6 @@ static struct trace_event trace_branch_event = {
.binary = trace_nop_print,
};

struct tracer branch_trace __read_mostly =
{
.name = "branch",
.init = branch_trace_init,
.reset = branch_trace_reset,
#ifdef CONFIG_FTRACE_SELFTEST
.selftest = trace_selftest_startup_branch,
#endif
};

__init static int init_branch_trace(void)
{
int ret;

ret = register_ftrace_event(&trace_branch_event);
if (!ret) {
printk(KERN_WARNING "Warning: could not register branch events\n");
return 1;
}

return register_tracer(&branch_trace);
}

device_initcall(init_branch_trace);
#else
static inline
void trace_likely_condition(struct ftrace_branch_data *f, int val, int expect)
Expand All @@ -236,66 +216,39 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect)
}
EXPORT_SYMBOL(ftrace_likely_update);

struct ftrace_pointer {
void *start;
void *stop;
int hit;
};
extern unsigned long __start_annotated_branch_profile[];
extern unsigned long __stop_annotated_branch_profile[];

static void *
t_next(struct seq_file *m, void *v, loff_t *pos)
static int annotated_branch_stat_headers(struct seq_file *m)
{
const struct ftrace_pointer *f = m->private;
struct ftrace_branch_data *p = v;

(*pos)++;

if (v == (void *)1)
return f->start;

++p;

if ((void *)p >= (void *)f->stop)
return NULL;

return p;
seq_printf(m, " correct incorrect %% ");
seq_printf(m, " Function "
" File Line\n"
" ------- --------- - "
" -------- "
" ---- ----\n");
return 0;
}

static void *t_start(struct seq_file *m, loff_t *pos)
static inline long get_incorrect_percent(struct ftrace_branch_data *p)
{
void *t = (void *)1;
loff_t l = 0;

for (; t && l < *pos; t = t_next(m, t, &l))
;
long percent;

return t;
}
if (p->correct) {
percent = p->incorrect * 100;
percent /= p->correct + p->incorrect;
} else
percent = p->incorrect ? 100 : -1;

static void t_stop(struct seq_file *m, void *p)
{
return percent;
}

static int t_show(struct seq_file *m, void *v)
static int branch_stat_show(struct seq_file *m, void *v)
{
const struct ftrace_pointer *fp = m->private;
struct ftrace_branch_data *p = v;
const char *f;
long percent;

if (v == (void *)1) {
if (fp->hit)
seq_printf(m, " miss hit %% ");
else
seq_printf(m, " correct incorrect %% ");
seq_printf(m, " Function "
" File Line\n"
" ------- --------- - "
" -------- "
" ---- ----\n");
return 0;
}

/* Only print the file, not the path */
f = p->file + strlen(p->file);
while (f >= p->file && *f != '/')
Expand All @@ -305,11 +258,7 @@ static int t_show(struct seq_file *m, void *v)
/*
* The miss is overlayed on correct, and hit on incorrect.
*/
if (p->correct) {
percent = p->incorrect * 100;
percent /= p->correct + p->incorrect;
} else
percent = p->incorrect ? 100 : -1;
percent = get_incorrect_percent(p);

seq_printf(m, "%8lu %8lu ", p->correct, p->incorrect);
if (percent < 0)
Expand All @@ -320,76 +269,143 @@ static int t_show(struct seq_file *m, void *v)
return 0;
}

static struct seq_operations tracing_likely_seq_ops = {
.start = t_start,
.next = t_next,
.stop = t_stop,
.show = t_show,
};
static void *annotated_branch_stat_start(void)
{
return __start_annotated_branch_profile;
}

static int tracing_branch_open(struct inode *inode, struct file *file)
static void *
annotated_branch_stat_next(void *v, int idx)
{
int ret;
struct ftrace_branch_data *p = v;

ret = seq_open(file, &tracing_likely_seq_ops);
if (!ret) {
struct seq_file *m = file->private_data;
m->private = (void *)inode->i_private;
}
++p;

return ret;
if ((void *)p >= (void *)__stop_annotated_branch_profile)
return NULL;

return p;
}

static const struct file_operations tracing_branch_fops = {
.open = tracing_branch_open,
.read = seq_read,
.llseek = seq_lseek,
};
static int annotated_branch_stat_cmp(void *p1, void *p2)
{
struct ftrace_branch_data *a = p1;
struct ftrace_branch_data *b = p2;

long percent_a, percent_b;

percent_a = get_incorrect_percent(a);
percent_b = get_incorrect_percent(b);

if (percent_a < percent_b)
return -1;
if (percent_a > percent_b)
return 1;
else
return 0;
}

#ifdef CONFIG_PROFILE_ALL_BRANCHES
extern unsigned long __start_branch_profile[];
extern unsigned long __stop_branch_profile[];
enum {
TRACE_BRANCH_OPT_ALL = 0x1
};

static const struct ftrace_pointer ftrace_branch_pos = {
.start = __start_branch_profile,
.stop = __stop_branch_profile,
.hit = 1,
static struct tracer_opt branch_opts[] = {
{ TRACER_OPT(stat_all_branch, TRACE_BRANCH_OPT_ALL) },
{ }
};

#endif /* CONFIG_PROFILE_ALL_BRANCHES */
static struct tracer_flags branch_flags = {
.val = 0,
.opts = branch_opts
};

extern unsigned long __start_annotated_branch_profile[];
extern unsigned long __stop_annotated_branch_profile[];
extern unsigned long __start_branch_profile[];
extern unsigned long __stop_branch_profile[];

static const struct ftrace_pointer ftrace_annotated_branch_pos = {
.start = __start_annotated_branch_profile,
.stop = __stop_annotated_branch_profile,
};
static int all_branch_stat_headers(struct seq_file *m)
{
seq_printf(m, " miss hit %% ");
seq_printf(m, " Function "
" File Line\n"
" ------- --------- - "
" -------- "
" ---- ----\n");
return 0;
}

static __init int ftrace_branch_init(void)
static void *all_branch_stat_start(void)
{
struct dentry *d_tracer;
struct dentry *entry;
return __start_branch_profile;
}

static void *
all_branch_stat_next(void *v, int idx)
{
struct ftrace_branch_data *p = v;

d_tracer = tracing_init_dentry();
++p;

entry = debugfs_create_file("profile_annotated_branch", 0444, d_tracer,
(void *)&ftrace_annotated_branch_pos,
&tracing_branch_fops);
if (!entry)
pr_warning("Could not create debugfs "
"'profile_annotatet_branch' entry\n");
if ((void *)p >= (void *)__stop_branch_profile)
return NULL;

#ifdef CONFIG_PROFILE_ALL_BRANCHES
entry = debugfs_create_file("profile_branch", 0444, d_tracer,
(void *)&ftrace_branch_pos,
&tracing_branch_fops);
if (!entry)
pr_warning("Could not create debugfs"
" 'profile_branch' entry\n");
#endif
return p;
}

static int branch_set_flag(u32 old_flags, u32 bit, int set)
{
if (bit == TRACE_BRANCH_OPT_ALL) {
if (set) {
branch_trace.stat_headers = all_branch_stat_headers;
branch_trace.stat_start = all_branch_stat_start;
branch_trace.stat_next = all_branch_stat_next;
branch_trace.stat_cmp = NULL;
} else {
branch_trace.stat_headers =
annotated_branch_stat_headers;
branch_trace.stat_start = annotated_branch_stat_start;
branch_trace.stat_next = annotated_branch_stat_next;
branch_trace.stat_cmp = annotated_branch_stat_cmp;
}
init_tracer_stat(&branch_trace);
}
return 0;
}

device_initcall(ftrace_branch_init);
#endif /* CONFIG_PROFILE_ALL_BRANCHES */

static struct tracer branch_trace __read_mostly =
{
.name = "branch",
#ifdef CONFIG_BRANCH_TRACER
.init = branch_trace_init,
.reset = branch_trace_reset,
#ifdef CONFIG_FTRACE_SELFTEST
.selftest = trace_selftest_startup_branch,
#endif /* CONFIG_FTRACE_SELFTEST */
#endif /* CONFIG_BRANCH_TRACER */
.stat_start = annotated_branch_stat_start,
.stat_next = annotated_branch_stat_next,
.stat_show = branch_stat_show,
.stat_headers = annotated_branch_stat_headers,
.stat_cmp = annotated_branch_stat_cmp,
#ifdef CONFIG_PROFILE_ALL_BRANCHES
.flags = &branch_flags,
.set_flag = branch_set_flag,
#endif
};

__init static int init_branch_trace(void)
{
#ifdef CONFIG_BRANCH_TRACER
int ret;
ret = register_ftrace_event(&trace_branch_event);
if (!ret) {
printk(KERN_WARNING "Warning: could not register branch events\n");
return 1;
}
#endif

return register_tracer(&branch_trace);
}
device_initcall(init_branch_trace);

0 comments on commit d70bb2c

Please sign in to comment.