mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-05-03 20:34:23 -04:00
Merge branch 'veristat-files-list-txt-notation-for-object-files-list'
Eduard Zingerman says: ==================== veristat: @files-list.txt notation for object files list A few small veristat improvements: - It is possible to hit command line parameters number limit, e.g. when running veristat for all object files generated for test_progs. This patch-set adds an option to read objects files list from a file. - Correct usage of strerror() function. - Avoid printing log lines to CSV output. Changelog: - v1 -> v2: - replace strerror(errno) with strerror(-err) in patch #2 (Andrii) v1: https://lore.kernel.org/bpf/3ee39a16-bc54-4820-984a-0add2b5b5f86@gmail.com/T/ ==================== Link: https://patch.msgid.link/20250301000147.1583999-1-eddyz87@gmail.com Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
@@ -268,10 +268,11 @@ static int append_filter(struct filter **filters, int *cnt, const char *str);
|
||||
static int append_filter_file(const char *path);
|
||||
static int append_var_preset(struct var_preset **presets, int *cnt, const char *expr);
|
||||
static int append_var_preset_file(const char *filename);
|
||||
static int append_file(const char *path);
|
||||
static int append_file_from_file(const char *path);
|
||||
|
||||
static error_t parse_arg(int key, char *arg, struct argp_state *state)
|
||||
{
|
||||
void *tmp;
|
||||
int err;
|
||||
|
||||
switch (key) {
|
||||
@@ -381,14 +382,14 @@ static error_t parse_arg(int key, char *arg, struct argp_state *state)
|
||||
break;
|
||||
}
|
||||
case ARGP_KEY_ARG:
|
||||
tmp = realloc(env.filenames, (env.filename_cnt + 1) * sizeof(*env.filenames));
|
||||
if (!tmp)
|
||||
return -ENOMEM;
|
||||
env.filenames = tmp;
|
||||
env.filenames[env.filename_cnt] = strdup(arg);
|
||||
if (!env.filenames[env.filename_cnt])
|
||||
return -ENOMEM;
|
||||
env.filename_cnt++;
|
||||
if (arg[0] == '@')
|
||||
err = append_file_from_file(arg + 1);
|
||||
else
|
||||
err = append_file(arg);
|
||||
if (err) {
|
||||
fprintf(stderr, "Failed to collect BPF object files: %d\n", err);
|
||||
return err;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return ARGP_ERR_UNKNOWN;
|
||||
@@ -659,7 +660,7 @@ static int append_filter_file(const char *path)
|
||||
f = fopen(path, "r");
|
||||
if (!f) {
|
||||
err = -errno;
|
||||
fprintf(stderr, "Failed to open filters in '%s': %s\n", path, strerror(err));
|
||||
fprintf(stderr, "Failed to open filters in '%s': %s\n", path, strerror(-err));
|
||||
return err;
|
||||
}
|
||||
|
||||
@@ -689,6 +690,49 @@ static const struct stat_specs default_output_spec = {
|
||||
},
|
||||
};
|
||||
|
||||
static int append_file(const char *path)
|
||||
{
|
||||
void *tmp;
|
||||
|
||||
tmp = realloc(env.filenames, (env.filename_cnt + 1) * sizeof(*env.filenames));
|
||||
if (!tmp)
|
||||
return -ENOMEM;
|
||||
env.filenames = tmp;
|
||||
env.filenames[env.filename_cnt] = strdup(path);
|
||||
if (!env.filenames[env.filename_cnt])
|
||||
return -ENOMEM;
|
||||
env.filename_cnt++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int append_file_from_file(const char *path)
|
||||
{
|
||||
char buf[1024];
|
||||
int err = 0;
|
||||
FILE *f;
|
||||
|
||||
f = fopen(path, "r");
|
||||
if (!f) {
|
||||
err = -errno;
|
||||
fprintf(stderr, "Failed to open object files list in '%s': %s\n",
|
||||
path, strerror(errno));
|
||||
return err;
|
||||
}
|
||||
|
||||
while (fscanf(f, " %1023[^\n]\n", buf) == 1) {
|
||||
/* lines starting with # are comments, skip them */
|
||||
if (buf[0] == '\0' || buf[0] == '#')
|
||||
continue;
|
||||
err = append_file(buf);
|
||||
if (err)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
cleanup:
|
||||
fclose(f);
|
||||
return err;
|
||||
}
|
||||
|
||||
static const struct stat_specs default_csv_output_spec = {
|
||||
.spec_cnt = 14,
|
||||
.ids = {
|
||||
@@ -1190,13 +1234,13 @@ static void fixup_obj(struct bpf_object *obj, struct bpf_program *prog, const ch
|
||||
bpf_program__set_expected_attach_type(prog, attach_type);
|
||||
|
||||
if (!env.quiet) {
|
||||
printf("Using guessed program type '%s' for %s/%s...\n",
|
||||
fprintf(stderr, "Using guessed program type '%s' for %s/%s...\n",
|
||||
libbpf_bpf_prog_type_str(prog_type),
|
||||
filename, prog_name);
|
||||
}
|
||||
} else {
|
||||
if (!env.quiet) {
|
||||
printf("Failed to guess program type for freplace program with context type name '%s' for %s/%s. Consider using canonical type names to help veristat...\n",
|
||||
fprintf(stderr, "Failed to guess program type for freplace program with context type name '%s' for %s/%s. Consider using canonical type names to help veristat...\n",
|
||||
ctx_name, filename, prog_name);
|
||||
}
|
||||
}
|
||||
@@ -1378,7 +1422,7 @@ static int append_var_preset_file(const char *filename)
|
||||
f = fopen(filename, "rt");
|
||||
if (!f) {
|
||||
err = -errno;
|
||||
fprintf(stderr, "Failed to open presets in '%s': %s\n", filename, strerror(err));
|
||||
fprintf(stderr, "Failed to open presets in '%s': %s\n", filename, strerror(-err));
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user