Linux Perf
jevents.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <ctype.h>
#include <unistd.h>
#include <stdarg.h>
#include <libgen.h>
#include <limits.h>
#include <dirent.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <ftw.h>
#include <sys/stat.h>
#include <linux/list.h>
#include "jsmn.h"
#include "json.h"
#include "jevents.h"
Include dependency graph for jevents.c:

Go to the source code of this file.

Classes

struct  msrmap
 
struct  field
 
struct  map
 
struct  perf_entry_data
 
struct  event_struct
 
struct  fixed
 

Macros

#define _XOPEN_SOURCE   500 /* needed for nftw() */
 
#define _GNU_SOURCE   /* needed for asprintf() */
 
#define EXPECT(e, t, m)
 
#define ADD_EVENT_FIELD(field)
 
#define FREE_EVENT_FIELD(field)   free(es->field)
 
#define TRY_FIXUP_FIELD(field)
 
#define FOR_ALL_EVENT_STRUCT_FIELDS(op)
 
#define PATH_MAX   4096
 

Functions

int eprintf (int level, int var, const char *fmt,...)
 
 __attribute__ ((weak))
 
static void addfield (char *map, char **dst, const char *sep, const char *a, jsmntok_t *bt)
 
static void fixname (char *s)
 
static void fixdesc (char *s)
 
static char * fixregex (char *s)
 
static void cut_comma (char *map, jsmntok_t *newval)
 
static int match_field (char *map, jsmntok_t *field, int nz, char **event, jsmntok_t *val)
 
static struct msrmaplookup_msr (char *map, jsmntok_t *val)
 
static const char * field_to_perf (struct map *table, char *map, jsmntok_t *val)
 
static char * get_topic (void)
 
static int add_topic (char *bname)
 
static void print_events_table_prefix (FILE *fp, const char *tblname)
 
static int print_events_table_entry (void *data, char *name, char *event, char *desc, char *long_desc, char *pmu, char *unit, char *perpkg, char *metric_expr, char *metric_name, char *metric_group)
 
static LIST_HEAD (arch_std_events)
 
static void free_arch_std_events (void)
 
static int save_arch_std_events (void *data, char *name, char *event, char *desc, char *long_desc, char *pmu, char *unit, char *perpkg, char *metric_expr, char *metric_name, char *metric_group)
 
static void print_events_table_suffix (FILE *outfp)
 
static char * real_event (const char *name, char *event)
 
static int try_fixup (const char *fn, char *arch_std, char **event, char **desc, char **name, char **long_desc, char **pmu, char **filter, char **perpkg, char **unit, char **metric_expr, char **metric_name, char **metric_group, unsigned long long eventcode)
 
int json_events (const char *fn, int(*func)(void *data, char *name, char *event, char *desc, char *long_desc, char *pmu, char *unit, char *perpkg, char *metric_expr, char *metric_name, char *metric_group), void *data)
 
static char * file_name_to_table_name (char *fname)
 
static void print_mapping_table_prefix (FILE *outfp)
 
static void print_mapping_table_suffix (FILE *outfp)
 
static int process_mapfile (FILE *outfp, char *fpath)
 
static void create_empty_mapping (const char *output_file)
 
static int get_maxfds (void)
 
static int is_leaf_dir (const char *fpath)
 
static int is_json_file (const char *name)
 
static int preprocess_arch_std_files (const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf)
 
static int process_one_file (const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf)
 
int main (int argc, char *argv[])
 

Variables

int verbose
 
char * prog
 
static struct msrmap msrmap []
 
static struct field fields []
 
static struct map unit_to_pmu []
 
static char * topic
 
static int close_table
 
static struct fixed fixed []
 
static FILE * eventsfp
 
static char * mapfile
 

Macro Definition Documentation

◆ _GNU_SOURCE

#define _GNU_SOURCE   /* needed for asprintf() */

Definition at line 2 of file jevents.c.

◆ _XOPEN_SOURCE

#define _XOPEN_SOURCE   500 /* needed for nftw() */

Definition at line 1 of file jevents.c.

◆ ADD_EVENT_FIELD

#define ADD_EVENT_FIELD (   field)
Value:
do { if (field) { \
es->field = strdup(field); \
if (!es->field) \
goto out_free; \
} } while (0)
Definition: jevents.c:169

Definition at line 369 of file jevents.c.

◆ EXPECT

