Skip to contentSkip to conversation

perf tool: Remove util/cache.h

PATCH Superseded Ian Rogers 2 participants 8 messages Aug 28 – Aug 31 perf events

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Ian Rogers

author reviewer
#0 lore raw

PATCH 1/2 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      |  2 +-
 tools/perf/builtin-config.c        |  2 +-
 tools/perf/builtin-help.c          |  2 +-
 tools/perf/perf.c                  |  8 +++++++-
 tools/perf/util/cache.h            | 31 ------------------------------
 tools/perf/util/config.c           |  2 +-
 tools/perf/util/help-unknown-cmd.c |  6 +++++-
 tools/perf/util/path.c             |  1 -
 tools/perf/util/path.h             |  3 +++
 tools/perf/util/strbuf.c           |  4 +++-
 10 files changed, 22 insertions(+), 39 deletions(-)
 delete mode 100644 tools/perf/util/cache.h
tools/perf/builtin-annotate.c +1 -1
index 69cb72b2082a..3efeb845099c 100644
@@ -11,7 +11,6 @@
 
 #include "util/color.h"
 #include <linux/list.h>
-#include "util/cache.h"
 #include <linux/rbtree.h>
 #include "util/symbol.h"
 
@@ -38,6 +37,7 @@
 #include "util/branch.h"
 #include "util/util.h"
 #include "ui/progress.h"
+#include "ui/ui.h"
 
 #include <dlfcn.h>
 #include <errno.h>
tools/perf/builtin-config.c +1 -1
index 237600643bbd..f4f916241d1d 100644
@@ -7,10 +7,10 @@
  */
 #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>
tools/perf/builtin-help.c +1 -1
index 2692b2e40a23..36f5c5e94289 100644
@@ -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>
tools/perf/perf.c +7 -1
index 1f51e8de6b1b..ad8c8067b765 100644
@@ -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"
@@ -39,6 +39,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
deleted file mode 100644
index 0b61840d4226..000000000000
@@ -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 +1 -1
index 7988149dc7ed..6a310e56a2f1 100644
@@ -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"
tools/perf/util/help-unknown-cmd.c +5 -1
index a0a46e34f8d1..f1cd9d4746f3 100644
@@ -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 +0 -1
index 2e62f272fda8..bf5d081707e4 100644
@@ -1,6 +1,5 @@
 // SPDX-License-Identifier: GPL-2.0
 #include "path.h"
-#include "cache.h"
 #include <linux/kernel.h>
 #include <limits.h>
 #include <stdio.h>
tools/perf/util/path.h +3 -0
index fb850fb55c60..e7cdb0cb1097 100644
@@ -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 +3 -1
index a64a37628f12..7b94aa1e5ade 100644
@@ -1,5 +1,4 @@
 // SPDX-License-Identifier: GPL-2.0
-#include "cache.h"
 #include "debug.h"
 #include "strbuf.h"
 #include <linux/kernel.h>
@@ -54,9 +53,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.897.gb25b4bd76c-goog
author reviewer
#1 lore raw

PATCH 2/2 perf tool: Sort headers from previous cache.h removal

Use git clang-format to sort headers.

---
 tools/perf/builtin-annotate.c      | 49 +++++++++++++++---------------
 tools/perf/builtin-config.c        | 14 +++++----
 tools/perf/builtin-help.c          | 31 ++++++++++---------
 tools/perf/perf.c                  | 49 ++++++++++++++++--------------
 tools/perf/util/config.c           | 34 ++++++++++++---------
 tools/perf/util/help-unknown-cmd.c |  9 ++++--
 tools/perf/util/path.c             |  8 +++--
 tools/perf/util/path.h             |  3 +-
 8 files changed, 107 insertions(+), 90 deletions(-)
