#define _XOPEN_SOURCE 500 /* needed for nftw() */
#define _GNU_SOURCE /* needed for asprintf() */
/* Parse event JSON files */
/*
* Copyright (c) 2014, Intel Corporation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#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> /* getrlimit */
#include <sys/resource.h> /* getrlimit */
#include <ftw.h>
#include <sys/stat.h>
#include <linux/list.h>
#include "jsmn.h"
#include "json.h"
#include "jevents.h"
int verbose;
char *prog;
int eprintf(int level, int var, const char *fmt, ...)
{
int ret;
va_list args;
if (var < level)
return 0;
va_start(args, fmt);
ret = vfprintf(stderr, fmt, args);
va_end(args);
return ret;
}
__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)
{
unsigned int len = strlen(a) + 1 + strlen(sep);
int olen = *dst ? strlen(*dst) : 0;
int blen = bt ? json_len(bt) : 0;
char *out;
out = realloc(*dst, len + olen + blen);
if (!out) {
/* Don't add field in this case */
return;
}
*dst = out;
if (!olen)
*(*dst) = 0;
else
strcat(*dst, sep);
strcat(*dst, a);
if (bt)
strncat(*dst, map + bt->start, blen);
}
static void fixname(char *s)
{
for (; *s; s++)
*s = tolower(*s);
}
static void fixdesc(char *s)
{
char *e = s + strlen(s);
/* Remove trailing dots that look ugly in perf list */
--e;
while (e >= s && isspace(*e))
--e;
if (*e == '.')
*e = 0;
}
/* Add escapes for '\' so they are proper C strings. */
static char *fixregex(char *s)
{
int len = 0;
int esc_count = 0;
char *fixed = NULL;
char *p, *q;
/* Count the number of '\' in string */
for (p