#define EXPECT (   e,
  t,
 
)
Value:
do { if (!(e)) { \
jsmntok_t *loc = (t); \
if (!(t)->start && (t) > tokens) \
loc = (t) - 1; \
pr_err("%s:%d: " m ", got %s\n", fn, \
json_line(map, loc), \
json_name(t)); \
err = -EIO; \
goto out_free; \
} } while (0)
int json_line(char *map, jsmntok_t *t)
Definition: json.c:132
u64 start
Definition: hists_common.c:25
Definition: jevents.c:228
const char * json_name(jsmntok_t *t)
Definition: json.c:147

Definition at line 250 of file jevents.c.

◆ FOR_ALL_EVENT_STRUCT_FIELDS

#define FOR_ALL_EVENT_STRUCT_FIELDS (   op)
Value:
do { \
op(name); \
op(event); \
op(desc); \
op(long_desc); \
op(pmu); \
op(unit); \
op(perpkg); \
op(metric_expr); \
op(metric_name); \
op(metric_group); \
} while (0)
const char * name
#define event
const char * desc
Definition: clang.c:10

Definition at line 383 of file jevents.c.

◆ FREE_EVENT_FIELD

#define FREE_EVENT_FIELD (   field)    free(es->field)

Definition at line 375 of file jevents.c.

◆ PATH_MAX

#define PATH_MAX   4096

Definition at line 1042 of file jevents.c.

◆ TRY_FIXUP_FIELD

#define TRY_FIXUP_FIELD (   field)
Value:
do { if (es->field && !*field) {\
*field = strdup(es->field); \
if (!*field) \
return -ENOMEM; \
} } while (0)
Definition: jevents.c:169

Definition at line 377 of file jevents.c.

Function Documentation

◆ __attribute__()

__attribute__ ( (weak)  )

Definition at line 74 of file jevents.c.

◆ add_topic()

static int add_topic ( char *  bname)
static

Definition at line 289 of file jevents.c.

Here is the call graph for this function:

◆ addfield()

static void addfield ( char *  map,
char **  dst,
const char *  sep,
const char *  a,
jsmntok_t bt 
)
static

Definition at line 79 of file jevents.c.

Here is the call graph for this function:

◆ create_empty_mapping()

static void create_empty_mapping ( const char *  output_file)
static

Definition at line 829 of file jevents.c.

Here is the call graph for this function:

◆ cut_comma()

static void cut_comma ( char *  map,
jsmntok_t newval 
)
static

Definition at line 184 of file jevents.c.

◆ eprintf()

int eprintf ( int  level,
int  var,
const char *  fmt,
  ... 
)

Definition at line 56 of file jevents.c.

◆ field_to_perf()

static const char* field_to_perf ( struct map table,
char *  map,
jsmntok_t val 
)
static

Definition at line 239 of file jevents.c.

Here is the call graph for this function:

◆ file_name_to_table_name()

static char* file_name_to_table_name ( char *  fname)
static

Definition at line 686 of file jevents.c.

Here is the call graph for this function:

◆ fixdesc()

static void fixdesc ( char *  s)
static

Definition at line 109 of file jevents.c.

◆ fixname()

static void fixname ( char *  s)
static

Definition at line 103 of file jevents.c.

◆ fixregex()

static char* fixregex ( char *  s)
static

Definition at line 122 of file jevents.c.

Here is the call graph for this function:

◆ free_arch_std_events()

static void free_arch_std_events ( void  )
static

Definition at line 398 of file jevents.c.

Here is the call graph for this function:

◆ get_maxfds()

static int get_maxfds ( void  )
static

Definition at line 848 of file jevents.c.

◆ get_topic()

static char* get_topic ( void  )
static

Definition at line 263 of file jevents.c.

◆ is_json_file()

static int is_json_file ( const char *  name)
static

Definition at line 902 of file jevents.c.

◆ is_leaf_dir()

static int is_leaf_dir ( const char *  fpath)
static

Definition at line 865 of file jevents.c.

◆ json_events()

int json_events ( const char *  fn,
int(*)(void *data, char *name, char *event, char *desc, char *long_desc, char *pmu, char *unit, char *perpkg, char *metric_expr, char *metric_name, char *metric_group)  func,
void *  data 
)

Definition at line 498 of file jevents.c.

Here is the call graph for this function:

◆ LIST_HEAD()

static LIST_HEAD ( arch_std_events  )
static

◆ lookup_msr()

static struct msrmap* lookup_msr ( char *  map,
jsmntok_t val 
)
static

Definition at line 210 of file jevents.c.

Here is the call graph for this function:

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 1057 of file jevents.c.

Here is the call graph for this function:

◆ match_field()

static int match_field ( char *  map,
jsmntok_t field,
int  nz,
char **  event,
jsmntok_t val 
)
static

