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/perf/util/symbol.c | |
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/perf/util/symbol.c')
-rw-r--r-- | tools/perf/util/symbol.c | 58 |
1 files changed, 58 insertions, 0 deletions
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; |