diff options
author | Jiri Olsa <jolsa@kernel.org> | 2018-08-17 05:48:10 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2018-08-20 07:54:59 -0400 |
commit | 8b42b7e5e8b5692bc5e57342bf00c40d64978407 (patch) | |
tree | 92cf5327174b5136e4ab83f080f4c3cad98c87cc | |
parent | c9a8a6131fb68f6eabec34fd855e69b4855155e4 (diff) |
perf tools: Add is_compressed callback to compressions array
Add is_compressed callback to the compressions array, that returns 0 if
the file is compressed or != 0 if not.
The new callback is used to recognize the situation when we have a
'compressed' object, like:
/lib/modules/.../drivers/net/ethernet/intel/igb/igb.ko.xz
but we need to read its debug data from debuginfo files, which might not
be compressed, like:
/root/.debug/.build-id/d6/...c4b301f/debug
So even for a 'compressed' object we read debug data from a plain
uncompressed object. To keep this transparent, we detect this in
decompress_kmodule() and return the file descriptor to the uncompressed
file.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Michael Petlan <mpetlan@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20180817094813.15086-11-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r-- | tools/perf/util/compress.h | 2 | ||||
-rw-r--r-- | tools/perf/util/dso.c | 23 | ||||
-rw-r--r-- | tools/perf/util/lzma.c | 5 | ||||
-rw-r--r-- | tools/perf/util/zlib.c | 6 |
4 files changed, 33 insertions, 3 deletions
diff --git a/tools/perf/util/compress.h b/tools/perf/util/compress.h index ecca688a25fb..892e92e7e7fc 100644 --- a/tools/perf/util/compress.h +++ b/tools/perf/util/compress.h | |||
@@ -4,10 +4,12 @@ | |||
4 | 4 | ||
5 | #ifdef HAVE_ZLIB_SUPPORT | 5 | #ifdef HAVE_ZLIB_SUPPORT |
6 | int gzip_decompress_to_file(const char *input, int output_fd); | 6 | int gzip_decompress_to_file(const char *input, int output_fd); |
7 | bool gzip_is_compressed(const char *input); | ||
7 | #endif | 8 | #endif |
8 | 9 | ||
9 | #ifdef HAVE_LZMA_SUPPORT | 10 | #ifdef HAVE_LZMA_SUPPORT |
10 | int lzma_decompress_to_file(const char *input, int output_fd); | 11 | int lzma_decompress_to_file(const char *input, int output_fd); |
12 | bool lzma_is_compressed(const char *input); | ||
11 | #endif | 13 | #endif |
12 | 14 | ||
13 | #endif /* PERF_COMPRESS_H */ | 15 | #endif /* PERF_COMPRESS_H */ |
diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c index cbeecf683333..8b9243f13b88 100644 --- a/tools/perf/util/dso.c +++ b/tools/perf/util/dso.c | |||
@@ -196,15 +196,16 @@ enum { | |||
196 | static const struct { | 196 | static const struct { |
197 | const char *fmt; | 197 | const char *fmt; |
198 | int (*decompress)(const char *input, int output); | 198 | int (*decompress)(const char *input, int output); |
199 | bool (*is_compressed)(const char *input); | ||
199 | } compressions[] = { | 200 | } compressions[] = { |
200 | [COMP_ID__NONE] = { .fmt = NULL, }, | 201 | [COMP_ID__NONE] = { .fmt = NULL, }, |
201 | #ifdef HAVE_ZLIB_SUPPORT | 202 | #ifdef HAVE_ZLIB_SUPPORT |
202 | { "gz", gzip_decompress_to_file }, | 203 | { "gz", gzip_decompress_to_file, gzip_is_compressed }, |
203 | #endif | 204 | #endif |
204 | #ifdef HAVE_LZMA_SUPPORT | 205 | #ifdef HAVE_LZMA_SUPPORT |
205 | { "xz", lzma_decompress_to_file }, | 206 | { "xz", lzma_decompress_to_file, lzma_is_compressed }, |
206 | #endif | 207 | #endif |
207 | { NULL, NULL }, | 208 | { NULL, NULL, NULL }, |
208 | }; | 209 | }; |
209 | 210 | ||
210 | static int is_supported_compression(const char *ext) | 211 | static int is_supported_compression(const char *ext) |
@@ -262,6 +263,22 @@ static int decompress_kmodule(struct dso *dso, const char *name, | |||
262 | if (dso->comp == COMP_ID__NONE) | 263 | if (dso->comp == COMP_ID__NONE) |
263 | return -1; | 264 | return -1; |
264 | 265 | ||
266 | /* | ||
267 | * We have proper compression id for DSO and yet the file | ||
268 | * behind the 'name' can still be plain uncompressed object. | ||
269 | * | ||
270 | * The reason is behind the logic we open the DSO object files, | ||
271 | * when we try all possible 'debug' objects until we find the | ||
272 | * data. So even if the DSO is represented by 'krava.xz' module, | ||
273 | * we can end up here opening ~/.debug/....23432432/debug' file | ||
274 | * which is not compressed. | ||
275 | * | ||
276 | * To keep this transparent, we detect this and return the file | ||
277 | * descriptor to the uncompressed file. | ||
278 | */ | ||
279 | if (!compressions[dso->comp].is_compressed(name)) | ||
280 | return open(name, O_RDONLY); | ||
281 | |||
265 | fd = mkstemp(tmpbuf); | 282 | fd = mkstemp(tmpbuf); |
266 | if (fd < 0) { | 283 | if (fd < 0) { |
267 | dso->load_errno = errno; | 284 | dso->load_errno = errno; |
diff --git a/tools/perf/util/lzma.c b/tools/perf/util/lzma.c index 07498eaddc08..7032caaf75eb 100644 --- a/tools/perf/util/lzma.c +++ b/tools/perf/util/lzma.c | |||
@@ -99,3 +99,8 @@ err_fclose: | |||
99 | fclose(infile); | 99 | fclose(infile); |
100 | return err; | 100 | return err; |
101 | } | 101 | } |
102 | |||
103 | bool lzma_is_compressed(const char *input __maybe_unused) | ||
104 | { | ||
105 | return true; | ||
106 | } | ||
diff --git a/tools/perf/util/zlib.c b/tools/perf/util/zlib.c index a725b958cf31..e68317214679 100644 --- a/tools/perf/util/zlib.c +++ b/tools/perf/util/zlib.c | |||
@@ -5,6 +5,7 @@ | |||
5 | #include <sys/stat.h> | 5 | #include <sys/stat.h> |
6 | #include <sys/mman.h> | 6 | #include <sys/mman.h> |
7 | #include <zlib.h> | 7 | #include <zlib.h> |
8 | #include <linux/compiler.h> | ||
8 | 9 | ||
9 | #include "util/compress.h" | 10 | #include "util/compress.h" |
10 | #include "util/util.h" | 11 | #include "util/util.h" |
@@ -79,3 +80,8 @@ out_close: | |||
79 | 80 | ||
80 | return ret == Z_STREAM_END ? 0 : -1; | 81 | return ret == Z_STREAM_END ? 0 : -1; |
81 | } | 82 | } |
83 | |||
84 | bool gzip_is_compressed(const char *input __maybe_unused) | ||
85 | { | ||
86 | return true; | ||
87 | } | ||