Skip to content

Commit 4b838b0

Browse files
olsajiriacmel
authored andcommitted
perf tools: Add compression id into 'struct kmod_path'
Store a decompression ID in 'struct kmod_path', so it can be later stored in 'struct dso'. Switch 'struct kmod_path's 'comp' from 'bool' to 'int' to return the compressions array index. Add 0 index item into compressions array, so that the comp usage stays as it was: 0 - no compression, != 0 compression index. Update the kmod_path tests. Committer notes: Use a designated initializer + terminating comma, e.g. { .fmt = NULL, }, to fix the build in several distros: centos:6: util/dso.c:201: error: missing initializer centos:6: util/dso.c:201: error: (near initialization for 'compressions[0].decompress') debian:9: util/dso.c:201:24: error: missing field 'decompress' initializer [-Werror,-Wmissing-field-initializers] fedora:25: util/dso.c:201:24: error: missing field 'decompress' initializer [-Werror,-Wmissing-field-initializers] fedora:26: util/dso.c:201:24: error: missing field 'decompress' initializer [-Werror,-Wmissing-field-initializers] fedora:27: util/dso.c:201:24: error: missing field 'decompress' initializer [-Werror,-Wmissing-field-initializers] oraclelinux:6: util/dso.c:201: error: missing initializer oraclelinux:6: util/dso.c:201: error: (near initialization for 'compressions[0].decompress') ubuntu:12.04.5: util/dso.c:201:2: error: missing initializer [-Werror=missing-field-initializers] ubuntu:12.04.5: util/dso.c:201:2: error: (near initialization for 'compressions[0].decompress') [-Werror=missing-field-initializers] ubuntu:16.04: util/dso.c:201:24: error: missing field 'decompress' initializer [-Werror,-Wmissing-field-initializers] ubuntu:16.10: util/dso.c:201:24: error: missing field 'decompress' initializer [-Werror,-Wmissing-field-initializers] ubuntu:16.10: util/dso.c:201:24: error: missing field 'decompress' initializer [-Werror,-Wmissing-field-initializers] ubuntu:17.10: util/dso.c:201:24: error: missing field 'decompress' initializer [-Werror,-Wmissing-field-initializers] 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-7-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent e1e1394 commit 4b838b0

3 files changed

Lines changed: 33 additions & 29 deletions

File tree

‎tools/perf/tests/kmod-path.c‎

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include "debug.h"
77