Definition at line 195 of file jevents.c.

Here is the call graph for this function:

◆ preprocess_arch_std_files()

static int preprocess_arch_std_files ( const char *  fpath,
const struct stat *  sb,
int  typeflag,
struct FTW *  ftwbuf 
)
static

Definition at line 916 of file jevents.c.

Here is the call graph for this function:

◆ print_events_table_entry()

static int print_events_table_entry ( void *  data,
char *  name,
char *  event,
char *  desc,
char *  long_desc,
char *  pmu,
char *  unit,
char *  perpkg,
char *  metric_expr,
char *  metric_name,
char *  metric_group 
)
static

Definition at line 314 of file jevents.c.

◆ print_events_table_prefix()

static void print_events_table_prefix ( FILE *  fp,
const char *  tblname 
)
static

Definition at line 308 of file jevents.c.

◆ print_events_table_suffix()

static void print_events_table_suffix ( FILE *  outfp)
static

Definition at line 430 of file jevents.c.

◆ print_mapping_table_prefix()

static void print_mapping_table_prefix ( FILE *  outfp)
static

Definition at line 725 of file jevents.c.

◆ print_mapping_table_suffix()

static void print_mapping_table_suffix ( FILE *  outfp)
static

Definition at line 730 of file jevents.c.

◆ process_mapfile()

static int process_mapfile ( FILE *  outfp,
char *  fpath 
)
static

Definition at line 746 of file jevents.c.

Here is the call graph for this function:

◆ process_one_file()

static int process_one_file ( const char *  fpath,
const struct stat *  sb,
int  typeflag,
struct FTW *  ftwbuf 
)
static

Definition at line 928 of file jevents.c.

Here is the call graph for this function:

◆ real_event()

static char* real_event ( const char *  name,
char *  event 
)
static

Definition at line 458 of file jevents.c.

◆ save_arch_std_events()

static int save_arch_std_events ( void *  data,
char *  name,
char *  event,
char *  desc,
char *  long_desc,
char *  pmu,
char *  unit,
char *  perpkg,
char *  metric_expr,
char *  metric_name,
char *  metric_group 
)
static

Definition at line 409 of file jevents.c.

Here is the call graph for this function:

◆ try_fixup()

static int try_fixup ( const char *  fn,
char *  arch_std,
char **  event,
char **  desc,
char **  name,
char **  long_desc,
char **  pmu,
char **  filter,
char **  perpkg,
char **  unit,
char **  metric_expr,
char **  metric_name,
char **  metric_group,
unsigned long long  eventcode 
)
static

Definition at line 472 of file jevents.c.

Here is the call graph for this function:

Variable Documentation

◆ close_table

int close_table
static

Definition at line 306 of file jevents.c.

◆ eventsfp

FILE* eventsfp
static

Definition at line 862 of file jevents.c.

◆ fields

struct field fields[]
static
Initial value:
= {
{ "UMask", "umask=" },
{ "CounterMask", "cmask=" },
{ "Invert", "inv=" },
{ "AnyThread", "any=" },
{ "EdgeDetect", "edge=" },
{ "SampleAfterValue", "period=" },
{ "FCMask", "fc_mask=" },
{ "PortMask", "ch_mask=" },
{ NULL, NULL }
}

◆ fixed

struct fixed fixed[]
static
Initial value:
= {
{ "inst_retired.any", "event=0xc0" },
{ "inst_retired.any_p", "event=0xc0" },
{ "cpu_clk_unhalted.ref", "event=0x0,umask=0x03" },
{ "cpu_clk_unhalted.thread", "event=0x3c" },
{ "cpu_clk_unhalted.thread_any", "event=0x3c,any=1" },
{ NULL, NULL},
}

◆ mapfile

char* mapfile
static

Definition at line 863 of file jevents.c.

◆ msrmap

struct msrmap msrmap[]
static
Initial value:
= {
{ "0x3F6", "ldlat=" },
{ "0x1A6", "offcore_rsp=" },
{ "0x1A7", "offcore_rsp=" },
{ "0x3F7", "frontend=" },
{ NULL, NULL }
}

◆ prog

char* prog

Definition at line 54 of file jevents.c.

◆ topic

char* topic
static

Definition at line 261 of file jevents.c.

◆ unit_to_pmu

struct map unit_to_pmu[]
static
Initial value:
= {
{ "CBO", "uncore_cbox" },
{ "QPI LL", "uncore_qpi" },
{ "SBO", "uncore_sbox" },
{ "iMPH-U", "uncore_arb" },
{}
}

◆ verbose

int verbose

Definition at line 53 of file jevents.c.