Re: [PATCH -tip v3 03/11] [CLEANUP] perf-probe: Replace line_list with intlist

2014-02-16 Thread Namhyung Kim
On Thu, 06 Feb 2014 05:32:09 +, Masami Hiramatsu wrote:
> Replace line_list (struct line_node) with intlist for
> reducing similar codes.

Acked-by: Namhyung Kim 

Thanks,
Namhyung
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH -tip v3 03/11] [CLEANUP] perf-probe: Replace line_list with intlist

2014-02-16 Thread Namhyung Kim
On Thu, 06 Feb 2014 05:32:09 +, Masami Hiramatsu wrote:
 Replace line_list (struct line_node) with intlist for
 reducing similar codes.

Acked-by: Namhyung Kim namhy...@kernel.org

Thanks,
Namhyung
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH -tip v3 03/11] [CLEANUP] perf-probe: Replace line_list with intlist

2014-02-05 Thread Masami Hiramatsu
Replace line_list (struct line_node) with intlist for
reducing similar codes.

Signed-off-by: Masami Hiramatsu 
---
 tools/perf/builtin-probe.c |   12 +++---
 tools/perf/util/probe-event.c  |   22 +--
 tools/perf/util/probe-event.h  |   12 +-
 tools/perf/util/probe-finder.c |   81 ++--
 tools/perf/util/probe-finder.h |3 +
 5 files changed, 35 insertions(+), 95 deletions(-)

diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c
index 7894888..cdcd4eb 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,
return 0;
 }
 
-static void init_params(void)
+static int init_params(void)
 {
-   line_range__init(_range);
+   return line_range__init(_range);
 }
 
 static void cleanup_params(void)
@@ -515,9 +515,11 @@ int cmd_probe(int argc, const char **argv, const char 
*prefix)
 {
int ret;
 
-   init_params();
-   ret = __cmd_probe(argc, argv, prefix);
-   cleanup_params();
+   ret = init_params();
+   if (!ret) {
+   ret = __cmd_probe(argc, argv, prefix);
+   cleanup_params();
+   }
 
return ret;
 }
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index a4649e7..f70fd08 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)
 static int __show_line_range(struct line_range *lr, const char *module)
 {
int l = 1;
-   struct line_node *ln;
+   struct int_node *ln;
struct debuginfo *dinfo;
FILE *fp;
int ret;
@@ -614,8 +614,8 @@ static int __show_line_range(struct line_range *lr, const 
char *module)
goto end;
}
 
