libpmc: jevents: Partial style(9) pass

Sort headers, move includes up to the top of the file, function return types on
their own line; no functional change.
This commit is contained in:
Conrad Meyer 2020-01-29 04:31:26 +00:00
parent 07a65f9d38
commit 3ea691c261
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=357241

View file

@ -35,18 +35,22 @@
#include <sys/resource.h> /* getrlimit */
#include <sys/stat.h>
#include <sys/time.h> /* getrlimit */
#include <ctype.h>
#include <dirent.h>
#include <errno.h>
#include <fts.h>
#include <ftw.h>
#include <libgen.h>
#include <limits.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <ftw.h>
#include "list.h"
#include "jsmn.h"
#include "json.h"
@ -56,12 +60,11 @@ static int
nftw_ordered(const char *path, int (*fn)(const char *, const struct stat *, int,
struct FTW *), int nfds, int ftwflags);
_Noreturn void _Exit(int);
int verbose;
static char *prog;
int eprintf(int level, int var, const char *fmt, ...)
int
eprintf(int level, int var, const char *fmt, ...)
{
int ret;
@ -79,13 +82,14 @@ int eprintf(int level, int var, const char *fmt, ...)
return ret;
}
__attribute__((weak)) char *get_cpu_str(void)
__attribute__((weak)) char *
get_cpu_str(void)
{
return NULL;
}
static void addfield(char *map, char **dst, const char *sep,
const char *a, jsmntok_t *bt)
static void
addfield(char *map, char **dst, const char *sep, const char *a, jsmntok_t *bt)
{
unsigned int len = strlen(a) + 1 + strlen(sep);
int olen = *dst ? strlen(*dst) : 0;
@ -108,13 +112,15 @@ static void addfield(char *map, char **dst, const char *sep,
strncat(*dst, map + bt->start, blen);
}
static void fixname(char *s)
static void
fixname(char *s)
{
for (; *s; s++)
*s = tolower(*s);
}
static void fixdesc(char *s)
static void
fixdesc(char *s)
{
char *e = s + strlen(s);
@ -127,7 +133,8 @@ static void fixdesc(char *s)
}
/* Add escapes for '\' so they are proper C strings. */
static char *fixregex(char *s)
static char *
fixregex(char *s)
{
int len = 0;
int esc_count = 0;
@ -191,7 +198,8 @@ static struct field {
{ NULL, NULL }
};
static void cut_comma(char *map, jsmntok_t *newval)
static void
cut_comma(char *map, jsmntok_t *newval)
{
int i;
@ -202,8 +210,8 @@ 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 int
match_field(char *map, jsmntok_t *field, int nz, char **event, jsmntok_t *val)
{
struct field *f;
jsmntok_t newval = *val;
@ -217,7 +225,8 @@ static int match_field(char *map, jsmntok_t *field, int nz,
return 0;
}
static struct msrmap *lookup_msr(char *map, jsmntok_t *val)
static struct msrmap *
lookup_msr(char *map, jsmntok_t *val)
{
jsmntok_t newval = *val;
static bool warned;
@ -246,7 +255,8 @@ static struct map {
{}
};
static const char *field_to_perf(struct map *table, char *map, jsmntok_t *val)
static const char *
field_to_perf(struct map *table, char *map, jsmntok_t *val)
{
int i;
@ -270,7 +280,8 @@ static const char *field_to_perf(struct map *table, char *map, jsmntok_t *val)
static char *topic;
static char *get_topic(void)
static char *
get_topic(void)
{
char *tp;
int i;
@ -296,7 +307,8 @@ static char *get_topic(void)
return tp;
}
static int add_topic(const char *bname)
static int
add_topic(const char *bname)
{
free(topic);
topic = strdup(bname);
@ -315,17 +327,17 @@ struct perf_entry_data {
static int close_table;
static void print_events_table_prefix(FILE *fp, const char *tblname)
static void
print_events_table_prefix(FILE *fp, const char *tblname)
{
fprintf(fp, "static struct pmu_event %s[] = {\n", tblname);
close_table = 1;
}
static int print_events_table_entry(void *data, char *name, const char *event,
char *desc, char *long_desc,
char *pmu, char *unit, char *perpkg,
char *metric_expr,
char *metric_name, char *metric_group)
static int
print_events_table_entry(void *data, char *name, const char *event, char *desc,
char *long_desc, char *pmu, char *unit, char *perpkg, char *metric_expr,
char *metric_name, char *metric_group)
{
struct perf_entry_data *pd = data;
FILE *outfp = pd->outfp;
@ -405,7 +417,8 @@ struct event_struct {
static LIST_HEAD(arch_std_events);
static void free_arch_std_events(void)
static void
free_arch_std_events(void)
{
struct event_struct *es, *next;
@ -416,10 +429,10 @@ static void free_arch_std_events(void)
}
}
static int save_arch_std_events(void *data __unused, char *name, const char *event,
char *desc, char *long_desc, char *pmu,
char *unit, char *perpkg, char *metric_expr,
char *metric_name, char *metric_group)
static int
save_arch_std_events(void *data __unused, char *name, const char *event,
char *desc, char *long_desc, char *pmu, char *unit, char *perpkg,
char *metric_expr, char *metric_name, char *metric_group)
{
struct event_struct *es;
@ -436,7 +449,8 @@ static int save_arch_std_events(void *data __unused, char *name, const char *eve
return -ENOMEM;
}
static void print_events_table_suffix(FILE *outfp)
static void
print_events_table_suffix(FILE *outfp)
{
fprintf(outfp, "{\n");
@ -464,7 +478,8 @@ static struct fixed {
/*
* Handle different fixed counter encodings between JSON and perf.
*/
static const char *real_event(const char *name, char *event)
static const char *
real_event(const char *name, char *event)
{
int i;
@ -479,9 +494,9 @@ static const 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 __unused,
char **perpkg, char **unit, char **metric_expr, char **metric_name,
char **metric_group, unsigned long long eventcode)
char **name, char **long_desc, char **pmu, char **filter __unused,
char **perpkg, char **unit, char **metric_expr, char **metric_name,
char **metric_group, unsigned long long eventcode)
{
/* try to find matching event from arch standard values */
struct event_struct *es;
@ -504,7 +519,8 @@ try_fixup(const char *fn, char *arch_std, char **event, char **desc,
}
/* Call func with each event in the json file */
int json_events(const char *fn,
int
json_events(const char *fn,
int (*func)(void *data, char *name, const char *event, char *desc,
char *long_desc,
char *pmu, char *unit, char *perpkg,
@ -692,7 +708,8 @@ int json_events(const char *fn,
return err;
}
static char *file_name_to_table_name(const char *fname)
static char *
file_name_to_table_name(const char *fname)
{
unsigned int i;
int n;
@ -734,12 +751,14 @@ static char *file_name_to_table_name(const char *fname)
return tblname;
}
static void print_mapping_table_prefix(FILE *outfp)
static void
print_mapping_table_prefix(FILE *outfp)
{
fprintf(outfp, "struct pmu_events_map pmu_events_map[] = {\n");
}
static void print_mapping_table_suffix(FILE *outfp)
static void
print_mapping_table_suffix(FILE *outfp)
{
/*
* Print the terminating, NULL entry.
@ -755,7 +774,8 @@ static void print_mapping_table_suffix(FILE *outfp)
fprintf(outfp, "};\n");
}
static int process_mapfile(FILE *outfp, char *fpath)
static int
process_mapfile(FILE *outfp, char *fpath)
{
int n = 16384;
FILE *mapfp;
@ -838,7 +858,8 @@ static int process_mapfile(FILE *outfp, char *fpath)
* table. This would at least allow perf to build even if we can't find/use
* the aliases.
*/
static void create_empty_mapping(const char *output_file)
static void
create_empty_mapping(const char *output_file)
{
FILE *outfp;
@ -857,7 +878,8 @@ static void create_empty_mapping(const char *output_file)
fclose(outfp);
}
static int get_maxfds(void)
static int
get_maxfds(void)
{
struct rlimit rlim;
@ -877,7 +899,8 @@ static int get_maxfds(void)
static FILE *eventsfp;
static char *mapfile;
static int is_leaf_dir(const char *fpath)
static int
is_leaf_dir(const char *fpath)
{
DIR *d;
struct dirent *dir;
@ -914,7 +937,8 @@ static int is_leaf_dir(const char *fpath)
return res;
}
static int is_json_file(const char *name)
static int
is_json_file(const char *name)
{
const char *suffix;
@ -928,8 +952,9 @@ static int is_json_file(const char *name)
return 0;
}
static int preprocess_arch_std_files(const char *fpath, const struct stat *sb,
int typeflag, struct FTW *ftwbuf)
static int
preprocess_arch_std_files(const char *fpath, const struct stat *sb,
int typeflag, struct FTW *ftwbuf)
{
int level = ftwbuf->level;
int is_file = typeflag == FTW_F;
@ -940,8 +965,9 @@ static int preprocess_arch_std_files(const char *fpath, const struct stat *sb,
return 0;
}
static int process_one_file(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)
{
char *tblname;
const char *bname;
@ -1070,7 +1096,8 @@ static int process_one_file(const char *fpath, const struct stat *sb,
*
* Write out the PMU events tables and the mapping table to pmu-event.c.
*/
int main(int argc, char *argv[])
int
main(int argc, char *argv[])
{
int rc;
int maxfds;
@ -1172,8 +1199,6 @@ int main(int argc, char *argv[])
return 0;
}
#include <fts.h>
static int
fts_compare(const FTSENT * const *a, const FTSENT * const *b)
{