88
static int test(const char *path, bool alloc_name, bool alloc_ext,
9-
bool kmod, bool comp, const char *name, const char *ext)
9+
bool kmod, int comp, const char *name, const char *ext)
1010
{
1111
struct kmod_path m;
1212

@@ -54,47 +54,47 @@ static int test_is_kernel_module(const char *path, int cpumode, bool expect)
5454
int test__kmod_path__parse(struct test *t __maybe_unused, int subtest __maybe_unused)
5555
{
5656
/* path alloc_name alloc_ext kmod comp name ext */
57-
T("/xxxx/xxxx/x-x.ko", true , true , true, false, "[x_x]", NULL);
58-
T("/xxxx/xxxx/x-x.ko", false , true , true, false, NULL , NULL);
59-
T("/xxxx/xxxx/x-x.ko", true , false , true, false, "[x_x]", NULL);
60-
T("/xxxx/xxxx/x-x.ko", false , false , true, false, NULL , NULL);
57+
T("/xxxx/xxxx/x-x.ko", true , true , true, 0 , "[x_x]", NULL);
58+
T("/xxxx/xxxx/x-x.ko", false , true , true, 0 , NULL , NULL);
59+
T("/xxxx/xxxx/x-x.ko", true , false , true, 0 , "[x_x]", NULL);
60+
T("/xxxx/xxxx/x-x.ko", false , false , true, 0 , NULL , NULL);
6161
M("/xxxx/xxxx/x-x.ko", PERF_RECORD_MISC_CPUMODE_UNKNOWN, true);
6262
M("/xxxx/xxxx/x-x.ko", PERF_RECORD_MISC_KERNEL, true);
6363
M("/xxxx/xxxx/x-x.ko", PERF_RECORD_MISC_USER, false);
6464

6565
#ifdef HAVE_ZLIB_SUPPORT
6666
/* path alloc_name alloc_ext kmod comp name ext */
67-
T("/xxxx/xxxx/x.ko.gz", true , true , true, true, "[x]", "gz");
68-
T("/xxxx/xxxx/x.ko.gz", false , true , true, true, NULL , "gz");
69-
T("/xxxx/xxxx/x.ko.gz", true , false , true, true, "[x]", NULL);
70-
T("/xxxx/xxxx/x.ko.gz", false , false , true, true, NULL , NULL);
67+
T("/xxxx/xxxx/x.ko.gz", true , true , true, 1 , "[x]", "gz");
68+
T("/xxxx/xxxx/x.ko.gz", false , true , true, 1 , NULL , "gz");
69+
T("/xxxx/xxxx/x.ko.gz", true , false , true, 1 , "[x]", NULL);
70+
T("/xxxx/xxxx/x.ko.gz", false , false , true, 1 , NULL , NULL);
7171
M("/xxxx/xxxx/x.ko.gz", PERF_RECORD_MISC_CPUMODE_UNKNOWN, true);
7272
M("/xxxx/xxxx/x.ko.gz", PERF_RECORD_MISC_KERNEL, true);
7373
M("/xxxx/xxxx/x.ko.gz", PERF_RECORD_MISC_USER, false);
7474

7575
/* path alloc_name alloc_ext kmod comp name ext */
76-
T("/xxxx/xxxx/x.gz", true , true , false, true, "x.gz" ,"gz");
77-
T("/xxxx/xxxx/x.gz", false , true , false, true, NULL ,"gz");
78-
T("/xxxx/xxxx/x.gz", true , false , false, true, "x.gz" , NULL);
79-
T("/xxxx/xxxx/x.gz", false , false , false, true, NULL , NULL);
76+
T("/xxxx/xxxx/x.gz", true , true , false, 1 , "x.gz" ,"gz");
77+
T("/xxxx/xxxx/x.gz", false , true , false, 1 , NULL ,"gz");
78+
T("/xxxx/xxxx/x.gz", true , false , false, 1 , "x.gz" , NULL);
79+
T("/xxxx/xxxx/x.gz", false , false , false, 1 , NULL , NULL);
8080
M("/xxxx/xxxx/x.gz", PERF_RECORD_MISC_CPUMODE_UNKNOWN, false);
8181
M("/xxxx/xxxx/x.gz", PERF_RECORD_MISC_KERNEL, false);
8282
M("/xxxx/xxxx/x.gz", PERF_RECORD_MISC_USER, false);
8383

8484
/* path alloc_name alloc_ext kmod comp name ext */
85-
T("x.gz", true , true , false, true, "x.gz", "gz");
86-
T("x.gz", false , true , false, true, NULL , "gz");
87-
T("x.gz", true , false , false, true, "x.gz", NULL);
88-
T("x.gz", false , false , false, true, NULL , NULL);
85+
T("x.gz", true , true , false, 1 , "x.gz", "gz");
86+
T("x.gz", false , true , false, 1 , NULL , "gz");
87+
T("x.gz", true , false , false, 1 , "x.gz", NULL);
88+
T("x.gz", false , false , false, 1 , NULL , NULL);
8989
M("x.gz", PERF_RECORD_MISC_CPUMODE_UNKNOWN, false);
9090
M("x.gz", PERF_RECORD_MISC_KERNEL, false);
9191
M("x.gz", PERF_RECORD_MISC_USER, false);
9292

9393
/* path alloc_name alloc_ext kmod comp name ext */
94-
T("x.ko.gz", true , true , true, true, "[x]", "gz");
95-
T("x.ko.gz", false , true , true, true, NULL , "gz");
96-
T("x.ko.gz", true , false , true, true, "[x]", NULL);
97-
T("x.ko.gz", false , false , true, true, NULL , NULL);
94+
T("x.ko.gz", true , true , true, 1 , "[x]", "gz");
95+
T("x.ko.gz", false , true , true, 1 , NULL , "gz");
96+
T("x.ko.gz", true , false , true, 1 , "[x]", NULL);
97+
T("x.ko.gz", false , false , true, 1 , NULL , NULL);
9898
M("x.ko.gz", PERF_RECORD_MISC_CPUMODE_UNKNOWN, true);
9999
M("x.ko.gz", PERF_RECORD_MISC_KERNEL, true);
100100
M("x.ko.gz", PERF_RECORD_MISC_USER, false);

‎tools/perf/util/dso.c‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,15 @@ int dso__read_binary_type_filename(const struct dso *dso,
189189
return ret;
190190
}
191191

192+
enum {
193+
COMP_ID__NONE = 0,
194+
};
195+
192196
static const struct {
193197
const char *fmt;
194198
int (*decompress)(const char *input, int output);
195199
} compressions[] = {
200+
[COMP_ID__NONE] = { .fmt = NULL, },
196201
#ifdef HAVE_ZLIB_SUPPORT
197202
{ "gz", gzip_decompress_to_file },
198203
#endif
@@ -202,15 +207,15 @@ static const struct {
202207
{ NULL, NULL },
203208
};
204209

205-
static bool is_supported_compression(const char *ext)
210+
static int is_supported_compression(const char *ext)
206211
{
207212
unsigned i;
208213

209-
for (i = 0; compressions[i].fmt; i++) {
214+
for (i = 1; compressions[i].fmt; i++) {
210215
if (!strcmp(ext, compressions[i].fmt))
211-
return true;
216+
return i;
212217
}
213-
return false;
218+
return COMP_ID__NONE;
214219
}
215220

216221
bool is_kernel_module(const char *pathname, int cpumode)
@@ -372,10 +377,9 @@ int __kmod_path__parse(struct kmod_path *m, const char *path,
372377
return 0;
373378
}
374379

375-
if (is_supported_compression(ext + 1)) {
376-
m->comp = true;
380+
m->comp = is_supported_compression(ext + 1);
381+
if (m->comp > COMP_ID__NONE)
377382
ext -= 3;
378-
}
379383

380384
/* Check .ko extension only if there's enough name left. */
381385
if (ext > name)

‎tools/perf/util/dso.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ int dso__decompress_kmodule_path(struct dso *dso, const char *name,
262262
struct kmod_path {
263263
char *name;
264264
char *ext;
265-
bool comp;
265+
int comp;
266266
bool kmod;
267267
};
268268

0 commit comments

Comments
 (0)