linux/tools/perf/util/evsel.h
<<
>>
Prefs
   1#ifndef __PERF_EVSEL_H
   2#define __PERF_EVSEL_H 1
   3
   4#include <linux/list.h>
   5#include <stdbool.h>
   6#include <stddef.h>
   7#include <linux/perf_event.h>
   8#include "types.h"
   9#include "xyarray.h"
  10#include "cgroup.h"
  11#include "hist.h"
  12#include "symbol.h"
  13 
  14struct perf_counts_values {
  15        union {
  16                struct {
  17                        u64 val;
  18                        u64 ena;
  19                        u64 run;
  20                };
  21                u64 values[3];
  22        };
  23};
  24
  25struct perf_counts {
  26        s8                        scaled;
  27        struct perf_counts_values aggr;
  28        struct perf_counts_values cpu[];
  29};
  30
  31struct perf_evsel;
  32
  33/*
  34 * Per fd, to map back from PERF_SAMPLE_ID to evsel, only used when there are
  35 * more than one entry in the evlist.
  36 */
  37struct perf_sample_id {
  38        struct hlist_node       node;
  39        u64                     id;
  40        struct perf_evsel       *evsel;
  41};
  42
  43/** struct perf_evsel - event selector
  44 *
  45 * @name - Can be set to retain the original event name passed by the user,
  46 *         so that when showing results in tools such as 'perf stat', we
  47 *         show the name used, not some alias.
  48 */
  49struct perf_evsel {
  50        struct list_head        node;
  51        struct perf_event_attr  attr;
  52        char                    *filter;
  53        struct xyarray          *fd;
  54        struct xyarray          *sample_id;
  55        u64                     *id;
  56        struct perf_counts      *counts;
  57        struct perf_counts      *prev_raw_counts;
  58        int                     idx;
  59        u32                     ids;
  60        struct hists            hists;
  61        char                    *name;
  62        struct event_format     *tp_format;
  63        union {
  64                void            *priv;
  65                off_t           id_offset;
  66        };
  67        struct cgroup_sel       *cgrp;
  68        struct {
  69                void            *func;
  70                void            *data;
  71        } handler;
  72        struct cpu_map          *cpus;
  73        unsigned int            sample_size;
  74        bool                    supported;
  75        bool                    needs_swap;
  76        /* parse modifier helper */
  77        int                     exclude_GH;
  78        int                     nr_members;
  79        struct perf_evsel       *leader;
  80        char                    *group_name;
  81};
  82
  83#define hists_to_evsel(h) container_of(h, struct perf_evsel, hists)
  84
  85struct cpu_map;
  86struct thread_map;
  87struct perf_evlist;
  88struct perf_record_opts;
  89
  90struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr, int idx);
  91struct perf_evsel *perf_evsel__newtp(const char *sys, const char *name, int idx);
  92
  93struct event_format *event_format__new(const char *sys, const char *name);
  94
  95void perf_evsel__init(struct perf_evsel *evsel,
  96                      struct perf_event_attr *attr, int idx);
  97void perf_evsel__exit(struct perf_evsel *evsel);
  98void perf_evsel__delete(struct perf_evsel *evsel);
  99
 100void perf_evsel__config(struct perf_evsel *evsel,
 101                        struct perf_record_opts *opts);
 102
 103bool perf_evsel__is_cache_op_valid(u8 type, u8 op);
 104
 105#define PERF_EVSEL__MAX_ALIASES 8
 106
 107extern const char *perf_evsel__hw_cache[PERF_COUNT_HW_CACHE_MAX]
 108                                       [PERF_EVSEL__MAX_ALIASES];
 109extern const char *perf_evsel__hw_cache_op[PERF_COUNT_HW_CACHE_OP_MAX]
 110                                          [PERF_EVSEL__MAX_ALIASES];
 111extern const char *perf_evsel__hw_cache_result[PERF_COUNT_HW_CACHE_RESULT_MAX]
 112                                              [PERF_EVSEL__MAX_ALIASES];
 113extern const char *perf_evsel__hw_names[PERF_COUNT_HW_MAX];
 114extern const char *perf_evsel__sw_names[PERF_COUNT_SW_MAX];
 115int __perf_evsel__hw_cache_type_op_res_name(u8 type, u8 op, u8 result,
 116                                            char *bf, size_t size);
 117const char *perf_evsel__name(struct perf_evsel *evsel);
 118const char *perf_evsel__group_name(struct perf_evsel *evsel);
 119int perf_evsel__group_desc(struct perf_evsel *evsel, char *buf, size_t size);
 120
 121int perf_evsel__alloc_fd(struct perf_evsel *evsel, int ncpus, int nthreads);
 122int perf_evsel__alloc_id(struct perf_evsel *evsel, int ncpus, int nthreads);
 123int perf_evsel__alloc_counts(struct perf_evsel *evsel, int ncpus);
 124void perf_evsel__reset_counts(struct perf_evsel *evsel, int ncpus);
 125void perf_evsel__free_fd(struct perf_evsel *evsel);
 126void perf_evsel__free_id(struct perf_evsel *evsel);
 127void perf_evsel__free_counts(struct perf_evsel *evsel);
 128void perf_evsel__close_fd(struct perf_evsel *evsel, int ncpus, int nthreads);
 129
 130void __perf_evsel__set_sample_bit(struct perf_evsel *evsel,
 131                                  enum perf_event_sample_format bit);
 132void __perf_evsel__reset_sample_bit(struct perf_evsel *evsel,
 133                                    enum perf_event_sample_format bit);
 134
 135#define perf_evsel__set_sample_bit(evsel, bit) \
 136        __perf_evsel__set_sample_bit(evsel, PERF_SAMPLE_##bit)
 137
 138#define perf_evsel__reset_sample_bit(evsel, bit) \
 139        __perf_evsel__reset_sample_bit(evsel, PERF_SAMPLE_##bit)
 140
 141void perf_evsel__set_sample_id(struct perf_evsel *evsel);
 142
 143int perf_evsel__set_filter(struct perf_evsel *evsel, int ncpus, int nthreads,
 144                           const char *filter);
 145
 146int perf_evsel__open_per_cpu(struct perf_evsel *evsel,
 147                             struct cpu_map *cpus);
 148int perf_evsel__open_per_thread(struct perf_evsel *evsel,
 149                                struct thread_map *threads);
 150int perf_evsel__open(struct perf_evsel *evsel, struct cpu_map *cpus,
 151                     struct thread_map *threads);
 152void perf_evsel__close(struct perf_evsel *evsel, int ncpus, int nthreads);
 153
 154struct perf_sample;
 155
 156void *perf_evsel__rawptr(struct perf_evsel *evsel, struct perf_sample *sample,
 157                         const char *name);
 158u64 perf_evsel__intval(struct perf_evsel *evsel, struct perf_sample *sample,
 159                       const char *name);
 160
 161static inline char *perf_evsel__strval(struct perf_evsel *evsel,
 162                                       struct perf_sample *sample,
 163                                       const char *name)
 164{
 165        return perf_evsel__rawptr(evsel, sample, name);
 166}
 167
 168struct format_field;
 169
 170struct format_field *perf_evsel__field(struct perf_evsel *evsel, const char *name);
 171
 172#define perf_evsel__match(evsel, t, c)          \
 173        (evsel->attr.type == PERF_TYPE_##t &&   \
 174         evsel->attr.config == PERF_COUNT_##c)
 175
 176static inline bool perf_evsel__match2(struct perf_evsel *e1,
 177                                      struct perf_evsel *e2)
 178{
 179        return (e1->attr.type == e2->attr.type) &&
 180               (e1->attr.config == e2->attr.config);
 181}
 182
 183int __perf_evsel__read_on_cpu(struct perf_evsel *evsel,
 184                              int cpu, int thread, bool scale);
 185
 186/**
 187 * perf_evsel__read_on_cpu - Read out the results on a CPU and thread
 188 *
 189 * @evsel - event selector to read value
 190 * @cpu - CPU of interest
 191 * @thread - thread of interest
 192 */
 193static inline int perf_evsel__read_on_cpu(struct perf_evsel *evsel,
 194                                          int cpu, int thread)
 195{
 196        return __perf_evsel__read_on_cpu(evsel, cpu, thread, false);
 197}
 198
 199/**
 200 * perf_evsel__read_on_cpu_scaled - Read out the results on a CPU and thread, scaled
 201 *
 202 * @evsel - event selector to read value
 203 * @cpu - CPU of interest
 204 * @thread - thread of interest
 205 */
 206static inline int perf_evsel__read_on_cpu_scaled(struct perf_evsel *evsel,
 207                                                 int cpu, int thread)
 208{
 209        return __perf_evsel__read_on_cpu(evsel, cpu, thread, true);
 210}
 211
 212int __perf_evsel__read(struct perf_evsel *evsel, int ncpus, int nthreads,
 213                       bool scale);
 214
 215/**
 216 * perf_evsel__read - Read the aggregate results on all CPUs
 217 *
 218 * @evsel - event selector to read value
 219 * @ncpus - Number of cpus affected, from zero
 220 * @nthreads - Number of threads affected, from zero
 221 */
 222static inline int perf_evsel__read(struct perf_evsel *evsel,
 223                                    int ncpus, int nthreads)
 224{
 225        return __perf_evsel__read(evsel, ncpus, nthreads, false);
 226}
 227
 228/**
 229 * perf_evsel__read_scaled - Read the aggregate results on all CPUs, scaled
 230 *
 231 * @evsel - event selector to read value
 232 * @ncpus - Number of cpus affected, from zero
 233 * @nthreads - Number of threads affected, from zero
 234 */
 235static inline int perf_evsel__read_scaled(struct perf_evsel *evsel,
 236                                          int ncpus, int nthreads)
 237{
 238        return __perf_evsel__read(evsel, ncpus, nthreads, true);
 239}
 240
 241void hists__init(struct hists *hists);
 242
 243int perf_evsel__parse_sample(struct perf_evsel *evsel, union perf_event *event,
 244                             struct perf_sample *sample);
 245
 246static inline struct perf_evsel *perf_evsel__next(struct perf_evsel *evsel)
 247{
 248        return list_entry(evsel->node.next, struct perf_evsel, node);
 249}
 250
 251/**
 252 * perf_evsel__is_group_leader - Return whether given evsel is a leader event
 253 *
 254 * @evsel - evsel selector to be tested
 255 *
 256 * Return %true if @evsel is a group leader or a stand-alone event
 257 */
 258static inline bool perf_evsel__is_group_leader(const struct perf_evsel *evsel)
 259{
 260        return evsel->leader == evsel;
 261}
 262
 263/**
 264 * perf_evsel__is_group_event - Return whether given evsel is a group event
 265 *
 266 * @evsel - evsel selector to be tested
 267 *
 268 * Return %true iff event group view is enabled and @evsel is a actual group
 269 * leader which has other members in the group
 270 */
 271static inline bool perf_evsel__is_group_event(struct perf_evsel *evsel)
 272{
 273        if (!symbol_conf.event_group)
 274                return false;
 275
 276        return perf_evsel__is_group_leader(evsel) && evsel->nr_members > 1;
 277}
 278
 279struct perf_attr_details {
 280        bool freq;
 281        bool verbose;
 282        bool event_group;
 283};
 284
 285int perf_evsel__fprintf(struct perf_evsel *evsel,
 286                        struct perf_attr_details *details, FILE *fp);
 287
 288bool perf_evsel__fallback(struct perf_evsel *evsel, int err,
 289                          char *msg, size_t msgsize);
 290int perf_evsel__open_strerror(struct perf_evsel *evsel,
 291                              struct perf_target *target,
 292                              int err, char *msg, size_t size);
 293
 294static inline int perf_evsel__group_idx(struct perf_evsel *evsel)
 295{
 296        return evsel->idx - evsel->leader->idx;
 297}
 298
 299#define for_each_group_member(_evsel, _leader)                                  \
 300for ((_evsel) = list_entry((_leader)->node.next, struct perf_evsel, node);      \
 301     (_evsel) && (_evsel)->leader == (_leader);                                 \
 302     (_evsel) = list_entry((_evsel)->node.next, struct perf_evsel, node))
 303
 304#endif /* __PERF_EVSEL_H */
 305