aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/util.c
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2010-01-14 15:30:06 -0500
committerIngo Molnar <mingo@elte.hu>2010-01-16 04:58:47 -0500
commit9e201442de7c954f03710ac76f28c1927d07550c (patch)
tree7682ebe87ca85468e0ecd28b277013e9359605c0 /tools/perf/util/util.c
parent8d0591f6ad9edf66697ce29de176fb6f3213b9e3 (diff)
perf symbols: Cache /proc/kallsyms files by build-id
So that when we don't have a vmlinux handy we can store the kallsyms for later use by 'perf report'. Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Frédéric Weisbecker <fweisbec@gmail.com> Cc: Mike Galbraith <efault@gmx.de> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Paul Mackerras <paulus@samba.org> LKML-Reference: <1263501006-14185-3-git-send-email-acme@infradead.org> Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'tools/perf/util/util.c')
-rw-r--r--tools/perf/util/util.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c
index f3c0798a5e78..f0685849b244 100644
--- a/tools/perf/util/util.c
+++ b/tools/perf/util/util.c
@@ -32,6 +32,33 @@ int mkdir_p(char *path, mode_t mode)
32 return (stat(path, &st) && mkdir(path, mode)) ? -1 : 0; 32 return (stat(path, &st) && mkdir(path, mode)) ? -1 : 0;
33} 33}
34 34
35static int slow_copyfile(const char *from, const char *to)
36{
37 int err = 0;
38 char *line = NULL;
39 size_t n;
40 FILE *from_fp = fopen(from, "r"), *to_fp;
41
42 if (from_fp == NULL)
43 goto out;
44
45 to_fp = fopen(to, "w");
46 if (to_fp == NULL)
47 goto out_fclose_from;
48
49 while (getline(&line, &n, from_fp) > 0)
50 if (fputs(line, to_fp) == EOF)
51 goto out_fclose_to;
52 err = 0;
53out_fclose_to:
54 fclose(to_fp);
55 free(line);
56out_fclose_from:
57 fclose(from_fp);
58out:
59 return err;
60}
61
35int copyfile(const char *from, const char *to) 62int copyfile(const char *from, const char *to)
36{ 63{
37 int fromfd, tofd; 64 int fromfd, tofd;
@@ -42,6 +69,9 @@ int copyfile(const char *from, const char *to)
42 if (stat(from, &st)) 69 if (stat(from, &st))
43 goto out; 70 goto out;
44 71
72 if (st.st_size == 0) /* /proc? do it slowly... */
73 return slow_copyfile(from, to);
74
45 fromfd = open(from, O_RDONLY); 75 fromfd = open(from, O_RDONLY);
46 if (fromfd < 0) 76 if (fromfd < 0)
47 goto out; 77 goto out;