diff options
author | Adrian Hunter <adrian.hunter@intel.com> | 2013-10-08 04:45:48 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2013-10-11 11:17:57 -0400 |
commit | 316d70d6dbde540b275289563cbddd9f0c903fc6 (patch) | |
tree | fdd1330b99d40d3a418ffa6e680fdd13660a6eec /tools | |
parent | 2969b12993ca7a8b9692048431e075a67815002d (diff) |
perf symbols: Make a separate function to parse /proc/modules
Make a separate function to parse /proc/modules so that it can be
reused.
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/1381221956-16699-2-git-send-email-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/perf/util/machine.c | 67 | ||||
-rw-r--r-- | tools/perf/util/symbol.c | 58 | ||||
-rw-r--r-- | tools/perf/util/symbol.h | 3 |
3 files changed, 79 insertions, 49 deletions
diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c index 901397ae82be..6b861aefd99a 100644 --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c | |||
@@ -793,12 +793,22 @@ static int machine__set_modules_path(struct machine *machine) | |||
793 | return map_groups__set_modules_path_dir(&machine->kmaps, modules_path); | 793 | return map_groups__set_modules_path_dir(&machine->kmaps, modules_path); |
794 | } | 794 | } |
795 | 795 | ||
796 | static int machine__create_modules(struct machine *machine) | 796 | static int machine__create_module(void *arg, const char *name, u64 start) |
797 | { | 797 | { |
798 | char *line = NULL; | 798 | struct machine *machine = arg; |
799 | size_t n; | ||
800 | FILE *file; | ||
801 | struct map *map; | 799 | struct map *map; |
800 | |||
801 | map = machine__new_module(machine, start, name); | ||
802 | if (map == NULL) | ||
803 | return -1; | ||
804 | |||
805 | dso__kernel_module_get_build_id(map->dso, machine->root_dir); | ||
806 | |||
807 | return 0; | ||
808 | } | ||
809 | |||
810 | static int machine__create_modules(struct machine *machine) | ||
811 | { | ||
802 | const char *modules; | 812 | const char *modules; |
803 | char path[PATH_MAX]; | 813 | char path[PATH_MAX]; |
804 | 814 | ||
@@ -812,56 +822,15 @@ static int machine__create_modules(struct machine *machine) | |||
812 | if (symbol__restricted_filename(modules, "/proc/modules")) | 822 | if (symbol__restricted_filename(modules, "/proc/modules")) |
813 | return -1; | 823 | return -1; |
814 | 824 | ||
815 | file = fopen(modules, "r"); | 825 | if (modules__parse(modules, machine, machine__create_module)) |
816 | if (file == NULL) | ||
817 | return -1; | 826 | return -1; |
818 | 827 | ||
819 | while (!feof(file)) { | 828 | if (!machine__set_modules_path(machine)) |
820 | char name[PATH_MAX]; | 829 | return 0; |
821 | u64 start; | ||
822 | char *sep; | ||
823 | int line_len; | ||
824 | |||
825 | line_len = getline(&line, &n, file); | ||
826 | if (line_len < 0) | ||
827 | break; | ||
828 | |||
829 | if (!line) | ||
830 | goto out_failure; | ||
831 | |||
832 | line[--line_len] = '\0'; /* \n */ | ||
833 | |||
834 | sep = strrchr(line, 'x'); | ||
835 | if (sep == NULL) | ||
836 | continue; | ||
837 | |||
838 | hex2u64(sep + 1, &start); | ||
839 | |||
840 | sep = strchr(line, ' '); | ||
841 | if (sep == NULL) | ||
842 | continue; | ||
843 | |||
844 | *sep = '\0'; | ||
845 | |||
846 | snprintf(name, sizeof(name), "[%s]", line); | ||
847 | map = machine__new_module(machine, start, name); | ||
848 | if (map == NULL) | ||
849 | goto out_delete_line; | ||
850 | dso__kernel_module_get_build_id(map->dso, machine->root_dir); | ||
851 | } | ||
852 | 830 | ||
853 | free(line); | 831 | pr_debug("Problems setting modules path maps, continuing anyway...\n"); |
854 | fclose(file); | ||
855 | 832 | ||
856 | if (machine__set_modules_path(machine) < 0) { | ||
857 | pr_debug("Problems setting modules path maps, continuing anyway...\n"); | ||
858 | } | ||
859 | return 0; | 833 | return 0; |
860 | |||
861 | out_delete_line: | ||
862 | free(line); | ||
863 | out_failure: | ||
864 | return -1; | ||
865 | } | 834 | } |
866 | 835 | ||
867 | int machine__create_kernel_maps(struct machine *machine) | 836 | int machine__create_kernel_maps(struct machine *machine) |
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c index 48c38791d61b..5fd95135e838 100644 --- a/tools/perf/util/symbol.c +++ b/tools/perf/util/symbol.c | |||
@@ -500,6 +500,64 @@ out_failure: | |||
500 | return -1; | 500 | return -1; |
501 | } | 501 | } |
502 | 502 | ||
503 | int modules__parse(const char *filename, void *arg, | ||
504 | int (*process_module)(void *arg, const char *name, | ||
505 | u64 start)) | ||
506 | { | ||
507 | char *line = NULL; | ||
508 | size_t n; | ||
509 | FILE *file; | ||
510 | int err = 0; | ||
511 | |||
512 | file = fopen(filename, "r"); | ||
513 | if (file == NULL) | ||
514 | return -1; | ||
515 | |||
516 | while (1) { | ||
517 | char name[PATH_MAX]; | ||
518 | u64 start; | ||
519 | char *sep; | ||
520 | ssize_t line_len; | ||
521 | |||
522 | line_len = getline(&line, &n, file); | ||
523 | if (line_len < 0) { | ||
524 | if (feof(file)) | ||
525 | break; | ||
526 | err = -1; | ||
527 | goto out; | ||
528 | } | ||
529 | |||
530 | if (!line) { | ||
531 | err = -1; | ||
532 | goto out; | ||
533 | } | ||
534 | |||
535 | line[--line_len] = '\0'; /* \n */ | ||
536 | |||
537 | sep = strrchr(line, 'x'); | ||
538 | if (sep == NULL) | ||
539 | continue; | ||
540 | |||
541 | hex2u64(sep + 1, &start); | ||
542 | |||
543 | sep = strchr(line, ' '); | ||
544 | if (sep == NULL) | ||
545 | continue; | ||
546 | |||
547 | *sep = '\0'; | ||
548 | |||
549 | scnprintf(name, sizeof(name), "[%s]", line); | ||
550 | |||
551 | err = process_module(arg, name, start); | ||
552 | if (err) | ||
553 | break; | ||
554 | } | ||
555 | out: | ||
556 | free(line); | ||
557 | fclose(file); | ||
558 | return err; | ||
559 | } | ||
560 | |||
503 | struct process_kallsyms_args { | 561 | struct process_kallsyms_args { |
504 | struct map *map; | 562 | struct map *map; |
505 | struct dso *dso; | 563 | struct dso *dso; |
diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h index 9b8b213a62c1..2d3eb43ab9f9 100644 --- a/tools/perf/util/symbol.h +++ b/tools/perf/util/symbol.h | |||
@@ -223,6 +223,9 @@ int sysfs__read_build_id(const char *filename, void *bf, size_t size); | |||
223 | int kallsyms__parse(const char *filename, void *arg, | 223 | int kallsyms__parse(const char *filename, void *arg, |
224 | int (*process_symbol)(void *arg, const char *name, | 224 | int (*process_symbol)(void *arg, const char *name, |
225 | char type, u64 start)); | 225 | char type, u64 start)); |
226 | int modules__parse(const char *filename, void *arg, | ||
227 | int (*process_module)(void *arg, const char *name, | ||
228 | u64 start)); | ||
226 | int filename__read_debuglink(const char *filename, char *debuglink, | 229 | int filename__read_debuglink(const char *filename, char *debuglink, |
227 | size_t size); | 230 | size_t size); |
228 | 231 | ||