perf report: Fix kernel symbol resolution
Commit-ID: 59d81029b6804c3d5895d07cad77d7dfddc6b5b2 Gitweb: http://git.kernel.org/tip/59d81029b6804c3d5895d07cad77d7dfddc6b5b2 Author: Arnaldo Carvalho de Melo <[email protected]> AuthorDate: Tue, 26 May 2009 11:14:27 -0300 Committer: Ingo Molnar <[email protected]> CommitDate: Tue, 26 May 2009 16:19:05 +0200
perf report: Fix kernel symbol resolution
kallsyms have just the symbol start, so we need to read two lines to get the len.
[ Impact: fix incorrect kernel symbol display in perf report ]
LKML-Reference: <new-submission>
--- Documentation/perf_counter/builtin-report.c | 30 ++++++++++++++++++++------ 1 files changed, 23 insertions(+), 7 deletions(-)
Documentation/perf_counter/builtin-report.c +21 -5
@@ -360,9 +360,17 @@ static int load_kallsyms(void)char *line =NULL ;size_t n; +if (getline (&line, &n, file) <0 || !line) + goto out_delete_dso; + +unsigned long long previous_start; +char c, previous_symbf[4096 ]; +if (sscanf (line,"%llx %c %s" , &previous_start, &c, previous_symbf) !=3 ) + goto out_delete_line; +while (!feof (file)) {unsigned long long start; -char c, symbf[4096 ]; +char symbf[4096 ];if (getline (&line, &n, file) <0 )break ;
@@ -371,12 +379,18 @@ static int load_kallsyms(void) goto out_delete_dso;if (sscanf (line,"%llx %c %s" , &start, &c, symbf) ==3 ) { -struct symbol *sym =symbol__new (start,0x1000000 , symbf); +if (start > previous_start) { +struct symbol *sym =symbol__new (previous_start, + start - previous_start, + previous_symbf); -if (sym ==NULL ) - goto out_delete_dso; +if (sym ==NULL ) + goto out_delete_dso; -dso__insert_symbol (kernel_dso, sym); +dso__insert_symbol (kernel_dso, sym); + previous_start = start; +strcpy (previous_symbf, symbf); + } } }
@@ -385,6 +399,8 @@ static int load_kallsyms(void)fclose (file);return 0 ; +out_delete_line: +free (line); out_delete_dso:dso__delete (kernel_dso);return -1 ;
PATCH 1/1 perf: Don't assume /proc/kallsyms is ordered
Please fix the previous fix with this:
commit 64d254523be740b224533e0e4982cda7f25c0348
Author: Arnaldo Carvalho de Melo <[email protected]> Date: Tue May 26 12:08:10 2009 -0300
perf: Don't assume /proc/kallsyms is ordered
Since we _are_ ordering it by the symbol start, just traverse the freshly built rbtree setting the prev->end members to curr->start - 1.
Documentation/perf_counter/builtin-report.c +25 -19
@@ -360,17 +360,9 @@ static int load_kallsyms(void)char *line =NULL ;size_t n; -if (getline (&line, &n, file) <0 || !line) - goto out_delete_dso; - -unsigned long long previous_start; -char c, previous_symbf[4096 ]; -if (sscanf (line,"%llx %c %s" , &previous_start, &c, previous_symbf) !=3 ) - goto out_delete_line; -while (!feof (file)) {unsigned long long start; -char symbf[4096 ]; +char c, symbf[4096 ];if (getline (&line, &n, file) <0 )break ;
@@ -379,21 +371,35 @@ static int load_kallsyms(void) goto out_delete_dso;if (sscanf (line,"%llx %c %s" , &start, &c, symbf) ==3 ) { -if (start > previous_start) { -struct symbol *sym =symbol__new (previous_start, - start - previous_start, - previous_symbf); +/* +* Well fix up the end later, when we have all sorted. +*/ +struct symbol *sym =symbol__new (start,0xdead , symbf); -if (sym ==NULL ) - goto out_delete_dso; +if (sym ==NULL ) + goto out_delete_dso; -dso__insert_symbol (kernel_dso, sym); - previous_start = start; -strcpy (previous_symbf, symbf); - } +dso__insert_symbol (kernel_dso, sym); } } +/* +* Now that we have all sorted out, just set the ->end of all +* symbols +*/ +struct rb_node *nd, *prevnd =rb_first (&kernel_dso->syms); + +if (prevnd ==NULL ) + goto out_delete_line; + +for (nd =rb_next (prevnd); nd; nd =rb_next (nd)) { + struct symbol *prev = rb_entry(prevnd, struct symbol, rb_node), + *curr = rb_entry(nd, struct symbol, rb_node); + + prev->end = curr->start -1 ; + prevnd = nd; + } +dsos__add (kernel_dso);free (line);fclose (file);
[tip:perfcounters/core] perf: Don't assume /proc/kallsyms is ordered
Commit-ID: abd54f68629fa73ed4fa040d433196211a9bbed2 Gitweb: http://git.kernel.org/tip/abd54f68629fa73ed4fa040d433196211a9bbed2 Author: Arnaldo Carvalho de Melo <[email protected]> AuthorDate: Tue, 26 May 2009 12:21:34 -0300 Committer: Ingo Molnar <[email protected]> CommitDate: Tue, 26 May 2009 17:36:13 +0200
perf: Don't assume /proc/kallsyms is ordered
perf: Don't assume /proc/kallsyms is ordered
Since we _are_ ordering it by the symbol start, just traverse the freshly built rbtree setting the prev->end members to curr->start - 1.
LKML-Reference: <[email protected]>
--- Documentation/perf_counter/builtin-report.c | 48 +++++++++++++++------------ 1 files changed, 27 insertions(+), 21 deletions(-)
Documentation/perf_counter/builtin-report.c +25 -19
@@ -360,17 +360,9 @@ static int load_kallsyms(void)char *line =NULL ;size_t n; -if (getline (&line, &n, file) <0 || !line) - goto out_delete_dso; - -unsigned long long previous_start; -char c, previous_symbf[4096 ]; -if (sscanf (line,"%llx %c %s" , &previous_start, &c, previous_symbf) !=3 ) - goto out_delete_line; -while (!feof (file)) {unsigned long long start; -char symbf[4096 ]; +char c, symbf[4096 ];if (getline (&line, &n, file) <0 )break ;
@@ -379,21 +371,35 @@ static int load_kallsyms(void) goto out_delete_dso;if (sscanf (line,"%llx %c %s" , &start, &c, symbf) ==3 ) { -if (start > previous_start) { -struct symbol *sym =symbol__new (previous_start, - start - previous_start, - previous_symbf); +/* +* Well fix up the end later, when we have all sorted. +*/ +struct symbol *sym =symbol__new (start,0xdead , symbf); -if (sym ==NULL ) - goto out_delete_dso; +if (sym ==NULL ) + goto out_delete_dso; -dso__insert_symbol (kernel_dso, sym); - previous_start = start; -strcpy (previous_symbf, symbf); - } +dso__insert_symbol (kernel_dso, sym); } } +/* +* Now that we have all sorted out, just set the ->end of all +* symbols +*/ +struct rb_node *nd, *prevnd =rb_first (&kernel_dso->syms); + +if (prevnd ==NULL ) + goto out_delete_line; + +for (nd =rb_next (prevnd); nd; nd =rb_next (nd)) { + struct symbol *prev = rb_entry(prevnd, struct symbol, rb_node), + *curr = rb_entry(nd, struct symbol, rb_node); + + prev->end = curr->start -1 ; + prevnd = nd; + } +dsos__add (kernel_dso);free (line);fclose (file);
Re: [PATCH 1/1 tip] perf: Don't assume /proc/kallsyms is ordered
In reply to Arnaldo Carvalho de MeloQuoted 1 line · Arnaldo Carvalho de Melo
Please fix the previous fix with this:
You don't need a second walk through the RB-tree like that, simply change the lookup function:
The below finds the first entry that has ->start > ip, we then walk backwards until we find an entry that has start <= ip < end and end > ip (should never be more than 1).
This way you can deal with holes (like userspace has), and deal with entries without size (like kallsyms) by setting size to a random large value.
---
Documentation/perf_counter/builtin-report.c +12 -3
@@ -147,16 +147,25 @@ static struct symbol *dso__find_symbol(sreturn NULL ;struct rb_node *n = self->syms.rb_node; +struct rb_node *last =NULL ; +struct symbol *s;while (n) { - struct symbol *s = rb_entry(n, struct symbol, rb_node); + last = n; + s = rb_entry(n, struct symbol, rb_node);if (ip < s->start) n = n->rb_left; -else if (ip > s->end) - n = n->rb_right;else + n = n->rb_right; + } + +while (last) { + s = rb_entry(last, struct symbol, rb_node); +if (s->start <= ip && ip < s->end)return s; + + last =rb_prev (last); }return NULL ;