Skip to content

Commit dbbd34a

Browse files
ahunter6acmel
authored andcommitted
perf machine: Add machine__is() to identify machine arch
Add a function to identify the machine architecture. Signed-off-by: Adrian Hunter <[email protected]> Tested-by: Jiri Olsa <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Andi Kleen <[email protected]> Cc: Andy Lutomirski <[email protected]> Cc: Dave Hansen <[email protected]> Cc: H. Peter Anvin <[email protected]> Cc: Joerg Roedel <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: [email protected] Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent cfc4033 commit dbbd34a

File tree

4 files changed

+31
-0
lines changed

4 files changed

+31
-0
lines changed

tools/perf/util/env.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,24 @@ int perf_env__read_cpu_topology_map(struct perf_env *env)
9393
return 0;
9494
}
9595

96+
static int perf_env__read_arch(struct perf_env *env)
97+
{
98+
struct utsname uts;
99+
100+
if (env->arch)
101+
return 0;
102+
103+
if (!uname(&uts))
104+
env->arch = strdup(uts.machine);
105+
106+
return env->arch ? 0 : -ENOMEM;
107+
}
108+
109+
const char *perf_env__raw_arch(struct perf_env *env)
110+
{
111+
return env && !perf_env__read_arch(env) ? env->arch : "unknown";
112+
}
113+
96114
void cpu_cache_level__free(struct cpu_cache_level *cache)
97115
{
98116
free(cache->type);

tools/perf/util/env.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,6 @@ int perf_env__read_cpu_topology_map(struct perf_env *env);
7676
void cpu_cache_level__free(struct cpu_cache_level *cache);
7777

7878
const char *perf_env__arch(struct perf_env *env);
79+
const char *perf_env__raw_arch(struct perf_env *env);
80+
7981
#endif /* __PERF_ENV_H */

tools/perf/util/machine.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2296,6 +2296,15 @@ int machine__set_current_tid(struct machine *machine, int cpu, pid_t pid,
22962296
return 0;
22972297
}
22982298

2299+
/*
2300+
* Compares the raw arch string. N.B. see instead perf_env__arch() if a
2301+
* normalized arch is needed.
2302+
*/
2303+
bool machine__is(struct machine *machine, const char *arch)
2304+
{
2305+
return machine && !strcmp(perf_env__raw_arch(machine->env), arch);
2306+
}
2307+
22992308
int machine__get_kernel_start(struct machine *machine)
23002309
{
23012310
struct map *map = machine__kernel_map(machine);

tools/perf/util/machine.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ static inline bool machine__is_host(struct machine *machine)
188188
return machine ? machine->pid == HOST_KERNEL_ID : false;
189189
}
190190

191+
bool machine__is(struct machine *machine, const char *arch);
192+
191193
struct thread *__machine__findnew_thread(struct machine *machine, pid_t pid, pid_t tid);
192194
struct thread *machine__findnew_thread(struct machine *machine, pid_t pid, pid_t tid);
193195

0 commit comments

Comments
 (0)