lkml.org 
[lkml]   [2016]   [Jun]   [29]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH v2 4/4] perf annotate: Define macro for arch names
Date
Define macro for each arch name and use them instead of using arch
name as string.

Signed-off-by: Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com>
---
Changes in v2:
- No changes

tools/perf/arch/common.c | 36 ++++++++++++++++++------------------
tools/perf/arch/common.h | 11 +++++++++++
tools/perf/util/annotate.c | 10 +++++-----
tools/perf/util/unwind-libunwind.c | 4 ++--
4 files changed, 36 insertions(+), 25 deletions(-)

diff --git a/tools/perf/arch/common.c b/tools/perf/arch/common.c
index ee69668..feb2113 100644
--- a/tools/perf/arch/common.c
+++ b/tools/perf/arch/common.c
@@ -122,25 +122,25 @@ static int lookup_triplets(const char *const *triplets, const char *name)
const char *normalize_arch(char *arch)
{
if (!strcmp(arch, "x86_64"))
- return "x86";
+ return NORM_X86;
if (arch[0] == 'i' && arch[2] == '8' && arch[3] == '6')
- return "x86";
+ return NORM_X86;
if (!strcmp(arch, "sun4u") || !strncmp(arch, "sparc", 5))
- return "sparc";
+ return NORM_SPARC;
if (!strcmp(arch, "aarch64") || !strcmp(arch, "arm64"))
- return "arm64";
+ return NORM_ARM64;
if (!strncmp(arch, "arm", 3) || !strcmp(arch, "sa110"))
- return "arm";
+ return NORM_ARM;
if (!strncmp(arch, "s390", 4))
- return "s390";
+ return NORM_S390;
if (!strncmp(arch, "parisc", 6))
- return "parisc";
+ return NORM_PARISC;
if (!strncmp(arch, "powerpc", 7) || !strncmp(arch, "ppc", 3))
- return "powerpc";
+ return NORM_POWERPC;
if (!strncmp(arch, "mips", 4))
- return "mips";
+ return NORM_MIPS;
if (!strncmp(arch, "sh", 2) && isdigit(arch[2]))
- return "sh";
+ return NORM_SH;

return arch;
}
@@ -180,21 +180,21 @@ static int perf_env__lookup_binutils_path(struct perf_env *env,
zfree(&buf);
}

- if (!strcmp(arch, "arm"))
+ if (!strcmp(arch, NORM_ARM))
path_list = arm_triplets;
- else if (!strcmp(arch, "arm64"))
+ else if (!strcmp(arch, NORM_ARM64))
path_list = arm64_triplets;
- else if (!strcmp(arch, "powerpc"))
+ else if (!strcmp(arch, NORM_POWERPC))
path_list = powerpc_triplets;
- else if (!strcmp(arch, "sh"))
+ else if (!strcmp(arch, NORM_SH))
path_list = sh_triplets;
- else if (!strcmp(arch, "s390"))
+ else if (!strcmp(arch, NORM_S390))
path_list = s390_triplets;
- else if (!strcmp(arch, "sparc"))
+ else if (!strcmp(arch, NORM_SPARC))
path_list = sparc_triplets;
- else if (!strcmp(arch, "x86"))
+ else if (!strcmp(arch, NORM_X86))
path_list = x86_triplets;
- else if (!strcmp(arch, "mips"))
+ else if (!strcmp(arch, NORM_MIPS))
path_list = mips_triplets;
else {
ui__error("binutils for %s not supported.\n", arch);
diff --git a/tools/perf/arch/common.h b/tools/perf/arch/common.h
index 6b01c73..14ca8ca 100644
--- a/tools/perf/arch/common.h
+++ b/tools/perf/arch/common.h
@@ -5,6 +5,17 @@

extern const char *objdump_path;

+/* Macro for normalized arch names */
+#define NORM_X86 "x86"
+#define NORM_SPARC "sparc"
+#define NORM_ARM64 "arm64"
+#define NORM_ARM "arm"
+#define NORM_S390 "s390"
+#define NORM_PARISC "parisc"
+#define NORM_POWERPC "powerpc"
+#define NORM_MIPS "mips"
+#define NORM_SH "sh"
+
int perf_env__lookup_objdump(struct perf_env *env);
const char *normalize_arch(char *arch);

diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 812bfad..8c27486 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -68,7 +68,7 @@ static int call__parse(struct ins_operands *ops,

name++;

- if (!strcmp(norm_arch, "arm") && strchr(name, '+'))
+ if (!strcmp(norm_arch, NORM_ARM) && strchr(name, '+'))
return -1;

tok = strchr(name, '>');
@@ -255,7 +255,7 @@ static int mov__parse(struct ins_operands *ops,

target = ++s;

- if (!strcmp(norm_arch, "arm"))
+ if (!strcmp(norm_arch, NORM_ARM))
comment = strchr(s, ';');
else
comment = strchr(s, '#');
@@ -624,13 +624,13 @@ static struct ins *ins__find(const char *name, const char *norm_arch)
sorted = true;
}

- if (!strcmp(norm_arch, "x86")) {
+ if (!strcmp(norm_arch, NORM_X86)) {
instructions = instructions_x86;
nmemb = ARRAY_SIZE(instructions_x86);
- } else if (!strcmp(norm_arch, "arm")) {
+ } else if (!strcmp(norm_arch, NORM_ARM)) {
instructions = instructions_arm;
nmemb = ARRAY_SIZE(instructions_arm);
- } else if (!strcmp(norm_arch, "powerpc")) {
+ } else if (!strcmp(norm_arch, NORM_POWERPC)) {
return ins__find_powerpc(name);
} else {
pr_err("perf annotate not supported by %s arch\n", norm_arch);
diff --git a/tools/perf/util/unwind-libunwind.c b/tools/perf/util/unwind-libunwind.c
index 8547119..8d4a53f 100644
--- a/tools/perf/util/unwind-libunwind.c
+++ b/tools/perf/util/unwind-libunwind.c
@@ -36,10 +36,10 @@ int unwind__prepare_access(struct thread *thread, struct map *map)

arch = normalize_arch(thread->mg->machine->env->arch);

- if (!strcmp(arch, "x86")) {
+ if (!strcmp(arch, NORM_X86)) {
if (dso_type != DSO__TYPE_64BIT)
ops = x86_32_unwind_libunwind_ops;
- } else if (!strcmp(arch, "arm64") || !strcmp(arch, "arm")) {
+ } else if (!strcmp(arch, NORM_ARM64) || !strcmp(arch, NORM_ARM)) {
if (dso_type == DSO__TYPE_64BIT)
ops = arm64_unwind_libunwind_ops;
}
--
2.5.5
\
 
 \ /
  Last update: 2016-06-29 14:01    [W:0.050 / U:1.164 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site