aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorMasami Hiramatsu <masami.hiramatsu.pt@hitachi.com>2014-02-06 00:32:09 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2014-02-18 07:34:50 -0500
commit5a62257a3ddd1a09cf278eae0697fcbe20897447 (patch)
treea26fefd435c259900e454c7ffc56d2db11aa568a /tools
parentf49540b17c1c6fa5a0734cc1d8b57614fd2036be (diff)
perf probe: Replace line_list with intlist
Replace line_list (struct line_node) with intlist for reducing similar codes. Signed-off-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com> Acked-by: Namhyung Kim <namhyung@kernel.org> Cc: David Ahern <dsahern@gmail.com> Cc: "David A. Long" <dave.long@linaro.org> Cc: Ingo Molnar <mingo@redhat.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Oleg Nesterov <oleg@redhat.com> Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: yrl.pp-manager.tt@hitachi.com Link: http://lkml.kernel.org/r/20140206053209.29635.81043.stgit@kbuild-fedora.yrl.intra.hitachi.co.jp Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/perf/builtin-probe.c12
-rw-r--r--tools/perf/util/probe-event.c22
-rw-r--r--tools/perf/util/probe-event.h12
-rw-r--r--tools/perf/util/probe-finder.c81
-rw-r--r--tools/perf/util/probe-finder.h3
5 files changed, 35 insertions, 95 deletions
diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c
index 78948882e3de..cdcd4eb3a57d 100644
--- a/tools/perf/builtin-probe.c
+++ b/tools/perf/builtin-probe.c
@@ -268,9 +268,9 @@ static int opt_set_filter(const struct option *opt __maybe_unused,
268 return 0; 268 return 0;
269} 269}
270 270
271static void init_params(void) 271static int init_params(void)
272{ 272{
273 line_range__init(&params.line_range); 273 return line_range__init(&params.line_range);
274} 274}
275 275
276static void cleanup_params(void) 276static void cleanup_params(void)
@@ -515,9 +515,11 @@ int cmd_probe(int argc, const char **argv, const char *prefix)
515{ 515{
516 int ret; 516 int ret;
517 517
518 init_params(); 518 ret = init_params();
519 ret = __cmd_probe(argc, argv, prefix); 519 if (!ret) {
520 cleanup_params(); 520 ret = __cmd_probe(argc, argv, prefix);
521 cleanup_params();
522 }
521 523
522 return ret; 524 return ret;
523} 525}
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index a4649e7449c5..f70fd08f00b7 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -561,7 +561,7 @@ static int _show_one_line(FILE *fp, int l, bool skip, bool show_num)
561static int __show_line_range(struct line_range *lr, const char *module) 561static int __show_line_range(struct line_range *lr, const char *module)
562{ 562{
563 int l = 1; 563 int l = 1;
564 struct line_node *ln; 564 struct int_node *ln;
565 struct debuginfo *dinfo; 565 struct debuginfo *dinfo;
566 FILE *fp; 566 FILE *fp;
567 int ret; 567 int ret;
@@ -614,8 +614,8 @@ static int __show_line_range(struct line_range *lr, const char *module)
614 goto end; 614 goto end;
615 } 615 }
616 616
617 list_for_each_entry(ln, &lr->line_list, list) { 617 intlist__for_each(ln, lr->line_list) {
618 for (; ln->line > l; l++) { 618 for (; ln->i > l; l++) {
619 ret = show_one_line(fp, l - lr->offset); 619 ret = show_one_line(fp, l - lr->offset);
620 if (ret < 0) 620 if (ret < 0)
621 goto end; 621 goto end;
@@ -775,24 +775,22 @@ int show_available_vars(struct perf_probe_event *pevs __maybe_unused,
775 775
776void line_range__clear(struct line_range *lr) 776void line_range__clear(struct line_range *lr)
777{ 777{
778 struct line_node *ln;
779
780 free(lr->function); 778 free(lr->function);
781 free(lr->file); 779 free(lr->file);
782 free(lr->path); 780 free(lr->path);
783 free(lr->comp_dir); 781 free(lr->comp_dir);
784 while (!list_empty(&lr->line_list)) { 782 intlist__delete(lr->line_list);
785 ln = list_first_entry(&lr->line_list, struct line_node, list);
786 list_del(&ln->list);
787 free(ln);
788 }
789 memset(lr, 0, sizeof(*lr)); 783 memset(lr, 0, sizeof(*lr));
790} 784}
791 785
792void line_range__init(struct line_range *lr) 786int line_range__init(struct line_range *lr)
793{ 787{
794 memset(lr, 0, sizeof(*lr)); 788 memset(lr, 0, sizeof(*lr));
795 INIT_LIST_HEAD(&lr->line_list); 789 lr->line_list = intlist__new(NULL);
790 if (!lr->line_list)
791 return -ENOMEM;
792 else
793 return 0;
796} 794}
797 795
798static int parse_line_num(char **ptr, int *val, const char *what) 796static int parse_line_num(char **ptr, int *val, const char *what)
diff --git a/tools/perf/util/probe-event.h b/tools/perf/util/probe-event.h
index fcaf7273e85a..776c9347a3b6 100644
--- a/tools/perf/util/probe-event.h
+++ b/tools/perf/util/probe-event.h
@@ -2,6 +2,7 @@
2#define _PROBE_EVENT_H 2#define _PROBE_EVENT_H
3 3
4#include <stdbool.h> 4#include <stdbool.h>
5#include "intlist.h"
5#include "strlist.h" 6#include "strlist.h"
6#include "strfilter.h" 7#include "strfilter.h"
7 8
@@ -76,13 +77,6 @@ struct perf_probe_event {
76 struct perf_probe_arg *args; /* Arguments */ 77 struct perf_probe_arg *args; /* Arguments */
77}; 78};
78 79
79
80/* Line number container */
81struct line_node {
82 struct list_head list;
83 int line;
84};
85
86/* Line range */ 80/* Line range */
87struct line_range { 81struct line_range {
88 char *file; /* File name */ 82 char *file; /* File name */
@@ -92,7 +86,7 @@ struct line_range {
92 int offset; /* Start line offset */ 86 int offset; /* Start line offset */
93 char *path; /* Real path name */ 87 char *path; /* Real path name */
94 char *comp_dir; /* Compile directory */ 88 char *comp_dir; /* Compile directory */
95 struct list_head line_list; /* Visible lines */ 89 struct intlist *line_list; /* Visible lines */
96}; 90};
97 91
98/* List of variables */ 92/* List of variables */
@@ -124,7 +118,7 @@ extern int parse_line_range_desc(const char *cmd, struct line_range *lr);
124extern void line_range__clear(struct line_range *lr); 118extern void line_range__clear(struct line_range *lr);
125 119
126/* Initialize line range */ 120/* Initialize line range */
127extern void line_range__init(struct line_range *lr); 121extern int line_range__init(struct line_range *lr);
128 122
129/* Internal use: Return kernel/module path */ 123/* Internal use: Return kernel/module path */
130extern const char *kernel_get_module_path(const char *module); 124extern const char *kernel_get_module_path(const char *module);
diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
index 061edb162b5b..e5e589fdef9b 100644
--- a/tools/perf/util/probe-finder.c
+++ b/tools/perf/util/probe-finder.c
@@ -35,6 +35,7 @@
35#include <linux/bitops.h> 35#include <linux/bitops.h>
36#include "event.h" 36#include "event.h"
37#include "debug.h" 37#include "debug.h"
38#include "intlist.h"
38#include "util.h" 39#include "util.h"
39#include "symbol.h" 40#include "symbol.h"
40#include "probe-finder.h" 41#include "probe-finder.h"
@@ -42,65 +43,6 @@
42/* Kprobe tracer basic type is up to u64 */ 43/* Kprobe tracer basic type is up to u64 */
43#define MAX_BASIC_TYPE_BITS 64 44#define MAX_BASIC_TYPE_BITS 64
44 45
45/* Line number list operations */
46
47/* Add a line to line number list */
48static int line_list__add_line(struct list_head *head, int line)
49{
50 struct line_node *ln;
51 struct list_head *p;
52
53 /* Reverse search, because new line will be the last one */
54 list_for_each_entry_reverse(ln, head, list) {
55 if (ln->line < line) {
56 p = &ln->list;
57 goto found;
58 } else if (ln->line == line) /* Already exist */
59 return 1;
60 }
61 /* List is empty, or the smallest entry */
62 p = head;
63found:
64 pr_debug("line list: add a line %u\n", line);
65 ln = zalloc(sizeof(struct line_node));
66 if (ln == NULL)
67 return -ENOMEM;
68 ln->line = line;
69 INIT_LIST_HEAD(&ln->list);
70 list_add(&ln->list, p);
71 return 0;
72}
73
74/* Check if the line in line number list */
75static int line_list__has_line(struct list_head *head, int line)
76{
77 struct line_node *ln;
78
79 /* Reverse search, because new line will be the last one */
80 list_for_each_entry(ln, head, list)
81 if (ln->line == line)
82 return 1;
83
84 return 0;
85}
86
87/* Init line number list */
88static void line_list__init(struct list_head *head)
89{
90 INIT_LIST_HEAD(head);
91}
92
93/* Free line number list */
94static void line_list__free(struct list_head *head)
95{
96 struct line_node *ln;
97 while (!list_empty(head)) {
98 ln = list_first_entry(head, struct line_node, list);
99 list_del(&ln->list);
100 free(ln);
101 }
102}
103
104/* Dwarf FL wrappers */ 46/* Dwarf FL wrappers */
105static char *debuginfo_path; /* Currently dummy */ 47static char *debuginfo_path; /* Currently dummy */
106 48
@@ -880,7 +822,7 @@ static int find_probe_point_by_line(struct probe_finder *pf)
880} 822}
881 823
882/* Find lines which match lazy pattern */ 824/* Find lines which match lazy pattern */
883static int find_lazy_match_lines(struct list_head *head, 825static int find_lazy_match_lines(struct intlist *list,
884 const char *fname, const char *pat) 826 const char *fname, const char *pat)
885{ 827{
886 FILE *fp; 828 FILE *fp;
@@ -901,7 +843,7 @@ static int find_lazy_match_lines(struct list_head *head,
901 line[len - 1] = '\0'; 843 line[len - 1] = '\0';
902 844
903 if (strlazymatch(line, pat)) { 845 if (strlazymatch(line, pat)) {
904 line_list__add_line(head, linenum); 846 intlist__add(list, linenum);
905 count++; 847 count++;
906 } 848 }
907 linenum++; 849 linenum++;
@@ -924,7 +866,7 @@ static int probe_point_lazy_walker(const char *fname, int lineno,
924 Dwarf_Die *sc_die, die_mem; 866 Dwarf_Die *sc_die, die_mem;
925 int ret; 867 int ret;
926 868
927 if (!line_list__has_line(&pf->lcache, lineno) || 869 if (!intlist__has_entry(pf->lcache, lineno) ||
928 strtailcmp(fname, pf->fname) != 0) 870 strtailcmp(fname, pf->fname) != 0)
929 return 0; 871 return 0;
930 872
@@ -952,9 +894,9 @@ static int find_probe_point_lazy(Dwarf_Die *sp_die, struct probe_finder *pf)
952{ 894{
953 int ret = 0; 895 int ret = 0;
954 896
955 if (list_empty(&pf->lcache)) { 897 if (intlist__empty(pf->lcache)) {
956 /* Matching lazy line pattern */ 898 /* Matching lazy line pattern */
957 ret = find_lazy_match_lines(&pf->lcache, pf->fname, 899 ret = find_lazy_match_lines(pf->lcache, pf->fname,
958 pf->pev->point.lazy_line); 900 pf->pev->point.lazy_line);
959 if (ret <= 0) 901 if (ret <= 0)
960 return ret; 902 return ret;
@@ -1096,7 +1038,9 @@ static int debuginfo__find_probes(struct debuginfo *dbg,
1096#endif 1038#endif
1097 1039
1098 off = 0; 1040 off = 0;
1099 line_list__init(&pf->lcache); 1041 pf->lcache = intlist__new(NULL);
1042 if (!pf->lcache)
1043 return -ENOMEM;
1100 1044
1101 /* Fastpath: lookup by function name from .debug_pubnames section */ 1045 /* Fastpath: lookup by function name from .debug_pubnames section */
1102 if (pp->function) { 1046 if (pp->function) {
@@ -1149,7 +1093,8 @@ static int debuginfo__find_probes(struct debuginfo *dbg,
1149 } 1093 }
1150 1094
1151found: 1095found:
1152 line_list__free(&pf->lcache); 1096 intlist__delete(pf->lcache);
1097 pf->lcache = NULL;
1153 1098
1154 return ret; 1099 return ret;
1155} 1100}
@@ -1537,7 +1482,7 @@ static int line_range_add_line(const char *src, unsigned int lineno,
1537 if (lr->path == NULL) 1482 if (lr->path == NULL)
1538 return -ENOMEM; 1483 return -ENOMEM;
1539 } 1484 }
1540 return line_list__add_line(&lr->line_list, lineno); 1485 return intlist__add(lr->line_list, lineno);
1541} 1486}
1542 1487
1543static int line_range_walk_cb(const char *fname, int lineno, 1488static int line_range_walk_cb(const char *fname, int lineno,
@@ -1565,7 +1510,7 @@ static int find_line_range_by_line(Dwarf_Die *sp_die, struct line_finder *lf)
1565 1510
1566 /* Update status */ 1511 /* Update status */
1567 if (ret >= 0) 1512 if (ret >= 0)
1568 if (!list_empty(&lf->lr->line_list)) 1513 if (!intlist__empty(lf->lr->line_list))
1569 ret = lf->found = 1; 1514 ret = lf->found = 1;
1570 else 1515 else
1571 ret = 0; /* Lines are not found */ 1516 ret = 0; /* Lines are not found */
diff --git a/tools/perf/util/probe-finder.h b/tools/perf/util/probe-finder.h
index ffc33cdd25cc..592c4dac3be9 100644
--- a/tools/perf/util/probe-finder.h
+++ b/tools/perf/util/probe-finder.h
@@ -3,6 +3,7 @@
3 3
4#include <stdbool.h> 4#include <stdbool.h>
5#include "util.h" 5#include "util.h"
6#include "intlist.h"
6#include "probe-event.h" 7#include "probe-event.h"
7 8
8#define MAX_PROBE_BUFFER 1024 9#define MAX_PROBE_BUFFER 1024
@@ -66,7 +67,7 @@ struct probe_finder {
66 const char *fname; /* Real file name */ 67 const char *fname; /* Real file name */
67 Dwarf_Die cu_die; /* Current CU */ 68 Dwarf_Die cu_die; /* Current CU */
68 Dwarf_Die sp_die; 69 Dwarf_Die sp_die;
69 struct list_head lcache; /* Line cache for lazy match */ 70 struct intlist *lcache; /* Line cache for lazy match */
70 71
71 /* For variable searching */ 72 /* For variable searching */
72#if _ELFUTILS_PREREQ(0, 142) 73#if _ELFUTILS_PREREQ(0, 142)