Re: [PATCH V3 3/5] perf,tools: Dump per-sample freq/CPU%/CORE_BUSY% in report -D

From: Jiri Olsa
Date: Wed Jul 29 2015 - 09:36:08 EST


On Tue, Jul 28, 2015 at 07:29:33AM -0400, kan.liang@xxxxxxxxx wrote:

SNIP

>
> static void event_swap(union perf_event *event, bool sample_id_all)
> diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h
> index b44afc7..e6e408b 100644
> --- a/tools/perf/util/session.h
> +++ b/tools/perf/util/session.h
> @@ -42,6 +42,53 @@ struct perf_session {
> #define PRINT_IP_OPT_ONELINE (1<<4)
> #define PRINT_IP_OPT_SRCLINE (1<<5)
>
> +#define PERF_MSR_TSC 0
> +#define PERF_MSR_APERF 1
> +#define PERF_MSR_MPERF 2
> +
> +enum perf_freq_perf_index {
> + FREQ_PERF_TSC = 0,
> + FREQ_PERF_APERF = 1,
> + FREQ_PERF_MPERF = 2,
> + FREQ_PERF_CYCLES = 3,
> + FREQ_PERF_REF_CYCLES = 4,
> +
> + FREQ_PERF_MAX
> +};

hum, rather than adding macros over anonymous array,
how about add perf_freq_t like:

typedef int perf_freq_t[FREQ_PERF_MAX];

and turn macros below into functions like:

SET_FREQ_PERF_VALUE perf_freq__init
HAS_FREQ perf_freq__has_freq
GET_FREQ perf_freq__get_freq
HAS_CPU_UTIL perf_freq__has_cpu_util
GET_CPU_UTIL perf_freq__get_cpu_util
HAS_CORE_BUSY perf_freq__has_core_busy
GET_CORE_BUSY perf_freq__get_core_busy

jirka

> +
> +#define SET_FREQ_PERF_VALUE(msr_pmu_type, event, array, value) \
> +{ \
> + if (event->attr.type == msr_pmu_type) { \
> + if (event->attr.config == PERF_MSR_TSC) \
> + array[FREQ_PERF_TSC] = value; \
> + if (event->attr.config == PERF_MSR_APERF) \
> + array[FREQ_PERF_APERF] = value; \
> + if (event->attr.config == PERF_MSR_MPERF) \
> + array[FREQ_PERF_MPERF] = value; \
> + } \
> + if (event->attr.type == PERF_TYPE_HARDWARE) { \
> + if (event->attr.config == PERF_COUNT_HW_CPU_CYCLES) \
> + array[FREQ_PERF_CYCLES] = value; \
> + if (event->attr.config == PERF_COUNT_HW_REF_CPU_CYCLES) \
> + array[FREQ_PERF_REF_CYCLES] = value; \
> + } \
> +}
> +
> +#define HAS_FREQ(array) \
> + ((array[FREQ_PERF_CYCLES] > 0) && (array[FREQ_PERF_REF_CYCLES] > 0))
> +#define GET_FREQ(array, cpu_max_freq) \
> + ((array[FREQ_PERF_CYCLES] * cpu_max_freq) / array[FREQ_PERF_REF_CYCLES])
> +
> +#define HAS_CPU_UTIL(array) \
> + ((array[FREQ_PERF_TSC] > 0) && (array[FREQ_PERF_REF_CYCLES] > 0))
> +#define GET_CPU_UTIL(array) \
> + ((100 * array[FREQ_PERF_REF_CYCLES]) / array[FREQ_PERF_TSC])
> +
> +#define HAS_CORE_BUSY(array) \
> + ((array[FREQ_PERF_APERF] > 0) && (array[FREQ_PERF_MPERF] > 0))
> +#define GET_CORE_BUSY(array) \
> + ((100 * array[FREQ_PERF_APERF]) / array[FREQ_PERF_MPERF])

SNIP
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/