-   list_for_each_entry(ln, >line_list, list) {
-   for (; ln->line > l; l++) {
+   intlist__for_each(ln, lr->line_list) {
+   for (; ln->i > l; l++) {
ret = show_one_line(fp, l - lr->offset);
if (ret < 0)
goto end;
@@ -775,24 +775,22 @@ int show_available_vars(struct perf_probe_event *pevs 
__maybe_unused,
 
 void line_range__clear(struct line_range *lr)
 {
-   struct line_node *ln;
-
free(lr->function);
free(lr->file);
free(lr->path);
free(lr->comp_dir);
-   while (!list_empty(>line_list)) {
-   ln = list_first_entry(>line_list, struct line_node, list);
-   list_del(>list);
-   free(ln);
-   }
+   intlist__delete(lr->line_list);
memset(lr, 0, sizeof(*lr));
 }
 
-void line_range__init(struct line_range *lr)
+int line_range__init(struct line_range *lr)
 {
memset(lr, 0, sizeof(*lr));
-   INIT_LIST_HEAD(>line_list);
+   lr->line_list = intlist__new(NULL);
+   if (!lr->line_list)
+   return -ENOMEM;
+   else
+   return 0;
 }
 
 static 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 fcaf727..776c934 100644
--- a/tools/perf/util/probe-event.h
+++ b/tools/perf/util/probe-event.h
@@ -2,6 +2,7 @@
 #define _PROBE_EVENT_H
 
 #include 
+#include "intlist.h"
 #include "strlist.h"
 #include "strfilter.h"
 
@@ -76,13 +77,6 @@ struct perf_probe_event {
struct perf_probe_arg   *args;  /* Arguments */
 };
 
-
-/* Line number container */
-struct line_node {
-   struct list_headlist;
-   int line;
-};
-
 /* Line range */
 struct line_range {
char*file;  /* File name */
@@ -92,7 +86,7 @@ struct line_range {
int offset; /* Start line offset */
char*path;  /* Real path name */
char*comp_dir;  /* Compile directory */
-   struct list_headline_list;  /* Visible lines */
+   struct intlist  *line_list; /* Visible lines */
 };
 
 /* List of variables */
@@ -124,7 +118,7 @@ extern int parse_line_range_desc(const char *cmd, struct 
line_range *lr);
 extern void line_range__clear(struct line_range *lr);
 
 /* Initialize line range */
-extern void line_range__init(struct line_range *lr);
+extern int line_range__init(struct line_range *lr);
 
 /* Internal use: Return kernel/module path */
 extern 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 061edb1..e5e589f 100644
--- a/tools/perf/util/probe-finder.c
+++ b/tools/perf/util/probe-finder.c
@@ -35,6 +35,7 @@
 #include 
 #include "event.h"
 #include "debug.h"
+#include "intlist.h"
 #include "util.h"
 #include "symbol.h"
 #include "probe-finder.h"
@@ -42,65 +43,6 @@
 /* Kprobe tracer basic type 

[PATCH -tip v3 03/11] [CLEANUP] perf-probe: Replace line_list with intlist

2014-02-05 Thread Masami Hiramatsu
Replace line_list (struct line_node) with intlist for
reducing similar codes.

Signed-off-by: Masami Hiramatsu masami.hiramatsu...@hitachi.com
---
 tools/perf/builtin-probe.c |   12 +++---
 tools/perf/util/probe-event.c  |   22 +--
 tools/perf/util/probe-event.h  |   12 +-
 tools/perf/util/probe-finder.c |   81 ++--
 tools/perf/util/probe-finder.h |3 +
 5 files changed, 35 insertions(+), 95 deletions(-)

diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c
index 7894888..cdcd4eb 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,
return 0;
 }
 
-static void init_params(void)
+static int init_params(void)
 {
-   line_range__init(params.line_range);
+   return line_range__init(params.line_range);
 }
 
 static void cleanup_params(void)
@@ -515,9 +515,11 @@ int cmd_probe(int argc, const char **argv, const char 
*prefix)
 {
int ret;
 
-   init_params();
-   ret = __cmd_probe(argc, argv, prefix);
-   cleanup_params();
+   ret = init_params();
+   if (!ret) {
+   ret = __cmd_probe(argc, argv, prefix);
+   cleanup_params();
+   }
 
return ret;
 }
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index a4649e7..f70fd08 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)
 static int __show_line_range(struct line_range *lr, const char *module)
 {
int l = 1;
-   struct line_node *ln;
+   struct int_node *ln;
struct debuginfo *dinfo;
FILE *fp;
int ret;
@@ -614,8 +614,8 @@ static int __show_line_range(struct line_range *lr, const 
char *module)
goto end;
}
 
-   list_for_each_entry(ln, lr-line_list, list) {
-   for (; ln-line  l; l++) {
+   intlist__for_each(ln, lr-line_list) {
+   for (; ln-i  l; l++) {
ret = show_one_line(fp, l - lr-offset);
if (ret  0)
goto end;
@@ -775,24 +775,22 @@ int show_available_vars(struct perf_probe_event *pevs 
__maybe_unused,
 
 void line_range__clear(struct line_range *lr)
 {
-   struct line_node *ln;
-
free(lr-function);
free(lr-file);
free(lr-path);
free(lr-comp_dir);
-   while (!list_empty(lr-line_list)) {
-   ln = list_first_entry(lr-line_list, struct line_node, list);
-   list_del(ln-list);
-   free(ln);
-   }
+   intlist__delete(lr-line_list);
memset(lr, 0, sizeof(*lr));
 }
 
-void line_range__init(struct line_range *lr)
+int line_range__init(struct line_range *lr)
 {
memset(lr, 0, sizeof(*lr));
-   INIT_LIST_HEAD(lr-line_list);
+   lr-line_list = intlist__new(NULL);
+   if (!lr-line_list)
+   return -ENOMEM;
+   else
+   return 0;
 }
 
 static 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 fcaf727..776c934 100644
--- a/tools/perf/util/probe-event.h
+++ b/tools/perf/util/probe-event.h
@@ -2,6 +2,7 @@
 #define _PROBE_EVENT_H
 
 #include stdbool.h
+#include intlist.h
 #include strlist.h
 #include strfilter.h
 
@@ -76,13 +77,6 @@ struct perf_probe_event {
struct perf_probe_arg   *args;  /* Arguments */
 };
 
-
-/* Line number container */
-struct line_node {
-   struct list_headlist;
-   int line;
-};
-
 /* Line range */
 struct line_range {
char*file;  /* File name */
@@ -92,7 +86,7 @@ struct line_range {
int offset; /* Start line offset */
char*path;  /* Real path name */
char*comp_dir;  /* Compile directory */
-   struct list_headline_list;  /* Visible lines */
+   struct intlist  *line_list; /* Visible lines */
 };
 
 /* List of variables */
@@ -124,7 +118,7 @@ extern int parse_line_range_desc(const char *cmd, struct 
line_range *lr);
 extern void line_range__clear(struct line_range *lr);
 
 /* Initialize line range */
-extern void line_range__init(struct line_range *lr);
+extern int line_range__init(struct line_range *lr);
 
 /* Internal use: Return kernel/module path */
 extern 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 061edb1..e5e589f 100644
--- a/tools/perf/util/probe-finder.c
+++ b/tools/perf/util/probe-finder.c
@@ -35,6 +35,7 @@
 #include linux/bitops.h
 #include event.h
 #include debug.h
+#include intlist.h
 #include util.h
 #include symbol.h
 #include