tools/perf/builtin-annotate.c +24 -25
index 3efeb845099c..fbdcfae858e2 100644
@@ -6,44 +6,43 @@
  * 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 "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/color.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/parse-events.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>
 
 struct perf_annotate {
 	struct perf_tool tool;
tools/perf/builtin-config.c +8 -6
index f4f916241d1d..1ee5461436b6 100644
@@ -5,16 +5,18 @@
  * Copyright (C) 2015, Taeung Song <[email protected]>
  *
  */
-#include "builtin.h"
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <linux/string.h>
 
 #include <subcmd/parse-options.h>
-#include "util/debug.h"
+
+#include "builtin.h"
 #include "util/config.h"
+#include "util/debug.h"
 #include "util/path.h"
-#include <linux/string.h>
-#include <limits.h>
-#include <stdio.h>
-#include <stdlib.h>
 
 static bool use_system_config, use_user_config;
 
tools/perf/builtin-help.c +17 -14
index 36f5c5e94289..676a0bb63b24 100644
@@ -4,28 +4,31 @@
  *
  * 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 <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <sys/types.h>
+
+#include <linux/kernel.h>
+#include <linux/string.h>
+#include <linux/zalloc.h>
 #include <sys/stat.h>
+#include <sys/types.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 +26 -23

64 lines not on this page · raw message

tools/perf/util/config.c +19 -15
index 6a310e56a2f1..a748c9fd629e 100644
@@ -9,28 +9,32 @@
  * Copyright (C) Johannes Schindelin, 2005
  *
  */
+#include "config.h"
+
 #include <errno.h>
+#include <stdlib.h>
+
+#include <linux/ctype.h>
+#include <linux/string.h>
+#include <linux/zalloc.h>
 #include <sys/param.h>
+#include <sys/stat.h>
+#include <sys/types.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 <stdlib.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
index f1cd9d4746f3..64dbe6e514f5 100644
@@ -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 +5 -3
index bf5d081707e4..7e85bbd8f751 100644
@@ -1,12 +1,14 @@
 // SPDX-License-Identifier: GPL-2.0
 #include "path.h"
-#include <linux/kernel.h>
+
 #include <limits.h>
 #include <stdio.h>
 #include <string.h>
-#include <sys/types.h>
-#include <sys/stat.h>
+
 #include <dirent.h>
+#include <linux/kernel.h>
+#include <sys/stat.h>
+#include <sys/types.h>
 #include <unistd.h>
 
 static char *cleanup_path(char *path)
tools/perf/util/path.h +2 -1
index e7cdb0cb1097..62e86d390589 100644
@@ -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;
Signature · 1 line
2.55.0.897.gb25b4bd76c-goog
#2 lore raw

Re: [PATCH v1 2/2] perf tool: Sort headers from previous cache.h removal

Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 3 lines

Use git clang-format to sort headers.

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
#3 lore raw
In reply to Ian Rogers
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] Removal of `util/cache.h` removes implicit inclusions of standard POSIX headers, causing musl…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] Removal of util/cache.h removes implicit inclusions of standard POSIX headers, causing musl compatibility violations due to missing explicit includes. --

commit 6e76c8b7f671374f4e87596d7f1af0426551795a
Author: Ian Rogers <[email protected]>

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 line 15

Quoted 10 lines
tools/perf/builtin-annotate.c +0 -1
@@ -11,7 +11,6 @@
 
 #include "util/color.h"
 #include <linux/list.h>
-#include "util/cache.h"
 #include <linux/rbtree.h>
 #include "util/symbol.h"

[Severity: Low]
Does the removal of util/cache.h drop implicit inclusions of standard POSIX headers? This file uses standard string and allocation functions, so it seems <string.h> and <stdlib.h> need to be explicitly included to avoid build failures on systems using musl libc.

[ ... ]

tools/perf/util/path.c line 4

Quoted 9 lines
tools/perf/util/path.c +0 -1
@@ -1,6 +1,5 @@
 // SPDX-License-Identifier: GPL-2.0
 #include "path.h"
-#include "cache.h"
 #include <linux/kernel.h>
 #include <limits.h>

[Severity: Low]
With cache.h removed, does mkpath() now lack the required <stdarg.h> include? Looking at mkpath() later in this file, it relies on va_start(args, fmt) which requires <stdarg.h>. Without the explicit include, this causes musl compatibility violations.

[ ... ]

tools/perf/util/strbuf.c line 3

Quoted 8 lines
tools/perf/util/strbuf.c +0 -1
@@ -1,5 +1,4 @@
 // SPDX-License-Identifier: GPL-2.0
-#include "cache.h"
 #include "debug.h"
 #include "strbuf.h"

[Severity: Low]
Should <string.h> be explicitly included here? Looking at strbuf_add(), it uses memcpy(), and relying on <linux/string.h> instead of the standard POSIX header can cause namespace pollution and musl compilation failures.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
author reviewer
#4 lore raw

PATCH v2 1/2 perf tool: Remove util/cache.h

In reply to Ian Rogers

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
index 69cb72b2082a..75cbea567196 100644
@@ -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
index 237600643bbd..845a8af67fc5 100644
@@ -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
index 2692b2e40a23..f0e95d741892 100644
@@ -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
index 1f51e8de6b1b..8ad01a78fdd5 100644
@@ -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
deleted file mode 100644
index 0b61840d4226..000000000000
@@ -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
index 7988149dc7ed..5b696139f655 100644
@@ -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
index a0a46e34f8d1..f1cd9d4746f3 100644
@@ -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
index 2e62f272fda8..5ba7861a3e65 100644
@@ -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
index fb850fb55c60..e7cdb0cb1097 100644
@@ -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
index a64a37628f12..df3f9c4123fd 100644
@@ -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.897.gb25b4bd76c-goog
author reviewer
#5 lore raw

PATCH v2 2/2 perf tool: Tidy up util/cache.h header file users

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.

Assisted-by Antigravity:gemini-3.1-pro
---
 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
index 75cbea567196..f208ff513238 100644
@@ -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
index 845a8af67fc5..cefd042e4f85 100644
@@ -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
index f0e95d741892..5bbdb4d9b9c0 100644
@@ -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
index 5b696139f655..b2972c35c1ec 100644
@@ -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
index f1cd9d4746f3..64dbe6e514f5 100644
@@ -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
index 5ba7861a3e65..b7592e16718d 100644
@@ -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
index e7cdb0cb1097..62e86d390589 100644
@@ -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
index df3f9c4123fd..4080bc02a533 100644
@@ -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.897.gb25b4bd76c-goog
#6 lore raw

Re: [PATCH v2 2/2] 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.

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
#7 lore raw
In reply to Ian Rogers
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 5 lines

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.

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