perf tool: Minor code clean ups
Ian Rogers
reviewercover perf tool: Minor code clean ups
Remove some unused functions, files, etc. Reduce scope of variables and functions. Constify arrays in perf.c.
Ian Rogers (5):
perf symbol: Reduce scope of elf__needs_adjust_symbols perf dump-insn: Remove dump-insn.c
perf tool: Constify the command and option arrays perf bpf_map: Remove unused code
perf record: Remove unused cpu-set-sched.h
tools/perf/builtin-record.c | 1 - tools/perf/builtin-trace.c | 1 - tools/perf/perf.c | 12 +++--- tools/perf/util/Build | 2 - tools/perf/util/bpf_map.c | 70 --------------------------------- tools/perf/util/bpf_map.h | 23 ----------- tools/perf/util/cpu-set-sched.h | 50 ----------------------- tools/perf/util/dump-insn.c | 23 ----------- tools/perf/util/symbol-elf.c | 8 ++-- tools/perf/util/symbol.h | 1 - 10 files changed, 10 insertions(+), 181 deletions(-) delete mode 100644 tools/perf/util/bpf_map.c delete mode 100644 tools/perf/util/bpf_map.h delete mode 100644 tools/perf/util/cpu-set-sched.h delete mode 100644 tools/perf/util/dump-insn.c
Signature · 1 line
2.53.0.239.g8d8fc8a987-goog
Ian Rogers
reviewerPATCH 1/5 perf symbol: Reduce scope of elf__needs_adjust_symbols
Function is only used by symsrc__init in symbol-elf.c, make static to reduce scope. Switch to not passing the argument by value but as a pointer.
--- tools/perf/util/symbol-elf.c | 8 ++++---- tools/perf/util/symbol.h | 1 - 2 files changed, 4 insertions(+), 5 deletions(-)
tools/perf/util/symbol-elf.c +4 -4
@@ -1054,15 +1054,15 @@ void symsrc__destroy(struct symsrc *ss)close (ss->fd); } -bool elf__needs_adjust_symbols (GElf_Ehdr ehdr) +static bool elf__needs_adjust_symbols (const GElf_Ehdr *ehdr) {/* * Usually vmlinux is an ELF file with type ET_EXEC for most * architectures; except Arm64 kernel is linked with option * '-share', so need to check type ET_DYN. */ -return ehdr.e_type ==ET_EXEC || ehdr.e_type ==ET_REL || - ehdr.e_type ==ET_DYN ; +return ehdr->e_type ==ET_EXEC || ehdr->e_type ==ET_REL || + ehdr->e_type ==ET_DYN ; }static Elf *read_gnu_debugdata (struct dso *dso,Elf *elf,const char *name,int *fd_ret)
@@ -1235,7 +1235,7 @@ int symsrc__init(struct symsrc *ss, struct dso *dso, const char *name,if (dso__kernel (dso) ==DSO_SPACE__USER ) ss->adjust_symbols = true;else - ss->adjust_symbols =elf__needs_adjust_symbols (ehdr); + ss->adjust_symbols =elf__needs_adjust_symbols (&ehdr); ss->name =strdup (name);if (!ss->name) {
tools/perf/util/symbol.h +0 -1
@@ -217,7 +217,6 @@ int setup_intlist(struct intlist **list, const char *list_str, const char *list_name);#ifdef HAVE_LIBELF_SUPPORT -bool elf__needs_adjust_symbols (GElf_Ehdr ehdr);void arch__sym_update (struct symbol *s,GElf_Sym *sym);#endif
Signature · 1 line
2.53.0.239.g8d8fc8a987-goog
Ian Rogers
reviewerPATCH 2/5 perf dump-insn: Remove dump-insn.c
In reply to Ian Rogersdump_insn and arch_is_uncond_branch are declared in intel-pt-insn-decoder.c which is unconditionally part of all perf builds. Don't declare weak versions of these symbols that will be unused.
--- tools/perf/util/Build | 1 - tools/perf/util/dump-insn.c | 23 ----------------------- 2 files changed, 24 deletions(-) delete mode 100644 tools/perf/util/dump-insn.c
tools/perf/util/Build +0 -1
@@ -149,7 +149,6 @@ endif perf-util-y += cs-etm-base.o perf-util-y += parse-branch-options.o -perf-util-y += dump-insn.o perf-util-y += parse-regs-options.o perf-util-y += parse-sublevel-options.o perf-util-y += term.o
tools/perf/util/dump-insn.c deleted +0 -23
@@ -1,23 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -#include <linux/compiler.h> -#include "dump-insn.h" - -/* Fallback code */ - -__weak -const char *dump_insn (struct perf_insn *x__maybe_unused , -u64 ip__maybe_unused ,u8 *inbuf__maybe_unused , -int inlen__maybe_unused ,int *lenp) -{ -if (lenp) - *lenp =0 ; -return "?" ; -} - -__weak -int arch_is_uncond_branch (const unsigned char *buf__maybe_unused , -size_t len__maybe_unused , -int x86_64__maybe_unused ) -{ -return 0 ; -}
Signature · 1 line
2.53.0.239.g8d8fc8a987-goog
Ian Rogers
reviewerPATCH 3/5 perf tool: Constify the command and option arrays
In reply to Ian RogersReduce scope and capture immutability.
--- tools/perf/perf.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
tools/perf/perf.c +6 -6
@@ -48,7 +48,7 @@ struct cmd_struct {int option; }; -static struct cmd_struct commands[] = { +static const struct cmd_struct commands[] = { {"archive" ,NULL ,0 }, {"buildid-cache" , cmd_buildid_cache,0 }, {"buildid-list" , cmd_buildid_list,0 },
@@ -178,7 +178,7 @@ static int set_debug_file(const char *path)return 0 ; } -struct option options[] = { +static const struct option options[] = {OPT_ARGUMENT ("help" ,"help" ),OPT_ARGUMENT ("version" ,"version" ),OPT_ARGUMENT ("exec-path" ,"exec-path" ),
@@ -280,7 +280,7 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)unsigned int i;for (i =0 ; i <ARRAY_SIZE (commands); i++) { -struct cmd_struct *p = commands+i; +const struct cmd_struct *p = commands + i;printf ("%s " , p->cmd); }putchar ('\n' );
@@ -289,7 +289,7 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)unsigned int i;for (i =0 ; i <ARRAY_SIZE (options)-1 ; i++) { -struct option *p = options+i; +const struct option *p = options + i;printf ("--%s " , p->long_name); }putchar ('\n' );
@@ -331,7 +331,7 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)#define RUN_SETUP (1<<0)#define USE_PAGER (1<<1) -static int run_builtin (struct cmd_struct *p,int argc,const char **argv) +static int run_builtin (const struct cmd_struct *p,int argc,const char **argv) {int status;struct stat st;
@@ -390,7 +390,7 @@ static void handle_internal_command(int argc, const char **argv) }for (i =0 ; i <ARRAY_SIZE (commands); i++) { -struct cmd_struct *p = commands+i; +const struct cmd_struct *p = commands+i;if (p->fn ==NULL )continue ;if (strcmp (p->cmd, cmd))
Signature · 1 line
2.53.0.239.g8d8fc8a987-goog
Ian Rogers
reviewerPATCH 4/5 perf bpf_map: Remove unused code
In reply to Ian Rogersbpf_map__fprintf is unused so delete it, the header file declaring it and the now unused static helper functions.
--- tools/perf/builtin-trace.c | 1 - tools/perf/util/Build | 1 - tools/perf/util/bpf_map.c | 70 -------------------------------------- tools/perf/util/bpf_map.h | 23 ------------- 4 files changed, 95 deletions(-) delete mode 100644 tools/perf/util/bpf_map.c delete mode 100644 tools/perf/util/bpf_map.h
tools/perf/builtin-trace.c +0 -1
@@ -21,7 +21,6 @@#include <bpf/libbpf.h> #include <bpf/btf.h> #endif -#include "util/bpf_map.h" #include "util/rlimit.h" #include "builtin.h" #include "util/cgroup.h"
tools/perf/util/Build +0 -1
@@ -170,7 +170,6 @@ perf-util-y += mutex.o perf-util-y += sharded_mutex.o perf-util-y += intel-tpebs.o -perf-util-$(CONFIG_LIBBPF) += bpf_map.o perf-util-$(CONFIG_PERF_BPF_SKEL) += bpf_counter.o perf-util-$(CONFIG_PERF_BPF_SKEL) += bpf_counter_cgroup.o perf-util-$(CONFIG_PERF_BPF_SKEL) += bpf_ftrace.o
tools/perf/util/bpf_map.c deleted +0 -70
70 lines not on this page · raw message
tools/perf/util/bpf_map.h deleted +0 -23
@@ -1,23 +0,0 @@ -// SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) -#ifndef __PERF_BPF_MAP_H -#define __PERF_BPF_MAP_H 1 - -#include <stdio.h> -struct bpf_map ; - -#ifdef HAVE_LIBBPF_SUPPORT - -int bpf_map__fprintf (struct bpf_map *map,FILE *fp); - -#else - -#include <linux/compiler.h> - -static inline int bpf_map__fprintf (struct bpf_map *map__maybe_unused ,FILE *fp__maybe_unused ) -{ -return 0 ; -} - -#endif // HAVE_LIBBPF_SUPPORT - -#endif // __PERF_BPF_MAP_H
Signature · 1 line
2.53.0.239.g8d8fc8a987-goog
Ian Rogers
reviewerPATCH 5/5 perf record: Remove unused cpu-set-sched.h
In reply to Ian RogersHeader file declares unused macros, so remove.
--- tools/perf/builtin-record.c | 1 - tools/perf/util/cpu-set-sched.h | 50 --------------------------------- 2 files changed, 51 deletions(-) delete mode 100644 tools/perf/util/cpu-set-sched.h
tools/perf/builtin-record.c +0 -1
@@ -40,7 +40,6 @@#include "util/perf_api_probe.h" #include "util/trigger.h" #include "util/perf-hooks.h" -#include "util/cpu-set-sched.h" #include "util/synthetic-events.h" #include "util/time-utils.h" #include "util/units.h"
tools/perf/util/cpu-set-sched.h deleted +0 -50
50 lines not on this page · raw message
Signature · 1 line
2.53.0.239.g8d8fc8a987-goog
Ian Rogers
reviewerQuoted 10 lines · Ian Rogers
Remove some unused functions, files, etc. Reduce scope of variables and functions. Constify arrays in
perf.c.Ian Rogers (5):
perf symbol: Reduce scope ofelf__needs_adjust_symbolsperf dump-insn: Removedump-insn.c
perf tool: Constify the command and option arrays perfbpf_map: Remove unused code
perf record: Remove unusedcpu-set-sched.h
Ping.
Thanks,
Ian
Quoted 19 lines
tools/perf/builtin-record.c | 1 - tools/perf/builtin-trace.c | 1 - tools/perf/perf.c | 12 +++--- tools/perf/util/Build | 2 - tools/perf/util/bpf_map.c | 70 --------------------------------- tools/perf/util/bpf_map.h | 23 ----------- tools/perf/util/cpu-set-sched.h | 50 ----------------------- tools/perf/util/dump-insn.c | 23 ----------- tools/perf/util/symbol-elf.c | 8 ++-- tools/perf/util/symbol.h | 1 - 10 files changed, 10 insertions(+), 181 deletions(-) delete mode 100644 tools/perf/util/bpf_map.c delete mode 100644 tools/perf/util/bpf_map.h delete mode 100644 tools/perf/util/cpu-set-sched.h delete mode 100644 tools/perf/util/dump-insn.c--
2.53.0.239.g8d8fc8a987-goog
Namhyung Kim
maintainerQuoted 11 lines · Ian Rogers
Quoted 10 lines · Ian Rogers
Remove some unused functions, files, etc. Reduce scope of variables and functions. Constify arrays in
perf.c.Ian Rogers (5):
perf symbol: Reduce scope ofelf__needs_adjust_symbolsperf dump-insn: Removedump-insn.c
perf tool: Constify the command and option arrays perfbpf_map: Remove unused code
perf record: Remove unusedcpu-set-sched.h
Sorry for the delay. Looks fine to me.
I'll test and process them soon.
Thanks,
Namhyung
Quoted 19 lines
Quoted 19 lines
tools/perf/builtin-record.c | 1 - tools/perf/builtin-trace.c | 1 - tools/perf/perf.c | 12 +++--- tools/perf/util/Build | 2 - tools/perf/util/bpf_map.c | 70 --------------------------------- tools/perf/util/bpf_map.h | 23 ----------- tools/perf/util/cpu-set-sched.h | 50 ----------------------- tools/perf/util/dump-insn.c | 23 ----------- tools/perf/util/symbol-elf.c | 8 ++-- tools/perf/util/symbol.h | 1 - 10 files changed, 10 insertions(+), 181 deletions(-) delete mode 100644 tools/perf/util/bpf_map.c delete mode 100644 tools/perf/util/bpf_map.h delete mode 100644 tools/perf/util/cpu-set-sched.h delete mode 100644 tools/perf/util/dump-insn.c--
2.53.0.239.g8d8fc8a987-goog
Quoted 13 lines · Namhyung Kim
Quoted 11 lines · Ian Rogers
Quoted 10 lines · Ian Rogers
Remove some unused functions, files, etc. Reduce scope of variables and functions. Constify arrays in
perf.c.Ian Rogers (5):
perf symbol: Reduce scope ofelf__needs_adjust_symbolsperf dump-insn: Removedump-insn.c
perf tool: Constify the command and option arrays perfbpf_map: Remove unused code
perf record: Remove unusedcpu-set-sched.h
Quoted 3 lines
Sorry for the delay. Looks fine to me.
I'll test and process them soon.
Applied to perf-tools-next, thanks!
Best regards,
Namhyung