2012-09-17 15:31:14 +07:00
|
|
|
#ifndef __PERF_STATS_H
|
|
|
|
#define __PERF_STATS_H
|
|
|
|
|
2014-04-26 02:31:02 +07:00
|
|
|
#include <linux/types.h>
|
2015-06-03 21:25:59 +07:00
|
|
|
#include <stdio.h>
|
2015-06-26 16:29:10 +07:00
|
|
|
#include "xyarray.h"
|
2012-09-17 15:31:14 +07:00
|
|
|
|
|
|
|
struct stats
|
|
|
|
{
|
|
|
|
double n, mean, M2;
|
2013-08-03 03:05:40 +07:00
|
|
|
u64 max, min;
|
2012-09-17 15:31:14 +07:00
|
|
|
};
|
|
|
|
|
2015-06-04 20:50:55 +07:00
|
|
|
enum perf_stat_evsel_id {
|
|
|
|
PERF_STAT_EVSEL_ID__NONE = 0,
|
2015-06-03 21:25:52 +07:00
|
|
|
PERF_STAT_EVSEL_ID__CYCLES_IN_TX,
|
|
|
|
PERF_STAT_EVSEL_ID__TRANSACTION_START,
|
|
|
|
PERF_STAT_EVSEL_ID__ELISION_START,
|
|
|
|
PERF_STAT_EVSEL_ID__CYCLES_IN_TX_CP,
|
2015-06-04 20:50:55 +07:00
|
|
|
PERF_STAT_EVSEL_ID__MAX,
|
|
|
|
};
|
|
|
|
|
2015-10-16 17:41:03 +07:00
|
|
|
struct perf_stat_evsel {
|
2015-06-04 20:50:55 +07:00
|
|
|
struct stats res_stats[3];
|
|
|
|
enum perf_stat_evsel_id id;
|
|
|
|
};
|
|
|
|
|
2015-06-03 21:25:59 +07:00
|
|
|
enum aggr_mode {
|
|
|
|
AGGR_NONE,
|
|
|
|
AGGR_GLOBAL,
|
|
|
|
AGGR_SOCKET,
|
|
|
|
AGGR_CORE,
|
perf stat: Introduce --per-thread option
Currently all the -p option PID arguments tasks values get aggregated
and printed as single values.
Adding --per-tasks option to print values per task.
$ perf stat -e cycles,instructions --per-thread -p 30190,30242
^C
Performance counter stats for process id '30190,30242':
cat-30190 0 cycles
yes-30242 3,842,525,421 cycles
cat-30190 0 instructions
yes-30242 10,370,817,010 instructions
1.143155657 seconds time elapsed
Also works under interval mode:
$ perf stat -e cycles,instructions --per-thread -p 30190,30242 -I 1000
# time comm-pid counts unit events
1.000073435 cat-30190 89,058 cycles
1.000073435 yes-30242 3,360,786,902 cycles (100.00%)
1.000073435 cat-30190 14,066 instructions
1.000073435 yes-30242 9,069,937,462 instructions
2.000204830 cat-30190 0 cycles
2.000204830 yes-30242 3,351,667,626 cycles
2.000204830 cat-30190 0 instructions
2.000204830 yes-30242 9,045,796,885 instructions
^C 2.771286639 cat-30190 0 cycles
2.771286639 yes-30242 2,593,884,166 cycles
2.771286639 cat-30190 0 instructions
2.771286639 yes-30242 7,001,171,191 instructions
It works only with -t and -p options, otherwise following error is
printed:
$ perf stat -e cycles --per-thread -I 1000 ls
The --per-thread option is only available when monitoring via -p -t options.
-p, --pid <pid> stat events on existing process id
-t, --tid <tid> stat events on existing thread id
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/1435310967-14570-23-git-send-email-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2015-06-26 16:29:27 +07:00
|
|
|
AGGR_THREAD,
|
2015-10-16 17:41:04 +07:00
|
|
|
AGGR_UNSET,
|
2015-06-03 21:25:59 +07:00
|
|
|
};
|
|
|
|
|
2015-07-21 19:31:22 +07:00
|
|
|
struct perf_stat_config {
|
|
|
|
enum aggr_mode aggr_mode;
|
2015-07-21 19:31:23 +07:00
|
|
|
bool scale;
|
2015-07-21 19:31:24 +07:00
|
|
|
FILE *output;
|
2015-07-21 19:31:25 +07:00
|
|
|
unsigned int interval;
|
2015-07-21 19:31:22 +07:00
|
|
|
};
|
|
|
|
|
2012-09-17 15:31:14 +07:00
|
|
|
void update_stats(struct stats *stats, u64 val);
|
|
|
|
double avg_stats(struct stats *stats);
|
|
|
|
double stddev_stats(struct stats *stats);
|
|
|
|
double rel_stddev_stats(double stddev, double avg);
|
|
|
|
|
2013-08-03 03:05:40 +07:00
|
|
|
static inline void init_stats(struct stats *stats)
|
|
|
|
{
|
|
|
|
stats->n = 0.0;
|
|
|
|
stats->mean = 0.0;
|
|
|
|
stats->M2 = 0.0;
|
|
|
|
stats->min = (u64) -1;
|
|
|
|
stats->max = 0;
|
|
|
|
}
|
2015-06-04 20:50:55 +07:00
|
|
|
|
|
|
|
struct perf_evsel;
|
2015-06-26 16:29:16 +07:00
|
|
|
struct perf_evlist;
|
|
|
|
|
2015-06-04 20:50:55 +07:00
|
|
|
bool __perf_evsel_stat__is(struct perf_evsel *evsel,
|
|
|
|
enum perf_stat_evsel_id id);
|
|
|
|
|
|
|
|
#define perf_stat_evsel__is(evsel, id) \
|
|
|
|
__perf_evsel_stat__is(evsel, PERF_STAT_EVSEL_ID__ ## id)
|
|
|
|
|
|
|
|
void perf_stat_evsel_id_init(struct perf_evsel *evsel);
|
|
|
|
|
2015-06-03 21:25:59 +07:00
|
|
|
extern struct stats walltime_nsecs_stats;
|
|
|
|
|
|
|
|
void perf_stat__reset_shadow_stats(void);
|
|
|
|
void perf_stat__update_shadow_stats(struct perf_evsel *counter, u64 *count,
|
|
|
|
int cpu);
|
|
|
|
void perf_stat__print_shadow_stats(FILE *out, struct perf_evsel *evsel,
|
|
|
|
double avg, int cpu, enum aggr_mode aggr);
|
|
|
|
|
2015-06-26 16:29:14 +07:00
|
|
|
void perf_evsel__reset_stat_priv(struct perf_evsel *evsel);
|
|
|
|
int perf_evsel__alloc_stat_priv(struct perf_evsel *evsel);
|
|
|
|
void perf_evsel__free_stat_priv(struct perf_evsel *evsel);
|
2015-06-26 16:29:15 +07:00
|
|
|
|
|
|
|
int perf_evsel__alloc_prev_raw_counts(struct perf_evsel *evsel,
|
|
|
|
int ncpus, int nthreads);
|
|
|
|
void perf_evsel__free_prev_raw_counts(struct perf_evsel *evsel);
|
2015-06-26 16:29:16 +07:00
|
|
|
|
2015-06-26 16:29:17 +07:00
|
|
|
int perf_evsel__alloc_stats(struct perf_evsel *evsel, bool alloc_raw);
|
|
|
|
|
2015-06-26 16:29:16 +07:00
|
|
|
int perf_evlist__alloc_stats(struct perf_evlist *evlist, bool alloc_raw);
|
|
|
|
void perf_evlist__free_stats(struct perf_evlist *evlist);
|
|
|
|
void perf_evlist__reset_stats(struct perf_evlist *evlist);
|
2015-07-21 19:31:27 +07:00
|
|
|
|
|
|
|
int perf_stat_process_counter(struct perf_stat_config *config,
|
|
|
|
struct perf_evsel *counter);
|
2012-09-17 15:31:14 +07:00
|
|
|
#endif
|