perf tool: Build dependency tidy up
Ian Rogers
reviewerv3 cover perf tool: Build dependency tidy up
In doing some work on bazel building of perf (bazel being stricter on how header files are used), rather than just making the bazel BUILD files more generous in how they accept header file issues like transitive dependencies it felt cleaner to address them. These patches tackle the most severe issues such as cache.h pulling in UI code, hist.h bringing in UI code, unused header files, transitive dependencies, etc.
While cleaning up the dependencies in perf.c, change how missing commands are handled to give a more meaningful error message at run time about missing build time dependencies.
v1 and v2 were previously sent just addressing the cache.h issue:
https://lore.kernel.org/linux-perf-users/[email protected]/
Ian Rogers (6):
perf tool: Remove util/cache.h
perf tool: Tidy up util/cache.h header file users perf tool: Remove unused includes in perf.c perf tool: Move usage strings and functions to perf.c perf tool: Add fallback stubs for missing dependencies perf hist: Remove keysym.h include from hist.h
tools/perf/builtin-annotate.c | 57 +++++++++------ tools/perf/builtin-c2c.c | 1 + tools/perf/builtin-config.c | 18 +++-- tools/perf/builtin-help.c | 30 ++++---- tools/perf/builtin-kvm.c | 1 + tools/perf/builtin-report.c | 1 + tools/perf/builtin-top.c | 1 + tools/perf/builtin.h | 3 + tools/perf/perf.c | 114 ++++++++++++++++++----------- tools/perf/ui/browsers/annotate.c | 1 + tools/perf/ui/browsers/hists.c | 1 + tools/perf/ui/browsers/scripts.c | 1 + tools/perf/ui/libslang.h | 2 + tools/perf/util/Build | 1 - tools/perf/util/cache.h | 31 -------- tools/perf/util/config.c | 38 ++++++---- tools/perf/util/help-unknown-cmd.c | 15 +++- tools/perf/util/hist.h | 6 -- tools/perf/util/path.c | 10 +-- tools/perf/util/path.h | 6 +- tools/perf/util/strbuf.c | 14 ++-- tools/perf/util/usage.c | 34 --------- tools/perf/util/util.h | 4 - 23 files changed, 194 insertions(+), 196 deletions(-) delete mode 100644 tools/perf/util/cache.h delete mode 100644 tools/perf/util/usage.c
Signature · 1 line
2.55.0.966.g6673acef38-goog
Ian Rogers
reviewerPATCH v3 1/6 perf tool: Remove util/cache.h
Move definitions to places they are used, or path.h in the case of path.c's mkpath function. Remove unused definitions. Fix transitive include dependencies.
--- tools/perf/builtin-annotate.c | 6 +++++- tools/perf/builtin-config.c | 4 +++- tools/perf/builtin-help.c | 3 ++- tools/perf/perf.c | 11 ++++++++++- tools/perf/util/cache.h | 31 ------------------------------ tools/perf/util/config.c | 5 ++++- tools/perf/util/help-unknown-cmd.c | 6 +++++- tools/perf/util/path.c | 2 +- tools/perf/util/path.h | 3 +++ tools/perf/util/strbuf.c | 5 ++++- 10 files changed, 37 insertions(+), 39 deletions(-) delete mode 100644 tools/perf/util/cache.h
tools/perf/builtin-annotate.c +5 -1
@@ -8,10 +8,10 @@*/ #include "builtin.h" #include "perf.h" +#include <stdbool.h> #include "util/color.h" #include <linux/list.h> -#include "util/cache.h" #include <linux/rbtree.h> #include "util/symbol.h"
@@ -38,12 +38,16 @@#include "util/branch.h" #include "util/util.h" #include "ui/progress.h" +#include "ui/ui.h" #include <dlfcn.h> #include <errno.h> #include <linux/bitmap.h> #include <linux/err.h> #include <inttypes.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> struct perf_annotate {struct perf_tool tool;
tools/perf/builtin-config.c +3 -1
@@ -7,14 +7,16 @@*/ #include "builtin.h" -#include "util/cache.h" #include <subcmd/parse-options.h> #include "util/debug.h" #include "util/config.h" +#include "util/path.h" #include <linux/string.h> #include <limits.h> #include <stdio.h> #include <stdlib.h> +#include <stdbool.h> +#include <string.h> static bool use_system_config, use_user_config;
tools/perf/builtin-help.c +2 -1
@@ -4,8 +4,8 @@* * Builtin help command */ -#include "util/cache.h" #include "util/config.h" +#include "util/path.h" #include "util/strbuf.h" #include "builtin.h" #include <subcmd/exec-cmd.h>
@@ -21,6 +21,7 @@#include <limits.h> #include <stdio.h> #include <stdlib.h> +#include <stdbool.h> #include <string.h> #include <sys/types.h> #include <sys/stat.h>
tools/perf/perf.c +10 -1
@@ -10,13 +10,13 @@#include "perf.h" #include "util/build-id.h" -#include "util/cache.h" #include "util/env.h" #include <internal/lib.h> // page_size #include <subcmd/exec-cmd.h> #include "util/config.h" #include <subcmd/run-command.h> #include "util/parse-events.h" +#include <subcmd/pager.h> #include <subcmd/parse-options.h> #include <subcmd/help.h> #include "util/debug.h"
@@ -30,7 +30,10 @@#include <errno.h> #include <pthread.h> #include <signal.h> +#include <stdio.h> #include <stdlib.h> +#include <string.h> +#include <stdbool.h> #include <time.h> #include <sys/types.h> #include <sys/stat.h>
@@ -39,6 +42,12 @@#include <linux/string.h> #include <linux/zalloc.h> +#define CMD_EXEC_PATH "--exec-path" +#define CMD_DEBUGFS_DIR "--debugfs-dir=" + +#define EXEC_PATH_ENVIRONMENT "PERF_EXEC_PATH" +#define PERF_PAGER_ENVIRONMENT "PERF_PAGER" +static int use_pager =-1 ;static FILE *debug_fp =NULL ;
tools/perf/util/cache.h deleted +0 -31
@@ -1,31 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#ifndef __PERF_CACHE_H -#define __PERF_CACHE_H - -#include "strbuf.h" -#include <subcmd/pager.h> -#include "../ui/ui.h" - -#include <linux/compiler.h> -#include <linux/string.h> - -#define CMD_EXEC_PATH "--exec-path" -#define CMD_DEBUGFS_DIR "--debugfs-dir=" - -#define EXEC_PATH_ENVIRONMENT "PERF_EXEC_PATH" -#define PERF_DEBUGFS_ENVIRONMENT "PERF_DEBUGFS_DIR" -#define PERF_TRACEFS_ENVIRONMENT "PERF_TRACEFS_DIR" -#define PERF_PAGER_ENVIRONMENT "PERF_PAGER" - -int split_cmdline (char *cmdline,const char ***argv); - -#define alloc_nr (x) (((x)+16)*3/2) - -static inline int is_absolute_path (const char *path) -{ -return path[0 ] =='/' ; -} - -char *mkpath (char *path_buf,size_t sz,const char *fmt, ...)__printf (3 ,4 ); - -#endif /* __PERF_CACHE_H */
tools/perf/util/config.c +4 -1
@@ -11,7 +11,6 @@*/ #include <errno.h> #include <sys/param.h> -#include "cache.h" #include "callchain.h" #include "header.h" #include <subcmd/exec-cmd.h>
@@ -19,6 +18,7 @@#include "util/hist.h" /* perf_hist_config */ #include "util/stat.h" /* perf_stat__set_big_num */ #include "util/evsel.h" /* evsel__hw_names, evsel__use_bpf_counters */ +#include "path.h" #include "srcline.h" #include "build-id.h" #include "debug.h"
@@ -26,7 +26,10 @@#include "unwind.h" #include <sys/types.h> #include <sys/stat.h> +#include <stdio.h> #include <stdlib.h> +#include <stdbool.h> +#include <string.h> #include <unistd.h> #include <linux/string.h> #include <linux/zalloc.h>
tools/perf/util/help-unknown-cmd.c +5 -1
@@ -1,9 +1,9 @@// SPDX-License-Identifier: GPL-2.0 -#include "cache.h" #include "config.h" #include <poll.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <subcmd/help.h> #include "../builtin.h" #include "levenshtein.h"
@@ -36,10 +36,14 @@ static int add_cmd_list(struct cmdnames *cmds, struct cmdnames *old)if (nr > cmds->alloc) {/* Choose bigger one to alloc */ +#define alloc_nr (x) (((x) + 16) * 3 / 2) +if (alloc_nr (cmds->alloc) < nr) cmds->alloc = nr;else cmds->alloc =alloc_nr (cmds->alloc); + +#undef alloc_nr tmp =realloc (cmds->names, cmds->alloc *sizeof (*cmds->names));if (!tmp)return -1 ;
tools/perf/util/path.c +1 -1
@@ -1,8 +1,8 @@// SPDX-License-Identifier: GPL-2.0 #include "path.h" -#include "cache.h" #include <linux/kernel.h> #include <limits.h> +#include <stdarg.h> #include <stdio.h> #include <string.h> #include <sys/types.h>
tools/perf/util/path.h +3 -0
@@ -4,9 +4,12 @@#include <stddef.h> #include <stdbool.h> +#include <linux/compiler.h> struct dirent ; +char *mkpath (char *path_buf,size_t sz,const char *fmt, ...)__printf (3 ,4 ); +int path__join (char *bf,size_t size,const char *path1,const char *path2);int path__join3 (char *bf,size_t size,const char *path1,const char *path2,const char *path3);
tools/perf/util/strbuf.c +4 -1
@@ -1,5 +1,4 @@// SPDX-License-Identifier: GPL-2.0 -#include "cache.h" #include "debug.h" #include "strbuf.h" #include <linux/kernel.h>
@@ -8,6 +7,7 @@#include <errno.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <unistd.h> /*
@@ -54,9 +54,12 @@ int strbuf_grow(struct strbuf *sb, size_t extra)if (nr <= sb->len)return -E2BIG ; +#define alloc_nr (x) (((x) + 16) * 3 / 2) +if (alloc_nr (sb->alloc) > nr) nr =alloc_nr (sb->alloc); +#undef alloc_nr/* * Note that sb->buf == strbuf_slopbuf if sb->alloc == 0, and it is * a static variable. Thus we have to avoid passing it to realloc.
Signature · 1 line
2.55.0.966.g6673acef38-goog
[email protected]
AI reviewRe: [PATCH v3 1/6] perf tool: Remove util/cache.h
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 5 lines
Move definitions to places they are used, or
path.hin the case of path.c's mkpath function. Remove unused definitions. Fix transitive include dependencies.Signed-off-by Ian Rogers <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Ian Rogers
reviewerPATCH v3 2/6 perf tool: Tidy up util/cache.h header file users
In reply to Ian RogersUse git clang-format to sort header files. Review header file includes removing those that were unnecessary or adding explicit includes in cases where transitive dependencies were be using.
--- tools/perf/builtin-annotate.c | 53 ++++++++++++++---------------- tools/perf/builtin-config.c | 18 +++++----- tools/perf/builtin-help.c | 31 ++++++++--------- tools/perf/perf.c | 45 +++++++++++-------------- tools/perf/util/config.c | 39 ++++++++++++---------- tools/perf/util/help-unknown-cmd.c | 9 +++-- tools/perf/util/path.c | 8 ++--- tools/perf/util/path.h | 3 +- tools/perf/util/strbuf.c | 9 ++--- 9 files changed, 109 insertions(+), 106 deletions(-)
tools/perf/builtin-annotate.c +25 -28
@@ -6,48 +6,45 @@* look up and read DSOs and symbol information and display * a histogram of results, along various sorting keys. */ -#include "builtin.h" -#include "perf.h" +#include <errno.h> +#include <inttypes.h> #include <stdbool.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> -#include "util/color.h" +#include <dlfcn.h> +#include <linux/bitmap.h> +#include <linux/err.h> #include <linux/list.h> #include <linux/rbtree.h> -#include "util/symbol.h" -#include "util/debug.h" +#include <subcmd/parse-options.h> -#include "util/evlist.h" -#include "util/evsel.h" -#include "util/annotate.h" +#include "arch/common.h" +#include "builtin.h" +#include "perf.h" +#include "ui/progress.h" +#include "ui/ui.h" #include "util/annotate-data.h" +#include "util/annotate.h" +#include "util/block-range.h" +#include "util/branch.h" +#include "util/data.h" +#include "util/debug.h" +#include "util/dso.h" #include "util/event.h" -#include <subcmd/parse-options.h> -#include "util/parse-events.h" -#include "util/sort.h" +#include "util/evlist.h" +#include "util/evsel.h" #include "util/hist.h" -#include "util/dso.h" #include "util/machine.h" #include "util/map.h" +#include "util/map_symbol.h" #include "util/session.h" +#include "util/sort.h" +#include "util/symbol.h" #include "util/tool.h" -#include "util/data.h" -#include "arch/common.h" -#include "util/block-range.h" -#include "util/map_symbol.h" -#include "util/branch.h" #include "util/util.h" -#include "ui/progress.h" -#include "ui/ui.h" - -#include <dlfcn.h> -#include <errno.h> -#include <linux/bitmap.h> -#include <linux/err.h> -#include <inttypes.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> struct perf_annotate {struct perf_tool tool;
tools/perf/builtin-config.c +10 -8
@@ -5,19 +5,21 @@* Copyright (C) 2015, Taeung Song <[email protected]> * */ -#include "builtin.h" - -#include <subcmd/parse-options.h> -#include "util/debug.h" -#include "util/config.h" -#include "util/path.h" -#include <linux/string.h> #include <limits.h> +#include <stdbool.h> #include <stdio.h> #include <stdlib.h> -#include <stdbool.h> #include <string.h> +#include <linux/string.h> + +#include <subcmd/parse-options.h> + +#include "builtin.h" +#include "util/config.h" +#include "util/debug.h" +#include "util/path.h" +static bool use_system_config, use_user_config;static const char *const config_usage[] = {
tools/perf/builtin-help.c +16 -15
@@ -4,29 +4,30 @@* * Builtin help command */ -#include "util/config.h" -#include "util/path.h" -#include "util/strbuf.h" -#include "builtin.h" -#include <subcmd/exec-cmd.h> -#include <subcmd/parse-options.h> -#include <subcmd/run-command.h> -#include <subcmd/help.h> -#include "util/debug.h" -#include "util/util.h" -#include <linux/kernel.h> -#include <linux/string.h> -#include <linux/zalloc.h> #include <errno.h> #include <limits.h> +#include <stdbool.h> #include <stdio.h> #include <stdlib.h> -#include <stdbool.h> #include <string.h> -#include <sys/types.h> + +#include <linux/string.h> +#include <linux/zalloc.h> #include <sys/stat.h> #include <unistd.h> +#include <subcmd/exec-cmd.h> +#include <subcmd/help.h> +#include <subcmd/parse-options.h> +#include <subcmd/run-command.h> + +#include "builtin.h" +#include "util/config.h" +#include "util/debug.h" +#include "util/path.h" +#include "util/strbuf.h" +#include "util/util.h" + static struct man_viewer_list { struct man_viewer_list *next; char name[0];
tools/perf/perf.c +20 -25
61 lines not on this page · raw message
tools/perf/util/config.c +21 -18
@@ -9,31 +9,34 @@* Copyright (C) Johannes Schindelin, 2005 * */ +#include "config.h" +#include <errno.h> +#include <stdbool.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include <linux/ctype.h> +#include <linux/string.h> +#include <linux/zalloc.h> #include <sys/param.h> +#include <sys/stat.h> +#include <unistd.h> + +#include <subcmd/exec-cmd.h> + +#include "build-id.h" #include "callchain.h" +#include "debug.h" #include "header.h" -#include <subcmd/exec-cmd.h> -#include "util/event.h" /* proc_map_timeout */ -#include "util/hist.h" /* perf_hist_config */ -#include "util/stat.h" /* perf_stat__set_big_num */ -#include "util/evsel.h" /* evsel__hw_names, evsel__use_bpf_counters */ #include "path.h" #include "srcline.h" -#include "build-id.h" -#include "debug.h" -#include "config.h" #include "unwind.h" -#include <sys/types.h> -#include <sys/stat.h> -#include <stdio.h> -#include <stdlib.h> -#include <stdbool.h> -#include <string.h> -#include <unistd.h> -#include <linux/string.h> -#include <linux/zalloc.h> -#include <linux/ctype.h> +#include "util/event.h" /* proc_map_timeout */ +#include "util/evsel.h" /* evsel__hw_names, evsel__use_bpf_counters */ +#include "util/hist.h" /* perf_hist_config */ +#include "util/stat.h" /* perf_stat__set_big_num */ #define MAXNAME (256)
tools/perf/util/help-unknown-cmd.c +6 -3
@@ -1,13 +1,16 @@// SPDX-License-Identifier: GPL-2.0 -#include "config.h" -#include <poll.h> #include <stdio.h> #include <stdlib.h> #include <string.h> + +#include <linux/zalloc.h> +#include <poll.h> +#include <subcmd/help.h> +#include "../builtin.h" +#include "config.h" #include "levenshtein.h" -#include <linux/zalloc.h> static int autocorrect;
tools/perf/util/path.c +4 -4
@@ -1,14 +1,14 @@// SPDX-License-Identifier: GPL-2.0 #include "path.h" -#include <linux/kernel.h> +#include <limits.h> #include <stdarg.h> #include <stdio.h> #include <string.h> -#include <sys/types.h> -#include <sys/stat.h> +#include <dirent.h> -#include <unistd.h> +#include <linux/kernel.h> +#include <sys/stat.h> static char *cleanup_path (char *path) {
tools/perf/util/path.h +2 -1
@@ -2,8 +2,9 @@#ifndef _PERF_PATH_H#define _PERF_PATH_H -#include <stddef.h> #include <stdbool.h> +#include <stddef.h> +#include <linux/compiler.h> struct dirent ;
tools/perf/util/strbuf.c +5 -4
@@ -1,15 +1,16 @@// SPDX-License-Identifier: GPL-2.0 -#include "debug.h" #include "strbuf.h" -#include <linux/kernel.h> -#include <linux/string.h> -#include <linux/zalloc.h> +#include <errno.h> #include <stdio.h> #include <stdlib.h> #include <string.h> + +#include <linux/zalloc.h> #include <unistd.h> +#include "debug.h" +/* * Used as the default ->buf value, so that people can always assume * buf is non NULL and ->buf is NUL terminated even for a freshly
Signature · 1 line
2.55.0.966.g6673acef38-goog
[email protected]
AI reviewRe: [PATCH v3 2/6] perf tool: Tidy up util/cache.h header file users
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 5 lines
Use git clang-format to sort header files. Review header file includes removing those that were unnecessary or adding explicit includes in cases where transitive dependencies were be using.
Signed-off-by Ian Rogers <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Ian Rogers
reviewerPATCH v3 3/6 perf tool: Remove unused includes in perf.c
In reply to Ian RogersRemove perf-sys.h, internal/lib.h (page_size), signal.h, and perf.h since their exports are not used directly in perf.c.
--- tools/perf/perf.c | 4 ---- 1 file changed, 4 deletions(-)
tools/perf/perf.c +0 -4
@@ -6,10 +6,8 @@* This is the main hub from which the sub-commands (perf stat, * perf top, perf record, perf report, etc.) are started. */ -#include "perf.h" #include <errno.h> -#include <signal.h> #include <stdbool.h> #include <stdio.h> #include <stdlib.h>
@@ -21,7 +19,6 @@#include <sys/stat.h> #include <api/fs/tracing_path.h> -#include <internal/lib.h> // page_size #include <perf/core.h> #include <subcmd/exec-cmd.h> #include <subcmd/help.h>
@@ -30,7 +27,6 @@#include <subcmd/run-command.h> #include "builtin.h" -#include "perf-sys.h" #include "ui/ui.h" #include "util/build-id.h" #include "util/config.h"
Signature · 1 line
2.55.0.966.g6673acef38-goog
[email protected]
AI reviewRe: [PATCH v3 3/6] perf tool: Remove unused includes in perf.c
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 4 lines
Remove
perf-sys.h,internal/lib.h(page_size),signal.h, andperf.hsince their exports are not used directly inperf.c.Signed-off-by Ian Rogers <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Ian Rogers
reviewerPATCH v3 4/6 perf tool: Move usage strings and functions to perf.c
In reply to Ian RogersThe code is mostly used by perf.c with additional unused functionality such as function pointers derived from early git code. Moving it into perf.c directly reduces the code footprint, drops the util/util.h dependence from perf.c, and allows us to remove util/usage.c entirely.
The string constants are exposed in builtin.h, as they are used in builtin-help.c.
--- tools/perf/builtin.h | 3 +++ tools/perf/perf.c | 13 ++++++++++++- tools/perf/util/Build | 1 - tools/perf/util/usage.c | 34 ---------------------------------- tools/perf/util/util.h | 4 ---- 5 files changed, 15 insertions(+), 40 deletions(-) delete mode 100644 tools/perf/util/usage.c
tools/perf/builtin.h +3 -0
@@ -2,6 +2,9 @@ #ifndef BUILTIN_H #define BUILTIN_H +extern const char perf_usage_string[]; +extern const char perf_more_info_string[]; + struct feature_status { const char *name; const char *macro;
tools/perf/perf.c +12 -1
@@ -31,7 +31,18 @@#include "util/build-id.h" #include "util/config.h" #include "util/debug.h" -#include "util/util.h" // usage() + +const char perf_usage_string[] = +"perf [--version] [--help] [OPTIONS] COMMAND [ARGS]" ; + +const char perf_more_info_string[] = +"See 'perf help COMMAND' for more information on a specific command." ; + +static void __noreturn usage (const char *err) +{ +fprintf (stderr,"\n Usage: %s\n" , err); +exit (129 ); +}#define CMD_EXEC_PATH "--exec-path"#define CMD_DEBUGFS_DIR "--debugfs-dir="
tools/perf/util/Build +0 -1
@@ -54,7 +54,6 @@ perf-util-y += string.o perf-util-y += strlist.o perf-util-y += strfilter.o perf-util-y += top.o -perf-util-y += usage.o perf-util-y += dso.o perf-util-y += dsos.o perf-util-y += symbol.o
tools/perf/util/usage.c deleted +0 -34
@@ -1,34 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* -* usage.c -* -* Various reporting routines. -* Originally copied from GIT source. -* -* Copyright (C) Linus Torvalds, 2005 -*/ -#include "util.h" -#include <stdio.h> -#include <stdlib.h> -#include <linux/compiler.h> - -const char perf_usage_string[] = -"perf [--version] [--help] [OPTIONS] COMMAND [ARGS]" ; - -const char perf_more_info_string[] = -"See 'perf help COMMAND' for more information on a specific command." ; - -static __noreturn void usage_builtin (const char *err) -{ -fprintf (stderr,"\n Usage: %s\n" , err); -exit (129 ); -} - -/* If we are in a dlopen()ed .so write to a global variable would segfault -* (ugh), so keep things static. */ -static void (*usage_routine)(const char *err)__noreturn = usage_builtin; - -void usage (const char *err) -{ -usage_routine (err); -}
tools/perf/util/util.h +0 -4
@@ -17,9 +17,6 @@#include <internal/cpumap.h> #endif -extern const char perf_usage_string[]; -extern const char perf_more_info_string[]; -extern const char *input_name;/* This will control if perf_{host,guest} will set attr.exclude_{host,guest}. */
@@ -29,7 +26,6 @@ extern bool perf_host;extern bool perf_guest;/* General helper functions */ -void usage (const char *err)__noreturn ;struct dirent ;struct strlist ;
Signature · 1 line
2.55.0.966.g6673acef38-goog
[email protected]
AI reviewRe: [PATCH v3 4/6] perf tool: Move usage strings and functions to perf.c
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 9 lines
The code is mostly used by
perf.cwith additional unused functionality such as function pointers derived from early git code. Moving it intoperf.cdirectly reduces the code footprint, drops theutil/util.hdependence fromperf.c, and allows us to removeutil/usage.centirely.The string constants are exposed in
builtin.h, as they are used inbuiltin-help.c.Signed-off-by Ian Rogers <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
Ian Rogers
reviewerPATCH v3 5/6 perf tool: Add fallback stubs for missing dependencies
In reply to Ian RogersDeclare stubs directly inside perf.c for commands that have library dependencies sometimes omitted at build time, such as libtraceevent (timechart, sched, kmem, lock, trace, kwork) and libelf (probe).
By unconditionally including these commands in the commands[] array, users will receive a clear, unified warning indicating the missing dependency instead of the command silently being absent.
Running perf trace with libtraceevent missing. Before:
```
perf: 'trace' is not a perf-command. See 'perf --help'.
Did you mean this?
ftrace
```After:
``` 'trace' command not available: missing libtraceevent devel package at build time. ```
--- tools/perf/perf.c | 51 ++++++++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 18 deletions(-)
tools/perf/perf.c +33 -18
@@ -7,6 +7,7 @@* perf top, perf record, perf report, etc.) are started. */ +#include <linux/compiler.h> #include <errno.h> #include <stdbool.h> #include <stdio.h>
@@ -53,6 +54,38 @@ static void __noreturn usage(const char *err)static int use_pager =-1 ;static FILE *debug_fp =NULL ; + +#ifndef HAVE_LIBTRACEEVENT +#define DECLARE_LIBTRACEEVENT_STUB (_cmd) \ + int cmd_##_cmd(int argc __always_unused, const char **argv __always_unused) \ + { \ + fprintf(stderr, \ + "'" #_cmd "' command not available: missing libtraceevent " \ + "devel package at build time.\n"); \ + return -1; \ + } + +DECLARE_LIBTRACEEVENT_STUB(timechart) +DECLARE_LIBTRACEEVENT_STUB(sched) +DECLARE_LIBTRACEEVENT_STUB(kmem) +DECLARE_LIBTRACEEVENT_STUB(lock) +DECLARE_LIBTRACEEVENT_STUB(trace) +DECLARE_LIBTRACEEVENT_STUB(kwork) +#endif + +#ifndef HAVE_LIBELF_SUPPORT +#define DECLARE_LIBELF_SUPPORT_STUB (_cmd) \ + int cmd_##_cmd(int argc __always_unused, const char **argv __always_unused) \ + { \ + fprintf(stderr, \ + "'" #_cmd "' command not available: missing libelf " \ + "devel package at build time.\n"); \ + return -1; \ + } + +DECLARE_LIBELF_SUPPORT_STUB(probe) +#endif +struct cmd_struct {const char *cmd;int (*fn)(int ,const char **);
@@ -76,36 +109,24 @@ static const struct cmd_struct commands[] = { { "report", cmd_report, 0 }, { "bench", cmd_bench, 0 }, { "stat", cmd_stat, 0 }, -#ifdef HAVE_LIBTRACEEVENT { "timechart", cmd_timechart, 0 }, -#endif { "top", cmd_top, 0 }, { "annotate", cmd_annotate, 0 }, { "version", cmd_version, 0 }, { "script", cmd_script, 0 }, -#ifdef HAVE_LIBTRACEEVENT { "sched", cmd_sched, 0 }, -#endif -#ifdef HAVE_LIBELF_SUPPORT { "probe", cmd_probe, 0 }, -#endif -#ifdef HAVE_LIBTRACEEVENT { "kmem", cmd_kmem, 0 }, { "lock", cmd_lock, 0 }, -#endif { "kvm", cmd_kvm, 0 }, { "test", cmd_test, 0 }, -#if defined(HAVE_LIBTRACEEVENT) { "trace", cmd_trace, 0 }, -#endif { "inject", cmd_inject, 0 }, { "mem", cmd_mem, 0 }, { "data", cmd_data, 0 }, { "ftrace", cmd_ftrace, 0 }, { "daemon", cmd_daemon, 0 }, -#ifdef HAVE_LIBTRACEEVENT { "kwork", cmd_kwork, 0 }, -#endif }; struct pager_config {
@@ -514,15 +535,9 @@ int main(int argc, const char **argv) argv[0 ] = cmd; }if (strstarts (cmd,"trace" )) { -#ifndef HAVE_LIBTRACEEVENT -fprintf (stderr, -"trace command not available: missing libtraceevent devel package at build time.\n" ); - goto out; -#else setup_path (); argv[0 ] ="trace" ;return cmd_trace (argc, argv); -#endif }/* Look for flags.. */ argv++;
Signature · 1 line
2.55.0.966.g6673acef38-goog
[email protected]
AI reviewRe: [PATCH v3 5/6] perf tool: Add fallback stubs for missing dependencies
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] Feature fallback stubs are generated in the C source file instead of providing dummy inline…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Feature fallback stubs are generated in the C source file instead of providing dummy inline stubs in the header file. --
commit f19b5b661c978968c83e8af505c2279ba5f83167
Author: Ian Rogers <[email protected]>
perf tool: Add fallback stubs for missing dependencies
This commit adds fallback stubs directly in perf.c for commands that have optional library dependencies, such as libtraceevent and libelf. This ensures a unified warning is shown when users try to run these commands, rather than silently omitting them from the commands array.
Quoted 4 lines
tools/perf/perf.c +0
-0
[ ... ]
Quoted 4 lines
tools/perf/perf.c +0
-0@@ -53,6 +54,38 @@ static void __noreturn usage(const char *err)static int use_pager =-1 ;static FILE *debug_fp =NULL ;
tools/perf/perf.c static void __noreturn usage(const char *err) · line 66
Quoted 10 lines
tools/perf/perf.c +10
-0+ +#ifndef HAVE_LIBTRACEEVENT +#define DECLARE_LIBTRACEEVENT_STUB (_cmd) \ + int cmd_##_cmd(int argc __always_unused, const char **argv __always_unused) \ + { \ + fprintf(stderr, \ + "'" #_cmd "' command not available: missing libtraceevent " \ + "devel package at build time.\n"); \ + return -1; \ + }
[Severity: Medium]
Does defining these fallback stubs directly in the C source file violate the subsystem guidelines for optional features?
The perf subsystem guide expects that header files provide compatible dummy inline stubs when a feature define is absent, rather than generating them via macros directly in the C source file.
Quoted 8 lines
tools/perf/perf.c +8
-0+ +DECLARE_LIBTRACEEVENT_STUB(timechart) +DECLARE_LIBTRACEEVENT_STUB(sched) +DECLARE_LIBTRACEEVENT_STUB(kmem) +DECLARE_LIBTRACEEVENT_STUB(lock) +DECLARE_LIBTRACEEVENT_STUB(trace) +DECLARE_LIBTRACEEVENT_STUB(kwork) +#endif
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
Ian Rogers
reviewerRe: [PATCH v3 5/6] perf tool: Add fallback stubs for missing dependencies
Quoted 39 lines · On Wed, Sep 2, 2026 at 8:58 AM <[email protected]> wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Feature fallback stubs are generated in the C source file instead of providing dummy inline stubs in the header file. --commit
f19b5b661c978968c83e8af505c2279ba5f83167
Author: Ian Rogers <[email protected]>perf tool: Add fallback stubs for missing dependencies
This commit adds fallback stubs directly in
perf.cfor commands that have optional library dependencies, such as libtraceevent and libelf. This ensures a unified warning is shown when users try to run these commands, rather than silently omitting them from the commands array.Quoted 4 lines
tools/perf/perf.c +0
-0[ ... ]
Quoted 4 lines
tools/perf/perf.c +0
-0@@ -53,6 +54,38 @@ static void __noreturn usage(const char *err)static int use_pager =-1 ;static FILE *debug_fp =NULL ;tools/perf/perf.c static void __noreturn usage(const char *err) · line 66
Quoted 10 lines
tools/perf/perf.c +10
-0+ +#ifndef HAVE_LIBTRACEEVENT +#define DECLARE_LIBTRACEEVENT_STUB (_cmd) \ + int cmd_##_cmd(int argc __always_unused, const char **argv __always_unused) \ + { \ + fprintf(stderr, \ + "'" #_cmd "' command not available: missing libtraceevent " \ + "devel package at build time.\n"); \ + return -1; \ + }[Severity: Medium]
Does defining these fallback stubs directly in the C source file violate the subsystem guidelines for optional features?
Quoted 3 lines
The perf subsystem guide expects that header files provide compatible dummy inline stubs when a feature define is absent, rather than generating them via macros directly in the C source file.
I saw this feedback on the internal Sashiko review, but I believed this change was legitimate. To put the fallback stubs into the affected file would mean not using the Build file config options and having a large #ifdef in each of the builtin files. This looked uglier than the change here, and the change here mirrors the previous #ifdef usage. This change also minimizes the scope of the necessary changes. I'm not sure it makes sense to update the subsystem guidance based on this feedback.
Thanks,
Ian
Quoted 12 lines
tools/perf/perf.c static void __noreturn usage(const char *err) · line 74
Quoted 8 lines
tools/perf/perf.c +8
-0+ +DECLARE_LIBTRACEEVENT_STUB(timechart) +DECLARE_LIBTRACEEVENT_STUB(sched) +DECLARE_LIBTRACEEVENT_STUB(kmem) +DECLARE_LIBTRACEEVENT_STUB(lock) +DECLARE_LIBTRACEEVENT_STUB(trace) +DECLARE_LIBTRACEEVENT_STUB(kwork) +#endif [ ... ]
--
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
Ian Rogers
reviewerPATCH v3 6/6 perf hist: Remove keysym.h include from hist.h
In reply to Ian Rogershist.h isn't related to UI and so remove the UI inclusion. Fix the transitive dependency issues this exposes.
--- tools/perf/builtin-annotate.c | 8 ++++++++ tools/perf/builtin-c2c.c | 1 + tools/perf/builtin-kvm.c | 1 + tools/perf/builtin-report.c | 1 + tools/perf/builtin-top.c | 1 + tools/perf/ui/browsers/annotate.c | 1 + tools/perf/ui/browsers/hists.c | 1 + tools/perf/ui/browsers/scripts.c | 1 + tools/perf/ui/libslang.h | 2 ++ tools/perf/util/hist.h | 6 ------ 10 files changed, 17 insertions(+), 6 deletions(-)
tools/perf/builtin-annotate.c +8 -0
@@ -24,6 +24,7 @@#include "arch/common.h" #include "builtin.h" #include "perf.h" +#include "ui/keysyms.h" #include "ui/progress.h" #include "ui/ui.h" #include "util/annotate-data.h"
@@ -46,6 +47,13 @@#include "util/tool.h" #include "util/util.h" +#ifndef HAVE_SLANG_SUPPORT +#undef K_LEFT +#define K_LEFT -1000 +#undef K_RIGHT +#define K_RIGHT -2000 +#endif +struct perf_annotate {struct perf_tool tool;struct perf_session *session;
tools/perf/builtin-c2c.c +1 -0
@@ -49,6 +49,7 @@#include "thread.h" #include "tool.h" #include "ui/browsers/hists.h" +#include "ui/keysyms.h" #include "ui/progress.h" #include "ui/ui.h" #include "util/annotate.h"
tools/perf/builtin-kvm.c +1 -0
@@ -27,6 +27,7 @@#include "util/kvm-stat.h" #include "util/util.h" #include "ui/browsers/hists.h" +#include "ui/keysyms.h" #include "ui/progress.h" #include "ui/ui.h" #include "util/string2.h"
tools/perf/builtin-report.c +1 -0
@@ -51,6 +51,7 @@#include "util/units.h" #include "util/unwind.h" #include "util/util.h" // perf_tip() +#include "ui/keysyms.h" #include "ui/ui.h" #include "ui/progress.h" #include "util/block-info.h"
tools/perf/builtin-top.c +1 -0
@@ -51,6 +51,7 @@#include "util/intlist.h" #include "util/parse-branch-options.h" #include "arch/common.h" +#include "ui/keysyms.h" #include "ui/ui.h" #include "util/debug.h"
tools/perf/ui/browsers/annotate.c +1 -0
@@ -1,6 +1,7 @@// SPDX-License-Identifier: GPL-2.0 #include "../browser.h" #include "../helpline.h" +#include "../keysyms.h" #include "../ui.h" #include "../../util/annotate.h" #include "../../util/debug.h"
tools/perf/ui/browsers/hists.c +1 -0
@@ -35,6 +35,7 @@#include "../browsers/hists.h" #include "../helpline.h" +#include "../keysyms.h" #include "../util.h" #include "../ui.h" #include "map.h"
tools/perf/ui/browsers/scripts.c +1 -0
@@ -7,6 +7,7 @@#include "../../util/session.h" #include "../../util/symbol.h" #include "../browser.h" +#include "../keysyms.h" #include "../libslang.h" #include "config.h" #include <linux/err.h>
tools/perf/ui/libslang.h +2 -0
@@ -15,7 +15,9 @@#define ENABLE_SLFUTURE_CONST 1#define ENABLE_SLFUTURE_VOID 1 +#ifdef HAVE_SLANG_SUPPORT #include <slang.h> +#endif #define SL_KEY_UNTAB 0x1000
tools/perf/util/hist.h +0 -6
@@ -714,7 +714,6 @@ struct block_hist {#define NO_ADDR 0#ifdef HAVE_SLANG_SUPPORT -#include "../ui/keysyms.h" void attr_to_script (char *buf,struct perf_event_attr *attr); int __hist_entry__tui_annotate(struct hist_entry *he, struct map_symbol *ms,
@@ -787,11 +786,6 @@ static inline int block_hists_tui_browse(struct block_hist *bh __maybe_unused, {return 0 ; } - -#define K_LEFT -1000 -#define K_RIGHT -2000 -#define K_SWITCH_INPUT_DATA -3000 -#define K_RELOAD -4000#endif unsigned int hists__sort_list_width (struct hists *hists);
Signature · 1 line
2.55.0.966.g6673acef38-goog
[email protected]
AI reviewRe: [PATCH v3 6/6] perf hist: Remove keysym.h include from hist.h
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] Unconditional inclusion of glibc-specific `<features.h>` breaks musl builds. --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] Unconditional inclusion of glibc-specific <features.h> breaks musl builds. --
commit 7fe3edc4f61ded07ac7e2f802a9ada49f3daa101
Author: Ian Rogers <[email protected]>
perf hist: Remove keysym.h include from hist.h
This commit removes the keysym.h inclusion from hist.h since it isn't related to the UI. It also addresses the transitive dependency issues by directly including ui/keysyms.h in several core and UI files.
tools/perf/builtin-annotate.c line 27
Quoted 9 lines
tools/perf/builtin-annotate.c +1
-0@@ -24,6 +24,7 @@#include "arch/common.h" #include "builtin.h" #include "perf.h" +#include "ui/keysyms.h"
[Severity: Low]
Does this unconditional inclusion of "ui/keysyms.h" introduce a build regression on musl libc systems when slang support is disabled?
Previously, "ui/keysyms.h" was guarded by #ifdef HAVE_SLANG_SUPPORT inside hist.h. By including it unconditionally here, it pulls in tools/perf/ui/libslang.h for all builds.
That header contains an unconditional inclusion of the glibc-specific <features.h> header:
tools/perf/ui/libslang.h:
...
#include <features.h>
#ifndef HAVE_LONG_LONG
#define HAVE_LONG_LONG __GLIBC_HAVE_LONG_LONG
#endif
...
Since musl libc systems do not provide <features.h>, can this cause the build to fail if slang is disabled?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
Quoted 8 lines · Ian Rogers
In doing some work on bazel building of perf (bazel being stricter on how header files are used), rather than just making the bazel BUILD files more generous in how they accept header file issues like transitive dependencies it felt cleaner to address them. These patches tackle the most severe issues such as
cache.hpulling in UI code,hist.hbringing in UI code, unused header files, transitive dependencies, etc.
Quoted 6 lines
While cleaning up the dependencies in
perf.c, change how missing commands are handled to give a more meaningful error message at run time about missing build time dependencies.v1 and v2 were previously sent just addressing the
cache.hissue:
https://lore.kernel.org/linux-perf-users/[email protected]/
Thanks, applied to perf-tools-next, for v7.4.
- Arnaldo