2018-08-16 23:10:15 +08:00
|
|
|
// SPDX-License-Identifier: LGPL-2.1
|
2012-04-06 06:47:53 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2009, 2010 Red Hat Inc, Steven Rostedt <srostedt@redhat.com>
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* The parts for function graph printing was taken and modified from the
|
|
|
|
* Linux Kernel that were written by
|
|
|
|
* - Copyright (C) 2009 Frederic Weisbecker,
|
|
|
|
* Frederic Weisbecker gave his permission to relicense the code to
|
|
|
|
* the Lesser General Public License.
|
|
|
|
*/
|
2016-07-14 22:23:25 +08:00
|
|
|
#include <inttypes.h>
|
2012-04-06 06:47:53 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <errno.h>
|
2012-08-08 01:43:14 +08:00
|
|
|
#include <stdint.h>
|
2012-09-13 04:30:50 +08:00
|
|
|
#include <limits.h>
|
2016-11-23 02:00:31 +08:00
|
|
|
#include <linux/time64.h>
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2016-07-14 22:23:25 +08:00
|
|
|
#include <netinet/in.h>
|
2012-04-06 06:47:53 +08:00
|
|
|
#include "event-parse.h"
|
2018-10-06 00:22:25 +08:00
|
|
|
|
|
|
|
#include "event-parse-local.h"
|
2012-04-06 06:47:55 +08:00
|
|
|
#include "event-utils.h"
|
2018-08-29 06:50:38 +08:00
|
|
|
#include "trace-seq.h"
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
static const char *input_buf;
|
|
|
|
static unsigned long long input_buf_ptr;
|
|
|
|
static unsigned long long input_buf_siz;
|
|
|
|
|
2012-04-06 06:47:58 +08:00
|
|
|
static int is_flag_field;
|
|
|
|
static int is_symbolic_field;
|
|
|
|
|
2012-04-06 06:47:53 +08:00
|
|
|
static int show_warning = 1;
|
|
|
|
|
|
|
|
#define do_warning(fmt, ...) \
|
|
|
|
do { \
|
|
|
|
if (show_warning) \
|
|
|
|
warning(fmt, ##__VA_ARGS__); \
|
|
|
|
} while (0)
|
|
|
|
|
2014-03-19 09:22:53 +08:00
|
|
|
#define do_warning_event(event, fmt, ...) \
|
|
|
|
do { \
|
|
|
|
if (!show_warning) \
|
|
|
|
continue; \
|
|
|
|
\
|
|
|
|
if (event) \
|
|
|
|
warning("[%s:%s] " fmt, event->system, \
|
|
|
|
event->name, ##__VA_ARGS__); \
|
|
|
|
else \
|
|
|
|
warning(fmt, ##__VA_ARGS__); \
|
|
|
|
} while (0)
|
|
|
|
|
2020-09-30 19:07:33 +08:00
|
|
|
/**
|
|
|
|
* init_input_buf - init buffer for parsing
|
|
|
|
* @buf: buffer to parse
|
|
|
|
* @size: the size of the buffer
|
|
|
|
*
|
|
|
|
* Initializes the internal buffer that tep_read_token() will parse.
|
|
|
|
*/
|
|
|
|
__hidden void init_input_buf(const char *buf, unsigned long long size)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
|
|
|
input_buf = buf;
|
|
|
|
input_buf_siz = size;
|
|
|
|
input_buf_ptr = 0;
|
|
|
|
}
|
|
|
|
|
2020-09-30 19:07:33 +08:00
|
|
|
__hidden const char *get_input_buf(void)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
|
|
|
return input_buf;
|
|
|
|
}
|
|
|
|
|
2020-09-30 19:07:33 +08:00
|
|
|
__hidden unsigned long long get_input_buf_ptr(void)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
|
|
|
return input_buf_ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct event_handler {
|
|
|
|
struct event_handler *next;
|
|
|
|
int id;
|
|
|
|
const char *sys_name;
|
|
|
|
const char *event_name;
|
2018-08-09 02:02:48 +08:00
|
|
|
tep_event_handler_func func;
|
2012-04-06 06:47:53 +08:00
|
|
|
void *context;
|
|
|
|
};
|
|
|
|
|
2018-08-09 02:03:09 +08:00
|
|
|
struct func_params {
|
|
|
|
struct func_params *next;
|
|
|
|
enum tep_func_arg_type type;
|
2012-04-06 06:47:53 +08:00
|
|
|
};
|
|
|
|
|
tools lib traceevent: Rename pevent_function* APIs
In order to make libtraceevent into a proper library, variables, data
structures and functions require a unique prefix to prevent name space
conflicts. That prefix will be "tep_" and not "pevent_". This changes
APIs: pevent_function_handler, pevent_func_handler,
pevent_func_arg_type, PEVENT_FUNC_ARG_VOID, PEVENT_FUNC_ARG_INT,
PEVENT_FUNC_ARG_LONG, PEVENT_FUNC_ARG_STRING, PEVENT_FUNC_ARG_PTRS,
PEVENT_FUNC_ARG_MAX_TYPES
Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
Cc: linux-trace-devel@vger.kernel.org
Link: http://lkml.kernel.org/r/20180808180701.935881193@goodmis.org
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2018-08-09 02:02:59 +08:00
|
|
|
struct tep_function_handler {
|
|
|
|
struct tep_function_handler *next;
|
|
|
|
enum tep_func_arg_type ret_type;
|
2012-04-06 06:47:53 +08:00
|
|
|
char *name;
|
tools lib traceevent: Rename pevent_function* APIs
In order to make libtraceevent into a proper library, variables, data
structures and functions require a unique prefix to prevent name space
conflicts. That prefix will be "tep_" and not "pevent_". This changes
APIs: pevent_function_handler, pevent_func_handler,
pevent_func_arg_type, PEVENT_FUNC_ARG_VOID, PEVENT_FUNC_ARG_INT,
PEVENT_FUNC_ARG_LONG, PEVENT_FUNC_ARG_STRING, PEVENT_FUNC_ARG_PTRS,
PEVENT_FUNC_ARG_MAX_TYPES
Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
Cc: linux-trace-devel@vger.kernel.org
Link: http://lkml.kernel.org/r/20180808180701.935881193@goodmis.org
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2018-08-09 02:02:59 +08:00
|
|
|
tep_func_handler func;
|
2018-08-09 02:03:09 +08:00
|
|
|
struct func_params *params;
|
2012-04-06 06:47:53 +08:00
|
|
|
int nr_args;
|
|
|
|
};
|
|
|
|
|
|
|
|
static unsigned long long
|
|
|
|
process_defined_func(struct trace_seq *s, void *data, int size,
|
2018-11-30 23:44:07 +08:00
|
|
|
struct tep_event *event, struct tep_print_arg *arg);
|
2012-04-06 06:47:53 +08:00
|
|
|
|
tools lib traceevent: Rename pevent_function* APIs
In order to make libtraceevent into a proper library, variables, data
structures and functions require a unique prefix to prevent name space
conflicts. That prefix will be "tep_" and not "pevent_". This changes
APIs: pevent_function_handler, pevent_func_handler,
pevent_func_arg_type, PEVENT_FUNC_ARG_VOID, PEVENT_FUNC_ARG_INT,
PEVENT_FUNC_ARG_LONG, PEVENT_FUNC_ARG_STRING, PEVENT_FUNC_ARG_PTRS,
PEVENT_FUNC_ARG_MAX_TYPES
Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
Cc: linux-trace-devel@vger.kernel.org
Link: http://lkml.kernel.org/r/20180808180701.935881193@goodmis.org
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2018-08-09 02:02:59 +08:00
|
|
|
static void free_func_handle(struct tep_function_handler *func);
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
void breakpoint(void)
|
|
|
|
{
|
|
|
|
static int x;
|
|
|
|
x++;
|
|
|
|
}
|
|
|
|
|
2020-09-30 19:07:33 +08:00
|
|
|
static struct tep_print_arg *alloc_arg(void)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
2018-09-20 02:56:49 +08:00
|
|
|
return calloc(1, sizeof(struct tep_print_arg));
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
|
2018-12-01 12:08:09 +08:00
|
|
|
struct tep_cmdline {
|
2012-04-06 06:47:53 +08:00
|
|
|
char *comm;
|
|
|
|
int pid;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int cmdline_cmp(const void *a, const void *b)
|
|
|
|
{
|
2018-12-01 12:08:09 +08:00
|
|
|
const struct tep_cmdline *ca = a;
|
|
|
|
const struct tep_cmdline *cb = b;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
if (ca->pid < cb->pid)
|
|
|
|
return -1;
|
|
|
|
if (ca->pid > cb->pid)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-08-29 03:05:29 +08:00
|
|
|
/* Looking for where to place the key */
|
|
|
|
static int cmdline_slot_cmp(const void *a, const void *b)
|
|
|
|
{
|
|
|
|
const struct tep_cmdline *ca = a;
|
|
|
|
const struct tep_cmdline *cb = b;
|
|
|
|
const struct tep_cmdline *cb1 = cb + 1;
|
|
|
|
|
|
|
|
if (ca->pid < cb->pid)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (ca->pid > cb->pid) {
|
|
|
|
if (ca->pid <= cb1->pid)
|
|
|
|
return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-04-06 06:47:53 +08:00
|
|
|
struct cmdline_list {
|
|
|
|
struct cmdline_list *next;
|
|
|
|
char *comm;
|
|
|
|
int pid;
|
|
|
|
};
|
|
|
|
|
2019-04-02 00:43:20 +08:00
|
|
|
static int cmdline_init(struct tep_handle *tep)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
2019-04-02 00:43:20 +08:00
|
|
|
struct cmdline_list *cmdlist = tep->cmdlist;
|
2012-04-06 06:47:53 +08:00
|
|
|
struct cmdline_list *item;
|
2018-12-01 12:08:09 +08:00
|
|
|
struct tep_cmdline *cmdlines;
|
2012-04-06 06:47:53 +08:00
|
|
|
int i;
|
|
|
|
|
2019-04-02 00:43:20 +08:00
|
|
|
cmdlines = malloc(sizeof(*cmdlines) * tep->cmdline_count);
|
2012-09-13 04:30:50 +08:00
|
|
|
if (!cmdlines)
|
|
|
|
return -1;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
i = 0;
|
|
|
|
while (cmdlist) {
|
|
|
|
cmdlines[i].pid = cmdlist->pid;
|
|
|
|
cmdlines[i].comm = cmdlist->comm;
|
|
|
|
i++;
|
|
|
|
item = cmdlist;
|
|
|
|
cmdlist = cmdlist->next;
|
|
|
|
free(item);
|
|
|
|
}
|
|
|
|
|
2019-04-02 00:43:20 +08:00
|
|
|
qsort(cmdlines, tep->cmdline_count, sizeof(*cmdlines), cmdline_cmp);
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2019-04-02 00:43:20 +08:00
|
|
|
tep->cmdlines = cmdlines;
|
|
|
|
tep->cmdlist = NULL;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-04-02 00:43:20 +08:00
|
|
|
static const char *find_cmdline(struct tep_handle *tep, int pid)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
2018-12-01 12:08:09 +08:00
|
|
|
const struct tep_cmdline *comm;
|
|
|
|
struct tep_cmdline key;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
if (!pid)
|
|
|
|
return "<idle>";
|
|
|
|
|
2019-04-02 00:43:20 +08:00
|
|
|
if (!tep->cmdlines && cmdline_init(tep))
|
2012-09-13 04:30:50 +08:00
|
|
|
return "<not enough memory for cmdlines!>";
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
key.pid = pid;
|
|
|
|
|
2019-04-02 00:43:20 +08:00
|
|
|
comm = bsearch(&key, tep->cmdlines, tep->cmdline_count,
|
|
|
|
sizeof(*tep->cmdlines), cmdline_cmp);
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
if (comm)
|
|
|
|
return comm->comm;
|
|
|
|
return "<...>";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-04-02 00:43:16 +08:00
|
|
|
* tep_is_pid_registered - return if a pid has a cmdline registered
|
2019-04-02 00:43:17 +08:00
|
|
|
* @tep: a handle to the trace event parser context
|
2012-04-06 06:47:53 +08:00
|
|
|
* @pid: The pid to check if it has a cmdline registered with.
|
|
|
|
*
|
2019-04-02 00:43:16 +08:00
|
|
|
* Returns true if the pid has a cmdline mapped to it
|
|
|
|
* false otherwise.
|
2012-04-06 06:47:53 +08:00
|
|
|
*/
|
2019-04-02 00:43:17 +08:00
|
|
|
bool tep_is_pid_registered(struct tep_handle *tep, int pid)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
2018-12-01 12:08:09 +08:00
|
|
|
const struct tep_cmdline *comm;
|
|
|
|
struct tep_cmdline key;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
if (!pid)
|
2019-04-02 00:43:16 +08:00
|
|
|
return true;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2019-04-02 00:43:17 +08:00
|
|
|
if (!tep->cmdlines && cmdline_init(tep))
|
2019-04-02 00:43:16 +08:00
|
|
|
return false;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
key.pid = pid;
|
|
|
|
|
2019-04-02 00:43:17 +08:00
|
|
|
comm = bsearch(&key, tep->cmdlines, tep->cmdline_count,
|
|
|
|
sizeof(*tep->cmdlines), cmdline_cmp);
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
if (comm)
|
2019-04-02 00:43:16 +08:00
|
|
|
return true;
|
|
|
|
return false;
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the command lines have been converted to an array, then
|
|
|
|
* we must add this pid. This is much slower than when cmdlines
|
|
|
|
* are added before the array is initialized.
|
|
|
|
*/
|
2019-04-02 00:43:20 +08:00
|
|
|
static int add_new_comm(struct tep_handle *tep,
|
2018-11-30 23:44:11 +08:00
|
|
|
const char *comm, int pid, bool override)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
2019-04-02 00:43:20 +08:00
|
|
|
struct tep_cmdline *cmdlines = tep->cmdlines;
|
2018-12-01 12:08:09 +08:00
|
|
|
struct tep_cmdline *cmdline;
|
|
|
|
struct tep_cmdline key;
|
2018-11-30 23:44:11 +08:00
|
|
|
char *new_comm;
|
2019-08-29 03:05:29 +08:00
|
|
|
int cnt;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
if (!pid)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* avoid duplicates */
|
|
|
|
key.pid = pid;
|
|
|
|
|
2019-04-02 00:43:20 +08:00
|
|
|
cmdline = bsearch(&key, tep->cmdlines, tep->cmdline_count,
|
|
|
|
sizeof(*tep->cmdlines), cmdline_cmp);
|
2012-04-06 06:47:53 +08:00
|
|
|
if (cmdline) {
|
2018-11-30 23:44:11 +08:00
|
|
|
if (!override) {
|
|
|
|
errno = EEXIST;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
new_comm = strdup(comm);
|
|
|
|
if (!new_comm) {
|
|
|
|
errno = ENOMEM;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
free(cmdline->comm);
|
|
|
|
cmdline->comm = new_comm;
|
|
|
|
|
|
|
|
return 0;
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
|
2019-04-02 00:43:20 +08:00
|
|
|
cmdlines = realloc(cmdlines, sizeof(*cmdlines) * (tep->cmdline_count + 1));
|
2012-04-06 06:47:53 +08:00
|
|
|
if (!cmdlines) {
|
|
|
|
errno = ENOMEM;
|
|
|
|
return -1;
|
|
|
|
}
|
2019-08-29 03:05:28 +08:00
|
|
|
tep->cmdlines = cmdlines;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2019-08-29 03:05:29 +08:00
|
|
|
key.comm = strdup(comm);
|
|
|
|
if (!key.comm) {
|
2012-09-13 04:30:50 +08:00
|
|
|
errno = ENOMEM;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2019-08-29 03:05:29 +08:00
|
|
|
if (!tep->cmdline_count) {
|
|
|
|
/* no entries yet */
|
|
|
|
tep->cmdlines[0] = key;
|
2019-04-02 00:43:20 +08:00
|
|
|
tep->cmdline_count++;
|
2019-08-29 03:05:29 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2019-08-29 03:05:29 +08:00
|
|
|
/* Now find where we want to store the new cmdline */
|
|
|
|
cmdline = bsearch(&key, tep->cmdlines, tep->cmdline_count - 1,
|
|
|
|
sizeof(*tep->cmdlines), cmdline_slot_cmp);
|
|
|
|
|
|
|
|
cnt = tep->cmdline_count;
|
|
|
|
if (cmdline) {
|
|
|
|
/* cmdline points to the one before the spot we want */
|
|
|
|
cmdline++;
|
|
|
|
cnt -= cmdline - tep->cmdlines;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
/* The new entry is either before or after the list */
|
|
|
|
if (key.pid > tep->cmdlines[tep->cmdline_count - 1].pid) {
|
|
|
|
tep->cmdlines[tep->cmdline_count++] = key;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
cmdline = &tep->cmdlines[0];
|
|
|
|
}
|
|
|
|
memmove(cmdline + 1, cmdline, (cnt * sizeof(*cmdline)));
|
|
|
|
*cmdline = key;
|
|
|
|
|
|
|
|
tep->cmdline_count++;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-04-02 00:43:17 +08:00
|
|
|
static int _tep_register_comm(struct tep_handle *tep,
|
2018-11-30 23:44:11 +08:00
|
|
|
const char *comm, int pid, bool override)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
|
|
|
struct cmdline_list *item;
|
|
|
|
|
2019-04-02 00:43:17 +08:00
|
|
|
if (tep->cmdlines)
|
|
|
|
return add_new_comm(tep, comm, pid, override);
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2012-09-13 04:30:50 +08:00
|
|
|
item = malloc(sizeof(*item));
|
|
|
|
if (!item)
|
|
|
|
return -1;
|
|
|
|
|
2015-03-24 21:57:49 +08:00
|
|
|
if (comm)
|
|
|
|
item->comm = strdup(comm);
|
|
|
|
else
|
|
|
|
item->comm = strdup("<...>");
|
2012-09-13 04:30:50 +08:00
|
|
|
if (!item->comm) {
|
|
|
|
free(item);
|
|
|
|
return -1;
|
|
|
|
}
|
2012-04-06 06:47:53 +08:00
|
|
|
item->pid = pid;
|
2019-04-02 00:43:17 +08:00
|
|
|
item->next = tep->cmdlist;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2019-04-02 00:43:17 +08:00
|
|
|
tep->cmdlist = item;
|
|
|
|
tep->cmdline_count++;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-11-30 23:44:11 +08:00
|
|
|
/**
|
|
|
|
* tep_register_comm - register a pid / comm mapping
|
2019-04-02 00:43:17 +08:00
|
|
|
* @tep: a handle to the trace event parser context
|
2018-11-30 23:44:11 +08:00
|
|
|
* @comm: the command line to register
|
|
|
|
* @pid: the pid to map the command line to
|
|
|
|
*
|
|
|
|
* This adds a mapping to search for command line names with
|
|
|
|
* a given pid. The comm is duplicated. If a command with the same pid
|
|
|
|
* already exist, -1 is returned and errno is set to EEXIST
|
|
|
|
*/
|
2019-04-02 00:43:17 +08:00
|
|
|
int tep_register_comm(struct tep_handle *tep, const char *comm, int pid)
|
2018-11-30 23:44:11 +08:00
|
|
|
{
|
2019-04-02 00:43:17 +08:00
|
|
|
return _tep_register_comm(tep, comm, pid, false);
|
2018-11-30 23:44:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* tep_override_comm - register a pid / comm mapping
|
2019-04-02 00:43:17 +08:00
|
|
|
* @tep: a handle to the trace event parser context
|
2018-11-30 23:44:11 +08:00
|
|
|
* @comm: the command line to register
|
|
|
|
* @pid: the pid to map the command line to
|
|
|
|
*
|
|
|
|
* This adds a mapping to search for command line names with
|
|
|
|
* a given pid. The comm is duplicated. If a command with the same pid
|
|
|
|
* already exist, the command string is udapted with the new one
|
|
|
|
*/
|
2019-04-02 00:43:17 +08:00
|
|
|
int tep_override_comm(struct tep_handle *tep, const char *comm, int pid)
|
2018-11-30 23:44:11 +08:00
|
|
|
{
|
2019-04-02 00:43:17 +08:00
|
|
|
if (!tep->cmdlines && cmdline_init(tep)) {
|
2018-11-30 23:44:11 +08:00
|
|
|
errno = ENOMEM;
|
|
|
|
return -1;
|
|
|
|
}
|
2019-04-02 00:43:17 +08:00
|
|
|
return _tep_register_comm(tep, comm, pid, true);
|
2018-11-30 23:44:11 +08:00
|
|
|
}
|
|
|
|
|
2012-04-06 06:47:53 +08:00
|
|
|
struct func_map {
|
|
|
|
unsigned long long addr;
|
|
|
|
char *func;
|
|
|
|
char *mod;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct func_list {
|
|
|
|
struct func_list *next;
|
|
|
|
unsigned long long addr;
|
|
|
|
char *func;
|
|
|
|
char *mod;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int func_cmp(const void *a, const void *b)
|
|
|
|
{
|
|
|
|
const struct func_map *fa = a;
|
|
|
|
const struct func_map *fb = b;
|
|
|
|
|
|
|
|
if (fa->addr < fb->addr)
|
|
|
|
return -1;
|
|
|
|
if (fa->addr > fb->addr)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We are searching for a record in between, not an exact
|
|
|
|
* match.
|
|
|
|
*/
|
|
|
|
static int func_bcmp(const void *a, const void *b)
|
|
|
|
{
|
|
|
|
const struct func_map *fa = a;
|
|
|
|
const struct func_map *fb = b;
|
|
|
|
|
|
|
|
if ((fa->addr == fb->addr) ||
|
|
|
|
|
|
|
|
(fa->addr > fb->addr &&
|
|
|
|
fa->addr < (fb+1)->addr))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (fa->addr < fb->addr)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2019-04-02 00:43:20 +08:00
|
|
|
static int func_map_init(struct tep_handle *tep)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
|
|
|
struct func_list *funclist;
|
|
|
|
struct func_list *item;
|
|
|
|
struct func_map *func_map;
|
|
|
|
int i;
|
|
|
|
|
2019-04-02 00:43:20 +08:00
|
|
|
func_map = malloc(sizeof(*func_map) * (tep->func_count + 1));
|
2012-09-13 04:30:50 +08:00
|
|
|
if (!func_map)
|
|
|
|
return -1;
|
|
|
|
|
2019-04-02 00:43:20 +08:00
|
|
|
funclist = tep->funclist;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
i = 0;
|
|
|
|
while (funclist) {
|
|
|
|
func_map[i].func = funclist->func;
|
|
|
|
func_map[i].addr = funclist->addr;
|
|
|
|
func_map[i].mod = funclist->mod;
|
|
|
|
i++;
|
|
|
|
item = funclist;
|
|
|
|
funclist = funclist->next;
|
|
|
|
free(item);
|
|
|
|
}
|
|
|
|
|
2019-04-02 00:43:20 +08:00
|
|
|
qsort(func_map, tep->func_count, sizeof(*func_map), func_cmp);
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Add a special record at the end.
|
|
|
|
*/
|
2019-04-02 00:43:20 +08:00
|
|
|
func_map[tep->func_count].func = NULL;
|
|
|
|
func_map[tep->func_count].addr = 0;
|
|
|
|
func_map[tep->func_count].mod = NULL;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2019-04-02 00:43:20 +08:00
|
|
|
tep->func_map = func_map;
|
|
|
|
tep->funclist = NULL;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct func_map *
|
2019-04-02 00:43:20 +08:00
|
|
|
__find_func(struct tep_handle *tep, unsigned long long addr)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
|
|
|
struct func_map *func;
|
|
|
|
struct func_map key;
|
|
|
|
|
2019-04-02 00:43:20 +08:00
|
|
|
if (!tep->func_map)
|
|
|
|
func_map_init(tep);
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
key.addr = addr;
|
|
|
|
|
2019-04-02 00:43:20 +08:00
|
|
|
func = bsearch(&key, tep->func_map, tep->func_count,
|
|
|
|
sizeof(*tep->func_map), func_bcmp);
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
return func;
|
|
|
|
}
|
|
|
|
|
2015-07-22 23:36:55 +08:00
|
|
|
struct func_resolver {
|
2018-08-09 02:02:49 +08:00
|
|
|
tep_func_resolver_t *func;
|
|
|
|
void *priv;
|
|
|
|
struct func_map map;
|
2015-07-22 23:36:55 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2018-08-09 02:02:55 +08:00
|
|
|
* tep_set_function_resolver - set an alternative function resolver
|
2019-04-02 00:43:17 +08:00
|
|
|
* @tep: a handle to the trace event parser context
|
2015-07-22 23:36:55 +08:00
|
|
|
* @resolver: function to be used
|
|
|
|
* @priv: resolver function private state.
|
|
|
|
*
|
|
|
|
* Some tools may have already a way to resolve kernel functions, allow them to
|
2019-04-02 00:43:17 +08:00
|
|
|
* keep using it instead of duplicating all the entries inside tep->funclist.
|
2015-07-22 23:36:55 +08:00
|
|
|
*/
|
2019-04-02 00:43:17 +08:00
|
|
|
int tep_set_function_resolver(struct tep_handle *tep,
|
2018-08-09 02:02:55 +08:00
|
|
|
tep_func_resolver_t *func, void *priv)
|
2015-07-22 23:36:55 +08:00
|
|
|
{
|
|
|
|
struct func_resolver *resolver = malloc(sizeof(*resolver));
|
|
|
|
|
|
|
|
if (resolver == NULL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
resolver->func = func;
|
|
|
|
resolver->priv = priv;
|
|
|
|
|
2019-04-02 00:43:17 +08:00
|
|
|
free(tep->func_resolver);
|
|
|
|
tep->func_resolver = resolver;
|
2015-07-22 23:36:55 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-09 02:03:08 +08:00
|
|
|
* tep_reset_function_resolver - reset alternative function resolver
|
2019-04-02 00:43:17 +08:00
|
|
|
* @tep: a handle to the trace event parser context
|
2015-07-22 23:36:55 +08:00
|
|
|
*
|
|
|
|
* Stop using whatever alternative resolver was set, use the default
|
|
|
|
* one instead.
|
|
|
|
*/
|
2019-04-02 00:43:17 +08:00
|
|
|
void tep_reset_function_resolver(struct tep_handle *tep)
|
2015-07-22 23:36:55 +08:00
|
|
|
{
|
2019-04-02 00:43:17 +08:00
|
|
|
free(tep->func_resolver);
|
|
|
|
tep->func_resolver = NULL;
|
2015-07-22 23:36:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct func_map *
|
2019-04-02 00:43:20 +08:00
|
|
|
find_func(struct tep_handle *tep, unsigned long long addr)
|
2015-07-22 23:36:55 +08:00
|
|
|
{
|
|
|
|
struct func_map *map;
|
|
|
|
|
2019-04-02 00:43:20 +08:00
|
|
|
if (!tep->func_resolver)
|
|
|
|
return __find_func(tep, addr);
|
2015-07-22 23:36:55 +08:00
|
|
|
|
2019-04-02 00:43:20 +08:00
|
|
|
map = &tep->func_resolver->map;
|
2015-07-22 23:36:55 +08:00
|
|
|
map->mod = NULL;
|
|
|
|
map->addr = addr;
|
2019-04-02 00:43:20 +08:00
|
|
|
map->func = tep->func_resolver->func(tep->func_resolver->priv,
|
|
|
|
&map->addr, &map->mod);
|
2015-07-22 23:36:55 +08:00
|
|
|
if (map->func == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return map;
|
|
|
|
}
|
|
|
|
|
2012-04-06 06:47:53 +08:00
|
|
|
/**
|
2018-08-09 02:03:05 +08:00
|
|
|
* tep_find_function - find a function by a given address
|
2019-04-02 00:43:17 +08:00
|
|
|
* @tep: a handle to the trace event parser context
|
2012-04-06 06:47:53 +08:00
|
|
|
* @addr: the address to find the function with
|
|
|
|
*
|
|
|
|
* Returns a pointer to the function stored that has the given
|
|
|
|
* address. Note, the address does not have to be exact, it
|
|
|
|
* will select the function that would contain the address.
|
|
|
|
*/
|
2019-04-02 00:43:17 +08:00
|
|
|
const char *tep_find_function(struct tep_handle *tep, unsigned long long addr)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
|
|
|
struct func_map *map;
|
|
|
|
|
2019-04-02 00:43:17 +08:00
|
|
|
map = find_func(tep, addr);
|
2012-04-06 06:47:53 +08:00
|
|
|
if (!map)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return map->func;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-09 02:03:05 +08:00
|
|
|
* tep_find_function_address - find a function address by a given address
|
2019-04-02 00:43:17 +08:00
|
|
|
* @tep: a handle to the trace event parser context
|
2012-04-06 06:47:53 +08:00
|
|
|
* @addr: the address to find the function with
|
|
|
|
*
|
|
|
|
* Returns the address the function starts at. This can be used in
|
2018-08-09 02:03:05 +08:00
|
|
|
* conjunction with tep_find_function to print both the function
|
2012-04-06 06:47:53 +08:00
|
|
|
* name and the function offset.
|
|
|
|
*/
|
|
|
|
unsigned long long
|
2019-04-02 00:43:17 +08:00
|
|
|
tep_find_function_address(struct tep_handle *tep, unsigned long long addr)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
|
|
|
struct func_map *map;
|
|
|
|
|
2019-04-02 00:43:17 +08:00
|
|
|
map = find_func(tep, addr);
|
2012-04-06 06:47:53 +08:00
|
|
|
if (!map)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return map->addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-09 02:03:02 +08:00
|
|
|
* tep_register_function - register a function with a given address
|
2019-04-02 00:43:17 +08:00
|
|
|
* @tep: a handle to the trace event parser context
|
2012-04-06 06:47:53 +08:00
|
|
|
* @function: the function name to register
|
|
|
|
* @addr: the address the function starts at
|
|
|
|
* @mod: the kernel module the function may be in (NULL for none)
|
|
|
|
*
|
|
|
|
* This registers a function name with an address and module.
|
|
|
|
* The @func passed in is duplicated.
|
|
|
|
*/
|
2019-04-02 00:43:17 +08:00
|
|
|
int tep_register_function(struct tep_handle *tep, char *func,
|
2018-08-09 02:03:02 +08:00
|
|
|
unsigned long long addr, char *mod)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
2012-09-13 04:30:50 +08:00
|
|
|
struct func_list *item = malloc(sizeof(*item));
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2012-09-13 04:30:50 +08:00
|
|
|
if (!item)
|
|
|
|
return -1;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2019-04-02 00:43:17 +08:00
|
|
|
item->next = tep->funclist;
|
2012-04-06 06:47:53 +08:00
|
|
|
item->func = strdup(func);
|
2012-09-13 04:30:50 +08:00
|
|
|
if (!item->func)
|
|
|
|
goto out_free;
|
|
|
|
|
|
|
|
if (mod) {
|
2012-04-06 06:47:53 +08:00
|
|
|
item->mod = strdup(mod);
|
2012-09-13 04:30:50 +08:00
|
|
|
if (!item->mod)
|
|
|
|
goto out_free_func;
|
|
|
|
} else
|
2012-04-06 06:47:53 +08:00
|
|
|
item->mod = NULL;
|
|
|
|
item->addr = addr;
|
|
|
|
|
2019-04-02 00:43:17 +08:00
|
|
|
tep->funclist = item;
|
|
|
|
tep->func_count++;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
return 0;
|
2012-09-13 04:30:50 +08:00
|
|
|
|
|
|
|
out_free_func:
|
|
|
|
free(item->func);
|
|
|
|
item->func = NULL;
|
|
|
|
out_free:
|
|
|
|
free(item);
|
|
|
|
errno = ENOMEM;
|
|
|
|
return -1;
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-09 02:02:52 +08:00
|
|
|
* tep_print_funcs - print out the stored functions
|
2019-04-02 00:43:17 +08:00
|
|
|
* @tep: a handle to the trace event parser context
|
2012-04-06 06:47:53 +08:00
|
|
|
*
|
|
|
|
* This prints out the stored functions.
|
|
|
|
*/
|
2019-04-02 00:43:17 +08:00
|
|
|
void tep_print_funcs(struct tep_handle *tep)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2019-04-02 00:43:17 +08:00
|
|
|
if (!tep->func_map)
|
|
|
|
func_map_init(tep);
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2019-04-02 00:43:17 +08:00
|
|
|
for (i = 0; i < (int)tep->func_count; i++) {
|
2012-04-06 06:47:53 +08:00
|
|
|
printf("%016llx %s",
|
2019-04-02 00:43:17 +08:00
|
|
|
tep->func_map[i].addr,
|
|
|
|
tep->func_map[i].func);
|
|
|
|
if (tep->func_map[i].mod)
|
|
|
|
printf(" [%s]\n", tep->func_map[i].mod);
|
2012-04-06 06:47:53 +08:00
|
|
|
else
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct printk_map {
|
|
|
|
unsigned long long addr;
|
|
|
|
char *printk;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct printk_list {
|
|
|
|
struct printk_list *next;
|
|
|
|
unsigned long long addr;
|
|
|
|
char *printk;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int printk_cmp(const void *a, const void *b)
|
|
|
|
{
|
2012-04-09 10:54:29 +08:00
|
|
|
const struct printk_map *pa = a;
|
|
|
|
const struct printk_map *pb = b;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2012-04-09 10:54:29 +08:00
|
|
|
if (pa->addr < pb->addr)
|
2012-04-06 06:47:53 +08:00
|
|
|
return -1;
|
2012-04-09 10:54:29 +08:00
|
|
|
if (pa->addr > pb->addr)
|
2012-04-06 06:47:53 +08:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-04-02 00:43:20 +08:00
|
|
|
static int printk_map_init(struct tep_handle *tep)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
|
|
|
struct printk_list *printklist;
|
|
|
|
struct printk_list *item;
|
|
|
|
struct printk_map *printk_map;
|
|
|
|
int i;
|
|
|
|
|
2019-04-02 00:43:20 +08:00
|
|
|
printk_map = malloc(sizeof(*printk_map) * (tep->printk_count + 1));
|
2012-09-13 04:30:50 +08:00
|
|
|
if (!printk_map)
|
|
|
|
return -1;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2019-04-02 00:43:20 +08:00
|
|
|
printklist = tep->printklist;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
i = 0;
|
|
|
|
while (printklist) {
|
|
|
|
printk_map[i].printk = printklist->printk;
|
|
|
|
printk_map[i].addr = printklist->addr;
|
|
|
|
i++;
|
|
|
|
item = printklist;
|
|
|
|
printklist = printklist->next;
|
|
|
|
free(item);
|
|
|
|
}
|
|
|
|
|
2019-04-02 00:43:20 +08:00
|
|
|
qsort(printk_map, tep->printk_count, sizeof(*printk_map), printk_cmp);
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2019-04-02 00:43:20 +08:00
|
|
|
tep->printk_map = printk_map;
|
|
|
|
tep->printklist = NULL;
|
2012-09-13 04:30:50 +08:00
|
|
|
|
|
|
|
return 0;
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct printk_map *
|
2019-04-02 00:43:20 +08:00
|
|
|
find_printk(struct tep_handle *tep, unsigned long long addr)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
|
|
|
struct printk_map *printk;
|
|
|
|
struct printk_map key;
|
|
|
|
|
2019-04-02 00:43:20 +08:00
|
|
|
if (!tep->printk_map && printk_map_init(tep))
|
2012-09-13 04:30:50 +08:00
|
|
|
return NULL;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
key.addr = addr;
|
|
|
|
|
2019-04-02 00:43:20 +08:00
|
|
|
printk = bsearch(&key, tep->printk_map, tep->printk_count,
|
|
|
|
sizeof(*tep->printk_map), printk_cmp);
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
return printk;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-09 02:02:54 +08:00
|
|
|
* tep_register_print_string - register a string by its address
|
2019-04-02 00:43:17 +08:00
|
|
|
* @tep: a handle to the trace event parser context
|
2012-04-06 06:47:53 +08:00
|
|
|
* @fmt: the string format to register
|
|
|
|
* @addr: the address the string was located at
|
|
|
|
*
|
|
|
|
* This registers a string by the address it was stored in the kernel.
|
|
|
|
* The @fmt passed in is duplicated.
|
|
|
|
*/
|
2019-04-02 00:43:17 +08:00
|
|
|
int tep_register_print_string(struct tep_handle *tep, const char *fmt,
|
2018-08-09 02:02:54 +08:00
|
|
|
unsigned long long addr)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
2012-09-13 04:30:50 +08:00
|
|
|
struct printk_list *item = malloc(sizeof(*item));
|
2013-11-02 05:53:54 +08:00
|
|
|
char *p;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2012-09-13 04:30:50 +08:00
|
|
|
if (!item)
|
|
|
|
return -1;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2019-04-02 00:43:17 +08:00
|
|
|
item->next = tep->printklist;
|
2012-04-06 06:47:53 +08:00
|
|
|
item->addr = addr;
|
|
|
|
|
2013-11-02 05:53:54 +08:00
|
|
|
/* Strip off quotes and '\n' from the end */
|
|
|
|
if (fmt[0] == '"')
|
|
|
|
fmt++;
|
2012-09-13 04:30:50 +08:00
|
|
|
item->printk = strdup(fmt);
|
2012-04-09 10:54:31 +08:00
|
|
|
if (!item->printk)
|
2012-09-13 04:30:50 +08:00
|
|
|
goto out_free;
|
2012-04-09 10:54:31 +08:00
|
|
|
|
2013-11-02 05:53:54 +08:00
|
|
|
p = item->printk + strlen(item->printk) - 1;
|
|
|
|
if (*p == '"')
|
|
|
|
*p = 0;
|
|
|
|
|
|
|
|
p -= 2;
|
|
|
|
if (strcmp(p, "\\n") == 0)
|
|
|
|
*p = 0;
|
|
|
|
|
2019-04-02 00:43:17 +08:00
|
|
|
tep->printklist = item;
|
|
|
|
tep->printk_count++;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
return 0;
|
2012-09-13 04:30:50 +08:00
|
|
|
|
|
|
|
out_free:
|
|
|
|
free(item);
|
|
|
|
errno = ENOMEM;
|
|
|
|
return -1;
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-09 02:02:52 +08:00
|
|
|
* tep_print_printk - print out the stored strings
|
2019-04-02 00:43:17 +08:00
|
|
|
* @tep: a handle to the trace event parser context
|
2012-04-06 06:47:53 +08:00
|
|
|
*
|
|
|
|
* This prints the string formats that were stored.
|
|
|
|
*/
|
2019-04-02 00:43:17 +08:00
|
|
|
void tep_print_printk(struct tep_handle *tep)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2019-04-02 00:43:17 +08:00
|
|
|
if (!tep->printk_map)
|
|
|
|
printk_map_init(tep);
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2019-04-02 00:43:17 +08:00
|
|
|
for (i = 0; i < (int)tep->printk_count; i++) {
|
2012-04-06 06:47:53 +08:00
|
|
|
printf("%016llx %s\n",
|
2019-04-02 00:43:17 +08:00
|
|
|
tep->printk_map[i].addr,
|
|
|
|
tep->printk_map[i].printk);
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-30 23:44:07 +08:00
|
|
|
static struct tep_event *alloc_event(void)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
2018-11-30 23:44:07 +08:00
|
|
|
return calloc(1, sizeof(struct tep_event));
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
|
2019-04-02 00:43:20 +08:00
|
|
|
static int add_event(struct tep_handle *tep, struct tep_event *event)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
|
|
|
int i;
|
2019-04-02 00:43:20 +08:00
|
|
|
struct tep_event **events = realloc(tep->events, sizeof(event) *
|
|
|
|
(tep->nr_events + 1));
|
2012-09-13 04:30:50 +08:00
|
|
|
if (!events)
|
|
|
|
return -1;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2019-04-02 00:43:20 +08:00
|
|
|
tep->events = events;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2019-04-02 00:43:20 +08:00
|
|
|
for (i = 0; i < tep->nr_events; i++) {
|
|
|
|
if (tep->events[i]->id > event->id)
|
2012-04-06 06:47:53 +08:00
|
|
|
break;
|
|
|
|
}
|
2019-04-02 00:43:20 +08:00
|
|
|
if (i < tep->nr_events)
|
|
|
|
memmove(&tep->events[i + 1],
|
|
|
|
&tep->events[i],
|
|
|
|
sizeof(event) * (tep->nr_events - i));
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2019-04-02 00:43:20 +08:00
|
|
|
tep->events[i] = event;
|
|
|
|
tep->nr_events++;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2019-04-02 00:43:20 +08:00
|
|
|
event->tep = tep;
|
2012-09-13 04:30:50 +08:00
|
|
|
|
|
|
|
return 0;
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
static int event_item_type(enum tep_event_type type)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
|
|
|
switch (type) {
|
2018-09-20 02:56:47 +08:00
|
|
|
case TEP_EVENT_ITEM ... TEP_EVENT_SQUOTE:
|
2012-04-06 06:47:53 +08:00
|
|
|
return 1;
|
2018-09-20 02:56:47 +08:00
|
|
|
case TEP_EVENT_ERROR ... TEP_EVENT_DELIM:
|
2012-04-06 06:47:53 +08:00
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-20 02:56:49 +08:00
|
|
|
static void free_flag_sym(struct tep_print_flag_sym *fsym)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
2018-09-20 02:56:49 +08:00
|
|
|
struct tep_print_flag_sym *next;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
while (fsym) {
|
|
|
|
next = fsym->next;
|
|
|
|
free(fsym->value);
|
|
|
|
free(fsym->str);
|
|
|
|
free(fsym);
|
|
|
|
fsym = next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-20 02:56:49 +08:00
|
|
|
static void free_arg(struct tep_print_arg *arg)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
2018-09-20 02:56:49 +08:00
|
|
|
struct tep_print_arg *farg;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
if (!arg)
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch (arg->type) {
|
2018-09-20 02:56:50 +08:00
|
|
|
case TEP_PRINT_ATOM:
|
2012-04-06 06:47:53 +08:00
|
|
|
free(arg->atom.atom);
|
|
|
|
break;
|
2018-09-20 02:56:50 +08:00
|
|
|
case TEP_PRINT_FIELD:
|
2012-04-06 06:47:53 +08:00
|
|
|
free(arg->field.name);
|
|
|
|
break;
|
2018-09-20 02:56:50 +08:00
|
|
|
case TEP_PRINT_FLAGS:
|
2012-04-06 06:47:53 +08:00
|
|
|
free_arg(arg->flags.field);
|
|
|
|
free(arg->flags.delim);
|
|
|
|
free_flag_sym(arg->flags.flags);
|
|
|
|
break;
|
2018-09-20 02:56:50 +08:00
|
|
|
case TEP_PRINT_SYMBOL:
|
2012-04-06 06:47:53 +08:00
|
|
|
free_arg(arg->symbol.field);
|
|
|
|
free_flag_sym(arg->symbol.symbols);
|
|
|
|
break;
|
2018-09-20 02:56:50 +08:00
|
|
|
case TEP_PRINT_HEX:
|
|
|
|
case TEP_PRINT_HEX_STR:
|
2012-06-27 08:41:41 +08:00
|
|
|
free_arg(arg->hex.field);
|
|
|
|
free_arg(arg->hex.size);
|
|
|
|
break;
|
2018-09-20 02:56:50 +08:00
|
|
|
case TEP_PRINT_INT_ARRAY:
|
2015-03-24 19:07:19 +08:00
|
|
|
free_arg(arg->int_array.field);
|
|
|
|
free_arg(arg->int_array.count);
|
|
|
|
free_arg(arg->int_array.el_size);
|
|
|
|
break;
|
2018-09-20 02:56:50 +08:00
|
|
|
case TEP_PRINT_TYPE:
|
2012-04-06 06:47:53 +08:00
|
|
|
free(arg->typecast.type);
|
|
|
|
free_arg(arg->typecast.item);
|
|
|
|
break;
|
2018-09-20 02:56:50 +08:00
|
|
|
case TEP_PRINT_STRING:
|
|
|
|
case TEP_PRINT_BSTRING:
|
2012-04-06 06:47:53 +08:00
|
|
|
free(arg->string.string);
|
|
|
|
break;
|
2018-09-20 02:56:50 +08:00
|
|
|
case TEP_PRINT_BITMASK:
|
2014-06-03 11:20:16 +08:00
|
|
|
free(arg->bitmask.bitmask);
|
|
|
|
break;
|
2018-09-20 02:56:50 +08:00
|
|
|
case TEP_PRINT_DYNAMIC_ARRAY:
|
|
|
|
case TEP_PRINT_DYNAMIC_ARRAY_LEN:
|
2012-04-06 06:47:53 +08:00
|
|
|
free(arg->dynarray.index);
|
|
|
|
break;
|
2018-09-20 02:56:50 +08:00
|
|
|
case TEP_PRINT_OP:
|
2012-04-06 06:47:53 +08:00
|
|
|
free(arg->op.op);
|
|
|
|
free_arg(arg->op.left);
|
|
|
|
free_arg(arg->op.right);
|
|
|
|
break;
|
2018-09-20 02:56:50 +08:00
|
|
|
case TEP_PRINT_FUNC:
|
2012-04-06 06:47:53 +08:00
|
|
|
while (arg->func.args) {
|
|
|
|
farg = arg->func.args;
|
|
|
|
arg->func.args = farg->next;
|
|
|
|
free_arg(farg);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2018-09-20 02:56:50 +08:00
|
|
|
case TEP_PRINT_NULL:
|
2012-04-06 06:47:53 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(arg);
|
|
|
|
}
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
static enum tep_event_type get_type(int ch)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
|
|
|
if (ch == '\n')
|
2018-09-20 02:56:47 +08:00
|
|
|
return TEP_EVENT_NEWLINE;
|
2012-04-06 06:47:53 +08:00
|
|
|
if (isspace(ch))
|
2018-09-20 02:56:47 +08:00
|
|
|
return TEP_EVENT_SPACE;
|
2012-04-06 06:47:53 +08:00
|
|
|
if (isalnum(ch) || ch == '_')
|
2018-09-20 02:56:47 +08:00
|
|
|
return TEP_EVENT_ITEM;
|
2012-04-06 06:47:53 +08:00
|
|
|
if (ch == '\'')
|
2018-09-20 02:56:47 +08:00
|
|
|
return TEP_EVENT_SQUOTE;
|
2012-04-06 06:47:53 +08:00
|
|
|
if (ch == '"')
|
2018-09-20 02:56:47 +08:00
|
|
|
return TEP_EVENT_DQUOTE;
|
2012-04-06 06:47:53 +08:00
|
|
|
if (!isprint(ch))
|
2018-09-20 02:56:47 +08:00
|
|
|
return TEP_EVENT_NONE;
|
2012-04-06 06:47:53 +08:00
|
|
|
if (ch == '(' || ch == ')' || ch == ',')
|
2018-09-20 02:56:47 +08:00
|
|
|
return TEP_EVENT_DELIM;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
return TEP_EVENT_OP;
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int __read_char(void)
|
|
|
|
{
|
|
|
|
if (input_buf_ptr >= input_buf_siz)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return input_buf[input_buf_ptr++];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-09-30 19:07:33 +08:00
|
|
|
* peek_char - peek at the next character that will be read
|
2012-04-06 06:47:53 +08:00
|
|
|
*
|
|
|
|
* Returns the next character read, or -1 if end of buffer.
|
|
|
|
*/
|
2020-09-30 19:07:33 +08:00
|
|
|
__hidden int peek_char(void)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
2020-09-30 19:07:33 +08:00
|
|
|
if (input_buf_ptr >= input_buf_siz)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return input_buf[input_buf_ptr];
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
|
2012-04-09 10:54:30 +08:00
|
|
|
static int extend_token(char **tok, char *buf, int size)
|
|
|
|
{
|
|
|
|
char *newtok = realloc(*tok, size);
|
|
|
|
|
|
|
|
if (!newtok) {
|
|
|
|
free(*tok);
|
|
|
|
*tok = NULL;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!*tok)
|
|
|
|
strcpy(newtok, buf);
|
|
|
|
else
|
|
|
|
strcat(newtok, buf);
|
|
|
|
*tok = newtok;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
static enum tep_event_type force_token(const char *str, char **tok);
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
static enum tep_event_type __read_token(char **tok)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
|
|
|
char buf[BUFSIZ];
|
|
|
|
int ch, last_ch, quote_ch, next_ch;
|
|
|
|
int i = 0;
|
|
|
|
int tok_size = 0;
|
2018-09-20 02:56:47 +08:00
|
|
|
enum tep_event_type type;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
*tok = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
ch = __read_char();
|
|
|
|
if (ch < 0)
|
2018-09-20 02:56:47 +08:00
|
|
|
return TEP_EVENT_NONE;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
type = get_type(ch);
|
2018-09-20 02:56:47 +08:00
|
|
|
if (type == TEP_EVENT_NONE)
|
2012-04-06 06:47:53 +08:00
|
|
|
return type;
|
|
|
|
|
|
|
|
buf[i++] = ch;
|
|
|
|
|
|
|
|
switch (type) {
|
2018-09-20 02:56:47 +08:00
|
|
|
case TEP_EVENT_NEWLINE:
|
|
|
|
case TEP_EVENT_DELIM:
|
2012-09-13 02:39:59 +08:00
|
|
|
if (asprintf(tok, "%c", ch) < 0)
|
2018-09-20 02:56:47 +08:00
|
|
|
return TEP_EVENT_ERROR;
|
2012-09-13 02:39:59 +08:00
|
|
|
|
2012-04-06 06:47:53 +08:00
|
|
|
return type;
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
case TEP_EVENT_OP:
|
2012-04-06 06:47:53 +08:00
|
|
|
switch (ch) {
|
|
|
|
case '-':
|
2020-09-30 19:07:33 +08:00
|
|
|
next_ch = peek_char();
|
2012-04-06 06:47:53 +08:00
|
|
|
if (next_ch == '>') {
|
|
|
|
buf[i++] = __read_char();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* fall through */
|
|
|
|
case '+':
|
|
|
|
case '|':
|
|
|
|
case '&':
|
|
|
|
case '>':
|
|
|
|
case '<':
|
|
|
|
last_ch = ch;
|
2020-09-30 19:07:33 +08:00
|
|
|
ch = peek_char();
|
2012-04-06 06:47:53 +08:00
|
|
|
if (ch != last_ch)
|
|
|
|
goto test_equal;
|
|
|
|
buf[i++] = __read_char();
|
|
|
|
switch (last_ch) {
|
|
|
|
case '>':
|
|
|
|
case '<':
|
|
|
|
goto test_equal;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '!':
|
|
|
|
case '=':
|
|
|
|
goto test_equal;
|
|
|
|
default: /* what should we do instead? */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
buf[i] = 0;
|
|
|
|
*tok = strdup(buf);
|
|
|
|
return type;
|
|
|
|
|
|
|
|
test_equal:
|
2020-09-30 19:07:33 +08:00
|
|
|
ch = peek_char();
|
2012-04-06 06:47:53 +08:00
|
|
|
if (ch == '=')
|
|
|
|
buf[i++] = __read_char();
|
|
|
|
goto out;
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
case TEP_EVENT_DQUOTE:
|
|
|
|
case TEP_EVENT_SQUOTE:
|
2012-04-06 06:47:53 +08:00
|
|
|
/* don't keep quotes */
|
|
|
|
i--;
|
|
|
|
quote_ch = ch;
|
|
|
|
last_ch = 0;
|
|
|
|
concat:
|
|
|
|
do {
|
|
|
|
if (i == (BUFSIZ - 1)) {
|
|
|
|
buf[i] = 0;
|
|
|
|
tok_size += BUFSIZ;
|
2012-04-09 10:54:30 +08:00
|
|
|
|
|
|
|
if (extend_token(tok, buf, tok_size) < 0)
|
2018-09-20 02:56:47 +08:00
|
|
|
return TEP_EVENT_NONE;
|
2012-04-06 06:47:53 +08:00
|
|
|
i = 0;
|
|
|
|
}
|
|
|
|
last_ch = ch;
|
|
|
|
ch = __read_char();
|
|
|
|
buf[i++] = ch;
|
|
|
|
/* the '\' '\' will cancel itself */
|
|
|
|
if (ch == '\\' && last_ch == '\\')
|
|
|
|
last_ch = 0;
|
|
|
|
} while (ch != quote_ch || last_ch == '\\');
|
|
|
|
/* remove the last quote */
|
|
|
|
i--;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For strings (double quotes) check the next token.
|
|
|
|
* If it is another string, concatinate the two.
|
|
|
|
*/
|
2018-09-20 02:56:47 +08:00
|
|
|
if (type == TEP_EVENT_DQUOTE) {
|
2012-04-06 06:47:53 +08:00
|
|
|
unsigned long long save_input_buf_ptr = input_buf_ptr;
|
|
|
|
|
|
|
|
do {
|
|
|
|
ch = __read_char();
|
|
|
|
} while (isspace(ch));
|
|
|
|
if (ch == '"')
|
|
|
|
goto concat;
|
|
|
|
input_buf_ptr = save_input_buf_ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
goto out;
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
case TEP_EVENT_ERROR ... TEP_EVENT_SPACE:
|
|
|
|
case TEP_EVENT_ITEM:
|
2012-04-06 06:47:53 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-09-30 19:07:33 +08:00
|
|
|
while (get_type(peek_char()) == type) {
|
2012-04-06 06:47:53 +08:00
|
|
|
if (i == (BUFSIZ - 1)) {
|
|
|
|
buf[i] = 0;
|
2012-04-09 10:54:30 +08:00
|
|
|
tok_size += BUFSIZ;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2012-04-09 10:54:30 +08:00
|
|
|
if (extend_token(tok, buf, tok_size) < 0)
|
2018-09-20 02:56:47 +08:00
|
|
|
return TEP_EVENT_NONE;
|
2012-04-06 06:47:53 +08:00
|
|
|
i = 0;
|
|
|
|
}
|
|
|
|
ch = __read_char();
|
|
|
|
buf[i++] = ch;
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
buf[i] = 0;
|
2012-04-09 10:54:30 +08:00
|
|
|
if (extend_token(tok, buf, tok_size + i + 1) < 0)
|
2018-09-20 02:56:47 +08:00
|
|
|
return TEP_EVENT_NONE;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
if (type == TEP_EVENT_ITEM) {
|
2012-04-06 06:47:53 +08:00
|
|
|
/*
|
|
|
|
* Older versions of the kernel has a bug that
|
|
|
|
* creates invalid symbols and will break the mac80211
|
|
|
|
* parsing. This is a work around to that bug.
|
|
|
|
*
|
|
|
|
* See Linux kernel commit:
|
|
|
|
* 811cb50baf63461ce0bdb234927046131fc7fa8b
|
|
|
|
*/
|
|
|
|
if (strcmp(*tok, "LOCAL_PR_FMT") == 0) {
|
|
|
|
free(*tok);
|
|
|
|
*tok = NULL;
|
2018-01-12 08:47:42 +08:00
|
|
|
return force_token("\"%s\" ", tok);
|
2012-04-06 06:47:53 +08:00
|
|
|
} else if (strcmp(*tok, "STA_PR_FMT") == 0) {
|
|
|
|
free(*tok);
|
|
|
|
*tok = NULL;
|
|
|
|
return force_token("\" sta:%pM\" ", tok);
|
|
|
|
} else if (strcmp(*tok, "VIF_PR_FMT") == 0) {
|
|
|
|
free(*tok);
|
|
|
|
*tok = NULL;
|
|
|
|
return force_token("\" vif:%p(%d)\" ", tok);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
static enum tep_event_type force_token(const char *str, char **tok)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
|
|
|
const char *save_input_buf;
|
|
|
|
unsigned long long save_input_buf_ptr;
|
|
|
|
unsigned long long save_input_buf_siz;
|
2018-09-20 02:56:47 +08:00
|
|
|
enum tep_event_type type;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
/* save off the current input pointers */
|
|
|
|
save_input_buf = input_buf;
|
|
|
|
save_input_buf_ptr = input_buf_ptr;
|
|
|
|
save_input_buf_siz = input_buf_siz;
|
|
|
|
|
|
|
|
init_input_buf(str, strlen(str));
|
|
|
|
|
|
|
|
type = __read_token(tok);
|
|
|
|
|
|
|
|
/* reset back to original token */
|
|
|
|
input_buf = save_input_buf;
|
|
|
|
input_buf_ptr = save_input_buf_ptr;
|
|
|
|
input_buf_siz = save_input_buf_siz;
|
|
|
|
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
2020-09-30 19:07:33 +08:00
|
|
|
/**
|
|
|
|
* free_token - free a token returned by tep_read_token
|
|
|
|
* @token: the token to free
|
|
|
|
*/
|
|
|
|
__hidden void free_token(char *tok)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
|
|
|
if (tok)
|
|
|
|
free(tok);
|
|
|
|
}
|
|
|
|
|
2020-09-30 19:07:33 +08:00
|
|
|
/**
|
|
|
|
* read_token - access to utilities to use the tep parser
|
|
|
|
* @tok: The token to return
|
|
|
|
*
|
|
|
|
* This will parse tokens from the string given by
|
|
|
|
* tep_init_data().
|
|
|
|
*
|
|
|
|
* Returns the token type.
|
|
|
|
*/
|
|
|
|
__hidden enum tep_event_type read_token(char **tok)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
2018-09-20 02:56:47 +08:00
|
|
|
enum tep_event_type type;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
type = __read_token(tok);
|
2018-09-20 02:56:47 +08:00
|
|
|
if (type != TEP_EVENT_SPACE)
|
2012-04-06 06:47:53 +08:00
|
|
|
return type;
|
|
|
|
|
|
|
|
free_token(*tok);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* not reached */
|
|
|
|
*tok = NULL;
|
2018-09-20 02:56:47 +08:00
|
|
|
return TEP_EVENT_NONE;
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* no newline */
|
2018-09-20 02:56:47 +08:00
|
|
|
static enum tep_event_type read_token_item(char **tok)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
2018-09-20 02:56:47 +08:00
|
|
|
enum tep_event_type type;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
type = __read_token(tok);
|
2018-09-20 02:56:47 +08:00
|
|
|
if (type != TEP_EVENT_SPACE && type != TEP_EVENT_NEWLINE)
|
2012-04-06 06:47:53 +08:00
|
|
|
return type;
|
|
|
|
free_token(*tok);
|
|
|
|
*tok = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* not reached */
|
|
|
|
*tok = NULL;
|
2018-09-20 02:56:47 +08:00
|
|
|
return TEP_EVENT_NONE;
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
static int test_type(enum tep_event_type type, enum tep_event_type expect)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
|
|
|
if (type != expect) {
|
|
|
|
do_warning("Error: expected type %d but read %d",
|
|
|
|
expect, type);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
static int test_type_token(enum tep_event_type type, const char *token,
|
|
|
|
enum tep_event_type expect, const char *expect_tok)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
|
|
|
if (type != expect) {
|
|
|
|
do_warning("Error: expected type %d but read %d",
|
|
|
|
expect, type);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcmp(token, expect_tok) != 0) {
|
|
|
|
do_warning("Error: expected '%s' but read '%s'",
|
|
|
|
expect_tok, token);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
static int __read_expect_type(enum tep_event_type expect, char **tok, int newline_ok)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
2018-09-20 02:56:47 +08:00
|
|
|
enum tep_event_type type;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
if (newline_ok)
|
|
|
|
type = read_token(tok);
|
|
|
|
else
|
|
|
|
type = read_token_item(tok);
|
|
|
|
return test_type(type, expect);
|
|
|
|
}
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
static int read_expect_type(enum tep_event_type expect, char **tok)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
|
|
|
return __read_expect_type(expect, tok, 1);
|
|
|
|
}
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
static int __read_expected(enum tep_event_type expect, const char *str,
|
2012-04-06 06:47:53 +08:00
|
|
|
int newline_ok)
|
|
|
|
{
|
2018-09-20 02:56:47 +08:00
|
|
|
enum tep_event_type type;
|
2012-04-06 06:47:53 +08:00
|
|
|
char *token;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (newline_ok)
|
|
|
|
type = read_token(&token);
|
|
|
|
else
|
|
|
|
type = read_token_item(&token);
|
|
|
|
|
|
|
|
ret = test_type_token(type, token, expect, str);
|
|
|
|
|
|
|
|
free_token(token);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
static int read_expected(enum tep_event_type expect, const char *str)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
|
|
|
return __read_expected(expect, str, 1);
|
|
|
|
}
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
static int read_expected_item(enum tep_event_type expect, const char *str)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
|
|
|
return __read_expected(expect, str, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *event_read_name(void)
|
|
|
|
{
|
|
|
|
char *token;
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
if (read_expected(TEP_EVENT_ITEM, "name") < 0)
|
2012-04-06 06:47:53 +08:00
|
|
|
return NULL;
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
if (read_expected(TEP_EVENT_OP, ":") < 0)
|
2012-04-06 06:47:53 +08:00
|
|
|
return NULL;
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
if (read_expect_type(TEP_EVENT_ITEM, &token) < 0)
|
2012-04-06 06:47:53 +08:00
|
|
|
goto fail;
|
|
|
|
|
|
|
|
return token;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
free_token(token);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int event_read_id(void)
|
|
|
|
{
|
|
|
|
char *token;
|
|
|
|
int id;
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
if (read_expected_item(TEP_EVENT_ITEM, "ID") < 0)
|
2012-04-06 06:47:53 +08:00
|
|
|
return -1;
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
if (read_expected(TEP_EVENT_OP, ":") < 0)
|
2012-04-06 06:47:53 +08:00
|
|
|
return -1;
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
if (read_expect_type(TEP_EVENT_ITEM, &token) < 0)
|
2012-04-06 06:47:53 +08:00
|
|
|
goto fail;
|
|
|
|
|
|
|
|
id = strtoul(token, NULL, 0);
|
|
|
|
free_token(token);
|
|
|
|
return id;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
free_token(token);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-09-20 02:56:45 +08:00
|
|
|
static int field_is_string(struct tep_format_field *field)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
2018-09-20 02:56:46 +08:00
|
|
|
if ((field->flags & TEP_FIELD_IS_ARRAY) &&
|
2012-04-06 06:47:53 +08:00
|
|
|
(strstr(field->type, "char") || strstr(field->type, "u8") ||
|
|
|
|
strstr(field->type, "s8")))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-09-20 02:56:45 +08:00
|
|
|
static int field_is_dynamic(struct tep_format_field *field)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
|
|
|
if (strncmp(field->type, "__data_loc", 10) == 0)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-11-22 17:30:40 +08:00
|
|
|
static int field_is_relative_dynamic(struct tep_format_field *field)
|
|
|
|
{
|
|
|
|
if (strncmp(field->type, "__rel_loc", 9) == 0)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-09-20 02:56:45 +08:00
|
|
|
static int field_is_long(struct tep_format_field *field)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
|
|
|
/* includes long long */
|
|
|
|
if (strstr(field->type, "long"))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-01-25 04:46:43 +08:00
|
|
|
static unsigned int type_size(const char *name)
|
|
|
|
{
|
2018-09-20 02:56:46 +08:00
|
|
|
/* This covers all TEP_FIELD_IS_STRING types. */
|
2013-01-25 04:46:43 +08:00
|
|
|
static struct {
|
|
|
|
const char *type;
|
|
|
|
unsigned int size;
|
|
|
|
} table[] = {
|
|
|
|
{ "u8", 1 },
|
|
|
|
{ "u16", 2 },
|
|
|
|
{ "u32", 4 },
|
|
|
|
{ "u64", 8 },
|
|
|
|
{ "s8", 1 },
|
|
|
|
{ "s16", 2 },
|
|
|
|
{ "s32", 4 },
|
|
|
|
{ "s64", 8 },
|
|
|
|
{ "char", 1 },
|
|
|
|
{ },
|
|
|
|
};
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; table[i].type; i++) {
|
|
|
|
if (!strcmp(table[i].type, name))
|
|
|
|
return table[i].size;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-03-25 04:08:46 +08:00
|
|
|
static int append(char **buf, const char *delim, const char *str)
|
|
|
|
{
|
|
|
|
char *new_buf;
|
|
|
|
|
|
|
|
new_buf = realloc(*buf, strlen(*buf) + strlen(delim) + strlen(str) + 1);
|
|
|
|
if (!new_buf)
|
|
|
|
return -1;
|
|
|
|
strcat(new_buf, delim);
|
|
|
|
strcat(new_buf, str);
|
|
|
|
*buf = new_buf;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-11-30 23:44:07 +08:00
|
|
|
static int event_read_fields(struct tep_event *event, struct tep_format_field **fields)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
2018-09-20 02:56:45 +08:00
|
|
|
struct tep_format_field *field = NULL;
|
2018-09-20 02:56:47 +08:00
|
|
|
enum tep_event_type type;
|
2012-04-06 06:47:53 +08:00
|
|
|
char *token;
|
|
|
|
char *last_token;
|
2020-03-25 04:08:47 +08:00
|
|
|
char *delim = " ";
|
2012-04-06 06:47:53 +08:00
|
|
|
int count = 0;
|
2020-03-25 04:08:46 +08:00
|
|
|
int ret;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
do {
|
2013-01-25 04:46:43 +08:00
|
|
|
unsigned int size_dynamic = 0;
|
|
|
|
|
2012-04-06 06:47:53 +08:00
|
|
|
type = read_token(&token);
|
2018-09-20 02:56:47 +08:00
|
|
|
if (type == TEP_EVENT_NEWLINE) {
|
2012-04-06 06:47:53 +08:00
|
|
|
free_token(token);
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
count++;
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
if (test_type_token(type, token, TEP_EVENT_ITEM, "field"))
|
2012-04-06 06:47:53 +08:00
|
|
|
goto fail;
|
|
|
|
free_token(token);
|
|
|
|
|
|
|
|
type = read_token(&token);
|
|
|
|
/*
|
|
|
|
* The ftrace fields may still use the "special" name.
|
|
|
|
* Just ignore it.
|
|
|
|
*/
|
2018-09-20 02:56:48 +08:00
|
|
|
if (event->flags & TEP_EVENT_FL_ISFTRACE &&
|
2018-09-20 02:56:47 +08:00
|
|
|
type == TEP_EVENT_ITEM && strcmp(token, "special") == 0) {
|
2012-04-06 06:47:53 +08:00
|
|
|
free_token(token);
|
|
|
|
type = read_token(&token);
|
|
|
|
}
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
if (test_type_token(type, token, TEP_EVENT_OP, ":") < 0)
|
2012-04-06 06:47:53 +08:00
|
|
|
goto fail;
|
|
|
|
|
|
|
|
free_token(token);
|
2018-09-20 02:56:47 +08:00
|
|
|
if (read_expect_type(TEP_EVENT_ITEM, &token) < 0)
|
2012-04-06 06:47:53 +08:00
|
|
|
goto fail;
|
|
|
|
|
|
|
|
last_token = token;
|
|
|
|
|
2012-09-13 02:39:59 +08:00
|
|
|
field = calloc(1, sizeof(*field));
|
|
|
|
if (!field)
|
|
|
|
goto fail;
|
|
|
|
|
2012-04-06 06:47:53 +08:00
|
|
|
field->event = event;
|
|
|
|
|
|
|
|
/* read the rest of the type */
|
|
|
|
for (;;) {
|
|
|
|
type = read_token(&token);
|
2018-09-20 02:56:47 +08:00
|
|
|
if (type == TEP_EVENT_ITEM ||
|
|
|
|
(type == TEP_EVENT_OP && strcmp(token, "*") == 0) ||
|
2012-04-06 06:47:53 +08:00
|
|
|
/*
|
|
|
|
* Some of the ftrace fields are broken and have
|
|
|
|
* an illegal "." in them.
|
|
|
|
*/
|
2018-09-20 02:56:48 +08:00
|
|
|
(event->flags & TEP_EVENT_FL_ISFTRACE &&
|
2018-09-20 02:56:47 +08:00
|
|
|
type == TEP_EVENT_OP && strcmp(token, ".") == 0)) {
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
if (strcmp(token, "*") == 0)
|
2018-09-20 02:56:46 +08:00
|
|
|
field->flags |= TEP_FIELD_IS_POINTER;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
if (field->type) {
|
2020-03-25 04:08:47 +08:00
|
|
|
ret = append(&field->type, delim, last_token);
|
2012-04-06 06:47:53 +08:00
|
|
|
free(last_token);
|
2020-03-25 04:08:46 +08:00
|
|
|
if (ret < 0)
|
|
|
|
goto fail;
|
2012-04-06 06:47:53 +08:00
|
|
|
} else
|
|
|
|
field->type = last_token;
|
|
|
|
last_token = token;
|
2020-03-25 04:08:47 +08:00
|
|
|
delim = " ";
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Handle __attribute__((user)) */
|
|
|
|
if ((type == TEP_EVENT_DELIM) &&
|
|
|
|
strcmp("__attribute__", last_token) == 0 &&
|
|
|
|
token[0] == '(') {
|
|
|
|
int depth = 1;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = append(&field->type, " ", last_token);
|
|
|
|
ret |= append(&field->type, "", "(");
|
|
|
|
if (ret < 0)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
delim = " ";
|
|
|
|
while ((type = read_token(&token)) != TEP_EVENT_NONE) {
|
|
|
|
if (type == TEP_EVENT_DELIM) {
|
|
|
|
if (token[0] == '(')
|
|
|
|
depth++;
|
|
|
|
else if (token[0] == ')')
|
|
|
|
depth--;
|
|
|
|
if (!depth)
|
|
|
|
break;
|
|
|
|
ret = append(&field->type, "", token);
|
|
|
|
delim = "";
|
|
|
|
} else {
|
|
|
|
ret = append(&field->type, delim, token);
|
|
|
|
delim = " ";
|
|
|
|
}
|
|
|
|
if (ret < 0)
|
|
|
|
goto fail;
|
|
|
|
free(last_token);
|
|
|
|
last_token = token;
|
|
|
|
}
|
2012-04-06 06:47:53 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!field->type) {
|
2014-03-19 09:22:53 +08:00
|
|
|
do_warning_event(event, "%s: no type found", __func__);
|
2012-04-06 06:47:53 +08:00
|
|
|
goto fail;
|
|
|
|
}
|
2015-04-18 23:50:18 +08:00
|
|
|
field->name = field->alias = last_token;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
if (test_type(type, TEP_EVENT_OP))
|
2012-04-06 06:47:53 +08:00
|
|
|
goto fail;
|
|
|
|
|
|
|
|
if (strcmp(token, "[") == 0) {
|
2018-09-20 02:56:47 +08:00
|
|
|
enum tep_event_type last_type = type;
|
2012-04-06 06:47:53 +08:00
|
|
|
char *brackets = token;
|
|
|
|
|
2018-09-20 02:56:46 +08:00
|
|
|
field->flags |= TEP_FIELD_IS_ARRAY;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
type = read_token(&token);
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
if (type == TEP_EVENT_ITEM)
|
2012-04-06 06:47:53 +08:00
|
|
|
field->arraylen = strtoul(token, NULL, 0);
|
|
|
|
else
|
|
|
|
field->arraylen = 0;
|
|
|
|
|
|
|
|
while (strcmp(token, "]") != 0) {
|
2020-03-25 04:08:46 +08:00
|
|
|
const char *delim;
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
if (last_type == TEP_EVENT_ITEM &&
|
|
|
|
type == TEP_EVENT_ITEM)
|
2020-03-25 04:08:46 +08:00
|
|
|
delim = " ";
|
2012-04-06 06:47:53 +08:00
|
|
|
else
|
2020-03-25 04:08:46 +08:00
|
|
|
delim = "";
|
|
|
|
|
2012-04-06 06:47:53 +08:00
|
|
|
last_type = type;
|
|
|
|
|
2020-03-25 04:08:46 +08:00
|
|
|
ret = append(&brackets, delim, token);
|
|
|
|
if (ret < 0) {
|
2012-04-09 10:54:33 +08:00
|
|
|
free(brackets);
|
|
|
|
goto fail;
|
|
|
|
}
|
2012-04-06 06:47:53 +08:00
|
|
|
/* We only care about the last token */
|
|
|
|
field->arraylen = strtoul(token, NULL, 0);
|
|
|
|
free_token(token);
|
|
|
|
type = read_token(&token);
|
2018-09-20 02:56:47 +08:00
|
|
|
if (type == TEP_EVENT_NONE) {
|
2020-03-25 04:08:46 +08:00
|
|
|
free(brackets);
|
2014-03-19 09:22:53 +08:00
|
|
|
do_warning_event(event, "failed to find token");
|
2012-04-06 06:47:53 +08:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
free_token(token);
|
|
|
|
|
2020-03-25 04:08:46 +08:00
|
|
|
ret = append(&brackets, "", "]");
|
|
|
|
if (ret < 0) {
|
2012-04-09 10:54:33 +08:00
|
|
|
free(brackets);
|
|
|
|
goto fail;
|
|
|
|
}
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
/* add brackets to type */
|
|
|
|
|
|
|
|
type = read_token(&token);
|
|
|
|
/*
|
|
|
|
* If the next token is not an OP, then it is of
|
|
|
|
* the format: type [] item;
|
|
|
|
*/
|
2018-09-20 02:56:47 +08:00
|
|
|
if (type == TEP_EVENT_ITEM) {
|
2020-03-25 04:08:46 +08:00
|
|
|
ret = append(&field->type, " ", field->name);
|
|
|
|
if (ret < 0) {
|
2012-04-09 10:54:33 +08:00
|
|
|
free(brackets);
|
|
|
|
goto fail;
|
|
|
|
}
|
2020-03-25 04:08:46 +08:00
|
|
|
ret = append(&field->type, "", brackets);
|
|
|
|
|
2013-01-25 04:46:43 +08:00
|
|
|
size_dynamic = type_size(field->name);
|
2012-04-06 06:47:53 +08:00
|
|
|
free_token(field->name);
|
2015-04-18 23:50:18 +08:00
|
|
|
field->name = field->alias = token;
|
2012-04-06 06:47:53 +08:00
|
|
|
type = read_token(&token);
|
|
|
|
} else {
|
2020-03-25 04:08:46 +08:00
|
|
|
ret = append(&field->type, "", brackets);
|
|
|
|
if (ret < 0) {
|
2012-04-09 10:54:33 +08:00
|
|
|
free(brackets);
|
|
|
|
goto fail;
|
|
|
|
}
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
free(brackets);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (field_is_string(field))
|
2018-09-20 02:56:46 +08:00
|
|
|
field->flags |= TEP_FIELD_IS_STRING;
|
2012-04-06 06:47:53 +08:00
|
|
|
if (field_is_dynamic(field))
|
2018-09-20 02:56:46 +08:00
|
|
|
field->flags |= TEP_FIELD_IS_DYNAMIC;
|
2021-11-22 17:30:40 +08:00
|
|
|
if (field_is_relative_dynamic(field))
|
|
|
|
field->flags |= TEP_FIELD_IS_DYNAMIC | TEP_FIELD_IS_RELATIVE;
|
2012-04-06 06:47:53 +08:00
|
|
|
if (field_is_long(field))
|
2018-09-20 02:56:46 +08:00
|
|
|
field->flags |= TEP_FIELD_IS_LONG;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
if (test_type_token(type, token, TEP_EVENT_OP, ";"))
|
2012-04-06 06:47:53 +08:00
|
|
|
goto fail;
|
|
|
|
free_token(token);
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
if (read_expected(TEP_EVENT_ITEM, "offset") < 0)
|
2012-04-06 06:47:53 +08:00
|
|
|
goto fail_expect;
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
if (read_expected(TEP_EVENT_OP, ":") < 0)
|
2012-04-06 06:47:53 +08:00
|
|
|
goto fail_expect;
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
if (read_expect_type(TEP_EVENT_ITEM, &token))
|
2012-04-06 06:47:53 +08:00
|
|
|
goto fail;
|
|
|
|
field->offset = strtoul(token, NULL, 0);
|
|
|
|
free_token(token);
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
if (read_expected(TEP_EVENT_OP, ";") < 0)
|
2012-04-06 06:47:53 +08:00
|
|
|
goto fail_expect;
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
if (read_expected(TEP_EVENT_ITEM, "size") < 0)
|
2012-04-06 06:47:53 +08:00
|
|
|
goto fail_expect;
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
if (read_expected(TEP_EVENT_OP, ":") < 0)
|
2012-04-06 06:47:53 +08:00
|
|
|
goto fail_expect;
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
if (read_expect_type(TEP_EVENT_ITEM, &token))
|
2012-04-06 06:47:53 +08:00
|
|
|
goto fail;
|
|
|
|
field->size = strtoul(token, NULL, 0);
|
|
|
|
free_token(token);
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
if (read_expected(TEP_EVENT_OP, ";") < 0)
|
2012-04-06 06:47:53 +08:00
|
|
|
goto fail_expect;
|
|
|
|
|
|
|
|
type = read_token(&token);
|
2018-09-20 02:56:47 +08:00
|
|
|
if (type != TEP_EVENT_NEWLINE) {
|
2012-04-06 06:47:53 +08:00
|
|
|
/* newer versions of the kernel have a "signed" type */
|
2018-09-20 02:56:47 +08:00
|
|
|
if (test_type_token(type, token, TEP_EVENT_ITEM, "signed"))
|
2012-04-06 06:47:53 +08:00
|
|
|
goto fail;
|
|
|
|
|
|
|
|
free_token(token);
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
if (read_expected(TEP_EVENT_OP, ":") < 0)
|
2012-04-06 06:47:53 +08:00
|
|
|
goto fail_expect;
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
if (read_expect_type(TEP_EVENT_ITEM, &token))
|
2012-04-06 06:47:53 +08:00
|
|
|
goto fail;
|
|
|
|
|
2013-01-19 03:51:25 +08:00
|
|
|
if (strtoul(token, NULL, 0))
|
2018-09-20 02:56:46 +08:00
|
|
|
field->flags |= TEP_FIELD_IS_SIGNED;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
free_token(token);
|
2018-09-20 02:56:47 +08:00
|
|
|
if (read_expected(TEP_EVENT_OP, ";") < 0)
|
2012-04-06 06:47:53 +08:00
|
|
|
goto fail_expect;
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
if (read_expect_type(TEP_EVENT_NEWLINE, &token))
|
2012-04-06 06:47:53 +08:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
free_token(token);
|
|
|
|
|
2018-09-20 02:56:46 +08:00
|
|
|
if (field->flags & TEP_FIELD_IS_ARRAY) {
|
2012-04-06 06:47:53 +08:00
|
|
|
if (field->arraylen)
|
|
|
|
field->elementsize = field->size / field->arraylen;
|
2018-09-20 02:56:46 +08:00
|
|
|
else if (field->flags & TEP_FIELD_IS_DYNAMIC)
|
2013-01-25 04:46:43 +08:00
|
|
|
field->elementsize = size_dynamic;
|
2018-09-20 02:56:46 +08:00
|
|
|
else if (field->flags & TEP_FIELD_IS_STRING)
|
2012-04-06 06:47:53 +08:00
|
|
|
field->elementsize = 1;
|
2018-09-20 02:56:46 +08:00
|
|
|
else if (field->flags & TEP_FIELD_IS_LONG)
|
2019-04-02 00:43:18 +08:00
|
|
|
field->elementsize = event->tep ?
|
|
|
|
event->tep->long_size :
|
2013-01-25 04:46:43 +08:00
|
|
|
sizeof(long);
|
2012-04-06 06:47:53 +08:00
|
|
|
} else
|
|
|
|
field->elementsize = field->size;
|
|
|
|
|
|
|
|
*fields = field;
|
|
|
|
fields = &field->next;
|
|
|
|
|
|
|
|
} while (1);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
free_token(token);
|
|
|
|
fail_expect:
|
2012-05-23 10:36:47 +08:00
|
|
|
if (field) {
|
|
|
|
free(field->type);
|
|
|
|
free(field->name);
|
2012-04-06 06:47:53 +08:00
|
|
|
free(field);
|
2012-05-23 10:36:47 +08:00
|
|
|
}
|
2012-04-06 06:47:53 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-11-30 23:44:07 +08:00
|
|
|
static int event_read_format(struct tep_event *event)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
|
|
|
char *token;
|
|
|
|
int ret;
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
if (read_expected_item(TEP_EVENT_ITEM, "format") < 0)
|
2012-04-06 06:47:53 +08:00
|
|
|
return -1;
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
if (read_expected(TEP_EVENT_OP, ":") < 0)
|
2012-04-06 06:47:53 +08:00
|
|
|
return -1;
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
if (read_expect_type(TEP_EVENT_NEWLINE, &token))
|
2012-04-06 06:47:53 +08:00
|
|
|
goto fail;
|
|
|
|
free_token(token);
|
|
|
|
|
|
|
|
ret = event_read_fields(event, &event->format.common_fields);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
event->format.nr_common = ret;
|
|
|
|
|
|
|
|
ret = event_read_fields(event, &event->format.fields);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
event->format.nr_fields = ret;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
free_token(token);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
static enum tep_event_type
|
2018-11-30 23:44:07 +08:00
|
|
|
process_arg_token(struct tep_event *event, struct tep_print_arg *arg,
|
2018-09-20 02:56:47 +08:00
|
|
|
char **tok, enum tep_event_type type);
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
static enum tep_event_type
|
2018-11-30 23:44:07 +08:00
|
|
|
process_arg(struct tep_event *event, struct tep_print_arg *arg, char **tok)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
2018-09-20 02:56:47 +08:00
|
|
|
enum tep_event_type type;
|
2012-04-06 06:47:53 +08:00
|
|
|
char *token;
|
|
|
|
|
|
|
|
type = read_token(&token);
|
|
|
|
*tok = token;
|
|
|
|
|
|
|
|
return process_arg_token(event, arg, tok, type);
|
|
|
|
}
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
static enum tep_event_type
|
2018-11-30 23:44:07 +08:00
|
|
|
process_op(struct tep_event *event, struct tep_print_arg *arg, char **tok);
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2013-11-19 03:23:14 +08:00
|
|
|
/*
|
|
|
|
* For __print_symbolic() and __print_flags, we need to completely
|
|
|
|
* evaluate the first argument, which defines what to print next.
|
|
|
|
*/
|
2018-09-20 02:56:47 +08:00
|
|
|
static enum tep_event_type
|
2018-11-30 23:44:07 +08:00
|
|
|
process_field_arg(struct tep_event *event, struct tep_print_arg *arg, char **tok)
|
2013-11-19 03:23:14 +08:00
|
|
|
{
|
2018-09-20 02:56:47 +08:00
|
|
|
enum tep_event_type type;
|
2013-11-19 03:23:14 +08:00
|
|
|
|
|
|
|
type = process_arg(event, arg, tok);
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
while (type == TEP_EVENT_OP) {
|
2013-11-19 03:23:14 +08:00
|
|
|
type = process_op(event, arg, tok);
|
|
|
|
}
|
|
|
|
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
static enum tep_event_type
|
2018-11-30 23:44:07 +08:00
|
|
|
process_cond(struct tep_event *event, struct tep_print_arg *top, char **tok)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
2018-09-20 02:56:49 +08:00
|
|
|
struct tep_print_arg *arg, *left, *right;
|
2018-09-20 02:56:47 +08:00
|
|
|
enum tep_event_type type;
|
2012-04-06 06:47:53 +08:00
|
|
|
char *token = NULL;
|
|
|
|
|
|
|
|
arg = alloc_arg();
|
|
|
|
left = alloc_arg();
|
|
|
|
right = alloc_arg();
|
|
|
|
|
2012-09-20 10:09:19 +08:00
|
|
|
if (!arg || !left || !right) {
|
2014-03-19 09:22:53 +08:00
|
|
|
do_warning_event(event, "%s: not enough memory!", __func__);
|
2012-09-20 10:09:19 +08:00
|
|
|
/* arg will be freed at out_free */
|
|
|
|
free_arg(left);
|
|
|
|
free_arg(right);
|
|
|
|
goto out_free;
|
|
|
|
}
|
|
|
|
|
2018-09-20 02:56:50 +08:00
|
|
|
arg->type = TEP_PRINT_OP;
|
2012-04-06 06:47:53 +08:00
|
|
|
arg->op.left = left;
|
|
|
|
arg->op.right = right;
|
|
|
|
|
|
|
|
*tok = NULL;
|
|
|
|
type = process_arg(event, left, &token);
|
|
|
|
|
|
|
|
again:
|
2018-09-20 02:56:47 +08:00
|
|
|
if (type == TEP_EVENT_ERROR)
|
2015-08-20 23:16:32 +08:00
|
|
|
goto out_free;
|
|
|
|
|
2012-04-06 06:47:53 +08:00
|
|
|
/* Handle other operations in the arguments */
|
2018-09-20 02:56:47 +08:00
|
|
|
if (type == TEP_EVENT_OP && strcmp(token, ":") != 0) {
|
2012-04-06 06:47:53 +08:00
|
|
|
type = process_op(event, left, &token);
|
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
if (test_type_token(type, token, TEP_EVENT_OP, ":"))
|
2012-04-06 06:47:53 +08:00
|
|
|
goto out_free;
|
|
|
|
|
|
|
|
arg->op.op = token;
|
|
|
|
|
|
|
|
type = process_arg(event, right, &token);
|
|
|
|
|
|
|
|
top->op.right = arg;
|
|
|
|
|
|
|
|
*tok = token;
|
|
|
|
return type;
|
|
|
|
|
|
|
|
out_free:
|
|
|
|
/* Top may point to itself */
|
|
|
|
top->op.right = NULL;
|
|
|
|
free_token(token);
|
|
|
|
free_arg(arg);
|
2018-09-20 02:56:47 +08:00
|
|
|
return TEP_EVENT_ERROR;
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
static enum tep_event_type
|
2018-11-30 23:44:07 +08:00
|
|
|
process_array(struct tep_event *event, struct tep_print_arg *top, char **tok)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
2018-09-20 02:56:49 +08:00
|
|
|
struct tep_print_arg *arg;
|
2018-09-20 02:56:47 +08:00
|
|
|
enum tep_event_type type;
|
2012-04-06 06:47:53 +08:00
|
|
|
char *token = NULL;
|
|
|
|
|
|
|
|
arg = alloc_arg();
|
2012-09-20 10:09:19 +08:00
|
|
|
if (!arg) {
|
2014-03-19 09:22:53 +08:00
|
|
|
do_warning_event(event, "%s: not enough memory!", __func__);
|
2012-09-20 10:09:19 +08:00
|
|
|
/* '*tok' is set to top->op.op. No need to free. */
|
|
|
|
*tok = NULL;
|
2018-09-20 02:56:47 +08:00
|
|
|
return TEP_EVENT_ERROR;
|
2012-09-20 10:09:19 +08:00
|
|
|
}
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
*tok = NULL;
|
|
|
|
type = process_arg(event, arg, &token);
|
2018-09-20 02:56:47 +08:00
|
|
|
if (test_type_token(type, token, TEP_EVENT_OP, "]"))
|
2012-04-06 06:47:53 +08:00
|
|
|
goto out_free;
|
|
|
|
|
|
|
|
top->op.right = arg;
|
|
|
|
|
|
|
|
free_token(token);
|
|
|
|
type = read_token_item(&token);
|
|
|
|
*tok = token;
|
|
|
|
|
|
|
|
return type;
|
|
|
|
|
|
|
|
out_free:
|
2012-09-19 14:58:41 +08:00
|
|
|
free_token(token);
|
2012-04-06 06:47:53 +08:00
|
|
|
free_arg(arg);
|
2018-09-20 02:56:47 +08:00
|
|
|
return TEP_EVENT_ERROR;
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int get_op_prio(char *op)
|
|
|
|
{
|
|
|
|
if (!op[1]) {
|
|
|
|
switch (op[0]) {
|
|
|
|
case '~':
|
|
|
|
case '!':
|
|
|
|
return 4;
|
|
|
|
case '*':
|
|
|
|
case '/':
|
|
|
|
case '%':
|
|
|
|
return 6;
|
|
|
|
case '+':
|
|
|
|
case '-':
|
|
|
|
return 7;
|
|
|
|
/* '>>' and '<<' are 8 */
|
|
|
|
case '<':
|
|
|
|
case '>':
|
|
|
|
return 9;
|
|
|
|
/* '==' and '!=' are 10 */
|
|
|
|
case '&':
|
|
|
|
return 11;
|
|
|
|
case '^':
|
|
|
|
return 12;
|
|
|
|
case '|':
|
|
|
|
return 13;
|
|
|
|
case '?':
|
|
|
|
return 16;
|
|
|
|
default:
|
2012-04-06 06:48:01 +08:00
|
|
|
do_warning("unknown op '%c'", op[0]);
|
2012-04-06 06:47:53 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (strcmp(op, "++") == 0 ||
|
|
|
|
strcmp(op, "--") == 0) {
|
|
|
|
return 3;
|
|
|
|
} else if (strcmp(op, ">>") == 0 ||
|
|
|
|
strcmp(op, "<<") == 0) {
|
|
|
|
return 8;
|
|
|
|
} else if (strcmp(op, ">=") == 0 ||
|
|
|
|
strcmp(op, "<=") == 0) {
|
|
|
|
return 9;
|
|
|
|
} else if (strcmp(op, "==") == 0 ||
|
|
|
|
strcmp(op, "!=") == 0) {
|
|
|
|
return 10;
|
|
|
|
} else if (strcmp(op, "&&") == 0) {
|
|
|
|
return 14;
|
|
|
|
} else if (strcmp(op, "||") == 0) {
|
|
|
|
return 15;
|
|
|
|
} else {
|
2012-04-06 06:48:01 +08:00
|
|
|
do_warning("unknown op '%s'", op);
|
2012-04-06 06:47:53 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-20 02:56:49 +08:00
|
|
|
static int set_op_prio(struct tep_print_arg *arg)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
/* single ops are the greatest */
|
2018-09-20 02:56:50 +08:00
|
|
|
if (!arg->op.left || arg->op.left->type == TEP_PRINT_NULL)
|
2012-04-06 06:47:53 +08:00
|
|
|
arg->op.prio = 0;
|
2012-04-06 06:48:01 +08:00
|
|
|
else
|
|
|
|
arg->op.prio = get_op_prio(arg->op.op);
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2012-04-06 06:48:01 +08:00
|
|
|
return arg->op.prio;
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Note, *tok does not get freed, but will most likely be saved */
|
2018-09-20 02:56:47 +08:00
|
|
|
static enum tep_event_type
|
2018-11-30 23:44:07 +08:00
|
|
|
process_op(struct tep_event *event, struct tep_print_arg *arg, char **tok)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
2018-09-20 02:56:49 +08:00
|
|
|
struct tep_print_arg *left, *right = NULL;
|
2018-09-20 02:56:47 +08:00
|
|
|
enum tep_event_type type;
|
2012-04-06 06:47:53 +08:00
|
|
|
char *token;
|
|
|
|
|
|
|
|
/* the op is passed in via tok */
|
|
|
|
token = *tok;
|
|
|
|
|
2018-09-20 02:56:50 +08:00
|
|
|
if (arg->type == TEP_PRINT_OP && !arg->op.left) {
|
2012-04-06 06:47:53 +08:00
|
|
|
/* handle single op */
|
|
|
|
if (token[1]) {
|
2014-03-19 09:22:53 +08:00
|
|
|
do_warning_event(event, "bad op token %s", token);
|
2012-04-06 06:47:53 +08:00
|
|
|
goto out_free;
|
|
|
|
}
|
|
|
|
switch (token[0]) {
|
|
|
|
case '~':
|
|
|
|
case '!':
|
|
|
|
case '+':
|
|
|
|
case '-':
|
|
|
|
break;
|
|
|
|
default:
|
2014-03-19 09:22:53 +08:00
|
|
|
do_warning_event(event, "bad op token %s", token);
|
2012-04-06 06:47:53 +08:00
|
|
|
goto out_free;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* make an empty left */
|
|
|
|
left = alloc_arg();
|
2012-09-20 10:09:19 +08:00
|
|
|
if (!left)
|
|
|
|
goto out_warn_free;
|
|
|
|
|
2018-09-20 02:56:50 +08:00
|
|
|
left->type = TEP_PRINT_NULL;
|
2012-04-06 06:47:53 +08:00
|
|
|
arg->op.left = left;
|
|
|
|
|
|
|
|
right = alloc_arg();
|
2012-09-20 10:09:19 +08:00
|
|
|
if (!right)
|
|
|
|
goto out_warn_free;
|
|
|
|
|
2012-04-06 06:47:53 +08:00
|
|
|
arg->op.right = right;
|
|
|
|
|
|
|
|
/* do not free the token, it belongs to an op */
|
|
|
|
*tok = NULL;
|
|
|
|
type = process_arg(event, right, tok);
|
|
|
|
|
|
|
|
} else if (strcmp(token, "?") == 0) {
|
|
|
|
|
|
|
|
left = alloc_arg();
|
2012-09-20 10:09:19 +08:00
|
|
|
if (!left)
|
|
|
|
goto out_warn_free;
|
|
|
|
|
2012-04-06 06:47:53 +08:00
|
|
|
/* copy the top arg to the left */
|
|
|
|
*left = *arg;
|
|
|
|
|
2018-09-20 02:56:50 +08:00
|
|
|
arg->type = TEP_PRINT_OP;
|
2012-04-06 06:47:53 +08:00
|
|
|
arg->op.op = token;
|
|
|
|
arg->op.left = left;
|
|
|
|
arg->op.prio = 0;
|
|
|
|
|
2012-09-19 14:58:42 +08:00
|
|
|
/* it will set arg->op.right */
|
2012-04-06 06:47:53 +08:00
|
|
|
type = process_cond(event, arg, tok);
|
|
|
|
|
|
|
|
} else if (strcmp(token, ">>") == 0 ||
|
|
|
|
strcmp(token, "<<") == 0 ||
|
|
|
|
strcmp(token, "&") == 0 ||
|
|
|
|
strcmp(token, "|") == 0 ||
|
|
|
|
strcmp(token, "&&") == 0 ||
|
|
|
|
strcmp(token, "||") == 0 ||
|
|
|
|
strcmp(token, "-") == 0 ||
|
|
|
|
strcmp(token, "+") == 0 ||
|
|
|
|
strcmp(token, "*") == 0 ||
|
|
|
|
strcmp(token, "^") == 0 ||
|
|
|
|
strcmp(token, "/") == 0 ||
|
2016-02-23 01:08:22 +08:00
|
|
|
strcmp(token, "%") == 0 ||
|
2012-04-06 06:47:53 +08:00
|
|
|
strcmp(token, "<") == 0 ||
|
|
|
|
strcmp(token, ">") == 0 ||
|
2013-01-15 16:02:19 +08:00
|
|
|
strcmp(token, "<=") == 0 ||
|
|
|
|
strcmp(token, ">=") == 0 ||
|
2012-04-06 06:47:53 +08:00
|
|
|
strcmp(token, "==") == 0 ||
|
|
|
|
strcmp(token, "!=") == 0) {
|
|
|
|
|
|
|
|
left = alloc_arg();
|
2012-09-20 10:09:19 +08:00
|
|
|
if (!left)
|
|
|
|
goto out_warn_free;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
/* copy the top arg to the left */
|
|
|
|
*left = *arg;
|
|
|
|
|
2018-09-20 02:56:50 +08:00
|
|
|
arg->type = TEP_PRINT_OP;
|
2012-04-06 06:47:53 +08:00
|
|
|
arg->op.op = token;
|
|
|
|
arg->op.left = left;
|
2012-09-19 14:58:42 +08:00
|
|
|
arg->op.right = NULL;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2012-04-06 06:48:01 +08:00
|
|
|
if (set_op_prio(arg) == -1) {
|
2018-09-20 02:56:48 +08:00
|
|
|
event->flags |= TEP_EVENT_FL_FAILED;
|
2012-05-23 10:36:49 +08:00
|
|
|
/* arg->op.op (= token) will be freed at out_free */
|
|
|
|
arg->op.op = NULL;
|
2012-04-06 06:48:01 +08:00
|
|
|
goto out_free;
|
|
|
|
}
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
type = read_token_item(&token);
|
|
|
|
*tok = token;
|
|
|
|
|
|
|
|
/* could just be a type pointer */
|
|
|
|
if ((strcmp(arg->op.op, "*") == 0) &&
|
2018-09-20 02:56:47 +08:00
|
|
|
type == TEP_EVENT_DELIM && (strcmp(token, ")") == 0)) {
|
2020-03-25 04:08:46 +08:00
|
|
|
int ret;
|
2012-04-09 10:54:33 +08:00
|
|
|
|
2018-09-20 02:56:50 +08:00
|
|
|
if (left->type != TEP_PRINT_ATOM) {
|
2014-03-19 09:22:53 +08:00
|
|
|
do_warning_event(event, "bad pointer type");
|
2012-09-13 04:30:50 +08:00
|
|
|
goto out_free;
|
|
|
|
}
|
2020-03-25 04:08:46 +08:00
|
|
|
ret = append(&left->atom.atom, " ", "*");
|
|
|
|
if (ret < 0)
|
2012-09-20 10:09:19 +08:00
|
|
|
goto out_warn_free;
|
2012-04-09 10:54:33 +08:00
|
|
|
|
2012-04-06 06:47:53 +08:00
|
|
|
free(arg->op.op);
|
|
|
|
*arg = *left;
|
|
|
|
free(left);
|
|
|
|
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
right = alloc_arg();
|
2012-09-20 10:09:19 +08:00
|
|
|
if (!right)
|
|
|
|
goto out_warn_free;
|
|
|
|
|
2012-04-06 06:47:53 +08:00
|
|
|
type = process_arg_token(event, right, tok, type);
|
2018-09-20 02:56:47 +08:00
|
|
|
if (type == TEP_EVENT_ERROR) {
|
2015-08-20 23:16:32 +08:00
|
|
|
free_arg(right);
|
|
|
|
/* token was freed in process_arg_token() via *tok */
|
|
|
|
token = NULL;
|
|
|
|
goto out_free;
|
|
|
|
}
|
2015-04-06 13:36:16 +08:00
|
|
|
|
2018-09-20 02:56:50 +08:00
|
|
|
if (right->type == TEP_PRINT_OP &&
|
2015-04-06 13:36:16 +08:00
|
|
|
get_op_prio(arg->op.op) < get_op_prio(right->op.op)) {
|
2018-09-20 02:56:49 +08:00
|
|
|
struct tep_print_arg tmp;
|
2015-04-06 13:36:16 +08:00
|
|
|
|
|
|
|
/* rotate ops according to the priority */
|
|
|
|
arg->op.right = right->op.left;
|
|
|
|
|
|
|
|
tmp = *arg;
|
|
|
|
*arg = *right;
|
|
|
|
*right = tmp;
|
|
|
|
|
|
|
|
arg->op.left = right;
|
|
|
|
} else {
|
|
|
|
arg->op.right = right;
|
|
|
|
}
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
} else if (strcmp(token, "[") == 0) {
|
|
|
|
|
|
|
|
left = alloc_arg();
|
2012-09-20 10:09:19 +08:00
|
|
|
if (!left)
|
|
|
|
goto out_warn_free;
|
|
|
|
|
2012-04-06 06:47:53 +08:00
|
|
|
*left = *arg;
|
|
|
|
|
2018-09-20 02:56:50 +08:00
|
|
|
arg->type = TEP_PRINT_OP;
|
2012-04-06 06:47:53 +08:00
|
|
|
arg->op.op = token;
|
|
|
|
arg->op.left = left;
|
|
|
|
|
|
|
|
arg->op.prio = 0;
|
|
|
|
|
2012-09-19 14:58:42 +08:00
|
|
|
/* it will set arg->op.right */
|
2012-04-06 06:47:53 +08:00
|
|
|
type = process_array(event, arg, tok);
|
|
|
|
|
|
|
|
} else {
|
2014-03-19 09:22:53 +08:00
|
|
|
do_warning_event(event, "unknown op '%s'", token);
|
2018-09-20 02:56:48 +08:00
|
|
|
event->flags |= TEP_EVENT_FL_FAILED;
|
2012-04-06 06:47:53 +08:00
|
|
|
/* the arg is now the left side */
|
|
|
|
goto out_free;
|
|
|
|
}
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
if (type == TEP_EVENT_OP && strcmp(*tok, ":") != 0) {
|
2012-04-06 06:47:53 +08:00
|
|
|
int prio;
|
|
|
|
|
|
|
|
/* higher prios need to be closer to the root */
|
|
|
|
prio = get_op_prio(*tok);
|
|
|
|
|
|
|
|
if (prio > arg->op.prio)
|
|
|
|
return process_op(event, arg, tok);
|
|
|
|
|
|
|
|
return process_op(event, right, tok);
|
|
|
|
}
|
|
|
|
|
|
|
|
return type;
|
|
|
|
|
2012-09-20 10:09:19 +08:00
|
|
|
out_warn_free:
|
2014-03-19 09:22:53 +08:00
|
|
|
do_warning_event(event, "%s: not enough memory!", __func__);
|
2012-09-20 10:09:19 +08:00
|
|
|
out_free:
|
2012-04-06 06:47:53 +08:00
|
|
|
free_token(token);
|
|
|
|
*tok = NULL;
|
2018-09-20 02:56:47 +08:00
|
|
|
return TEP_EVENT_ERROR;
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
static enum tep_event_type
|
2018-11-30 23:44:07 +08:00
|
|
|
process_entry(struct tep_event *event __maybe_unused, struct tep_print_arg *arg,
|
2012-04-06 06:47:53 +08:00
|
|
|
char **tok)
|
|
|
|
{
|
2018-09-20 02:56:47 +08:00
|
|
|
enum tep_event_type type;
|
2012-04-06 06:47:53 +08:00
|
|
|
char *field;
|
|
|
|
char *token;
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
if (read_expected(TEP_EVENT_OP, "->") < 0)
|
2012-04-06 06:47:53 +08:00
|
|
|
goto out_err;
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
if (read_expect_type(TEP_EVENT_ITEM, &token) < 0)
|
2012-04-06 06:47:53 +08:00
|
|
|
goto out_free;
|
|
|
|
field = token;
|
|
|
|
|
2018-09-20 02:56:50 +08:00
|
|
|
arg->type = TEP_PRINT_FIELD;
|
2012-04-06 06:47:53 +08:00
|
|
|
arg->field.name = field;
|
|
|
|
|
2012-04-06 06:47:58 +08:00
|
|
|
if (is_flag_field) {
|
2018-08-09 02:02:50 +08:00
|
|
|
arg->field.field = tep_find_any_field(event, arg->field.name);
|
2018-09-20 02:56:46 +08:00
|
|
|
arg->field.field->flags |= TEP_FIELD_IS_FLAG;
|
2012-04-06 06:47:58 +08:00
|
|
|
is_flag_field = 0;
|
|
|
|
} else if (is_symbolic_field) {
|
2018-08-09 02:02:50 +08:00
|
|
|
arg->field.field = tep_find_any_field(event, arg->field.name);
|
2018-09-20 02:56:46 +08:00
|
|
|
arg->field.field->flags |= TEP_FIELD_IS_SYMBOLIC;
|
2012-04-06 06:47:58 +08:00
|
|
|
is_symbolic_field = 0;
|
|
|
|
}
|
|
|
|
|
2012-04-06 06:47:53 +08:00
|
|
|
type = read_token(&token);
|
|
|
|
*tok = token;
|
|
|
|
|
|
|
|
return type;
|
|
|
|
|
|
|
|
out_free:
|
|
|
|
free_token(token);
|
|
|
|
out_err:
|
|
|
|
*tok = NULL;
|
2018-09-20 02:56:47 +08:00
|
|
|
return TEP_EVENT_ERROR;
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
|
2018-11-30 23:44:07 +08:00
|
|
|
static int alloc_and_process_delim(struct tep_event *event, char *next_token,
|
2018-09-20 02:56:49 +08:00
|
|
|
struct tep_print_arg **print_arg)
|
2015-03-21 02:12:55 +08:00
|
|
|
{
|
2018-09-20 02:56:49 +08:00
|
|
|
struct tep_print_arg *field;
|
2018-09-20 02:56:47 +08:00
|
|
|
enum tep_event_type type;
|
2015-03-21 02:12:55 +08:00
|
|
|
char *token;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
field = alloc_arg();
|
|
|
|
if (!field) {
|
|
|
|
do_warning_event(event, "%s: not enough memory!", __func__);
|
|
|
|
errno = ENOMEM;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
type = process_arg(event, field, &token);
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
if (test_type_token(type, token, TEP_EVENT_DELIM, next_token)) {
|
2015-03-21 02:12:55 +08:00
|
|
|
errno = EINVAL;
|
|
|
|
ret = -1;
|
|
|
|
free_arg(field);
|
|
|
|
goto out_free_token;
|
|
|
|
}
|
|
|
|
|
|
|
|
*print_arg = field;
|
|
|
|
|
|
|
|
out_free_token:
|
|
|
|
free_token(token);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-09-20 02:56:49 +08:00
|
|
|
static char *arg_eval (struct tep_print_arg *arg);
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
static unsigned long long
|
|
|
|
eval_type_str(unsigned long long val, const char *type, int pointer)
|
|
|
|
{
|
|
|
|
int sign = 0;
|
|
|
|
char *ref;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
len = strlen(type);
|
|
|
|
|
|
|
|
if (pointer) {
|
|
|
|
|
|
|
|
if (type[len-1] != '*') {
|
|
|
|
do_warning("pointer expected with non pointer type");
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2012-09-13 04:30:50 +08:00
|
|
|
ref = malloc(len);
|
|
|
|
if (!ref) {
|
|
|
|
do_warning("%s: not enough memory!", __func__);
|
|
|
|
return val;
|
|
|
|
}
|
2012-04-06 06:47:53 +08:00
|
|
|
memcpy(ref, type, len);
|
|
|
|
|
|
|
|
/* chop off the " *" */
|
|
|
|
ref[len - 2] = 0;
|
|
|
|
|
|
|
|
val = eval_type_str(val, ref, 0);
|
|
|
|
free(ref);
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check if this is a pointer */
|
|
|
|
if (type[len - 1] == '*')
|
|
|
|
return val;
|
|
|
|
|
|
|
|
/* Try to figure out the arg size*/
|
|
|
|
if (strncmp(type, "struct", 6) == 0)
|
|
|
|
/* all bets off */
|
|
|
|
return val;
|
|
|
|
|
|
|
|
if (strcmp(type, "u8") == 0)
|
|
|
|
return val & 0xff;
|
|
|
|
|
|
|
|
if (strcmp(type, "u16") == 0)
|
|
|
|
return val & 0xffff;
|
|
|
|
|
|
|
|
if (strcmp(type, "u32") == 0)
|
|
|
|
return val & 0xffffffff;
|
|
|
|
|
|
|
|
if (strcmp(type, "u64") == 0 ||
|
tools lib traceevent: Fix missing equality check for strcmp
There was a missing comparison with 0 when checking if type is "s64" or
"u64". Therefore, the body of the if-statement was entered if "type" was
"u64" or not "s64", which made the first strcmp() redundant since if
type is "u64", it's not "s64".
If type is "s64", the body of the if-statement is not entered but since
the remainder of the function consists of if-statements which will not
be entered if type is "s64", we will just return "val", which is
correct, albeit at the cost of a few more calls to strcmp(), i.e., it
will behave just as if the if-statement was entered.
If type is neither "s64" or "u64", the body of the if-statement will be
entered incorrectly and "val" returned. This means that any type that is
checked after "s64" and "u64" is handled the same way as "s64" and
"u64", i.e., the limiting of "val" to fit in for example "s8" is never
reached.
This was introduced in the kernel tree when the sources were copied from
trace-cmd in commit f7d82350e597 ("tools/events: Add files to create
libtraceevent.a"), and in the trace-cmd repo in 1cdbae6035cei
("Implement typecasting in parser") when the function was introduced,
i.e., it has always behaved the wrong way.
Detected by cppcheck.
Signed-off-by: Rikard Falkeborn <rikard.falkeborn@gmail.com>
Reviewed-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Cc: Tzvetomir Stoyanov <tstoyanov@vmware.com>
Fixes: f7d82350e597 ("tools/events: Add files to create libtraceevent.a")
Link: http://lkml.kernel.org/r/20190409091529.2686-1-rikard.falkeborn@gmail.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2019-04-09 17:15:29 +08:00
|
|
|
strcmp(type, "s64") == 0)
|
2012-04-06 06:47:53 +08:00
|
|
|
return val;
|
|
|
|
|
|
|
|
if (strcmp(type, "s8") == 0)
|
|
|
|
return (unsigned long long)(char)val & 0xff;
|
|
|
|
|
|
|
|
if (strcmp(type, "s16") == 0)
|
|
|
|
return (unsigned long long)(short)val & 0xffff;
|
|
|
|
|
|
|
|
if (strcmp(type, "s32") == 0)
|
|
|
|
return (unsigned long long)(int)val & 0xffffffff;
|
|
|
|
|
|
|
|
if (strncmp(type, "unsigned ", 9) == 0) {
|
|
|
|
sign = 0;
|
|
|
|
type += 9;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcmp(type, "char") == 0) {
|
|
|
|
if (sign)
|
|
|
|
return (unsigned long long)(char)val & 0xff;
|
|
|
|
else
|
|
|
|
return val & 0xff;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcmp(type, "short") == 0) {
|
|
|
|
if (sign)
|
|
|
|
return (unsigned long long)(short)val & 0xffff;
|
|
|
|
else
|
|
|
|
return val & 0xffff;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcmp(type, "int") == 0) {
|
|
|
|
if (sign)
|
|
|
|
return (unsigned long long)(int)val & 0xffffffff;
|
|
|
|
else
|
|
|
|
return val & 0xffffffff;
|
|
|
|
}
|
|
|
|
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Try to figure out the type.
|
|
|
|
*/
|
|
|
|
static unsigned long long
|
2018-09-20 02:56:49 +08:00
|
|
|
eval_type(unsigned long long val, struct tep_print_arg *arg, int pointer)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
2018-09-20 02:56:50 +08:00
|
|
|
if (arg->type != TEP_PRINT_TYPE) {
|
2012-09-13 04:30:50 +08:00
|
|
|
do_warning("expected type argument");
|
|
|
|
return 0;
|
|
|
|
}
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
return eval_type_str(val, arg->typecast.type, pointer);
|
|
|
|
}
|
|
|
|
|
2018-09-20 02:56:49 +08:00
|
|
|
static int arg_num_eval(struct tep_print_arg *arg, long long *val)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
|
|
|
long long left, right;
|
2012-04-06 06:48:00 +08:00
|
|
|
int ret = 1;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
switch (arg->type) {
|
2018-09-20 02:56:50 +08:00
|
|
|
case TEP_PRINT_ATOM:
|
2012-04-06 06:48:00 +08:00
|
|
|
*val = strtoll(arg->atom.atom, NULL, 0);
|
2012-04-06 06:47:53 +08:00
|
|
|
break;
|
2018-09-20 02:56:50 +08:00
|
|
|
case TEP_PRINT_TYPE:
|
2012-04-06 06:48:00 +08:00
|
|
|
ret = arg_num_eval(arg->typecast.item, val);
|
|
|
|
if (!ret)
|
|
|
|
break;
|
|
|
|
*val = eval_type(*val, arg, 0);
|
2012-04-06 06:47:53 +08:00
|
|
|
break;
|
2018-09-20 02:56:50 +08:00
|
|
|
case TEP_PRINT_OP:
|
2012-04-06 06:47:53 +08:00
|
|
|
switch (arg->op.op[0]) {
|
|
|
|
case '|':
|
2012-04-06 06:48:00 +08:00
|
|
|
ret = arg_num_eval(arg->op.left, &left);
|
|
|
|
if (!ret)
|
|
|
|
break;
|
|
|
|
ret = arg_num_eval(arg->op.right, &right);
|
|
|
|
if (!ret)
|
|
|
|
break;
|
2012-04-06 06:47:53 +08:00
|
|
|
if (arg->op.op[1])
|
2012-04-06 06:48:00 +08:00
|
|
|
*val = left || right;
|
2012-04-06 06:47:53 +08:00
|
|
|
else
|
2012-04-06 06:48:00 +08:00
|
|
|
*val = left | right;
|
2012-04-06 06:47:53 +08:00
|
|
|
break;
|
|
|
|
case '&':
|
2012-04-06 06:48:00 +08:00
|
|
|
ret = arg_num_eval(arg->op.left, &left);
|
|
|
|
if (!ret)
|
|
|
|
break;
|
|
|
|
ret = arg_num_eval(arg->op.right, &right);
|
|
|
|
if (!ret)
|
|
|
|
break;
|
2012-04-06 06:47:53 +08:00
|
|
|
if (arg->op.op[1])
|
2012-04-06 06:48:00 +08:00
|
|
|
*val = left && right;
|
2012-04-06 06:47:53 +08:00
|
|
|
else
|
2012-04-06 06:48:00 +08:00
|
|
|
*val = left & right;
|
2012-04-06 06:47:53 +08:00
|
|
|
break;
|
|
|
|
case '<':
|
2012-04-06 06:48:00 +08:00
|
|
|
ret = arg_num_eval(arg->op.left, &left);
|
|
|
|
if (!ret)
|
|
|
|
break;
|
|
|
|
ret = arg_num_eval(arg->op.right, &right);
|
|
|
|
if (!ret)
|
|
|
|
break;
|
2012-04-06 06:47:53 +08:00
|
|
|
switch (arg->op.op[1]) {
|
|
|
|
case 0:
|
2012-04-06 06:48:00 +08:00
|
|
|
*val = left < right;
|
2012-04-06 06:47:53 +08:00
|
|
|
break;
|
|
|
|
case '<':
|
2012-04-06 06:48:00 +08:00
|
|
|
*val = left << right;
|
2012-04-06 06:47:53 +08:00
|
|
|
break;
|
|
|
|
case '=':
|
2012-04-06 06:48:00 +08:00
|
|
|
*val = left <= right;
|
2012-04-06 06:47:53 +08:00
|
|
|
break;
|
|
|
|
default:
|
2012-04-06 06:48:00 +08:00
|
|
|
do_warning("unknown op '%s'", arg->op.op);
|
|
|
|
ret = 0;
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '>':
|
2012-04-06 06:48:00 +08:00
|
|
|
ret = arg_num_eval(arg->op.left, &left);
|
|
|
|
if (!ret)
|
|
|
|
break;
|
|
|
|
ret = arg_num_eval(arg->op.right, &right);
|
|
|
|
if (!ret)
|
|
|
|
break;
|
2012-04-06 06:47:53 +08:00
|
|
|
switch (arg->op.op[1]) {
|
|
|
|
case 0:
|
2012-04-06 06:48:00 +08:00
|
|
|
*val = left > right;
|
2012-04-06 06:47:53 +08:00
|
|
|
break;
|
|
|
|
case '>':
|
2012-04-06 06:48:00 +08:00
|
|
|
*val = left >> right;
|
2012-04-06 06:47:53 +08:00
|
|
|
break;
|
|
|
|
case '=':
|
2012-04-06 06:48:00 +08:00
|
|
|
*val = left >= right;
|
2012-04-06 06:47:53 +08:00
|
|
|
break;
|
|
|
|
default:
|
2012-04-06 06:48:00 +08:00
|
|
|
do_warning("unknown op '%s'", arg->op.op);
|
|
|
|
ret = 0;
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '=':
|
2012-04-06 06:48:00 +08:00
|
|
|
ret = arg_num_eval(arg->op.left, &left);
|
|
|
|
if (!ret)
|
|
|
|
break;
|
|
|
|
ret = arg_num_eval(arg->op.right, &right);
|
|
|
|
if (!ret)
|
|
|
|
break;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2012-04-06 06:48:00 +08:00
|
|
|
if (arg->op.op[1] != '=') {
|
|
|
|
do_warning("unknown op '%s'", arg->op.op);
|
|
|
|
ret = 0;
|
|
|
|
} else
|
|
|
|
*val = left == right;
|
2012-04-06 06:47:53 +08:00
|
|
|
break;
|
|
|
|
case '!':
|
2012-04-06 06:48:00 +08:00
|
|
|
ret = arg_num_eval(arg->op.left, &left);
|
|
|
|
if (!ret)
|
|
|
|
break;
|
|
|
|
ret = arg_num_eval(arg->op.right, &right);
|
|
|
|
if (!ret)
|
|
|
|
break;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
switch (arg->op.op[1]) {
|
|
|
|
case '=':
|
2012-04-06 06:48:00 +08:00
|
|
|
*val = left != right;
|
2012-04-06 06:47:53 +08:00
|
|
|
break;
|
|
|
|
default:
|
2012-04-06 06:48:00 +08:00
|
|
|
do_warning("unknown op '%s'", arg->op.op);
|
|
|
|
ret = 0;
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '-':
|
|
|
|
/* check for negative */
|
2018-09-20 02:56:50 +08:00
|
|
|
if (arg->op.left->type == TEP_PRINT_NULL)
|
2012-04-06 06:47:53 +08:00
|
|
|
left = 0;
|
|
|
|
else
|
2012-04-06 06:48:00 +08:00
|
|
|
ret = arg_num_eval(arg->op.left, &left);
|
|
|
|
if (!ret)
|
|
|
|
break;
|
|
|
|
ret = arg_num_eval(arg->op.right, &right);
|
|
|
|
if (!ret)
|
|
|
|
break;
|
|
|
|
*val = left - right;
|
2012-04-06 06:47:53 +08:00
|
|
|
break;
|
2012-04-06 06:48:03 +08:00
|
|
|
case '+':
|
2018-09-20 02:56:50 +08:00
|
|
|
if (arg->op.left->type == TEP_PRINT_NULL)
|
2012-04-06 06:48:03 +08:00
|
|
|
left = 0;
|
|
|
|
else
|
|
|
|
ret = arg_num_eval(arg->op.left, &left);
|
|
|
|
if (!ret)
|
|
|
|
break;
|
|
|
|
ret = arg_num_eval(arg->op.right, &right);
|
|
|
|
if (!ret)
|
|
|
|
break;
|
|
|
|
*val = left + right;
|
|
|
|
break;
|
2016-02-27 07:13:28 +08:00
|
|
|
case '~':
|
|
|
|
ret = arg_num_eval(arg->op.right, &right);
|
|
|
|
if (!ret)
|
|
|
|
break;
|
|
|
|
*val = ~right;
|
|
|
|
break;
|
2012-04-06 06:47:53 +08:00
|
|
|
default:
|
2012-04-06 06:48:00 +08:00
|
|
|
do_warning("unknown op '%s'", arg->op.op);
|
|
|
|
ret = 0;
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2018-09-20 02:56:50 +08:00
|
|
|
case TEP_PRINT_NULL:
|
|
|
|
case TEP_PRINT_FIELD ... TEP_PRINT_SYMBOL:
|
|
|
|
case TEP_PRINT_STRING:
|
|
|
|
case TEP_PRINT_BSTRING:
|
|
|
|
case TEP_PRINT_BITMASK:
|
2012-04-06 06:47:53 +08:00
|
|
|
default:
|
2012-04-06 06:48:00 +08:00
|
|
|
do_warning("invalid eval type %d", arg->type);
|
|
|
|
ret = 0;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
}
|
2012-04-06 06:48:00 +08:00
|
|
|
return ret;
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
|
2018-09-20 02:56:49 +08:00
|
|
|
static char *arg_eval (struct tep_print_arg *arg)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
|
|
|
long long val;
|
2019-02-28 09:55:32 +08:00
|
|
|
static char buf[24];
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
switch (arg->type) {
|
2018-09-20 02:56:50 +08:00
|
|
|
case TEP_PRINT_ATOM:
|
2012-04-06 06:47:53 +08:00
|
|
|
return arg->atom.atom;
|
2018-09-20 02:56:50 +08:00
|
|
|
case TEP_PRINT_TYPE:
|
2012-04-06 06:47:53 +08:00
|
|
|
return arg_eval(arg->typecast.item);
|
2018-09-20 02:56:50 +08:00
|
|
|
case TEP_PRINT_OP:
|
2012-04-06 06:48:00 +08:00
|
|
|
if (!arg_num_eval(arg, &val))
|
|
|
|
break;
|
2012-04-06 06:47:53 +08:00
|
|
|
sprintf(buf, "%lld", val);
|
|
|
|
return buf;
|
|
|
|
|
2018-09-20 02:56:50 +08:00
|
|
|
case TEP_PRINT_NULL:
|
|
|
|
case TEP_PRINT_FIELD ... TEP_PRINT_SYMBOL:
|
|
|
|
case TEP_PRINT_STRING:
|
|
|
|
case TEP_PRINT_BSTRING:
|
|
|
|
case TEP_PRINT_BITMASK:
|
2012-04-06 06:47:53 +08:00
|
|
|
default:
|
2012-09-13 04:30:50 +08:00
|
|
|
do_warning("invalid eval type %d", arg->type);
|
2012-04-06 06:47:53 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
static enum tep_event_type
|
2018-11-30 23:44:07 +08:00
|
|
|
process_fields(struct tep_event *event, struct tep_print_flag_sym **list, char **tok)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
2018-09-20 02:56:47 +08:00
|
|
|
enum tep_event_type type;
|
2018-09-20 02:56:49 +08:00
|
|
|
struct tep_print_arg *arg = NULL;
|
|
|
|
struct tep_print_flag_sym *field;
|
2012-04-06 06:47:53 +08:00
|
|
|
char *token = *tok;
|
|
|
|
char *value;
|
|
|
|
|
|
|
|
do {
|
|
|
|
free_token(token);
|
|
|
|
type = read_token_item(&token);
|
2018-09-20 02:56:47 +08:00
|
|
|
if (test_type_token(type, token, TEP_EVENT_OP, "{"))
|
2012-04-06 06:47:53 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
arg = alloc_arg();
|
2012-09-20 10:09:19 +08:00
|
|
|
if (!arg)
|
|
|
|
goto out_free;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
free_token(token);
|
|
|
|
type = process_arg(event, arg, &token);
|
2012-05-23 10:36:42 +08:00
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
if (type == TEP_EVENT_OP)
|
2012-05-23 10:36:42 +08:00
|
|
|
type = process_op(event, arg, &token);
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
if (type == TEP_EVENT_ERROR)
|
2012-05-23 10:36:42 +08:00
|
|
|
goto out_free;
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
if (test_type_token(type, token, TEP_EVENT_DELIM, ","))
|
2012-04-06 06:47:53 +08:00
|
|
|
goto out_free;
|
|
|
|
|
2012-09-13 02:39:59 +08:00
|
|
|
field = calloc(1, sizeof(*field));
|
|
|
|
if (!field)
|
|
|
|
goto out_free;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
value = arg_eval(arg);
|
2012-04-06 06:48:00 +08:00
|
|
|
if (value == NULL)
|
2012-09-19 14:58:43 +08:00
|
|
|
goto out_free_field;
|
2012-04-06 06:47:53 +08:00
|
|
|
field->value = strdup(value);
|
2012-04-09 10:54:31 +08:00
|
|
|
if (field->value == NULL)
|
2012-09-19 14:58:43 +08:00
|
|
|
goto out_free_field;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
free_arg(arg);
|
|
|
|
arg = alloc_arg();
|
2012-09-20 10:09:19 +08:00
|
|
|
if (!arg)
|
|
|
|
goto out_free;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
free_token(token);
|
|
|
|
type = process_arg(event, arg, &token);
|
2018-09-20 02:56:47 +08:00
|
|
|
if (test_type_token(type, token, TEP_EVENT_OP, "}"))
|
2012-09-19 14:58:43 +08:00
|
|
|
goto out_free_field;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
value = arg_eval(arg);
|
2012-04-06 06:48:00 +08:00
|
|
|
if (value == NULL)
|
2012-09-19 14:58:43 +08:00
|
|
|
goto out_free_field;
|
2012-04-06 06:47:53 +08:00
|
|
|
field->str = strdup(value);
|
2012-04-09 10:54:31 +08:00
|
|
|
if (field->str == NULL)
|
2012-09-19 14:58:43 +08:00
|
|
|
goto out_free_field;
|
2012-04-06 06:47:53 +08:00
|
|
|
free_arg(arg);
|
|
|
|
arg = NULL;
|
|
|
|
|
|
|
|
*list = field;
|
|
|
|
list = &field->next;
|
|
|
|
|
|
|
|
free_token(token);
|
|
|
|
type = read_token_item(&token);
|
2018-09-20 02:56:47 +08:00
|
|
|
} while (type == TEP_EVENT_DELIM && strcmp(token, ",") == 0);
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
*tok = token;
|
|
|
|
return type;
|
|
|
|
|
2012-09-19 14:58:43 +08:00
|
|
|
out_free_field:
|
|
|
|
free_flag_sym(field);
|
2012-04-06 06:47:53 +08:00
|
|
|
out_free:
|
|
|
|
free_arg(arg);
|
|
|
|
free_token(token);
|
|
|
|
*tok = NULL;
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
return TEP_EVENT_ERROR;
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
static enum tep_event_type
|
2018-11-30 23:44:07 +08:00
|
|
|
process_flags(struct tep_event *event, struct tep_print_arg *arg, char **tok)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
2018-09-20 02:56:49 +08:00
|
|
|
struct tep_print_arg *field;
|
2018-09-20 02:56:47 +08:00
|
|
|
enum tep_event_type type;
|
2014-06-24 19:09:10 +08:00
|
|
|
char *token = NULL;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
memset(arg, 0, sizeof(*arg));
|
2018-09-20 02:56:50 +08:00
|
|
|
arg->type = TEP_PRINT_FLAGS;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
field = alloc_arg();
|
2012-09-20 10:09:19 +08:00
|
|
|
if (!field) {
|
2014-03-19 09:22:53 +08:00
|
|
|
do_warning_event(event, "%s: not enough memory!", __func__);
|
2012-09-20 10:09:19 +08:00
|
|
|
goto out_free;
|
|
|
|
}
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2013-11-19 03:23:14 +08:00
|
|
|
type = process_field_arg(event, field, &token);
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
/* Handle operations in the first argument */
|
2018-09-20 02:56:47 +08:00
|
|
|
while (type == TEP_EVENT_OP)
|
2012-04-06 06:47:53 +08:00
|
|
|
type = process_op(event, field, &token);
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
if (test_type_token(type, token, TEP_EVENT_DELIM, ","))
|
2012-09-19 14:58:44 +08:00
|
|
|
goto out_free_field;
|
2012-04-06 06:47:53 +08:00
|
|
|
free_token(token);
|
|
|
|
|
|
|
|
arg->flags.field = field;
|
|
|
|
|
|
|
|
type = read_token_item(&token);
|
|
|
|
if (event_item_type(type)) {
|
|
|
|
arg->flags.delim = token;
|
|
|
|
type = read_token_item(&token);
|
|
|
|
}
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
if (test_type_token(type, token, TEP_EVENT_DELIM, ","))
|
2012-04-06 06:47:53 +08:00
|
|
|
goto out_free;
|
|
|
|
|
|
|
|
type = process_fields(event, &arg->flags.flags, &token);
|
2018-09-20 02:56:47 +08:00
|
|
|
if (test_type_token(type, token, TEP_EVENT_DELIM, ")"))
|
2012-04-06 06:47:53 +08:00
|
|
|
goto out_free;
|
|
|
|
|
|
|
|
free_token(token);
|
|
|
|
type = read_token_item(tok);
|
|
|
|
return type;
|
|
|
|
|
2012-09-19 14:58:44 +08:00
|
|
|
out_free_field:
|
|
|
|
free_arg(field);
|
|
|
|
out_free:
|
2012-04-06 06:47:53 +08:00
|
|
|
free_token(token);
|
|
|
|
*tok = NULL;
|
2018-09-20 02:56:47 +08:00
|
|
|
return TEP_EVENT_ERROR;
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
static enum tep_event_type
|
2018-11-30 23:44:07 +08:00
|
|
|
process_symbols(struct tep_event *event, struct tep_print_arg *arg, char **tok)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
2018-09-20 02:56:49 +08:00
|
|
|
struct tep_print_arg *field;
|
2018-09-20 02:56:47 +08:00
|
|
|
enum tep_event_type type;
|
2014-06-24 19:09:10 +08:00
|
|
|
char *token = NULL;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
memset(arg, 0, sizeof(*arg));
|
2018-09-20 02:56:50 +08:00
|
|
|
arg->type = TEP_PRINT_SYMBOL;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
field = alloc_arg();
|
2012-09-20 10:09:19 +08:00
|
|
|
if (!field) {
|
2014-03-19 09:22:53 +08:00
|
|
|
do_warning_event(event, "%s: not enough memory!", __func__);
|
2012-09-20 10:09:19 +08:00
|
|
|
goto out_free;
|
|
|
|
}
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2013-11-19 03:23:14 +08:00
|
|
|
type = process_field_arg(event, field, &token);
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
if (test_type_token(type, token, TEP_EVENT_DELIM, ","))
|
2012-09-19 14:58:44 +08:00
|
|
|
goto out_free_field;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
arg->symbol.field = field;
|
|
|
|
|
|
|
|
type = process_fields(event, &arg->symbol.symbols, &token);
|
2018-09-20 02:56:47 +08:00
|
|
|
if (test_type_token(type, token, TEP_EVENT_DELIM, ")"))
|
2012-04-06 06:47:53 +08:00
|
|
|
goto out_free;
|
|
|
|
|
|
|
|
free_token(token);
|
|
|
|
type = read_token_item(tok);
|
|
|
|
return type;
|
|
|
|
|
2012-09-19 14:58:44 +08:00
|
|
|
out_free_field:
|
|
|
|
free_arg(field);
|
|
|
|
out_free:
|
2012-04-06 06:47:53 +08:00
|
|
|
free_token(token);
|
|
|
|
*tok = NULL;
|
2018-09-20 02:56:47 +08:00
|
|
|
return TEP_EVENT_ERROR;
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
static enum tep_event_type
|
2018-11-30 23:44:07 +08:00
|
|
|
process_hex_common(struct tep_event *event, struct tep_print_arg *arg,
|
2018-09-20 02:56:50 +08:00
|
|
|
char **tok, enum tep_print_arg_type type)
|
2012-06-27 08:41:41 +08:00
|
|
|
{
|
|
|
|
memset(arg, 0, sizeof(*arg));
|
2017-01-25 09:28:17 +08:00
|
|
|
arg->type = type;
|
2012-06-27 08:41:41 +08:00
|
|
|
|
2015-03-21 02:12:55 +08:00
|
|
|
if (alloc_and_process_delim(event, ",", &arg->hex.field))
|
|
|
|
goto out;
|
2012-09-20 10:09:19 +08:00
|
|
|
|
2015-03-21 02:12:55 +08:00
|
|
|
if (alloc_and_process_delim(event, ")", &arg->hex.size))
|
|
|
|
goto free_field;
|
2012-06-27 08:41:41 +08:00
|
|
|
|
2015-03-21 02:12:55 +08:00
|
|
|
return read_token_item(tok);
|
2012-06-27 08:41:41 +08:00
|
|
|
|
2015-03-21 02:12:55 +08:00
|
|
|
free_field:
|
|
|
|
free_arg(arg->hex.field);
|
2016-02-10 04:40:16 +08:00
|
|
|
arg->hex.field = NULL;
|
2015-03-21 02:12:55 +08:00
|
|
|
out:
|
2012-06-27 08:41:41 +08:00
|
|
|
*tok = NULL;
|
2018-09-20 02:56:47 +08:00
|
|
|
return TEP_EVENT_ERROR;
|
2012-06-27 08:41:41 +08:00
|
|
|
}
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
static enum tep_event_type
|
2018-11-30 23:44:07 +08:00
|
|
|
process_hex(struct tep_event *event, struct tep_print_arg *arg, char **tok)
|
2017-01-25 09:28:17 +08:00
|
|
|
{
|
2018-09-20 02:56:50 +08:00
|
|
|
return process_hex_common(event, arg, tok, TEP_PRINT_HEX);
|
2017-01-25 09:28:17 +08:00
|
|
|
}
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
static enum tep_event_type
|
2018-11-30 23:44:07 +08:00
|
|
|
process_hex_str(struct tep_event *event, struct tep_print_arg *arg,
|
2017-01-25 09:28:17 +08:00
|
|
|
char **tok)
|
|
|
|
{
|
2018-09-20 02:56:50 +08:00
|
|
|
return process_hex_common(event, arg, tok, TEP_PRINT_HEX_STR);
|
2017-01-25 09:28:17 +08:00
|
|
|
}
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
static enum tep_event_type
|
2018-11-30 23:44:07 +08:00
|
|
|
process_int_array(struct tep_event *event, struct tep_print_arg *arg, char **tok)
|
2015-03-24 19:07:19 +08:00
|
|
|
{
|
|
|
|
memset(arg, 0, sizeof(*arg));
|
2018-09-20 02:56:50 +08:00
|
|
|
arg->type = TEP_PRINT_INT_ARRAY;
|
2012-09-20 10:09:19 +08:00
|
|
|
|
2015-03-24 19:07:19 +08:00
|
|
|
if (alloc_and_process_delim(event, ",", &arg->int_array.field))
|
|
|
|
goto out;
|
2012-06-27 08:41:41 +08:00
|
|
|
|
2015-03-24 19:07:19 +08:00
|
|
|
if (alloc_and_process_delim(event, ",", &arg->int_array.count))
|
|
|
|
goto free_field;
|
2012-06-27 08:41:41 +08:00
|
|
|
|
2015-03-24 19:07:19 +08:00
|
|
|
if (alloc_and_process_delim(event, ")", &arg->int_array.el_size))
|
|
|
|
goto free_size;
|
2012-06-27 08:41:41 +08:00
|
|
|
|
2015-03-24 19:07:19 +08:00
|
|
|
return read_token_item(tok);
|
2012-06-27 08:41:41 +08:00
|
|
|
|
2015-03-24 19:07:19 +08:00
|
|
|
free_size:
|
|
|
|
free_arg(arg->int_array.count);
|
2016-02-10 04:40:16 +08:00
|
|
|
arg->int_array.count = NULL;
|
2015-03-24 19:07:19 +08:00
|
|
|
free_field:
|
|
|
|
free_arg(arg->int_array.field);
|
2016-02-10 04:40:16 +08:00
|
|
|
arg->int_array.field = NULL;
|
2015-03-24 19:07:19 +08:00
|
|
|
out:
|
2012-06-27 08:41:41 +08:00
|
|
|
*tok = NULL;
|
2018-09-20 02:56:47 +08:00
|
|
|
return TEP_EVENT_ERROR;
|
2012-06-27 08:41:41 +08:00
|
|
|
}
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
static enum tep_event_type
|
2018-11-30 23:44:07 +08:00
|
|
|
process_dynamic_array(struct tep_event *event, struct tep_print_arg *arg, char **tok)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
2018-09-20 02:56:45 +08:00
|
|
|
struct tep_format_field *field;
|
2018-09-20 02:56:47 +08:00
|
|
|
enum tep_event_type type;
|
2012-04-06 06:47:53 +08:00
|
|
|
char *token;
|
|
|
|
|
|
|
|
memset(arg, 0, sizeof(*arg));
|
2018-09-20 02:56:50 +08:00
|
|
|
arg->type = TEP_PRINT_DYNAMIC_ARRAY;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The item within the parenthesis is another field that holds
|
|
|
|
* the index into where the array starts.
|
|
|
|
*/
|
|
|
|
type = read_token(&token);
|
|
|
|
*tok = token;
|
2018-09-20 02:56:47 +08:00
|
|
|
if (type != TEP_EVENT_ITEM)
|
2012-04-06 06:47:53 +08:00
|
|
|
goto out_free;
|
|
|
|
|
|
|
|
/* Find the field */
|
|
|
|
|
2018-08-09 02:02:50 +08:00
|
|
|
field = tep_find_field(event, token);
|
2012-04-06 06:47:53 +08:00
|
|
|
if (!field)
|
|
|
|
goto out_free;
|
|
|
|
|
|
|
|
arg->dynarray.field = field;
|
|
|
|
arg->dynarray.index = 0;
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
if (read_expected(TEP_EVENT_DELIM, ")") < 0)
|
2012-04-06 06:47:53 +08:00
|
|
|
goto out_free;
|
|
|
|
|
|
|
|
free_token(token);
|
|
|
|
type = read_token_item(&token);
|
|
|
|
*tok = token;
|
2018-09-20 02:56:47 +08:00
|
|
|
if (type != TEP_EVENT_OP || strcmp(token, "[") != 0)
|
2012-04-06 06:47:53 +08:00
|
|
|
return type;
|
|
|
|
|
|
|
|
free_token(token);
|
|
|
|
arg = alloc_arg();
|
2012-12-22 04:00:58 +08:00
|
|
|
if (!arg) {
|
2014-03-19 09:22:53 +08:00
|
|
|
do_warning_event(event, "%s: not enough memory!", __func__);
|
2012-09-20 10:09:19 +08:00
|
|
|
*tok = NULL;
|
2018-09-20 02:56:47 +08:00
|
|
|
return TEP_EVENT_ERROR;
|
2012-09-20 10:09:19 +08:00
|
|
|
}
|
|
|
|
|
2012-04-06 06:47:53 +08:00
|
|
|
type = process_arg(event, arg, &token);
|
2018-09-20 02:56:47 +08:00
|
|
|
if (type == TEP_EVENT_ERROR)
|
2012-05-23 10:36:50 +08:00
|
|
|
goto out_free_arg;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
if (!test_type_token(type, token, TEP_EVENT_OP, "]"))
|
2012-05-23 10:36:50 +08:00
|
|
|
goto out_free_arg;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
free_token(token);
|
|
|
|
type = read_token_item(tok);
|
|
|
|
return type;
|
|
|
|
|
2012-05-23 10:36:50 +08:00
|
|
|
out_free_arg:
|
|
|
|
free_arg(arg);
|
2012-04-06 06:47:53 +08:00
|
|
|
out_free:
|
|
|
|
free_token(token);
|
|
|
|
*tok = NULL;
|
2018-09-20 02:56:47 +08:00
|
|
|
return TEP_EVENT_ERROR;
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
static enum tep_event_type
|
2018-11-30 23:44:07 +08:00
|
|
|
process_dynamic_array_len(struct tep_event *event, struct tep_print_arg *arg,
|
2015-08-29 12:22:05 +08:00
|
|
|
char **tok)
|
|
|
|
{
|
2018-09-20 02:56:45 +08:00
|
|
|
struct tep_format_field *field;
|
2018-09-20 02:56:47 +08:00
|
|
|
enum tep_event_type type;
|
2015-08-29 12:22:05 +08:00
|
|
|
char *token;
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
if (read_expect_type(TEP_EVENT_ITEM, &token) < 0)
|
2015-08-29 12:22:05 +08:00
|
|
|
goto out_free;
|
|
|
|
|
2018-09-20 02:56:50 +08:00
|
|
|
arg->type = TEP_PRINT_DYNAMIC_ARRAY_LEN;
|
2015-08-29 12:22:05 +08:00
|
|
|
|
|
|
|
/* Find the field */
|
2018-08-09 02:02:50 +08:00
|
|
|
field = tep_find_field(event, token);
|
2015-08-29 12:22:05 +08:00
|
|
|
if (!field)
|
|
|
|
goto out_free;
|
|
|
|
|
|
|
|
arg->dynarray.field = field;
|
|
|
|
arg->dynarray.index = 0;
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
if (read_expected(TEP_EVENT_DELIM, ")") < 0)
|
2015-08-29 12:22:05 +08:00
|
|
|
goto out_err;
|
|
|
|
|
2020-07-30 23:02:36 +08:00
|
|
|
free_token(token);
|
2015-08-29 12:22:05 +08:00
|
|
|
type = read_token(&token);
|
|
|
|
*tok = token;
|
|
|
|
|
|
|
|
return type;
|
|
|
|
|
|
|
|
out_free:
|
|
|
|
free_token(token);
|
|
|
|
out_err:
|
|
|
|
*tok = NULL;
|
2018-09-20 02:56:47 +08:00
|
|
|
return TEP_EVENT_ERROR;
|
2015-08-29 12:22:05 +08:00
|
|
|
}
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
static enum tep_event_type
|
2018-11-30 23:44:07 +08:00
|
|
|
process_paren(struct tep_event *event, struct tep_print_arg *arg, char **tok)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
2018-09-20 02:56:49 +08:00
|
|
|
struct tep_print_arg *item_arg;
|
2018-09-20 02:56:47 +08:00
|
|
|
enum tep_event_type type;
|
2012-04-06 06:47:53 +08:00
|
|
|
char *token;
|
|
|
|
|
|
|
|
type = process_arg(event, arg, &token);
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
if (type == TEP_EVENT_ERROR)
|
2012-04-06 06:47:53 +08:00
|
|
|
goto out_free;
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
if (type == TEP_EVENT_OP)
|
2012-04-06 06:47:53 +08:00
|
|
|
type = process_op(event, arg, &token);
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
if (type == TEP_EVENT_ERROR)
|
2012-04-06 06:47:53 +08:00
|
|
|
goto out_free;
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
if (test_type_token(type, token, TEP_EVENT_DELIM, ")"))
|
2012-04-06 06:47:53 +08:00
|
|
|
goto out_free;
|
|
|
|
|
|
|
|
free_token(token);
|
|
|
|
type = read_token_item(&token);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the next token is an item or another open paren, then
|
|
|
|
* this was a typecast.
|
|
|
|
*/
|
|
|
|
if (event_item_type(type) ||
|
2018-09-20 02:56:47 +08:00
|
|
|
(type == TEP_EVENT_DELIM && strcmp(token, "(") == 0)) {
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
/* make this a typecast and contine */
|
|
|
|
|
|
|
|
/* prevous must be an atom */
|
2018-09-20 02:56:50 +08:00
|
|
|
if (arg->type != TEP_PRINT_ATOM) {
|
|
|
|
do_warning_event(event, "previous needed to be TEP_PRINT_ATOM");
|
2012-09-13 04:30:50 +08:00
|
|
|
goto out_free;
|
|
|
|
}
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
item_arg = alloc_arg();
|
2012-09-20 10:09:19 +08:00
|
|
|
if (!item_arg) {
|
2014-03-19 09:22:53 +08:00
|
|
|
do_warning_event(event, "%s: not enough memory!",
|
|
|
|
__func__);
|
2012-09-20 10:09:19 +08:00
|
|
|
goto out_free;
|
|
|
|
}
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2018-09-20 02:56:50 +08:00
|
|
|
arg->type = TEP_PRINT_TYPE;
|
2012-04-06 06:47:53 +08:00
|
|
|
arg->typecast.type = arg->atom.atom;
|
|
|
|
arg->typecast.item = item_arg;
|
|
|
|
type = process_arg_token(event, item_arg, &token, type);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
*tok = token;
|
|
|
|
return type;
|
|
|
|
|
|
|
|
out_free:
|
|
|
|
free_token(token);
|
|
|
|
*tok = NULL;
|
2018-09-20 02:56:47 +08:00
|
|
|
return TEP_EVENT_ERROR;
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
static enum tep_event_type
|
2018-11-30 23:44:07 +08:00
|
|
|
process_str(struct tep_event *event __maybe_unused, struct tep_print_arg *arg,
|
2012-09-11 06:15:03 +08:00
|
|
|
char **tok)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
2018-09-20 02:56:47 +08:00
|
|
|
enum tep_event_type type;
|
2012-04-06 06:47:53 +08:00
|
|
|
char *token;
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
if (read_expect_type(TEP_EVENT_ITEM, &token) < 0)
|
2012-04-06 06:47:53 +08:00
|
|
|
goto out_free;
|
|
|
|
|
2018-09-20 02:56:50 +08:00
|
|
|
arg->type = TEP_PRINT_STRING;
|
2012-04-06 06:47:53 +08:00
|
|
|
arg->string.string = token;
|
2021-11-22 17:30:40 +08:00
|
|
|
arg->string.field = NULL;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
if (read_expected(TEP_EVENT_DELIM, ")") < 0)
|
2012-04-06 06:47:53 +08:00
|
|
|
goto out_err;
|
|
|
|
|
|
|
|
type = read_token(&token);
|
|
|
|
*tok = token;
|
|
|
|
|
|
|
|
return type;
|
|
|
|
|
|
|
|
out_free:
|
|
|
|
free_token(token);
|
|
|
|
out_err:
|
|
|
|
*tok = NULL;
|
2018-09-20 02:56:47 +08:00
|
|
|
return TEP_EVENT_ERROR;
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
static enum tep_event_type
|
2018-11-30 23:44:07 +08:00
|
|
|
process_bitmask(struct tep_event *event __maybe_unused, struct tep_print_arg *arg,
|
2018-09-20 02:56:44 +08:00
|
|
|
char **tok)
|
2014-06-03 11:20:16 +08:00
|
|
|
{
|
2018-09-20 02:56:47 +08:00
|
|
|
enum tep_event_type type;
|
2014-06-03 11:20:16 +08:00
|
|
|
char *token;
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
if (read_expect_type(TEP_EVENT_ITEM, &token) < 0)
|
2014-06-03 11:20:16 +08:00
|
|
|
goto out_free;
|
|
|
|
|
2018-09-20 02:56:50 +08:00
|
|
|
arg->type = TEP_PRINT_BITMASK;
|
2014-06-03 11:20:16 +08:00
|
|
|
arg->bitmask.bitmask = token;
|
2021-11-22 17:30:40 +08:00
|
|
|
arg->bitmask.field = NULL;
|
2014-06-03 11:20:16 +08:00
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
if (read_expected(TEP_EVENT_DELIM, ")") < 0)
|
2014-06-03 11:20:16 +08:00
|
|
|
goto out_err;
|
|
|
|
|
|
|
|
type = read_token(&token);
|
|
|
|
*tok = token;
|
|
|
|
|
|
|
|
return type;
|
|
|
|
|
|
|
|
out_free:
|
|
|
|
free_token(token);
|
|
|
|
out_err:
|
|
|
|
*tok = NULL;
|
2018-09-20 02:56:47 +08:00
|
|
|
return TEP_EVENT_ERROR;
|
2014-06-03 11:20:16 +08:00
|
|
|
}
|
|
|
|
|
tools lib traceevent: Rename pevent_function* APIs
In order to make libtraceevent into a proper library, variables, data
structures and functions require a unique prefix to prevent name space
conflicts. That prefix will be "tep_" and not "pevent_". This changes
APIs: pevent_function_handler, pevent_func_handler,
pevent_func_arg_type, PEVENT_FUNC_ARG_VOID, PEVENT_FUNC_ARG_INT,
PEVENT_FUNC_ARG_LONG, PEVENT_FUNC_ARG_STRING, PEVENT_FUNC_ARG_PTRS,
PEVENT_FUNC_ARG_MAX_TYPES
Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
Cc: linux-trace-devel@vger.kernel.org
Link: http://lkml.kernel.org/r/20180808180701.935881193@goodmis.org
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2018-08-09 02:02:59 +08:00
|
|
|
static struct tep_function_handler *
|
2019-04-02 00:43:20 +08:00
|
|
|
find_func_handler(struct tep_handle *tep, char *func_name)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
tools lib traceevent: Rename pevent_function* APIs
In order to make libtraceevent into a proper library, variables, data
structures and functions require a unique prefix to prevent name space
conflicts. That prefix will be "tep_" and not "pevent_". This changes
APIs: pevent_function_handler, pevent_func_handler,
pevent_func_arg_type, PEVENT_FUNC_ARG_VOID, PEVENT_FUNC_ARG_INT,
PEVENT_FUNC_ARG_LONG, PEVENT_FUNC_ARG_STRING, PEVENT_FUNC_ARG_PTRS,
PEVENT_FUNC_ARG_MAX_TYPES
Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
Cc: linux-trace-devel@vger.kernel.org
Link: http://lkml.kernel.org/r/20180808180701.935881193@goodmis.org
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2018-08-09 02:02:59 +08:00
|
|
|
struct tep_function_handler *func;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2019-04-02 00:43:20 +08:00
|
|
|
if (!tep)
|
2012-10-02 08:13:51 +08:00
|
|
|
return NULL;
|
|
|
|
|
2019-04-02 00:43:20 +08:00
|
|
|
for (func = tep->func_handlers; func; func = func->next) {
|
2012-04-06 06:47:53 +08:00
|
|
|
if (strcmp(func->name, func_name) == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return func;
|
|
|
|
}
|
|
|
|
|
2019-04-02 00:43:20 +08:00
|
|
|
static void remove_func_handler(struct tep_handle *tep, char *func_name)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
tools lib traceevent: Rename pevent_function* APIs
In order to make libtraceevent into a proper library, variables, data
structures and functions require a unique prefix to prevent name space
conflicts. That prefix will be "tep_" and not "pevent_". This changes
APIs: pevent_function_handler, pevent_func_handler,
pevent_func_arg_type, PEVENT_FUNC_ARG_VOID, PEVENT_FUNC_ARG_INT,
PEVENT_FUNC_ARG_LONG, PEVENT_FUNC_ARG_STRING, PEVENT_FUNC_ARG_PTRS,
PEVENT_FUNC_ARG_MAX_TYPES
Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
Cc: linux-trace-devel@vger.kernel.org
Link: http://lkml.kernel.org/r/20180808180701.935881193@goodmis.org
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2018-08-09 02:02:59 +08:00
|
|
|
struct tep_function_handler *func;
|
|
|
|
struct tep_function_handler **next;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2019-04-02 00:43:20 +08:00
|
|
|
next = &tep->func_handlers;
|
2012-04-06 06:47:53 +08:00
|
|
|
while ((func = *next)) {
|
|
|
|
if (strcmp(func->name, func_name) == 0) {
|
|
|
|
*next = func->next;
|
|
|
|
free_func_handle(func);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
next = &func->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
static enum tep_event_type
|
2018-11-30 23:44:07 +08:00
|
|
|
process_func_handler(struct tep_event *event, struct tep_function_handler *func,
|
2018-09-20 02:56:49 +08:00
|
|
|
struct tep_print_arg *arg, char **tok)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
2018-09-20 02:56:49 +08:00
|
|
|
struct tep_print_arg **next_arg;
|
|
|
|
struct tep_print_arg *farg;
|
2018-09-20 02:56:47 +08:00
|
|
|
enum tep_event_type type;
|
2012-04-06 06:47:53 +08:00
|
|
|
char *token;
|
|
|
|
int i;
|
|
|
|
|
2018-09-20 02:56:50 +08:00
|
|
|
arg->type = TEP_PRINT_FUNC;
|
2012-04-06 06:47:53 +08:00
|
|
|
arg->func.func = func;
|
|
|
|
|
|
|
|
*tok = NULL;
|
|
|
|
|
|
|
|
next_arg = &(arg->func.args);
|
|
|
|
for (i = 0; i < func->nr_args; i++) {
|
|
|
|
farg = alloc_arg();
|
2012-09-20 10:09:19 +08:00
|
|
|
if (!farg) {
|
2014-03-19 09:22:53 +08:00
|
|
|
do_warning_event(event, "%s: not enough memory!",
|
|
|
|
__func__);
|
2018-09-20 02:56:47 +08:00
|
|
|
return TEP_EVENT_ERROR;
|
2012-09-20 10:09:19 +08:00
|
|
|
}
|
|
|
|
|
2012-04-06 06:47:53 +08:00
|
|
|
type = process_arg(event, farg, &token);
|
2013-11-19 10:38:20 +08:00
|
|
|
if (i < (func->nr_args - 1)) {
|
2018-09-20 02:56:47 +08:00
|
|
|
if (type != TEP_EVENT_DELIM || strcmp(token, ",") != 0) {
|
2014-03-19 09:22:54 +08:00
|
|
|
do_warning_event(event,
|
|
|
|
"Error: function '%s()' expects %d arguments but event %s only uses %d",
|
2013-11-19 10:38:20 +08:00
|
|
|
func->name, func->nr_args,
|
|
|
|
event->name, i + 1);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
} else {
|
2018-09-20 02:56:47 +08:00
|
|
|
if (type != TEP_EVENT_DELIM || strcmp(token, ")") != 0) {
|
2014-03-19 09:22:54 +08:00
|
|
|
do_warning_event(event,
|
|
|
|
"Error: function '%s()' only expects %d arguments but event %s has more",
|
2013-11-19 10:38:20 +08:00
|
|
|
func->name, func->nr_args, event->name);
|
|
|
|
goto err;
|
|
|
|
}
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
*next_arg = farg;
|
|
|
|
next_arg = &(farg->next);
|
|
|
|
free_token(token);
|
|
|
|
}
|
|
|
|
|
|
|
|
type = read_token(&token);
|
|
|
|
*tok = token;
|
|
|
|
|
|
|
|
return type;
|
2013-11-19 10:38:20 +08:00
|
|
|
|
|
|
|
err:
|
|
|
|
free_arg(farg);
|
|
|
|
free_token(token);
|
2018-09-20 02:56:47 +08:00
|
|
|
return TEP_EVENT_ERROR;
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
|
2020-03-25 04:08:48 +08:00
|
|
|
static enum tep_event_type
|
|
|
|
process_builtin_expect(struct tep_event *event, struct tep_print_arg *arg, char **tok)
|
|
|
|
{
|
|
|
|
enum tep_event_type type;
|
|
|
|
char *token = NULL;
|
|
|
|
|
|
|
|
/* Handle __builtin_expect( cond, #) */
|
|
|
|
type = process_arg(event, arg, &token);
|
|
|
|
|
|
|
|
if (type != TEP_EVENT_DELIM || token[0] != ',')
|
|
|
|
goto out_free;
|
|
|
|
|
|
|
|
free_token(token);
|
|
|
|
|
|
|
|
/* We don't care what the second parameter is of the __builtin_expect() */
|
|
|
|
if (read_expect_type(TEP_EVENT_ITEM, &token) < 0)
|
|
|
|
goto out_free;
|
|
|
|
|
|
|
|
if (read_expected(TEP_EVENT_DELIM, ")") < 0)
|
|
|
|
goto out_free;
|
|
|
|
|
|
|
|
free_token(token);
|
|
|
|
type = read_token_item(tok);
|
|
|
|
return type;
|
|
|
|
|
|
|
|
out_free:
|
|
|
|
free_token(token);
|
|
|
|
*tok = NULL;
|
|
|
|
return TEP_EVENT_ERROR;
|
|
|
|
}
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
static enum tep_event_type
|
2018-11-30 23:44:07 +08:00
|
|
|
process_function(struct tep_event *event, struct tep_print_arg *arg,
|
2012-04-06 06:47:53 +08:00
|
|
|
char *token, char **tok)
|
|
|
|
{
|
tools lib traceevent: Rename pevent_function* APIs
In order to make libtraceevent into a proper library, variables, data
structures and functions require a unique prefix to prevent name space
conflicts. That prefix will be "tep_" and not "pevent_". This changes
APIs: pevent_function_handler, pevent_func_handler,
pevent_func_arg_type, PEVENT_FUNC_ARG_VOID, PEVENT_FUNC_ARG_INT,
PEVENT_FUNC_ARG_LONG, PEVENT_FUNC_ARG_STRING, PEVENT_FUNC_ARG_PTRS,
PEVENT_FUNC_ARG_MAX_TYPES
Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
Cc: linux-trace-devel@vger.kernel.org
Link: http://lkml.kernel.org/r/20180808180701.935881193@goodmis.org
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2018-08-09 02:02:59 +08:00
|
|
|
struct tep_function_handler *func;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
if (strcmp(token, "__print_flags") == 0) {
|
|
|
|
free_token(token);
|
2012-04-06 06:47:58 +08:00
|
|
|
is_flag_field = 1;
|
2012-04-06 06:47:53 +08:00
|
|
|
return process_flags(event, arg, tok);
|
|
|
|
}
|
|
|
|
if (strcmp(token, "__print_symbolic") == 0) {
|
|
|
|
free_token(token);
|
2012-04-06 06:47:58 +08:00
|
|
|
is_symbolic_field = 1;
|
2012-04-06 06:47:53 +08:00
|
|
|
return process_symbols(event, arg, tok);
|
|
|
|
}
|
2012-06-27 08:41:41 +08:00
|
|
|
if (strcmp(token, "__print_hex") == 0) {
|
|
|
|
free_token(token);
|
|
|
|
return process_hex(event, arg, tok);
|
|
|
|
}
|
2017-01-25 09:28:17 +08:00
|
|
|
if (strcmp(token, "__print_hex_str") == 0) {
|
|
|
|
free_token(token);
|
|
|
|
return process_hex_str(event, arg, tok);
|
|
|
|
}
|
2015-03-24 19:07:19 +08:00
|
|
|
if (strcmp(token, "__print_array") == 0) {
|
|
|
|
free_token(token);
|
|
|
|
return process_int_array(event, arg, tok);
|
|
|
|
}
|
2021-11-22 17:30:40 +08:00
|
|
|
if (strcmp(token, "__get_str") == 0 ||
|
|
|
|
strcmp(token, "__get_rel_str") == 0) {
|
2012-04-06 06:47:53 +08:00
|
|
|
free_token(token);
|
|
|
|
return process_str(event, arg, tok);
|
|
|
|
}
|
2021-11-22 17:30:40 +08:00
|
|
|
if (strcmp(token, "__get_bitmask") == 0 ||
|
|
|
|
strcmp(token, "__get_rel_bitmask") == 0) {
|
2014-06-03 11:20:16 +08:00
|
|
|
free_token(token);
|
|
|
|
return process_bitmask(event, arg, tok);
|
|
|
|
}
|
2021-11-22 17:30:40 +08:00
|
|
|
if (strcmp(token, "__get_dynamic_array") == 0 ||
|
|
|
|
strcmp(token, "__get_rel_dynamic_array") == 0) {
|
2012-04-06 06:47:53 +08:00
|
|
|
free_token(token);
|
|
|
|
return process_dynamic_array(event, arg, tok);
|
|
|
|
}
|
2021-11-22 17:30:40 +08:00
|
|
|
if (strcmp(token, "__get_dynamic_array_len") == 0 ||
|
|
|
|
strcmp(token, "__get_rel_dynamic_array_len") == 0) {
|
2015-08-29 12:22:05 +08:00
|
|
|
free_token(token);
|
|
|
|
return process_dynamic_array_len(event, arg, tok);
|
|
|
|
}
|
2020-03-25 04:08:48 +08:00
|
|
|
if (strcmp(token, "__builtin_expect") == 0) {
|
|
|
|
free_token(token);
|
|
|
|
return process_builtin_expect(event, arg, tok);
|
|
|
|
}
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2019-04-02 00:43:18 +08:00
|
|
|
func = find_func_handler(event->tep, token);
|
2012-04-06 06:47:53 +08:00
|
|
|
if (func) {
|
|
|
|
free_token(token);
|
|
|
|
return process_func_handler(event, func, arg, tok);
|
|
|
|
}
|
|
|
|
|
2014-03-19 09:22:53 +08:00
|
|
|
do_warning_event(event, "function %s not defined", token);
|
2012-04-06 06:47:53 +08:00
|
|
|
free_token(token);
|
2018-09-20 02:56:47 +08:00
|
|
|
return TEP_EVENT_ERROR;
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
static enum tep_event_type
|
2018-11-30 23:44:07 +08:00
|
|
|
process_arg_token(struct tep_event *event, struct tep_print_arg *arg,
|
2018-09-20 02:56:47 +08:00
|
|
|
char **tok, enum tep_event_type type)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
|
|
|
char *token;
|
|
|
|
char *atom;
|
|
|
|
|
|
|
|
token = *tok;
|
|
|
|
|
|
|
|
switch (type) {
|
2018-09-20 02:56:47 +08:00
|
|
|
case TEP_EVENT_ITEM:
|
2012-04-06 06:47:53 +08:00
|
|
|
if (strcmp(token, "REC") == 0) {
|
|
|
|
free_token(token);
|
|
|
|
type = process_entry(event, arg, &token);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
atom = token;
|
|
|
|
/* test the next token */
|
|
|
|
type = read_token_item(&token);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the next token is a parenthesis, then this
|
|
|
|
* is a function.
|
|
|
|
*/
|
2018-09-20 02:56:47 +08:00
|
|
|
if (type == TEP_EVENT_DELIM && strcmp(token, "(") == 0) {
|
2012-04-06 06:47:53 +08:00
|
|
|
free_token(token);
|
|
|
|
token = NULL;
|
|
|
|
/* this will free atom. */
|
|
|
|
type = process_function(event, arg, atom, &token);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* atoms can be more than one token long */
|
2018-09-20 02:56:47 +08:00
|
|
|
while (type == TEP_EVENT_ITEM) {
|
2020-03-25 04:08:46 +08:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = append(&atom, " ", token);
|
|
|
|
if (ret < 0) {
|
2012-04-09 10:54:33 +08:00
|
|
|
free(atom);
|
|
|
|
*tok = NULL;
|
|
|
|
free_token(token);
|
2018-09-20 02:56:47 +08:00
|
|
|
return TEP_EVENT_ERROR;
|
2012-04-09 10:54:33 +08:00
|
|
|
}
|
2012-04-06 06:47:53 +08:00
|
|
|
free_token(token);
|
|
|
|
type = read_token_item(&token);
|
|
|
|
}
|
|
|
|
|
2018-09-20 02:56:50 +08:00
|
|
|
arg->type = TEP_PRINT_ATOM;
|
2012-04-06 06:47:53 +08:00
|
|
|
arg->atom.atom = atom;
|
|
|
|
break;
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
case TEP_EVENT_DQUOTE:
|
|
|
|
case TEP_EVENT_SQUOTE:
|
2018-09-20 02:56:50 +08:00
|
|
|
arg->type = TEP_PRINT_ATOM;
|
2012-04-06 06:47:53 +08:00
|
|
|
arg->atom.atom = token;
|
|
|
|
type = read_token_item(&token);
|
|
|
|
break;
|
2018-09-20 02:56:47 +08:00
|
|
|
case TEP_EVENT_DELIM:
|
2012-04-06 06:47:53 +08:00
|
|
|
if (strcmp(token, "(") == 0) {
|
|
|
|
free_token(token);
|
|
|
|
type = process_paren(event, arg, &token);
|
|
|
|
break;
|
|
|
|
}
|
2018-09-20 02:56:47 +08:00
|
|
|
case TEP_EVENT_OP:
|
2012-04-06 06:47:53 +08:00
|
|
|
/* handle single ops */
|
2018-09-20 02:56:50 +08:00
|
|
|
arg->type = TEP_PRINT_OP;
|
2012-04-06 06:47:53 +08:00
|
|
|
arg->op.op = token;
|
|
|
|
arg->op.left = NULL;
|
|
|
|
type = process_op(event, arg, &token);
|
|
|
|
|
|
|
|
/* On error, the op is freed */
|
2018-09-20 02:56:47 +08:00
|
|
|
if (type == TEP_EVENT_ERROR)
|
2012-04-06 06:47:53 +08:00
|
|
|
arg->op.op = NULL;
|
|
|
|
|
|
|
|
/* return error type if errored */
|
|
|
|
break;
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
case TEP_EVENT_ERROR ... TEP_EVENT_NEWLINE:
|
2012-04-06 06:47:53 +08:00
|
|
|
default:
|
2014-03-19 09:22:53 +08:00
|
|
|
do_warning_event(event, "unexpected type %d", type);
|
2018-09-20 02:56:47 +08:00
|
|
|
return TEP_EVENT_ERROR;
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
*tok = token;
|
|
|
|
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
2018-11-30 23:44:07 +08:00
|
|
|
static int event_read_print_args(struct tep_event *event, struct tep_print_arg **list)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
2018-09-20 02:56:47 +08:00
|
|
|
enum tep_event_type type = TEP_EVENT_ERROR;
|
2018-09-20 02:56:49 +08:00
|
|
|
struct tep_print_arg *arg;
|
2012-04-06 06:47:53 +08:00
|
|
|
char *token;
|
|
|
|
int args = 0;
|
|
|
|
|
|
|
|
do {
|
2018-09-20 02:56:47 +08:00
|
|
|
if (type == TEP_EVENT_NEWLINE) {
|
2012-04-06 06:47:53 +08:00
|
|
|
type = read_token_item(&token);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
arg = alloc_arg();
|
2012-09-20 10:09:19 +08:00
|
|
|
if (!arg) {
|
2014-03-19 09:22:53 +08:00
|
|
|
do_warning_event(event, "%s: not enough memory!",
|
|
|
|
__func__);
|
2012-09-20 10:09:19 +08:00
|
|
|
return -1;
|
|
|
|
}
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
type = process_arg(event, arg, &token);
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
if (type == TEP_EVENT_ERROR) {
|
2012-04-06 06:47:53 +08:00
|
|
|
free_token(token);
|
|
|
|
free_arg(arg);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
*list = arg;
|
|
|
|
args++;
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
if (type == TEP_EVENT_OP) {
|
2012-04-06 06:47:53 +08:00
|
|
|
type = process_op(event, arg, &token);
|
|
|
|
free_token(token);
|
2018-09-20 02:56:47 +08:00
|
|
|
if (type == TEP_EVENT_ERROR) {
|
2012-04-06 06:47:53 +08:00
|
|
|
*list = NULL;
|
|
|
|
free_arg(arg);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
list = &arg->next;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
if (type == TEP_EVENT_DELIM && strcmp(token, ",") == 0) {
|
2012-04-06 06:47:53 +08:00
|
|
|
free_token(token);
|
|
|
|
*list = arg;
|
|
|
|
list = &arg->next;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
2018-09-20 02:56:47 +08:00
|
|
|
} while (type != TEP_EVENT_NONE);
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
if (type != TEP_EVENT_NONE && type != TEP_EVENT_ERROR)
|
2012-04-06 06:47:53 +08:00
|
|
|
free_token(token);
|
|
|
|
|
|
|
|
return args;
|
|
|
|
}
|
|
|
|
|
2018-11-30 23:44:07 +08:00
|
|
|
static int event_read_print(struct tep_event *event)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
2018-09-20 02:56:47 +08:00
|
|
|
enum tep_event_type type;
|
2012-04-06 06:47:53 +08:00
|
|
|
char *token;
|
|
|
|
int ret;
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
if (read_expected_item(TEP_EVENT_ITEM, "print") < 0)
|
2012-04-06 06:47:53 +08:00
|
|
|
return -1;
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
if (read_expected(TEP_EVENT_ITEM, "fmt") < 0)
|
2012-04-06 06:47:53 +08:00
|
|
|
return -1;
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
if (read_expected(TEP_EVENT_OP, ":") < 0)
|
2012-04-06 06:47:53 +08:00
|
|
|
return -1;
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
if (read_expect_type(TEP_EVENT_DQUOTE, &token) < 0)
|
2012-04-06 06:47:53 +08:00
|
|
|
goto fail;
|
|
|
|
|
|
|
|
concat:
|
|
|
|
event->print_fmt.format = token;
|
|
|
|
event->print_fmt.args = NULL;
|
|
|
|
|
|
|
|
/* ok to have no arg */
|
|
|
|
type = read_token_item(&token);
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
if (type == TEP_EVENT_NONE)
|
2012-04-06 06:47:53 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Handle concatenation of print lines */
|
2018-09-20 02:56:47 +08:00
|
|
|
if (type == TEP_EVENT_DQUOTE) {
|
2012-04-06 06:47:53 +08:00
|
|
|
char *cat;
|
|
|
|
|
2012-09-13 02:39:59 +08:00
|
|
|
if (asprintf(&cat, "%s%s", event->print_fmt.format, token) < 0)
|
|
|
|
goto fail;
|
2012-04-06 06:47:53 +08:00
|
|
|
free_token(token);
|
|
|
|
free_token(event->print_fmt.format);
|
|
|
|
event->print_fmt.format = NULL;
|
|
|
|
token = cat;
|
|
|
|
goto concat;
|
|
|
|
}
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
if (test_type_token(type, token, TEP_EVENT_DELIM, ","))
|
2012-04-06 06:47:53 +08:00
|
|
|
goto fail;
|
|
|
|
|
|
|
|
free_token(token);
|
|
|
|
|
|
|
|
ret = event_read_print_args(event, &event->print_fmt.args);
|
|
|
|
if (ret < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
free_token(token);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-09 02:02:50 +08:00
|
|
|
* tep_find_common_field - return a common field by event
|
2012-04-06 06:47:53 +08:00
|
|
|
* @event: handle for the event
|
|
|
|
* @name: the name of the common field to return
|
|
|
|
*
|
|
|
|
* Returns a common field from the event by the given @name.
|
2018-12-03 18:22:00 +08:00
|
|
|
* This only searches the common fields and not all field.
|
2012-04-06 06:47:53 +08:00
|
|
|
*/
|
2018-09-20 02:56:45 +08:00
|
|
|
struct tep_format_field *
|
2018-11-30 23:44:07 +08:00
|
|
|
tep_find_common_field(struct tep_event *event, const char *name)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
2018-09-20 02:56:45 +08:00
|
|
|
struct tep_format_field *format;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
for (format = event->format.common_fields;
|
|
|
|
format; format = format->next) {
|
|
|
|
if (strcmp(format->name, name) == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return format;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-09 02:02:50 +08:00
|
|
|
* tep_find_field - find a non-common field
|
2012-04-06 06:47:53 +08:00
|
|
|
* @event: handle for the event
|
|
|
|
* @name: the name of the non-common field
|
|
|
|
*
|
|
|
|
* Returns a non-common field by the given @name.
|
|
|
|
* This does not search common fields.
|
|
|
|
*/
|
2018-09-20 02:56:45 +08:00
|
|
|
struct tep_format_field *
|
2018-11-30 23:44:07 +08:00
|
|
|
tep_find_field(struct tep_event *event, const char *name)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
2018-09-20 02:56:45 +08:00
|
|
|
struct tep_format_field *format;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
for (format = event->format.fields;
|
|
|
|
format; format = format->next) {
|
|
|
|
if (strcmp(format->name, name) == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return format;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-09 02:02:50 +08:00
|
|
|
* tep_find_any_field - find any field by name
|
2012-04-06 06:47:53 +08:00
|
|
|
* @event: handle for the event
|
|
|
|
* @name: the name of the field
|
|
|
|
*
|
|
|
|
* Returns a field by the given @name.
|
2018-12-03 18:22:00 +08:00
|
|
|
* This searches the common field names first, then
|
2012-04-06 06:47:53 +08:00
|
|
|
* the non-common ones if a common one was not found.
|
|
|
|
*/
|
2018-09-20 02:56:45 +08:00
|
|
|
struct tep_format_field *
|
2018-11-30 23:44:07 +08:00
|
|
|
tep_find_any_field(struct tep_event *event, const char *name)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
2018-09-20 02:56:45 +08:00
|
|
|
struct tep_format_field *format;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2018-08-09 02:02:50 +08:00
|
|
|
format = tep_find_common_field(event, name);
|
2012-04-06 06:47:53 +08:00
|
|
|
if (format)
|
|
|
|
return format;
|
2018-08-09 02:02:50 +08:00
|
|
|
return tep_find_field(event, name);
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-09 02:02:53 +08:00
|
|
|
* tep_read_number - read a number from data
|
2019-04-02 00:43:17 +08:00
|
|
|
* @tep: a handle to the trace event parser context
|
2012-04-06 06:47:53 +08:00
|
|
|
* @ptr: the raw data
|
|
|
|
* @size: the size of the data that holds the number
|
|
|
|
*
|
|
|
|
* Returns the number (converted to host) from the
|
|
|
|
* raw data.
|
|
|
|
*/
|
2019-04-02 00:43:17 +08:00
|
|
|
unsigned long long tep_read_number(struct tep_handle *tep,
|
2018-08-09 02:02:53 +08:00
|
|
|
const void *ptr, int size)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
2018-11-30 23:44:10 +08:00
|
|
|
unsigned long long val;
|
|
|
|
|
2012-04-06 06:47:53 +08:00
|
|
|
switch (size) {
|
|
|
|
case 1:
|
|
|
|
return *(unsigned char *)ptr;
|
|
|
|
case 2:
|
2020-09-30 19:07:33 +08:00
|
|
|
return data2host2(tep, *(unsigned short *)ptr);
|
2012-04-06 06:47:53 +08:00
|
|
|
case 4:
|
2020-09-30 19:07:33 +08:00
|
|
|
return data2host4(tep, *(unsigned int *)ptr);
|
2012-04-06 06:47:53 +08:00
|
|
|
case 8:
|
2018-11-30 23:44:10 +08:00
|
|
|
memcpy(&val, (ptr), sizeof(unsigned long long));
|
2020-09-30 19:07:33 +08:00
|
|
|
return data2host8(tep, val);
|
2012-04-06 06:47:53 +08:00
|
|
|
default:
|
|
|
|
/* BUG! */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-09 02:02:53 +08:00
|
|
|
* tep_read_number_field - read a number from data
|
2012-04-06 06:47:53 +08:00
|
|
|
* @field: a handle to the field
|
|
|
|
* @data: the raw data to read
|
|
|
|
* @value: the value to place the number in
|
|
|
|
*
|
|
|
|
* Reads raw data according to a field offset and size,
|
|
|
|
* and translates it into @value.
|
|
|
|
*
|
|
|
|
* Returns 0 on success, -1 otherwise.
|
|
|
|
*/
|
2018-09-20 02:56:45 +08:00
|
|
|
int tep_read_number_field(struct tep_format_field *field, const void *data,
|
2018-08-09 02:02:53 +08:00
|
|
|
unsigned long long *value)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
|
|
|
if (!field)
|
|
|
|
return -1;
|
|
|
|
switch (field->size) {
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
case 4:
|
|
|
|
case 8:
|
2019-04-02 00:43:18 +08:00
|
|
|
*value = tep_read_number(field->event->tep,
|
2018-08-09 02:02:53 +08:00
|
|
|
data + field->offset, field->size);
|
2012-04-06 06:47:53 +08:00
|
|
|
return 0;
|
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-02 00:43:20 +08:00
|
|
|
static int get_common_info(struct tep_handle *tep,
|
2012-04-06 06:47:53 +08:00
|
|
|
const char *type, int *offset, int *size)
|
|
|
|
{
|
2018-11-30 23:44:07 +08:00
|
|
|
struct tep_event *event;
|
2018-09-20 02:56:45 +08:00
|
|
|
struct tep_format_field *field;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* All events should have the same common elements.
|
|
|
|
* Pick any event to find where the type is;
|
|
|
|
*/
|
2019-04-02 00:43:20 +08:00
|
|
|
if (!tep->events) {
|
2012-09-13 04:30:50 +08:00
|
|
|
do_warning("no event_list!");
|
|
|
|
return -1;
|
|
|
|
}
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2019-04-02 00:43:20 +08:00
|
|
|
event = tep->events[0];
|
2018-08-09 02:02:50 +08:00
|
|
|
field = tep_find_common_field(event, type);
|
2012-04-06 06:47:53 +08:00
|
|
|
if (!field)
|
2012-05-22 13:52:40 +08:00
|
|
|
return -1;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
*offset = field->offset;
|
|
|
|
*size = field->size;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-04-02 00:43:20 +08:00
|
|
|
static int __parse_common(struct tep_handle *tep, void *data,
|
2012-04-06 06:47:53 +08:00
|
|
|
int *size, int *offset, const char *name)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!*size) {
|
2019-04-02 00:43:20 +08:00
|
|
|
ret = get_common_info(tep, name, offset, size);
|
2012-04-06 06:47:53 +08:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
}
|
2019-04-02 00:43:20 +08:00
|
|
|
return tep_read_number(tep, data + *offset, *size);
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
|
2019-04-02 00:43:20 +08:00
|
|
|
static int trace_parse_common_type(struct tep_handle *tep, void *data)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
2019-04-02 00:43:20 +08:00
|
|
|
return __parse_common(tep, data,
|
|
|
|
&tep->type_size, &tep->type_offset,
|
2012-04-06 06:47:53 +08:00
|
|
|
"common_type");
|
|
|
|
}
|
|
|
|
|
2019-04-02 00:43:20 +08:00
|
|
|
static int parse_common_pid(struct tep_handle *tep, void *data)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
2019-04-02 00:43:20 +08:00
|
|
|
return __parse_common(tep, data,
|
|
|
|
&tep->pid_size, &tep->pid_offset,
|
2012-04-06 06:47:53 +08:00
|
|
|
"common_pid");
|
|
|
|
}
|
|
|
|
|
2019-04-02 00:43:20 +08:00
|
|
|
static int parse_common_pc(struct tep_handle *tep, void *data)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
2019-04-02 00:43:20 +08:00
|
|
|
return __parse_common(tep, data,
|
|
|
|
&tep->pc_size, &tep->pc_offset,
|
2012-04-06 06:47:53 +08:00
|
|
|
"common_preempt_count");
|
|
|
|
}
|
|
|
|
|
2019-04-02 00:43:20 +08:00
|
|
|
static int parse_common_flags(struct tep_handle *tep, void *data)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
2019-04-02 00:43:20 +08:00
|
|
|
return __parse_common(tep, data,
|
|
|
|
&tep->flags_size, &tep->flags_offset,
|
2012-04-06 06:47:53 +08:00
|
|
|
"common_flags");
|
|
|
|
}
|
|
|
|
|
2019-04-02 00:43:20 +08:00
|
|
|
static int parse_common_lock_depth(struct tep_handle *tep, void *data)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
2019-04-02 00:43:20 +08:00
|
|
|
return __parse_common(tep, data,
|
|
|
|
&tep->ld_size, &tep->ld_offset,
|
2012-05-22 13:52:40 +08:00
|
|
|
"common_lock_depth");
|
|
|
|
}
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2019-04-02 00:43:20 +08:00
|
|
|
static int parse_common_migrate_disable(struct tep_handle *tep, void *data)
|
2012-05-22 13:52:40 +08:00
|
|
|
{
|
2019-04-02 00:43:20 +08:00
|
|
|
return __parse_common(tep, data,
|
|
|
|
&tep->ld_size, &tep->ld_offset,
|
2012-05-22 13:52:40 +08:00
|
|
|
"common_migrate_disable");
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int events_id_cmp(const void *a, const void *b);
|
|
|
|
|
|
|
|
/**
|
2018-08-09 02:02:50 +08:00
|
|
|
* tep_find_event - find an event by given id
|
2019-04-02 00:43:17 +08:00
|
|
|
* @tep: a handle to the trace event parser context
|
2012-04-06 06:47:53 +08:00
|
|
|
* @id: the id of the event
|
|
|
|
*
|
|
|
|
* Returns an event that has a given @id.
|
|
|
|
*/
|
2019-04-02 00:43:17 +08:00
|
|
|
struct tep_event *tep_find_event(struct tep_handle *tep, int id)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
2018-11-30 23:44:07 +08:00
|
|
|
struct tep_event **eventptr;
|
|
|
|
struct tep_event key;
|
|
|
|
struct tep_event *pkey = &key;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
/* Check cache first */
|
2019-04-02 00:43:17 +08:00
|
|
|
if (tep->last_event && tep->last_event->id == id)
|
|
|
|
return tep->last_event;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
key.id = id;
|
|
|
|
|
2019-04-02 00:43:17 +08:00
|
|
|
eventptr = bsearch(&pkey, tep->events, tep->nr_events,
|
|
|
|
sizeof(*tep->events), events_id_cmp);
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
if (eventptr) {
|
2019-04-02 00:43:17 +08:00
|
|
|
tep->last_event = *eventptr;
|
2012-04-06 06:47:53 +08:00
|
|
|
return *eventptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-09 02:03:05 +08:00
|
|
|
* tep_find_event_by_name - find an event by given name
|
2019-04-02 00:43:17 +08:00
|
|
|
* @tep: a handle to the trace event parser context
|
2012-04-06 06:47:53 +08:00
|
|
|
* @sys: the system name to search for
|
|
|
|
* @name: the name of the event to search for
|
|
|
|
*
|
|
|
|
* This returns an event with a given @name and under the system
|
|
|
|
* @sys. If @sys is NULL the first event with @name is returned.
|
|
|
|
*/
|
2018-11-30 23:44:07 +08:00
|
|
|
struct tep_event *
|
2019-04-02 00:43:17 +08:00
|
|
|
tep_find_event_by_name(struct tep_handle *tep,
|
2018-08-09 02:03:05 +08:00
|
|
|
const char *sys, const char *name)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
2018-11-30 23:44:07 +08:00
|
|
|
struct tep_event *event = NULL;
|
2012-04-06 06:47:53 +08:00
|
|
|
int i;
|
|
|
|
|
2019-04-02 00:43:17 +08:00
|
|
|
if (tep->last_event &&
|
|
|
|
strcmp(tep->last_event->name, name) == 0 &&
|
|
|
|
(!sys || strcmp(tep->last_event->system, sys) == 0))
|
|
|
|
return tep->last_event;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2019-04-02 00:43:17 +08:00
|
|
|
for (i = 0; i < tep->nr_events; i++) {
|
|
|
|
event = tep->events[i];
|
2012-04-06 06:47:53 +08:00
|
|
|
if (strcmp(event->name, name) == 0) {
|
|
|
|
if (!sys)
|
|
|
|
break;
|
|
|
|
if (strcmp(event->system, sys) == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-04-02 00:43:17 +08:00
|
|
|
if (i == tep->nr_events)
|
2012-04-06 06:47:53 +08:00
|
|
|
event = NULL;
|
|
|
|
|
2019-04-02 00:43:17 +08:00
|
|
|
tep->last_event = event;
|
2012-04-06 06:47:53 +08:00
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned long long
|
2018-11-30 23:44:07 +08:00
|
|
|
eval_num_arg(void *data, int size, struct tep_event *event, struct tep_print_arg *arg)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
2019-04-02 00:43:20 +08:00
|
|
|
struct tep_handle *tep = event->tep;
|
2012-04-06 06:47:53 +08:00
|
|
|
unsigned long long val = 0;
|
|
|
|
unsigned long long left, right;
|
2018-09-20 02:56:49 +08:00
|
|
|
struct tep_print_arg *typearg = NULL;
|
|
|
|
struct tep_print_arg *larg;
|
2012-04-06 06:47:53 +08:00
|
|
|
unsigned long offset;
|
|
|
|
unsigned int field_size;
|
|
|
|
|
|
|
|
switch (arg->type) {
|
2018-09-20 02:56:50 +08:00
|
|
|
case TEP_PRINT_NULL:
|
2012-04-06 06:47:53 +08:00
|
|
|
/* ?? */
|
|
|
|
return 0;
|
2018-09-20 02:56:50 +08:00
|
|
|
case TEP_PRINT_ATOM:
|
2012-04-06 06:47:53 +08:00
|
|
|
return strtoull(arg->atom.atom, NULL, 0);
|
2018-09-20 02:56:50 +08:00
|
|
|
case TEP_PRINT_FIELD:
|
2012-04-06 06:47:53 +08:00
|
|
|
if (!arg->field.field) {
|
2018-08-09 02:02:50 +08:00
|
|
|
arg->field.field = tep_find_any_field(event, arg->field.name);
|
2012-04-06 06:47:53 +08:00
|
|
|
if (!arg->field.field)
|
2012-09-13 04:30:50 +08:00
|
|
|
goto out_warning_field;
|
|
|
|
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
/* must be a number */
|
2019-04-02 00:43:20 +08:00
|
|
|
val = tep_read_number(tep, data + arg->field.field->offset,
|
2018-08-09 02:02:53 +08:00
|
|
|
arg->field.field->size);
|
2012-04-06 06:47:53 +08:00
|
|
|
break;
|
2018-09-20 02:56:50 +08:00
|
|
|
case TEP_PRINT_FLAGS:
|
|
|
|
case TEP_PRINT_SYMBOL:
|
|
|
|
case TEP_PRINT_INT_ARRAY:
|
|
|
|
case TEP_PRINT_HEX:
|
|
|
|
case TEP_PRINT_HEX_STR:
|
2012-04-06 06:47:53 +08:00
|
|
|
break;
|
2018-09-20 02:56:50 +08:00
|
|
|
case TEP_PRINT_TYPE:
|
2012-04-06 06:47:53 +08:00
|
|
|
val = eval_num_arg(data, size, event, arg->typecast.item);
|
|
|
|
return eval_type(val, arg, 0);
|
2018-09-20 02:56:50 +08:00
|
|
|
case TEP_PRINT_STRING:
|
|
|
|
case TEP_PRINT_BSTRING:
|
|
|
|
case TEP_PRINT_BITMASK:
|
2012-04-06 06:47:53 +08:00
|
|
|
return 0;
|
2018-09-20 02:56:50 +08:00
|
|
|
case TEP_PRINT_FUNC: {
|
2012-04-06 06:47:53 +08:00
|
|
|
struct trace_seq s;
|
|
|
|
trace_seq_init(&s);
|
|
|
|
val = process_defined_func(&s, data, size, event, arg);
|
|
|
|
trace_seq_destroy(&s);
|
|
|
|
return val;
|
|
|
|
}
|
2018-09-20 02:56:50 +08:00
|
|
|
case TEP_PRINT_OP:
|
2012-04-06 06:47:53 +08:00
|
|
|
if (strcmp(arg->op.op, "[") == 0) {
|
|
|
|
/*
|
|
|
|
* Arrays are special, since we don't want
|
|
|
|
* to read the arg as is.
|
|
|
|
*/
|
|
|
|
right = eval_num_arg(data, size, event, arg->op.right);
|
|
|
|
|
|
|
|
/* handle typecasts */
|
|
|
|
larg = arg->op.left;
|
2018-09-20 02:56:50 +08:00
|
|
|
while (larg->type == TEP_PRINT_TYPE) {
|
2012-04-06 06:47:53 +08:00
|
|
|
if (!typearg)
|
|
|
|
typearg = larg;
|
|
|
|
larg = larg->typecast.item;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Default to long size */
|
2019-04-02 00:43:20 +08:00
|
|
|
field_size = tep->long_size;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
switch (larg->type) {
|
2018-09-20 02:56:50 +08:00
|
|
|
case TEP_PRINT_DYNAMIC_ARRAY:
|
2019-04-02 00:43:20 +08:00
|
|
|
offset = tep_read_number(tep,
|
2012-04-06 06:47:53 +08:00
|
|
|
data + larg->dynarray.field->offset,
|
|
|
|
larg->dynarray.field->size);
|
|
|
|
if (larg->dynarray.field->elementsize)
|
|
|
|
field_size = larg->dynarray.field->elementsize;
|
|
|
|
/*
|
|
|
|
* The actual length of the dynamic array is stored
|
|
|
|
* in the top half of the field, and the offset
|
|
|
|
* is in the bottom half of the 32 bit field.
|
|
|
|
*/
|
|
|
|
offset &= 0xffff;
|
|
|
|
offset += right;
|
|
|
|
break;
|
2018-09-20 02:56:50 +08:00
|
|
|
case TEP_PRINT_FIELD:
|
2012-04-06 06:47:53 +08:00
|
|
|
if (!larg->field.field) {
|
|
|
|
larg->field.field =
|
2018-08-09 02:02:50 +08:00
|
|
|
tep_find_any_field(event, larg->field.name);
|
2012-09-13 04:30:50 +08:00
|
|
|
if (!larg->field.field) {
|
|
|
|
arg = larg;
|
|
|
|
goto out_warning_field;
|
|
|
|
}
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
field_size = larg->field.field->elementsize;
|
|
|
|
offset = larg->field.field->offset +
|
|
|
|
right * larg->field.field->elementsize;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto default_op; /* oops, all bets off */
|
|
|
|
}
|
2019-04-02 00:43:20 +08:00
|
|
|
val = tep_read_number(tep,
|
2018-08-09 02:02:53 +08:00
|
|
|
data + offset, field_size);
|
2012-04-06 06:47:53 +08:00
|
|
|
if (typearg)
|
|
|
|
val = eval_type(val, typearg, 1);
|
|
|
|
break;
|
|
|
|
} else if (strcmp(arg->op.op, "?") == 0) {
|
|
|
|
left = eval_num_arg(data, size, event, arg->op.left);
|
|
|
|
arg = arg->op.right;
|
|
|
|
if (left)
|
|
|
|
val = eval_num_arg(data, size, event, arg->op.left);
|
|
|
|
else
|
|
|
|
val = eval_num_arg(data, size, event, arg->op.right);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default_op:
|
|
|
|
left = eval_num_arg(data, size, event, arg->op.left);
|
|
|
|
right = eval_num_arg(data, size, event, arg->op.right);
|
|
|
|
switch (arg->op.op[0]) {
|
|
|
|
case '!':
|
|
|
|
switch (arg->op.op[1]) {
|
|
|
|
case 0:
|
|
|
|
val = !right;
|
|
|
|
break;
|
|
|
|
case '=':
|
|
|
|
val = left != right;
|
|
|
|
break;
|
|
|
|
default:
|
2012-09-13 04:30:50 +08:00
|
|
|
goto out_warning_op;
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '~':
|
|
|
|
val = ~right;
|
|
|
|
break;
|
|
|
|
case '|':
|
|
|
|
if (arg->op.op[1])
|
|
|
|
val = left || right;
|
|
|
|
else
|
|
|
|
val = left | right;
|
|
|
|
break;
|
|
|
|
case '&':
|
|
|
|
if (arg->op.op[1])
|
|
|
|
val = left && right;
|
|
|
|
else
|
|
|
|
val = left & right;
|
|
|
|
break;
|
|
|
|
case '<':
|
|
|
|
switch (arg->op.op[1]) {
|
|
|
|
case 0:
|
|
|
|
val = left < right;
|
|
|
|
break;
|
|
|
|
case '<':
|
|
|
|
val = left << right;
|
|
|
|
break;
|
|
|
|
case '=':
|
|
|
|
val = left <= right;
|
|
|
|
break;
|
|
|
|
default:
|
2012-09-13 04:30:50 +08:00
|
|
|
goto out_warning_op;
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '>':
|
|
|
|
switch (arg->op.op[1]) {
|
|
|
|
case 0:
|
|
|
|
val = left > right;
|
|
|
|
break;
|
|
|
|
case '>':
|
|
|
|
val = left >> right;
|
|
|
|
break;
|
|
|
|
case '=':
|
|
|
|
val = left >= right;
|
|
|
|
break;
|
|
|
|
default:
|
2012-09-13 04:30:50 +08:00
|
|
|
goto out_warning_op;
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '=':
|
|
|
|
if (arg->op.op[1] != '=')
|
2012-09-13 04:30:50 +08:00
|
|
|
goto out_warning_op;
|
|
|
|
|
2012-04-06 06:47:53 +08:00
|
|
|
val = left == right;
|
|
|
|
break;
|
|
|
|
case '-':
|
|
|
|
val = left - right;
|
|
|
|
break;
|
|
|
|
case '+':
|
|
|
|
val = left + right;
|
|
|
|
break;
|
2012-04-06 06:48:04 +08:00
|
|
|
case '/':
|
|
|
|
val = left / right;
|
|
|
|
break;
|
2016-02-23 01:08:22 +08:00
|
|
|
case '%':
|
|
|
|
val = left % right;
|
|
|
|
break;
|
2012-04-06 06:48:04 +08:00
|
|
|
case '*':
|
|
|
|
val = left * right;
|
|
|
|
break;
|
2012-04-06 06:47:53 +08:00
|
|
|
default:
|
2012-09-13 04:30:50 +08:00
|
|
|
goto out_warning_op;
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
break;
|
2018-09-20 02:56:50 +08:00
|
|
|
case TEP_PRINT_DYNAMIC_ARRAY_LEN:
|
2019-04-02 00:43:20 +08:00
|
|
|
offset = tep_read_number(tep,
|
2018-08-09 02:02:53 +08:00
|
|
|
data + arg->dynarray.field->offset,
|
|
|
|
arg->dynarray.field->size);
|
2015-08-29 12:22:05 +08:00
|
|
|
/*
|
|
|
|
* The total allocated length of the dynamic array is
|
|
|
|
* stored in the top half of the field, and the offset
|
|
|
|
* is in the bottom half of the 32 bit field.
|
|
|
|
*/
|
|
|
|
val = (unsigned long long)(offset >> 16);
|
|
|
|
break;
|
2018-09-20 02:56:50 +08:00
|
|
|
case TEP_PRINT_DYNAMIC_ARRAY:
|
2013-11-12 05:08:10 +08:00
|
|
|
/* Without [], we pass the address to the dynamic data */
|
2019-04-02 00:43:20 +08:00
|
|
|
offset = tep_read_number(tep,
|
2018-08-09 02:02:53 +08:00
|
|
|
data + arg->dynarray.field->offset,
|
|
|
|
arg->dynarray.field->size);
|
2013-11-12 05:08:10 +08:00
|
|
|
/*
|
2015-08-29 12:22:05 +08:00
|
|
|
* The total allocated length of the dynamic array is
|
|
|
|
* stored in the top half of the field, and the offset
|
2013-11-12 05:08:10 +08:00
|
|
|
* is in the bottom half of the 32 bit field.
|
|
|
|
*/
|
|
|
|
offset &= 0xffff;
|
2013-11-20 03:14:51 +08:00
|
|
|
val = (unsigned long long)((unsigned long)data + offset);
|
2013-11-12 05:08:10 +08:00
|
|
|
break;
|
2012-04-06 06:47:53 +08:00
|
|
|
default: /* not sure what to do there */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return val;
|
2012-09-13 04:30:50 +08:00
|
|
|
|
|
|
|
out_warning_op:
|
2014-03-19 09:22:53 +08:00
|
|
|
do_warning_event(event, "%s: unknown op '%s'", __func__, arg->op.op);
|
2012-09-13 04:30:50 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
out_warning_field:
|
2014-03-19 09:22:53 +08:00
|
|
|
do_warning_event(event, "%s: field %s not found",
|
|
|
|
__func__, arg->field.name);
|
2012-09-13 04:30:50 +08:00
|
|
|
return 0;
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
struct flag {
|
|
|
|
const char *name;
|
|
|
|
unsigned long long value;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct flag flags[] = {
|
|
|
|
{ "HI_SOFTIRQ", 0 },
|
|
|
|
{ "TIMER_SOFTIRQ", 1 },
|
|
|
|
{ "NET_TX_SOFTIRQ", 2 },
|
|
|
|
{ "NET_RX_SOFTIRQ", 3 },
|
|
|
|
{ "BLOCK_SOFTIRQ", 4 },
|
2015-11-10 21:56:14 +08:00
|
|
|
{ "IRQ_POLL_SOFTIRQ", 5 },
|
2012-04-06 06:47:53 +08:00
|
|
|
{ "TASKLET_SOFTIRQ", 6 },
|
|
|
|
{ "SCHED_SOFTIRQ", 7 },
|
|
|
|
{ "HRTIMER_SOFTIRQ", 8 },
|
|
|
|
{ "RCU_SOFTIRQ", 9 },
|
|
|
|
|
|
|
|
{ "HRTIMER_NORESTART", 0 },
|
|
|
|
{ "HRTIMER_RESTART", 1 },
|
|
|
|
};
|
|
|
|
|
tools lib traceevent: Zero should not be considered "not found" in eval_flag()
Guilherme Cox found that:
There is, however, a potential bug if there is an item with code zero
that is not the first one in the symbol list, since eval_flag(..)
returns 0 when it doesn't find anything.
That is, if you have the following enums:
enum {
FOO_START = 0,
FOO_GO = 1,
FOO_END = 2
}
and then have:
__print_symbolic(foo, FOO_GO, "go", FOO_START, "start",
FOO_END, "end")
If none of the enums are known to pevent, then eval_flag() will return
zero, and it will match it to the first item in the list, which would be
FOO_GO, which is not zero.
Luckily, in most cases, the first element would be zero, and the parsing
would match out of sheer luck.
Reported-by: Guilherme Cox <cox@computer.org>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: http://lkml.kernel.org/r/20150324145813.0bfe95ba@gandalf.local.home
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2015-03-25 02:58:13 +08:00
|
|
|
static long long eval_flag(const char *flag)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Some flags in the format files do not get converted.
|
|
|
|
* If the flag is not numeric, see if it is something that
|
|
|
|
* we already know about.
|
|
|
|
*/
|
|
|
|
if (isdigit(flag[0]))
|
|
|
|
return strtoull(flag, NULL, 0);
|
|
|
|
|
|
|
|
for (i = 0; i < (int)(sizeof(flags)/sizeof(flags[0])); i++)
|
|
|
|
if (strcmp(flags[i].name, flag) == 0)
|
|
|
|
return flags[i].value;
|
|
|
|
|
tools lib traceevent: Zero should not be considered "not found" in eval_flag()
Guilherme Cox found that:
There is, however, a potential bug if there is an item with code zero
that is not the first one in the symbol list, since eval_flag(..)
returns 0 when it doesn't find anything.
That is, if you have the following enums:
enum {
FOO_START = 0,
FOO_GO = 1,
FOO_END = 2
}
and then have:
__print_symbolic(foo, FOO_GO, "go", FOO_START, "start",
FOO_END, "end")
If none of the enums are known to pevent, then eval_flag() will return
zero, and it will match it to the first item in the list, which would be
FOO_GO, which is not zero.
Luckily, in most cases, the first element would be zero, and the parsing
would match out of sheer luck.
Reported-by: Guilherme Cox <cox@computer.org>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: http://lkml.kernel.org/r/20150324145813.0bfe95ba@gandalf.local.home
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2015-03-25 02:58:13 +08:00
|
|
|
return -1LL;
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void print_str_to_seq(struct trace_seq *s, const char *format,
|
|
|
|
int len_arg, const char *str)
|
|
|
|
{
|
|
|
|
if (len_arg >= 0)
|
|
|
|
trace_seq_printf(s, format, len_arg, str);
|
|
|
|
else
|
|
|
|
trace_seq_printf(s, format, str);
|
|
|
|
}
|
|
|
|
|
2019-04-02 00:43:20 +08:00
|
|
|
static void print_bitmask_to_seq(struct tep_handle *tep,
|
2014-06-03 11:20:16 +08:00
|
|
|
struct trace_seq *s, const char *format,
|
|
|
|
int len_arg, const void *data, int size)
|
|
|
|
{
|
|
|
|
int nr_bits = size * 8;
|
|
|
|
int str_size = (nr_bits + 3) / 4;
|
|
|
|
int len = 0;
|
|
|
|
char buf[3];
|
|
|
|
char *str;
|
|
|
|
int index;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The kernel likes to put in commas every 32 bits, we
|
|
|
|
* can do the same.
|
|
|
|
*/
|
|
|
|
str_size += (nr_bits - 1) / 32;
|
|
|
|
|
|
|
|
str = malloc(str_size + 1);
|
|
|
|
if (!str) {
|
|
|
|
do_warning("%s: not enough memory!", __func__);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
str[str_size] = 0;
|
|
|
|
|
|
|
|
/* Start out with -2 for the two chars per byte */
|
|
|
|
for (i = str_size - 2; i >= 0; i -= 2) {
|
|
|
|
/*
|
|
|
|
* data points to a bit mask of size bytes.
|
|
|
|
* In the kernel, this is an array of long words, thus
|
2018-12-03 18:22:00 +08:00
|
|
|
* endianness is very important.
|
2014-06-03 11:20:16 +08:00
|
|
|
*/
|
2019-04-02 00:43:20 +08:00
|
|
|
if (tep->file_bigendian)
|
2014-06-03 11:20:16 +08:00
|
|
|
index = size - (len + 1);
|
|
|
|
else
|
|
|
|
index = len;
|
|
|
|
|
|
|
|
snprintf(buf, 3, "%02x", *((unsigned char *)data + index));
|
|
|
|
memcpy(str + i, buf, 2);
|
|
|
|
len++;
|
|
|
|
if (!(len & 3) && i > 0) {
|
|
|
|
i--;
|
|
|
|
str[i] = ',';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (len_arg >= 0)
|
|
|
|
trace_seq_printf(s, format, len_arg, str);
|
|
|
|
else
|
|
|
|
trace_seq_printf(s, format, str);
|
|
|
|
|
|
|
|
free(str);
|
|
|
|
}
|
|
|
|
|
2012-04-06 06:47:53 +08:00
|
|
|
static void print_str_arg(struct trace_seq *s, void *data, int size,
|
2018-11-30 23:44:07 +08:00
|
|
|
struct tep_event *event, const char *format,
|
2018-09-20 02:56:49 +08:00
|
|
|
int len_arg, struct tep_print_arg *arg)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
2019-04-02 00:43:20 +08:00
|
|
|
struct tep_handle *tep = event->tep;
|
2018-09-20 02:56:49 +08:00
|
|
|
struct tep_print_flag_sym *flag;
|
2018-09-20 02:56:45 +08:00
|
|
|
struct tep_format_field *field;
|
2013-11-02 05:53:55 +08:00
|
|
|
struct printk_map *printk;
|
tools lib traceevent: Zero should not be considered "not found" in eval_flag()
Guilherme Cox found that:
There is, however, a potential bug if there is an item with code zero
that is not the first one in the symbol list, since eval_flag(..)
returns 0 when it doesn't find anything.
That is, if you have the following enums:
enum {
FOO_START = 0,
FOO_GO = 1,
FOO_END = 2
}
and then have:
__print_symbolic(foo, FOO_GO, "go", FOO_START, "start",
FOO_END, "end")
If none of the enums are known to pevent, then eval_flag() will return
zero, and it will match it to the first item in the list, which would be
FOO_GO, which is not zero.
Luckily, in most cases, the first element would be zero, and the parsing
would match out of sheer luck.
Reported-by: Guilherme Cox <cox@computer.org>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: http://lkml.kernel.org/r/20150324145813.0bfe95ba@gandalf.local.home
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2015-03-25 02:58:13 +08:00
|
|
|
long long val, fval;
|
2015-09-22 21:22:03 +08:00
|
|
|
unsigned long long addr;
|
2012-04-06 06:47:53 +08:00
|
|
|
char *str;
|
2012-06-27 08:41:41 +08:00
|
|
|
unsigned char *hex;
|
2012-04-06 06:47:53 +08:00
|
|
|
int print;
|
2012-06-27 08:41:41 +08:00
|
|
|
int i, len;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
switch (arg->type) {
|
2018-09-20 02:56:50 +08:00
|
|
|
case TEP_PRINT_NULL:
|
2012-04-06 06:47:53 +08:00
|
|
|
/* ?? */
|
|
|
|
return;
|
2018-09-20 02:56:50 +08:00
|
|
|
case TEP_PRINT_ATOM:
|
2012-04-06 06:47:53 +08:00
|
|
|
print_str_to_seq(s, format, len_arg, arg->atom.atom);
|
|
|
|
return;
|
2018-09-20 02:56:50 +08:00
|
|
|
case TEP_PRINT_FIELD:
|
2012-06-27 08:41:40 +08:00
|
|
|
field = arg->field.field;
|
|
|
|
if (!field) {
|
2018-08-09 02:02:50 +08:00
|
|
|
field = tep_find_any_field(event, arg->field.name);
|
2012-09-13 04:30:50 +08:00
|
|
|
if (!field) {
|
|
|
|
str = arg->field.name;
|
|
|
|
goto out_warning_field;
|
|
|
|
}
|
2012-06-27 08:41:40 +08:00
|
|
|
arg->field.field = field;
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
/* Zero sized fields, mean the rest of the data */
|
2012-06-27 08:41:40 +08:00
|
|
|
len = field->size ? : size - field->offset;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Some events pass in pointers. If this is not an array
|
|
|
|
* and the size is the same as long_size, assume that it
|
|
|
|
* is a pointer.
|
|
|
|
*/
|
2018-09-20 02:56:46 +08:00
|
|
|
if (!(field->flags & TEP_FIELD_IS_ARRAY) &&
|
2019-04-02 00:43:20 +08:00
|
|
|
field->size == tep->long_size) {
|
2015-09-22 21:22:03 +08:00
|
|
|
|
|
|
|
/* Handle heterogeneous recording and processing
|
|
|
|
* architectures
|
|
|
|
*
|
|
|
|
* CASE I:
|
|
|
|
* Traces recorded on 32-bit devices (32-bit
|
|
|
|
* addressing) and processed on 64-bit devices:
|
|
|
|
* In this case, only 32 bits should be read.
|
|
|
|
*
|
|
|
|
* CASE II:
|
|
|
|
* Traces recorded on 64 bit devices and processed
|
|
|
|
* on 32-bit devices:
|
|
|
|
* In this case, 64 bits must be read.
|
|
|
|
*/
|
2019-04-02 00:43:20 +08:00
|
|
|
addr = (tep->long_size == 8) ?
|
2015-09-22 21:22:03 +08:00
|
|
|
*(unsigned long long *)(data + field->offset) :
|
|
|
|
(unsigned long long)*(unsigned int *)(data + field->offset);
|
|
|
|
|
2013-11-02 05:53:55 +08:00
|
|
|
/* Check if it matches a print format */
|
2019-04-02 00:43:20 +08:00
|
|
|
printk = find_printk(tep, addr);
|
2013-11-02 05:53:55 +08:00
|
|
|
if (printk)
|
|
|
|
trace_seq_puts(s, printk->printk);
|
|
|
|
else
|
2015-09-22 21:22:03 +08:00
|
|
|
trace_seq_printf(s, "%llx", addr);
|
2012-04-06 06:47:53 +08:00
|
|
|
break;
|
|
|
|
}
|
2012-09-13 04:30:50 +08:00
|
|
|
str = malloc(len + 1);
|
|
|
|
if (!str) {
|
2014-03-19 09:22:53 +08:00
|
|
|
do_warning_event(event, "%s: not enough memory!",
|
|
|
|
__func__);
|
2012-09-13 04:30:50 +08:00
|
|
|
return;
|
|
|
|
}
|
2012-06-27 08:41:40 +08:00
|
|
|
memcpy(str, data + field->offset, len);
|
2012-04-06 06:47:53 +08:00
|
|
|
str[len] = 0;
|
|
|
|
print_str_to_seq(s, format, len_arg, str);
|
|
|
|
free(str);
|
|
|
|
break;
|
2018-09-20 02:56:50 +08:00
|
|
|
case TEP_PRINT_FLAGS:
|
2012-04-06 06:47:53 +08:00
|
|
|
val = eval_num_arg(data, size, event, arg->flags.field);
|
|
|
|
print = 0;
|
|
|
|
for (flag = arg->flags.flags; flag; flag = flag->next) {
|
|
|
|
fval = eval_flag(flag->value);
|
tools lib traceevent: Zero should not be considered "not found" in eval_flag()
Guilherme Cox found that:
There is, however, a potential bug if there is an item with code zero
that is not the first one in the symbol list, since eval_flag(..)
returns 0 when it doesn't find anything.
That is, if you have the following enums:
enum {
FOO_START = 0,
FOO_GO = 1,
FOO_END = 2
}
and then have:
__print_symbolic(foo, FOO_GO, "go", FOO_START, "start",
FOO_END, "end")
If none of the enums are known to pevent, then eval_flag() will return
zero, and it will match it to the first item in the list, which would be
FOO_GO, which is not zero.
Luckily, in most cases, the first element would be zero, and the parsing
would match out of sheer luck.
Reported-by: Guilherme Cox <cox@computer.org>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: http://lkml.kernel.org/r/20150324145813.0bfe95ba@gandalf.local.home
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2015-03-25 02:58:13 +08:00
|
|
|
if (!val && fval < 0) {
|
2012-04-06 06:47:53 +08:00
|
|
|
print_str_to_seq(s, format, len_arg, flag->str);
|
|
|
|
break;
|
|
|
|
}
|
tools lib traceevent: Zero should not be considered "not found" in eval_flag()
Guilherme Cox found that:
There is, however, a potential bug if there is an item with code zero
that is not the first one in the symbol list, since eval_flag(..)
returns 0 when it doesn't find anything.
That is, if you have the following enums:
enum {
FOO_START = 0,
FOO_GO = 1,
FOO_END = 2
}
and then have:
__print_symbolic(foo, FOO_GO, "go", FOO_START, "start",
FOO_END, "end")
If none of the enums are known to pevent, then eval_flag() will return
zero, and it will match it to the first item in the list, which would be
FOO_GO, which is not zero.
Luckily, in most cases, the first element would be zero, and the parsing
would match out of sheer luck.
Reported-by: Guilherme Cox <cox@computer.org>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: http://lkml.kernel.org/r/20150324145813.0bfe95ba@gandalf.local.home
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2015-03-25 02:58:13 +08:00
|
|
|
if (fval > 0 && (val & fval) == fval) {
|
2012-04-06 06:47:53 +08:00
|
|
|
if (print && arg->flags.delim)
|
|
|
|
trace_seq_puts(s, arg->flags.delim);
|
|
|
|
print_str_to_seq(s, format, len_arg, flag->str);
|
|
|
|
print = 1;
|
|
|
|
val &= ~fval;
|
|
|
|
}
|
|
|
|
}
|
2018-01-12 08:47:43 +08:00
|
|
|
if (val) {
|
|
|
|
if (print && arg->flags.delim)
|
|
|
|
trace_seq_puts(s, arg->flags.delim);
|
|
|
|
trace_seq_printf(s, "0x%llx", val);
|
|
|
|
}
|
2012-04-06 06:47:53 +08:00
|
|
|
break;
|
2018-09-20 02:56:50 +08:00
|
|
|
case TEP_PRINT_SYMBOL:
|
2012-04-06 06:47:53 +08:00
|
|
|
val = eval_num_arg(data, size, event, arg->symbol.field);
|
|
|
|
for (flag = arg->symbol.symbols; flag; flag = flag->next) {
|
|
|
|
fval = eval_flag(flag->value);
|
|
|
|
if (val == fval) {
|
|
|
|
print_str_to_seq(s, format, len_arg, flag->str);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-01-12 08:47:44 +08:00
|
|
|
if (!flag)
|
|
|
|
trace_seq_printf(s, "0x%llx", val);
|
2012-04-06 06:47:53 +08:00
|
|
|
break;
|
2018-09-20 02:56:50 +08:00
|
|
|
case TEP_PRINT_HEX:
|
|
|
|
case TEP_PRINT_HEX_STR:
|
|
|
|
if (arg->hex.field->type == TEP_PRINT_DYNAMIC_ARRAY) {
|
2013-11-02 05:53:56 +08:00
|
|
|
unsigned long offset;
|
2019-04-02 00:43:20 +08:00
|
|
|
offset = tep_read_number(tep,
|
2013-11-02 05:53:56 +08:00
|
|
|
data + arg->hex.field->dynarray.field->offset,
|
|
|
|
arg->hex.field->dynarray.field->size);
|
|
|
|
hex = data + (offset & 0xffff);
|
|
|
|
} else {
|
|
|
|
field = arg->hex.field->field.field;
|
|
|
|
if (!field) {
|
|
|
|
str = arg->hex.field->field.name;
|
2018-08-09 02:02:50 +08:00
|
|
|
field = tep_find_any_field(event, str);
|
2013-11-02 05:53:56 +08:00
|
|
|
if (!field)
|
|
|
|
goto out_warning_field;
|
|
|
|
arg->hex.field->field.field = field;
|
|
|
|
}
|
|
|
|
hex = data + field->offset;
|
2012-06-27 08:41:41 +08:00
|
|
|
}
|
|
|
|
len = eval_num_arg(data, size, event, arg->hex.size);
|
|
|
|
for (i = 0; i < len; i++) {
|
2018-09-20 02:56:50 +08:00
|
|
|
if (i && arg->type == TEP_PRINT_HEX)
|
2012-06-27 08:41:41 +08:00
|
|
|
trace_seq_putc(s, ' ');
|
|
|
|
trace_seq_printf(s, "%02x", hex[i]);
|
|
|
|
}
|
|
|
|
break;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2018-09-20 02:56:50 +08:00
|
|
|
case TEP_PRINT_INT_ARRAY: {
|
2015-03-24 19:07:19 +08:00
|
|
|
void *num;
|
|
|
|
int el_size;
|
|
|
|
|
2018-09-20 02:56:50 +08:00
|
|
|
if (arg->int_array.field->type == TEP_PRINT_DYNAMIC_ARRAY) {
|
2015-03-24 19:07:19 +08:00
|
|
|
unsigned long offset;
|
2018-09-20 02:56:45 +08:00
|
|
|
struct tep_format_field *field =
|
2015-03-24 19:07:19 +08:00
|
|
|
arg->int_array.field->dynarray.field;
|
2019-04-02 00:43:20 +08:00
|
|
|
offset = tep_read_number(tep,
|
2018-08-09 02:02:53 +08:00
|
|
|
data + field->offset,
|
|
|
|
field->size);
|
2015-03-24 19:07:19 +08:00
|
|
|
num = data + (offset & 0xffff);
|
|
|
|
} else {
|
|
|
|
field = arg->int_array.field->field.field;
|
|
|
|
if (!field) {
|
|
|
|
str = arg->int_array.field->field.name;
|
2018-08-09 02:02:50 +08:00
|
|
|
field = tep_find_any_field(event, str);
|
2015-03-24 19:07:19 +08:00
|
|
|
if (!field)
|
|
|
|
goto out_warning_field;
|
|
|
|
arg->int_array.field->field.field = field;
|
|
|
|
}
|
|
|
|
num = data + field->offset;
|
|
|
|
}
|
|
|
|
len = eval_num_arg(data, size, event, arg->int_array.count);
|
|
|
|
el_size = eval_num_arg(data, size, event,
|
|
|
|
arg->int_array.el_size);
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
if (i)
|
|
|
|
trace_seq_putc(s, ' ');
|
|
|
|
|
|
|
|
if (el_size == 1) {
|
|
|
|
trace_seq_printf(s, "%u", *(uint8_t *)num);
|
|
|
|
} else if (el_size == 2) {
|
|
|
|
trace_seq_printf(s, "%u", *(uint16_t *)num);
|
|
|
|
} else if (el_size == 4) {
|
|
|
|
trace_seq_printf(s, "%u", *(uint32_t *)num);
|
|
|
|
} else if (el_size == 8) {
|
2015-04-24 09:45:16 +08:00
|
|
|
trace_seq_printf(s, "%"PRIu64, *(uint64_t *)num);
|
2015-03-24 19:07:19 +08:00
|
|
|
} else {
|
|
|
|
trace_seq_printf(s, "BAD SIZE:%d 0x%x",
|
|
|
|
el_size, *(uint8_t *)num);
|
|
|
|
el_size = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
num += el_size;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2018-09-20 02:56:50 +08:00
|
|
|
case TEP_PRINT_TYPE:
|
2012-04-06 06:47:53 +08:00
|
|
|
break;
|
2018-09-20 02:56:50 +08:00
|
|
|
case TEP_PRINT_STRING: {
|
2012-04-06 06:47:53 +08:00
|
|
|
int str_offset;
|
|
|
|
|
2021-11-22 17:30:40 +08:00
|
|
|
if (!arg->string.field)
|
|
|
|
arg->string.field = tep_find_any_field(event, arg->string.string);
|
|
|
|
if (!arg->string.field)
|
|
|
|
break;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2021-11-22 17:30:40 +08:00
|
|
|
str_offset = data2host4(tep,
|
|
|
|
*(unsigned int *)(data + arg->string.field->offset));
|
2012-04-06 06:47:53 +08:00
|
|
|
str_offset &= 0xffff;
|
2021-11-22 17:30:40 +08:00
|
|
|
if (arg->string.field->flags & TEP_FIELD_IS_RELATIVE)
|
|
|
|
str_offset += arg->string.field->offset + arg->string.field->size;
|
2012-04-06 06:47:53 +08:00
|
|
|
print_str_to_seq(s, format, len_arg, ((char *)data) + str_offset);
|
|
|
|
break;
|
|
|
|
}
|
2018-09-20 02:56:50 +08:00
|
|
|
case TEP_PRINT_BSTRING:
|
2011-11-16 07:47:48 +08:00
|
|
|
print_str_to_seq(s, format, len_arg, arg->string.string);
|
2012-04-06 06:47:53 +08:00
|
|
|
break;
|
2018-09-20 02:56:50 +08:00
|
|
|
case TEP_PRINT_BITMASK: {
|
2014-06-03 11:20:16 +08:00
|
|
|
int bitmask_offset;
|
|
|
|
int bitmask_size;
|
|
|
|
|
2021-11-22 17:30:40 +08:00
|
|
|
if (!arg->bitmask.field)
|
|
|
|
arg->bitmask.field = tep_find_any_field(event, arg->bitmask.bitmask);
|
|
|
|
if (!arg->bitmask.field)
|
|
|
|
break;
|
|
|
|
bitmask_offset = data2host4(tep,
|
|
|
|
*(unsigned int *)(data + arg->bitmask.field->offset));
|
2014-06-03 11:20:16 +08:00
|
|
|
bitmask_size = bitmask_offset >> 16;
|
|
|
|
bitmask_offset &= 0xffff;
|
2021-11-22 17:30:40 +08:00
|
|
|
if (arg->bitmask.field->flags & TEP_FIELD_IS_RELATIVE)
|
|
|
|
bitmask_offset += arg->bitmask.field->offset + arg->bitmask.field->size;
|
2019-04-02 00:43:20 +08:00
|
|
|
print_bitmask_to_seq(tep, s, format, len_arg,
|
2014-06-03 11:20:16 +08:00
|
|
|
data + bitmask_offset, bitmask_size);
|
|
|
|
break;
|
|
|
|
}
|
2018-09-20 02:56:50 +08:00
|
|
|
case TEP_PRINT_OP:
|
2012-04-06 06:47:53 +08:00
|
|
|
/*
|
|
|
|
* The only op for string should be ? :
|
|
|
|
*/
|
|
|
|
if (arg->op.op[0] != '?')
|
|
|
|
return;
|
|
|
|
val = eval_num_arg(data, size, event, arg->op.left);
|
|
|
|
if (val)
|
|
|
|
print_str_arg(s, data, size, event,
|
|
|
|
format, len_arg, arg->op.right->op.left);
|
|
|
|
else
|
|
|
|
print_str_arg(s, data, size, event,
|
|
|
|
format, len_arg, arg->op.right->op.right);
|
|
|
|
break;
|
2018-09-20 02:56:50 +08:00
|
|
|
case TEP_PRINT_FUNC:
|
2012-04-06 06:47:53 +08:00
|
|
|
process_defined_func(s, data, size, event, arg);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* well... */
|
|
|
|
break;
|
|
|
|
}
|
2012-09-13 04:30:50 +08:00
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
out_warning_field:
|
2014-03-19 09:22:53 +08:00
|
|
|
do_warning_event(event, "%s: field %s not found",
|
|
|
|
__func__, arg->field.name);
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned long long
|
|
|
|
process_defined_func(struct trace_seq *s, void *data, int size,
|
2018-11-30 23:44:07 +08:00
|
|
|
struct tep_event *event, struct tep_print_arg *arg)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
tools lib traceevent: Rename pevent_function* APIs
In order to make libtraceevent into a proper library, variables, data
structures and functions require a unique prefix to prevent name space
conflicts. That prefix will be "tep_" and not "pevent_". This changes
APIs: pevent_function_handler, pevent_func_handler,
pevent_func_arg_type, PEVENT_FUNC_ARG_VOID, PEVENT_FUNC_ARG_INT,
PEVENT_FUNC_ARG_LONG, PEVENT_FUNC_ARG_STRING, PEVENT_FUNC_ARG_PTRS,
PEVENT_FUNC_ARG_MAX_TYPES
Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
Cc: linux-trace-devel@vger.kernel.org
Link: http://lkml.kernel.org/r/20180808180701.935881193@goodmis.org
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2018-08-09 02:02:59 +08:00
|
|
|
struct tep_function_handler *func_handle = arg->func.func;
|
2018-08-09 02:03:09 +08:00
|
|
|
struct func_params *param;
|
2012-04-06 06:47:53 +08:00
|
|
|
unsigned long long *args;
|
|
|
|
unsigned long long ret;
|
2018-09-20 02:56:49 +08:00
|
|
|
struct tep_print_arg *farg;
|
2012-04-06 06:47:53 +08:00
|
|
|
struct trace_seq str;
|
|
|
|
struct save_str {
|
|
|
|
struct save_str *next;
|
|
|
|
char *str;
|
|
|
|
} *strings = NULL, *string;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!func_handle->nr_args) {
|
|
|
|
ret = (*func_handle->func)(s, NULL);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
farg = arg->func.args;
|
|
|
|
param = func_handle->params;
|
|
|
|
|
2012-09-13 04:30:50 +08:00
|
|
|
ret = ULLONG_MAX;
|
|
|
|
args = malloc(sizeof(*args) * func_handle->nr_args);
|
|
|
|
if (!args)
|
|
|
|
goto out;
|
|
|
|
|
2012-04-06 06:47:53 +08:00
|
|
|
for (i = 0; i < func_handle->nr_args; i++) {
|
|
|
|
switch (param->type) {
|
tools lib traceevent: Rename pevent_function* APIs
In order to make libtraceevent into a proper library, variables, data
structures and functions require a unique prefix to prevent name space
conflicts. That prefix will be "tep_" and not "pevent_". This changes
APIs: pevent_function_handler, pevent_func_handler,
pevent_func_arg_type, PEVENT_FUNC_ARG_VOID, PEVENT_FUNC_ARG_INT,
PEVENT_FUNC_ARG_LONG, PEVENT_FUNC_ARG_STRING, PEVENT_FUNC_ARG_PTRS,
PEVENT_FUNC_ARG_MAX_TYPES
Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
Cc: linux-trace-devel@vger.kernel.org
Link: http://lkml.kernel.org/r/20180808180701.935881193@goodmis.org
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2018-08-09 02:02:59 +08:00
|
|
|
case TEP_FUNC_ARG_INT:
|
|
|
|
case TEP_FUNC_ARG_LONG:
|
|
|
|
case TEP_FUNC_ARG_PTR:
|
2012-04-06 06:47:53 +08:00
|
|
|
args[i] = eval_num_arg(data, size, event, farg);
|
|
|
|
break;
|
tools lib traceevent: Rename pevent_function* APIs
In order to make libtraceevent into a proper library, variables, data
structures and functions require a unique prefix to prevent name space
conflicts. That prefix will be "tep_" and not "pevent_". This changes
APIs: pevent_function_handler, pevent_func_handler,
pevent_func_arg_type, PEVENT_FUNC_ARG_VOID, PEVENT_FUNC_ARG_INT,
PEVENT_FUNC_ARG_LONG, PEVENT_FUNC_ARG_STRING, PEVENT_FUNC_ARG_PTRS,
PEVENT_FUNC_ARG_MAX_TYPES
Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
Cc: linux-trace-devel@vger.kernel.org
Link: http://lkml.kernel.org/r/20180808180701.935881193@goodmis.org
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2018-08-09 02:02:59 +08:00
|
|
|
case TEP_FUNC_ARG_STRING:
|
2012-04-06 06:47:53 +08:00
|
|
|
trace_seq_init(&str);
|
|
|
|
print_str_arg(&str, data, size, event, "%s", -1, farg);
|
|
|
|
trace_seq_terminate(&str);
|
2012-09-13 04:30:50 +08:00
|
|
|
string = malloc(sizeof(*string));
|
|
|
|
if (!string) {
|
2014-03-19 09:22:53 +08:00
|
|
|
do_warning_event(event, "%s(%d): malloc str",
|
|
|
|
__func__, __LINE__);
|
2012-09-13 04:30:50 +08:00
|
|
|
goto out_free;
|
|
|
|
}
|
2012-04-06 06:47:53 +08:00
|
|
|
string->next = strings;
|
|
|
|
string->str = strdup(str.buffer);
|
2012-09-13 04:30:50 +08:00
|
|
|
if (!string->str) {
|
|
|
|
free(string);
|
2014-03-19 09:22:53 +08:00
|
|
|
do_warning_event(event, "%s(%d): malloc str",
|
|
|
|
__func__, __LINE__);
|
2012-09-13 04:30:50 +08:00
|
|
|
goto out_free;
|
|
|
|
}
|
2012-08-08 01:43:14 +08:00
|
|
|
args[i] = (uintptr_t)string->str;
|
2012-04-06 06:47:53 +08:00
|
|
|
strings = string;
|
|
|
|
trace_seq_destroy(&str);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/*
|
|
|
|
* Something went totally wrong, this is not
|
|
|
|
* an input error, something in this code broke.
|
|
|
|
*/
|
2014-03-19 09:22:53 +08:00
|
|
|
do_warning_event(event, "Unexpected end of arguments\n");
|
2012-09-13 04:30:50 +08:00
|
|
|
goto out_free;
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
farg = farg->next;
|
2012-05-23 10:36:51 +08:00
|
|
|
param = param->next;
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = (*func_handle->func)(s, args);
|
2012-09-13 04:30:50 +08:00
|
|
|
out_free:
|
2012-04-06 06:47:53 +08:00
|
|
|
free(args);
|
|
|
|
while (strings) {
|
|
|
|
string = strings;
|
|
|
|
strings = string->next;
|
|
|
|
free(string->str);
|
|
|
|
free(string);
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
/* TBD : handle return type here */
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-09-20 02:56:49 +08:00
|
|
|
static void free_args(struct tep_print_arg *args)
|
2012-09-13 02:39:59 +08:00
|
|
|
{
|
2018-09-20 02:56:49 +08:00
|
|
|
struct tep_print_arg *next;
|
2012-09-13 02:39:59 +08:00
|
|
|
|
|
|
|
while (args) {
|
|
|
|
next = args->next;
|
|
|
|
|
|
|
|
free_arg(args);
|
|
|
|
args = next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-30 23:44:07 +08:00
|
|
|
static struct tep_print_arg *make_bprint_args(char *fmt, void *data, int size, struct tep_event *event)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
2019-04-02 00:43:20 +08:00
|
|
|
struct tep_handle *tep = event->tep;
|
2018-09-20 02:56:45 +08:00
|
|
|
struct tep_format_field *field, *ip_field;
|
2018-09-20 02:56:49 +08:00
|
|
|
struct tep_print_arg *args, *arg, **next;
|
2012-04-06 06:47:53 +08:00
|
|
|
unsigned long long ip, val;
|
|
|
|
char *ptr;
|
|
|
|
void *bptr;
|
2018-11-22 19:29:37 +08:00
|
|
|
int vsize = 0;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2019-04-02 00:43:20 +08:00
|
|
|
field = tep->bprint_buf_field;
|
|
|
|
ip_field = tep->bprint_ip_field;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
if (!field) {
|
2018-08-09 02:02:50 +08:00
|
|
|
field = tep_find_field(event, "buf");
|
2012-09-13 04:30:50 +08:00
|
|
|
if (!field) {
|
2014-03-19 09:22:53 +08:00
|
|
|
do_warning_event(event, "can't find buffer field for binary printk");
|
2012-09-13 04:30:50 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
2018-08-09 02:02:50 +08:00
|
|
|
ip_field = tep_find_field(event, "ip");
|
2012-09-13 04:30:50 +08:00
|
|
|
if (!ip_field) {
|
2014-03-19 09:22:53 +08:00
|
|
|
do_warning_event(event, "can't find ip field for binary printk");
|
2012-09-13 04:30:50 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
2019-04-02 00:43:20 +08:00
|
|
|
tep->bprint_buf_field = field;
|
|
|
|
tep->bprint_ip_field = ip_field;
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
|
2019-04-02 00:43:20 +08:00
|
|
|
ip = tep_read_number(tep, data + ip_field->offset, ip_field->size);
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The first arg is the IP pointer.
|
|
|
|
*/
|
|
|
|
args = alloc_arg();
|
2012-09-20 10:09:19 +08:00
|
|
|
if (!args) {
|
2014-03-19 09:22:53 +08:00
|
|
|
do_warning_event(event, "%s(%d): not enough memory!",
|
|
|
|
__func__, __LINE__);
|
2012-09-20 10:09:19 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
2012-04-06 06:47:53 +08:00
|
|
|
arg = args;
|
|
|
|
arg->next = NULL;
|
|
|
|
next = &arg->next;
|
|
|
|
|
2018-09-20 02:56:50 +08:00
|
|
|
arg->type = TEP_PRINT_ATOM;
|
2012-09-13 02:39:59 +08:00
|
|
|
|
|
|
|
if (asprintf(&arg->atom.atom, "%lld", ip) < 0)
|
|
|
|
goto out_free;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2015-03-12 11:13:57 +08:00
|
|
|
/* skip the first "%ps: " */
|
2013-11-02 05:53:57 +08:00
|
|
|
for (ptr = fmt + 5, bptr = data + field->offset;
|
2012-04-06 06:47:53 +08:00
|
|
|
bptr < data + size && *ptr; ptr++) {
|
|
|
|
int ls = 0;
|
|
|
|
|
|
|
|
if (*ptr == '%') {
|
|
|
|
process_again:
|
|
|
|
ptr++;
|
|
|
|
switch (*ptr) {
|
|
|
|
case '%':
|
|
|
|
break;
|
|
|
|
case 'l':
|
|
|
|
ls++;
|
|
|
|
goto process_again;
|
|
|
|
case 'L':
|
|
|
|
ls = 2;
|
|
|
|
goto process_again;
|
|
|
|
case '0' ... '9':
|
|
|
|
goto process_again;
|
2011-11-16 07:47:48 +08:00
|
|
|
case '.':
|
|
|
|
goto process_again;
|
2015-03-24 21:57:51 +08:00
|
|
|
case 'z':
|
|
|
|
case 'Z':
|
|
|
|
ls = 1;
|
|
|
|
goto process_again;
|
2012-04-06 06:47:53 +08:00
|
|
|
case 'p':
|
|
|
|
ls = 1;
|
2018-01-12 08:47:46 +08:00
|
|
|
if (isalnum(ptr[1])) {
|
|
|
|
ptr++;
|
|
|
|
/* Check for special pointers */
|
|
|
|
switch (*ptr) {
|
|
|
|
case 's':
|
|
|
|
case 'S':
|
2019-04-02 00:43:06 +08:00
|
|
|
case 'x':
|
2018-01-12 08:47:46 +08:00
|
|
|
break;
|
2019-09-18 21:34:07 +08:00
|
|
|
case 'f':
|
|
|
|
case 'F':
|
|
|
|
/*
|
|
|
|
* Pre-5.5 kernels use %pf and
|
|
|
|
* %pF for printing symbols
|
|
|
|
* while kernels since 5.5 use
|
|
|
|
* %pfw for fwnodes. So check
|
|
|
|
* %p[fF] isn't followed by 'w'.
|
|
|
|
*/
|
|
|
|
if (ptr[1] != 'w')
|
|
|
|
break;
|
|
|
|
/* fall through */
|
2018-01-12 08:47:46 +08:00
|
|
|
default:
|
|
|
|
/*
|
|
|
|
* Older kernels do not process
|
|
|
|
* dereferenced pointers.
|
|
|
|
* Only process if the pointer
|
|
|
|
* value is a printable.
|
|
|
|
*/
|
|
|
|
if (isprint(*(char *)bptr))
|
|
|
|
goto process_string;
|
|
|
|
}
|
|
|
|
}
|
2012-04-06 06:47:53 +08:00
|
|
|
/* fall through */
|
|
|
|
case 'd':
|
|
|
|
case 'u':
|
|
|
|
case 'i':
|
2019-11-10 18:11:01 +08:00
|
|
|
case 'x':
|
|
|
|
case 'X':
|
|
|
|
case 'o':
|
2012-04-06 06:47:53 +08:00
|
|
|
switch (ls) {
|
|
|
|
case 0:
|
2011-11-16 07:47:48 +08:00
|
|
|
vsize = 4;
|
2012-04-06 06:47:53 +08:00
|
|
|
break;
|
|
|
|
case 1:
|
2019-04-02 00:43:20 +08:00
|
|
|
vsize = tep->long_size;
|
2012-04-06 06:47:53 +08:00
|
|
|
break;
|
|
|
|
case 2:
|
2011-11-16 07:47:48 +08:00
|
|
|
vsize = 8;
|
2012-04-25 05:19:40 +08:00
|
|
|
break;
|
2012-04-06 06:47:53 +08:00
|
|
|
default:
|
2011-11-16 07:47:48 +08:00
|
|
|
vsize = ls; /* ? */
|
2012-04-06 06:47:53 +08:00
|
|
|
break;
|
|
|
|
}
|
2011-11-16 07:47:48 +08:00
|
|
|
/* fall through */
|
|
|
|
case '*':
|
|
|
|
if (*ptr == '*')
|
|
|
|
vsize = 4;
|
|
|
|
|
|
|
|
/* the pointers are always 4 bytes aligned */
|
|
|
|
bptr = (void *)(((unsigned long)bptr + 3) &
|
|
|
|
~3);
|
2019-04-02 00:43:20 +08:00
|
|
|
val = tep_read_number(tep, bptr, vsize);
|
2011-11-16 07:47:48 +08:00
|
|
|
bptr += vsize;
|
2012-04-06 06:47:53 +08:00
|
|
|
arg = alloc_arg();
|
2012-09-20 10:09:19 +08:00
|
|
|
if (!arg) {
|
2014-03-19 09:22:53 +08:00
|
|
|
do_warning_event(event, "%s(%d): not enough memory!",
|
2012-09-20 10:09:19 +08:00
|
|
|
__func__, __LINE__);
|
|
|
|
goto out_free;
|
|
|
|
}
|
2012-04-06 06:47:53 +08:00
|
|
|
arg->next = NULL;
|
2018-09-20 02:56:50 +08:00
|
|
|
arg->type = TEP_PRINT_ATOM;
|
2012-09-13 02:39:59 +08:00
|
|
|
if (asprintf(&arg->atom.atom, "%lld", val) < 0) {
|
|
|
|
free(arg);
|
|
|
|
goto out_free;
|
|
|
|
}
|
2012-04-06 06:47:53 +08:00
|
|
|
*next = arg;
|
|
|
|
next = &arg->next;
|
2011-11-16 07:47:48 +08:00
|
|
|
/*
|
|
|
|
* The '*' case means that an arg is used as the length.
|
|
|
|
* We need to continue to figure out for what.
|
|
|
|
*/
|
|
|
|
if (*ptr == '*')
|
|
|
|
goto process_again;
|
|
|
|
|
2012-04-06 06:47:53 +08:00
|
|
|
break;
|
|
|
|
case 's':
|
2018-01-12 08:47:46 +08:00
|
|
|
process_string:
|
2012-04-06 06:47:53 +08:00
|
|
|
arg = alloc_arg();
|
2012-09-20 10:09:19 +08:00
|
|
|
if (!arg) {
|
2014-03-19 09:22:53 +08:00
|
|
|
do_warning_event(event, "%s(%d): not enough memory!",
|
2012-09-20 10:09:19 +08:00
|
|
|
__func__, __LINE__);
|
|
|
|
goto out_free;
|
|
|
|
}
|
2012-04-06 06:47:53 +08:00
|
|
|
arg->next = NULL;
|
2018-09-20 02:56:50 +08:00
|
|
|
arg->type = TEP_PRINT_BSTRING;
|
2012-04-06 06:47:53 +08:00
|
|
|
arg->string.string = strdup(bptr);
|
2012-04-09 10:54:31 +08:00
|
|
|
if (!arg->string.string)
|
2012-09-13 04:30:50 +08:00
|
|
|
goto out_free;
|
2012-04-06 06:47:53 +08:00
|
|
|
bptr += strlen(bptr) + 1;
|
|
|
|
*next = arg;
|
|
|
|
next = &arg->next;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return args;
|
|
|
|
|
2012-09-13 02:39:59 +08:00
|
|
|
out_free:
|
|
|
|
free_args(args);
|
|
|
|
return NULL;
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
2012-09-11 06:15:03 +08:00
|
|
|
get_bprint_format(void *data, int size __maybe_unused,
|
2018-11-30 23:44:07 +08:00
|
|
|
struct tep_event *event)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
2019-04-02 00:43:20 +08:00
|
|
|
struct tep_handle *tep = event->tep;
|
2012-04-06 06:47:53 +08:00
|
|
|
unsigned long long addr;
|
2018-09-20 02:56:45 +08:00
|
|
|
struct tep_format_field *field;
|
2012-04-06 06:47:53 +08:00
|
|
|
struct printk_map *printk;
|
|
|
|
char *format;
|
|
|
|
|
2019-04-02 00:43:20 +08:00
|
|
|
field = tep->bprint_fmt_field;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
if (!field) {
|
2018-08-09 02:02:50 +08:00
|
|
|
field = tep_find_field(event, "fmt");
|
2012-09-13 04:30:50 +08:00
|
|
|
if (!field) {
|
2014-03-19 09:22:53 +08:00
|
|
|
do_warning_event(event, "can't find format field for binary printk");
|
2012-09-13 04:30:50 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
2019-04-02 00:43:20 +08:00
|
|
|
tep->bprint_fmt_field = field;
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
|
2019-04-02 00:43:20 +08:00
|
|
|
addr = tep_read_number(tep, data + field->offset, field->size);
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2019-04-02 00:43:20 +08:00
|
|
|
printk = find_printk(tep, addr);
|
2012-04-06 06:47:53 +08:00
|
|
|
if (!printk) {
|
2019-09-18 21:34:07 +08:00
|
|
|
if (asprintf(&format, "%%ps: (NO FORMAT FOUND at %llx)\n", addr) < 0)
|
2012-09-13 02:39:59 +08:00
|
|
|
return NULL;
|
2012-04-06 06:47:53 +08:00
|
|
|
return format;
|
|
|
|
}
|
|
|
|
|
2019-09-18 21:34:07 +08:00
|
|
|
if (asprintf(&format, "%s: %s", "%ps", printk->printk) < 0)
|
2012-09-13 02:39:59 +08:00
|
|
|
return NULL;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
return format;
|
|
|
|
}
|
|
|
|
|
2020-07-03 02:53:50 +08:00
|
|
|
static int print_mac_arg(struct trace_seq *s, const char *format,
|
|
|
|
void *data, int size, struct tep_event *event,
|
|
|
|
struct tep_print_arg *arg)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
2012-11-10 04:40:47 +08:00
|
|
|
const char *fmt = "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x";
|
2020-07-03 02:53:50 +08:00
|
|
|
bool reverse = false;
|
|
|
|
unsigned char *buf;
|
|
|
|
int ret = 0;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2018-09-20 02:56:50 +08:00
|
|
|
if (arg->type == TEP_PRINT_FUNC) {
|
2012-04-06 06:47:53 +08:00
|
|
|
process_defined_func(s, data, size, event, arg);
|
2020-07-03 02:53:50 +08:00
|
|
|
return 0;
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
|
2018-09-20 02:56:50 +08:00
|
|
|
if (arg->type != TEP_PRINT_FIELD) {
|
2012-04-06 06:47:53 +08:00
|
|
|
trace_seq_printf(s, "ARG TYPE NOT FIELD BUT %d",
|
|
|
|
arg->type);
|
2020-07-03 02:53:50 +08:00
|
|
|
return 0;
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
|
2020-07-03 02:53:50 +08:00
|
|
|
if (format[0] == 'm') {
|
2012-04-06 06:47:53 +08:00
|
|
|
fmt = "%.2x%.2x%.2x%.2x%.2x%.2x";
|
2020-07-03 02:53:50 +08:00
|
|
|
} else if (format[0] == 'M' && format[1] == 'F') {
|
|
|
|
fmt = "%.2x-%.2x-%.2x-%.2x-%.2x-%.2x";
|
|
|
|
ret++;
|
|
|
|
}
|
|
|
|
if (format[1] == 'R') {
|
|
|
|
reverse = true;
|
|
|
|
ret++;
|
|
|
|
}
|
|
|
|
|
2012-04-06 06:47:53 +08:00
|
|
|
if (!arg->field.field) {
|
|
|
|
arg->field.field =
|
2018-08-09 02:02:50 +08:00
|
|
|
tep_find_any_field(event, arg->field.name);
|
2012-09-13 04:30:50 +08:00
|
|
|
if (!arg->field.field) {
|
2014-03-19 09:22:53 +08:00
|
|
|
do_warning_event(event, "%s: field %s not found",
|
|
|
|
__func__, arg->field.name);
|
2020-07-03 02:53:50 +08:00
|
|
|
return ret;
|
2012-09-13 04:30:50 +08:00
|
|
|
}
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
if (arg->field.field->size != 6) {
|
|
|
|
trace_seq_printf(s, "INVALIDMAC");
|
2020-07-03 02:53:50 +08:00
|
|
|
return ret;
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
2020-07-03 02:53:50 +08:00
|
|
|
|
2012-04-06 06:47:53 +08:00
|
|
|
buf = data + arg->field.field->offset;
|
2020-07-03 02:53:50 +08:00
|
|
|
if (reverse)
|
|
|
|
trace_seq_printf(s, fmt, buf[5], buf[4], buf[3], buf[2], buf[1], buf[0]);
|
|
|
|
else
|
|
|
|
trace_seq_printf(s, fmt, buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int parse_ip4_print_args(struct tep_handle *tep,
|
|
|
|
const char *ptr, bool *reverse)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
*reverse = false;
|
|
|
|
|
|
|
|
/* hnbl */
|
|
|
|
switch (*ptr) {
|
|
|
|
case 'h':
|
|
|
|
if (tep->file_bigendian)
|
|
|
|
*reverse = false;
|
|
|
|
else
|
|
|
|
*reverse = true;
|
|
|
|
ret++;
|
2020-07-22 09:16:48 +08:00
|
|
|
break;
|
2020-07-03 02:53:50 +08:00
|
|
|
case 'l':
|
|
|
|
*reverse = true;
|
|
|
|
ret++;
|
2020-07-22 09:16:48 +08:00
|
|
|
break;
|
2020-07-03 02:53:50 +08:00
|
|
|
case 'n':
|
|
|
|
case 'b':
|
|
|
|
ret++;
|
|
|
|
/* fall through */
|
|
|
|
default:
|
|
|
|
*reverse = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
|
2020-07-03 02:53:50 +08:00
|
|
|
static void print_ip4_addr(struct trace_seq *s, char i, bool reverse, unsigned char *buf)
|
2014-12-19 10:11:11 +08:00
|
|
|
{
|
|
|
|
const char *fmt;
|
|
|
|
|
|
|
|
if (i == 'i')
|
|
|
|
fmt = "%03d.%03d.%03d.%03d";
|
|
|
|
else
|
|
|
|
fmt = "%d.%d.%d.%d";
|
|
|
|
|
2020-07-03 02:53:50 +08:00
|
|
|
if (reverse)
|
|
|
|
trace_seq_printf(s, fmt, buf[3], buf[2], buf[1], buf[0]);
|
|
|
|
else
|
|
|
|
trace_seq_printf(s, fmt, buf[0], buf[1], buf[2], buf[3]);
|
|
|
|
|
2014-12-19 10:11:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool ipv6_addr_v4mapped(const struct in6_addr *a)
|
|
|
|
{
|
|
|
|
return ((unsigned long)(a->s6_addr32[0] | a->s6_addr32[1]) |
|
|
|
|
(unsigned long)(a->s6_addr32[2] ^ htonl(0x0000ffff))) == 0UL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool ipv6_addr_is_isatap(const struct in6_addr *addr)
|
|
|
|
{
|
|
|
|
return (addr->s6_addr32[2] | htonl(0x02000000)) == htonl(0x02005EFE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void print_ip6c_addr(struct trace_seq *s, unsigned char *addr)
|
|
|
|
{
|
|
|
|
int i, j, range;
|
|
|
|
unsigned char zerolength[8];
|
|
|
|
int longest = 1;
|
|
|
|
int colonpos = -1;
|
|
|
|
uint16_t word;
|
|
|
|
uint8_t hi, lo;
|
|
|
|
bool needcolon = false;
|
|
|
|
bool useIPv4;
|
|
|
|
struct in6_addr in6;
|
|
|
|
|
|
|
|
memcpy(&in6, addr, sizeof(struct in6_addr));
|
|
|
|
|
|
|
|
useIPv4 = ipv6_addr_v4mapped(&in6) || ipv6_addr_is_isatap(&in6);
|
|
|
|
|
|
|
|
memset(zerolength, 0, sizeof(zerolength));
|
|
|
|
|
|
|
|
if (useIPv4)
|
|
|
|
range = 6;
|
|
|
|
else
|
|
|
|
range = 8;
|
|
|
|
|
|
|
|
/* find position of longest 0 run */
|
|
|
|
for (i = 0; i < range; i++) {
|
|
|
|
for (j = i; j < range; j++) {
|
|
|
|
if (in6.s6_addr16[j] != 0)
|
|
|
|
break;
|
|
|
|
zerolength[i]++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (i = 0; i < range; i++) {
|
|
|
|
if (zerolength[i] > longest) {
|
|
|
|
longest = zerolength[i];
|
|
|
|
colonpos = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (longest == 1) /* don't compress a single 0 */
|
|
|
|
colonpos = -1;
|
|
|
|
|
|
|
|
/* emit address */
|
|
|
|
for (i = 0; i < range; i++) {
|
|
|
|
if (i == colonpos) {
|
|
|
|
if (needcolon || i == 0)
|
|
|
|
trace_seq_printf(s, ":");
|
|
|
|
trace_seq_printf(s, ":");
|
|
|
|
needcolon = false;
|
|
|
|
i += longest - 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (needcolon) {
|
|
|
|
trace_seq_printf(s, ":");
|
|
|
|
needcolon = false;
|
|
|
|
}
|
|
|
|
/* hex u16 without leading 0s */
|
|
|
|
word = ntohs(in6.s6_addr16[i]);
|
|
|
|
hi = word >> 8;
|
|
|
|
lo = word & 0xff;
|
|
|
|
if (hi)
|
|
|
|
trace_seq_printf(s, "%x%02x", hi, lo);
|
|
|
|
else
|
|
|
|
trace_seq_printf(s, "%x", lo);
|
|
|
|
|
|
|
|
needcolon = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (useIPv4) {
|
|
|
|
if (needcolon)
|
|
|
|
trace_seq_printf(s, ":");
|
2020-07-03 02:53:50 +08:00
|
|
|
print_ip4_addr(s, 'I', false, &in6.s6_addr[12]);
|
2014-12-19 10:11:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void print_ip6_addr(struct trace_seq *s, char i, unsigned char *buf)
|
|
|
|
{
|
|
|
|
int j;
|
|
|
|
|
|
|
|
for (j = 0; j < 16; j += 2) {
|
|
|
|
trace_seq_printf(s, "%02x%02x", buf[j], buf[j+1]);
|
|
|
|
if (i == 'I' && j < 14)
|
|
|
|
trace_seq_printf(s, ":");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* %pi4 print an IPv4 address with leading zeros
|
|
|
|
* %pI4 print an IPv4 address without leading zeros
|
|
|
|
* %pi6 print an IPv6 address without colons
|
|
|
|
* %pI6 print an IPv6 address with colons
|
|
|
|
* %pI6c print an IPv6 address in compressed form with colons
|
|
|
|
* %pISpc print an IP address based on sockaddr; p adds port.
|
|
|
|
*/
|
|
|
|
static int print_ipv4_arg(struct trace_seq *s, const char *ptr, char i,
|
2018-11-30 23:44:07 +08:00
|
|
|
void *data, int size, struct tep_event *event,
|
2018-09-20 02:56:49 +08:00
|
|
|
struct tep_print_arg *arg)
|
2014-12-19 10:11:11 +08:00
|
|
|
{
|
2020-07-03 02:53:50 +08:00
|
|
|
bool reverse = false;
|
2014-12-19 10:11:11 +08:00
|
|
|
unsigned char *buf;
|
2020-07-03 02:53:50 +08:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = parse_ip4_print_args(event->tep, ptr, &reverse);
|
2014-12-19 10:11:11 +08:00
|
|
|
|
2018-09-20 02:56:50 +08:00
|
|
|
if (arg->type == TEP_PRINT_FUNC) {
|
2014-12-19 10:11:11 +08:00
|
|
|
process_defined_func(s, data, size, event, arg);
|
2020-07-03 02:53:50 +08:00
|
|
|
return ret;
|
2014-12-19 10:11:11 +08:00
|
|
|
}
|
|
|
|
|
2018-09-20 02:56:50 +08:00
|
|
|
if (arg->type != TEP_PRINT_FIELD) {
|
2014-12-19 10:11:11 +08:00
|
|
|
trace_seq_printf(s, "ARG TYPE NOT FIELD BUT %d", arg->type);
|
2020-07-03 02:53:50 +08:00
|
|
|
return ret;
|
2014-12-19 10:11:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!arg->field.field) {
|
|
|
|
arg->field.field =
|
2018-08-09 02:02:50 +08:00
|
|
|
tep_find_any_field(event, arg->field.name);
|
2014-12-19 10:11:11 +08:00
|
|
|
if (!arg->field.field) {
|
|
|
|
do_warning("%s: field %s not found",
|
|
|
|
__func__, arg->field.name);
|
2020-07-03 02:53:50 +08:00
|
|
|
return ret;
|
2014-12-19 10:11:11 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
buf = data + arg->field.field->offset;
|
|
|
|
|
|
|
|
if (arg->field.field->size != 4) {
|
|
|
|
trace_seq_printf(s, "INVALIDIPv4");
|
2020-07-03 02:53:50 +08:00
|
|
|
return ret;
|
2014-12-19 10:11:11 +08:00
|
|
|
}
|
|
|
|
|
2020-07-03 02:53:50 +08:00
|
|
|
print_ip4_addr(s, i, reverse, buf);
|
|
|
|
return ret;
|
|
|
|
|
2014-12-19 10:11:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int print_ipv6_arg(struct trace_seq *s, const char *ptr, char i,
|
2018-11-30 23:44:07 +08:00
|
|
|
void *data, int size, struct tep_event *event,
|
2018-09-20 02:56:49 +08:00
|
|
|
struct tep_print_arg *arg)
|
2014-12-19 10:11:11 +08:00
|
|
|
{
|
|
|
|
char have_c = 0;
|
|
|
|
unsigned char *buf;
|
|
|
|
int rc = 0;
|
|
|
|
|
|
|
|
/* pI6c */
|
|
|
|
if (i == 'I' && *ptr == 'c') {
|
|
|
|
have_c = 1;
|
|
|
|
ptr++;
|
|
|
|
rc++;
|
|
|
|
}
|
|
|
|
|
2018-09-20 02:56:50 +08:00
|
|
|
if (arg->type == TEP_PRINT_FUNC) {
|
2014-12-19 10:11:11 +08:00
|
|
|
process_defined_func(s, data, size, event, arg);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2018-09-20 02:56:50 +08:00
|
|
|
if (arg->type != TEP_PRINT_FIELD) {
|
2014-12-19 10:11:11 +08:00
|
|
|
trace_seq_printf(s, "ARG TYPE NOT FIELD BUT %d", arg->type);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!arg->field.field) {
|
|
|
|
arg->field.field =
|
2018-08-09 02:02:50 +08:00
|
|
|
tep_find_any_field(event, arg->field.name);
|
2014-12-19 10:11:11 +08:00
|
|
|
if (!arg->field.field) {
|
|
|
|
do_warning("%s: field %s not found",
|
|
|
|
__func__, arg->field.name);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
buf = data + arg->field.field->offset;
|
|
|
|
|
|
|
|
if (arg->field.field->size != 16) {
|
|
|
|
trace_seq_printf(s, "INVALIDIPv6");
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (have_c)
|
|
|
|
print_ip6c_addr(s, buf);
|
|
|
|
else
|
|
|
|
print_ip6_addr(s, i, buf);
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int print_ipsa_arg(struct trace_seq *s, const char *ptr, char i,
|
2018-11-30 23:44:07 +08:00
|
|
|
void *data, int size, struct tep_event *event,
|
2018-09-20 02:56:49 +08:00
|
|
|
struct tep_print_arg *arg)
|
2014-12-19 10:11:11 +08:00
|
|
|
{
|
|
|
|
char have_c = 0, have_p = 0;
|
|
|
|
unsigned char *buf;
|
|
|
|
struct sockaddr_storage *sa;
|
2020-07-03 02:53:50 +08:00
|
|
|
bool reverse = false;
|
2014-12-19 10:11:11 +08:00
|
|
|
int rc = 0;
|
2020-07-03 02:53:50 +08:00
|
|
|
int ret;
|
2014-12-19 10:11:11 +08:00
|
|
|
|
|
|
|
/* pISpc */
|
|
|
|
if (i == 'I') {
|
|
|
|
if (*ptr == 'p') {
|
|
|
|
have_p = 1;
|
|
|
|
ptr++;
|
|
|
|
rc++;
|
|
|
|
}
|
|
|
|
if (*ptr == 'c') {
|
|
|
|
have_c = 1;
|
|
|
|
ptr++;
|
|
|
|
rc++;
|
|
|
|
}
|
|
|
|
}
|
2020-07-03 02:53:50 +08:00
|
|
|
ret = parse_ip4_print_args(event->tep, ptr, &reverse);
|
|
|
|
ptr += ret;
|
|
|
|
rc += ret;
|
2014-12-19 10:11:11 +08:00
|
|
|
|
2018-09-20 02:56:50 +08:00
|
|
|
if (arg->type == TEP_PRINT_FUNC) {
|
2014-12-19 10:11:11 +08:00
|
|
|
process_defined_func(s, data, size, event, arg);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2018-09-20 02:56:50 +08:00
|
|
|
if (arg->type != TEP_PRINT_FIELD) {
|
2014-12-19 10:11:11 +08:00
|
|
|
trace_seq_printf(s, "ARG TYPE NOT FIELD BUT %d", arg->type);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!arg->field.field) {
|
|
|
|
arg->field.field =
|
2018-08-09 02:02:50 +08:00
|
|
|
tep_find_any_field(event, arg->field.name);
|
2014-12-19 10:11:11 +08:00
|
|
|
if (!arg->field.field) {
|
|
|
|
do_warning("%s: field %s not found",
|
|
|
|
__func__, arg->field.name);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sa = (struct sockaddr_storage *) (data + arg->field.field->offset);
|
|
|
|
|
|
|
|
if (sa->ss_family == AF_INET) {
|
|
|
|
struct sockaddr_in *sa4 = (struct sockaddr_in *) sa;
|
|
|
|
|
|
|
|
if (arg->field.field->size < sizeof(struct sockaddr_in)) {
|
|
|
|
trace_seq_printf(s, "INVALIDIPv4");
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2020-07-03 02:53:50 +08:00
|
|
|
print_ip4_addr(s, i, reverse, (unsigned char *) &sa4->sin_addr);
|
2014-12-19 10:11:11 +08:00
|
|
|
if (have_p)
|
|
|
|
trace_seq_printf(s, ":%d", ntohs(sa4->sin_port));
|
|
|
|
|
|
|
|
|
|
|
|
} else if (sa->ss_family == AF_INET6) {
|
|
|
|
struct sockaddr_in6 *sa6 = (struct sockaddr_in6 *) sa;
|
|
|
|
|
|
|
|
if (arg->field.field->size < sizeof(struct sockaddr_in6)) {
|
|
|
|
trace_seq_printf(s, "INVALIDIPv6");
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (have_p)
|
|
|
|
trace_seq_printf(s, "[");
|
|
|
|
|
|
|
|
buf = (unsigned char *) &sa6->sin6_addr;
|
|
|
|
if (have_c)
|
|
|
|
print_ip6c_addr(s, buf);
|
|
|
|
else
|
|
|
|
print_ip6_addr(s, i, buf);
|
|
|
|
|
|
|
|
if (have_p)
|
|
|
|
trace_seq_printf(s, "]:%d", ntohs(sa6->sin6_port));
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int print_ip_arg(struct trace_seq *s, const char *ptr,
|
2018-11-30 23:44:07 +08:00
|
|
|
void *data, int size, struct tep_event *event,
|
2018-09-20 02:56:49 +08:00
|
|
|
struct tep_print_arg *arg)
|
2014-12-19 10:11:11 +08:00
|
|
|
{
|
|
|
|
char i = *ptr; /* 'i' or 'I' */
|
2020-07-03 02:53:50 +08:00
|
|
|
int rc = 1;
|
2014-12-19 10:11:11 +08:00
|
|
|
|
2020-07-03 02:53:50 +08:00
|
|
|
/* IP version */
|
2014-12-19 10:11:11 +08:00
|
|
|
ptr++;
|
|
|
|
|
2020-07-03 02:53:50 +08:00
|
|
|
switch (*ptr) {
|
2014-12-19 10:11:11 +08:00
|
|
|
case '4':
|
2020-07-03 02:53:50 +08:00
|
|
|
rc += print_ipv4_arg(s, ptr + 1, i, data, size, event, arg);
|
2014-12-19 10:11:11 +08:00
|
|
|
break;
|
|
|
|
case '6':
|
2020-07-03 02:53:50 +08:00
|
|
|
rc += print_ipv6_arg(s, ptr + 1, i, data, size, event, arg);
|
2014-12-19 10:11:11 +08:00
|
|
|
break;
|
|
|
|
case 'S':
|
2020-07-03 02:53:50 +08:00
|
|
|
rc += print_ipsa_arg(s, ptr + 1, i, data, size, event, arg);
|
2014-12-19 10:11:11 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2020-07-03 02:53:50 +08:00
|
|
|
static const int guid_index[16] = {3, 2, 1, 0, 5, 4, 7, 6, 8, 9, 10, 11, 12, 13, 14, 15};
|
|
|
|
static const int uuid_index[16] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
|
|
|
|
|
|
|
|
static int print_uuid_arg(struct trace_seq *s, const char *ptr,
|
|
|
|
void *data, int size, struct tep_event *event,
|
|
|
|
struct tep_print_arg *arg)
|
|
|
|
{
|
|
|
|
const int *index = uuid_index;
|
|
|
|
char *format = "%02x";
|
|
|
|
int ret = 0;
|
|
|
|
char *buf;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
switch (*(ptr + 1)) {
|
|
|
|
case 'L':
|
|
|
|
format = "%02X";
|
|
|
|
/* fall through */
|
|
|
|
case 'l':
|
|
|
|
index = guid_index;
|
|
|
|
ret++;
|
|
|
|
break;
|
|
|
|
case 'B':
|
|
|
|
format = "%02X";
|
|
|
|
/* fall through */
|
|
|
|
case 'b':
|
|
|
|
ret++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (arg->type == TEP_PRINT_FUNC) {
|
|
|
|
process_defined_func(s, data, size, event, arg);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (arg->type != TEP_PRINT_FIELD) {
|
|
|
|
trace_seq_printf(s, "ARG TYPE NOT FIELD BUT %d", arg->type);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!arg->field.field) {
|
|
|
|
arg->field.field =
|
|
|
|
tep_find_any_field(event, arg->field.name);
|
|
|
|
if (!arg->field.field) {
|
|
|
|
do_warning("%s: field %s not found",
|
|
|
|
__func__, arg->field.name);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (arg->field.field->size != 16) {
|
|
|
|
trace_seq_printf(s, "INVALIDUUID");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
buf = data + arg->field.field->offset;
|
|
|
|
|
|
|
|
for (i = 0; i < 16; i++) {
|
|
|
|
trace_seq_printf(s, format, buf[index[i]] & 0xff);
|
|
|
|
switch (i) {
|
|
|
|
case 3:
|
|
|
|
case 5:
|
|
|
|
case 7:
|
|
|
|
case 9:
|
|
|
|
trace_seq_printf(s, "-");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int print_raw_buff_arg(struct trace_seq *s, const char *ptr,
|
|
|
|
void *data, int size, struct tep_event *event,
|
|
|
|
struct tep_print_arg *arg, int print_len)
|
|
|
|
{
|
|
|
|
int plen = print_len;
|
|
|
|
char *delim = " ";
|
|
|
|
int ret = 0;
|
|
|
|
char *buf;
|
|
|
|
int i;
|
|
|
|
unsigned long offset;
|
|
|
|
int arr_len;
|
|
|
|
|
|
|
|
switch (*(ptr + 1)) {
|
|
|
|
case 'C':
|
|
|
|
delim = ":";
|
|
|
|
ret++;
|
|
|
|
break;
|
|
|
|
case 'D':
|
|
|
|
delim = "-";
|
|
|
|
ret++;
|
|
|
|
break;
|
|
|
|
case 'N':
|
|
|
|
delim = "";
|
|
|
|
ret++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (arg->type == TEP_PRINT_FUNC) {
|
|
|
|
process_defined_func(s, data, size, event, arg);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (arg->type != TEP_PRINT_DYNAMIC_ARRAY) {
|
|
|
|
trace_seq_printf(s, "ARG TYPE NOT FIELD BUT %d", arg->type);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
offset = tep_read_number(event->tep,
|
|
|
|
data + arg->dynarray.field->offset,
|
|
|
|
arg->dynarray.field->size);
|
|
|
|
arr_len = (unsigned long long)(offset >> 16);
|
|
|
|
buf = data + (offset & 0xffff);
|
|
|
|
|
|
|
|
if (arr_len < plen)
|
|
|
|
plen = arr_len;
|
|
|
|
|
|
|
|
if (plen < 1)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
trace_seq_printf(s, "%02x", buf[0] & 0xff);
|
|
|
|
for (i = 1; i < plen; i++)
|
|
|
|
trace_seq_printf(s, "%s%02x", delim, buf[i] & 0xff);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
tools lib traceevent: Check string is really printable
When libtraceevent parses format fields, it assumes that array of 1 byte
is string but it's not always true. The kvm_emulate_insn contains 15 u8
array of insn that contains (binary) instructions. Thus when it's
printed, it'll have broken output like below:
kvm_emulate_insn: [FAILED TO PARSE] rip=3238197797 csbase=0 len=2 \
insn=<89>P^]<B4>& flags=5 failed=0
With this patch:
kvm_emulate_insn: [FAILED TO PARSE] rip=3238197797 csbase=0 len=2 \
insn=ARRAY[89, 10, 5d, c3, 8d, b4, 26, 00, 00, 00, 00, 55, 89, e5, 3e] flags=5 failed=0
Suggested-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Steven Rostedt <rostedt@goodmis.org>
Link: http://lkml.kernel.org/r/1340352615-20737-2-git-send-email-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2012-06-22 16:10:15 +08:00
|
|
|
static int is_printable_array(char *p, unsigned int len)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; i < len && p[i]; i++)
|
2013-11-02 05:53:58 +08:00
|
|
|
if (!isprint(p[i]) && !isspace(p[i]))
|
tools lib traceevent: Check string is really printable
When libtraceevent parses format fields, it assumes that array of 1 byte
is string but it's not always true. The kvm_emulate_insn contains 15 u8
array of insn that contains (binary) instructions. Thus when it's
printed, it'll have broken output like below:
kvm_emulate_insn: [FAILED TO PARSE] rip=3238197797 csbase=0 len=2 \
insn=<89>P^]<B4>& flags=5 failed=0
With this patch:
kvm_emulate_insn: [FAILED TO PARSE] rip=3238197797 csbase=0 len=2 \
insn=ARRAY[89, 10, 5d, c3, 8d, b4, 26, 00, 00, 00, 00, 55, 89, e5, 3e] flags=5 failed=0
Suggested-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Steven Rostedt <rostedt@goodmis.org>
Link: http://lkml.kernel.org/r/1340352615-20737-2-git-send-email-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2012-06-22 16:10:15 +08:00
|
|
|
return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2018-08-09 02:02:52 +08:00
|
|
|
void tep_print_field(struct trace_seq *s, void *data,
|
2018-09-20 02:56:45 +08:00
|
|
|
struct tep_format_field *field)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
|
|
|
unsigned long long val;
|
|
|
|
unsigned int offset, len, i;
|
2019-04-02 00:43:20 +08:00
|
|
|
struct tep_handle *tep = field->event->tep;
|
2015-12-23 21:08:41 +08:00
|
|
|
|
2018-09-20 02:56:46 +08:00
|
|
|
if (field->flags & TEP_FIELD_IS_ARRAY) {
|
2015-12-23 21:08:41 +08:00
|
|
|
offset = field->offset;
|
|
|
|
len = field->size;
|
2018-09-20 02:56:46 +08:00
|
|
|
if (field->flags & TEP_FIELD_IS_DYNAMIC) {
|
2019-04-02 00:43:20 +08:00
|
|
|
val = tep_read_number(tep, data + offset, len);
|
2015-12-23 21:08:41 +08:00
|
|
|
offset = val;
|
|
|
|
len = offset >> 16;
|
|
|
|
offset &= 0xffff;
|
2021-11-22 17:30:40 +08:00
|
|
|
if (field->flags & TEP_FIELD_IS_RELATIVE)
|
|
|
|
offset += field->offset + field->size;
|
2015-12-23 21:08:41 +08:00
|
|
|
}
|
2018-09-20 02:56:46 +08:00
|
|
|
if (field->flags & TEP_FIELD_IS_STRING &&
|
2015-12-23 21:08:41 +08:00
|
|
|
is_printable_array(data + offset, len)) {
|
|
|
|
trace_seq_printf(s, "%s", (char *)data + offset);
|
2012-04-06 06:47:53 +08:00
|
|
|
} else {
|
2015-12-23 21:08:41 +08:00
|
|
|
trace_seq_puts(s, "ARRAY[");
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
if (i)
|
|
|
|
trace_seq_puts(s, ", ");
|
|
|
|
trace_seq_printf(s, "%02x",
|
|
|
|
*((unsigned char *)data + offset + i));
|
|
|
|
}
|
|
|
|
trace_seq_putc(s, ']');
|
2018-09-20 02:56:46 +08:00
|
|
|
field->flags &= ~TEP_FIELD_IS_STRING;
|
2015-12-23 21:08:41 +08:00
|
|
|
}
|
|
|
|
} else {
|
2019-04-02 00:43:20 +08:00
|
|
|
val = tep_read_number(tep, data + field->offset,
|
2018-08-09 02:02:53 +08:00
|
|
|
field->size);
|
2018-09-20 02:56:46 +08:00
|
|
|
if (field->flags & TEP_FIELD_IS_POINTER) {
|
2015-12-23 21:08:41 +08:00
|
|
|
trace_seq_printf(s, "0x%llx", val);
|
2018-09-20 02:56:46 +08:00
|
|
|
} else if (field->flags & TEP_FIELD_IS_SIGNED) {
|
2015-12-23 21:08:41 +08:00
|
|
|
switch (field->size) {
|
|
|
|
case 4:
|
|
|
|
/*
|
|
|
|
* If field is long then print it in hex.
|
|
|
|
* A long usually stores pointers.
|
|
|
|
*/
|
2018-09-20 02:56:46 +08:00
|
|
|
if (field->flags & TEP_FIELD_IS_LONG)
|
2015-12-23 21:08:41 +08:00
|
|
|
trace_seq_printf(s, "0x%x", (int)val);
|
2012-04-06 06:47:53 +08:00
|
|
|
else
|
2015-12-23 21:08:41 +08:00
|
|
|
trace_seq_printf(s, "%d", (int)val);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
trace_seq_printf(s, "%2d", (short)val);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
trace_seq_printf(s, "%1d", (char)val);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
trace_seq_printf(s, "%lld", val);
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
2015-12-23 21:08:41 +08:00
|
|
|
} else {
|
2018-09-20 02:56:46 +08:00
|
|
|
if (field->flags & TEP_FIELD_IS_LONG)
|
2015-12-23 21:08:41 +08:00
|
|
|
trace_seq_printf(s, "0x%llx", val);
|
|
|
|
else
|
|
|
|
trace_seq_printf(s, "%llu", val);
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
2015-12-23 21:08:41 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-09 02:02:52 +08:00
|
|
|
void tep_print_fields(struct trace_seq *s, void *data,
|
2018-11-30 23:44:07 +08:00
|
|
|
int size __maybe_unused, struct tep_event *event)
|
2015-12-23 21:08:41 +08:00
|
|
|
{
|
2018-09-20 02:56:45 +08:00
|
|
|
struct tep_format_field *field;
|
2015-12-23 21:08:41 +08:00
|
|
|
|
|
|
|
field = event->format.fields;
|
|
|
|
while (field) {
|
|
|
|
trace_seq_printf(s, " %s=", field->name);
|
2018-08-09 02:02:52 +08:00
|
|
|
tep_print_field(s, data, field);
|
2012-04-06 06:47:53 +08:00
|
|
|
field = field->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-03 02:53:50 +08:00
|
|
|
static int print_function(struct trace_seq *s, const char *format,
|
|
|
|
void *data, int size, struct tep_event *event,
|
|
|
|
struct tep_print_arg *arg)
|
|
|
|
{
|
|
|
|
struct func_map *func;
|
|
|
|
unsigned long long val;
|
|
|
|
|
|
|
|
val = eval_num_arg(data, size, event, arg);
|
|
|
|
func = find_func(event->tep, val);
|
|
|
|
if (func) {
|
|
|
|
trace_seq_puts(s, func->func);
|
|
|
|
if (*format == 'F' || *format == 'S')
|
|
|
|
trace_seq_printf(s, "+0x%llx", val - func->addr);
|
|
|
|
} else {
|
|
|
|
if (event->tep->long_size == 4)
|
|
|
|
trace_seq_printf(s, "0x%lx", (long)val);
|
|
|
|
else
|
|
|
|
trace_seq_printf(s, "0x%llx", (long long)val);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-07-03 02:53:51 +08:00
|
|
|
static int print_arg_pointer(struct trace_seq *s, const char *format, int plen,
|
|
|
|
void *data, int size,
|
|
|
|
struct tep_event *event, struct tep_print_arg *arg)
|
2020-07-03 02:53:50 +08:00
|
|
|
{
|
|
|
|
unsigned long long val;
|
|
|
|
int ret = 1;
|
|
|
|
|
2020-07-03 02:53:51 +08:00
|
|
|
if (arg->type == TEP_PRINT_BSTRING) {
|
|
|
|
trace_seq_puts(s, arg->string.string);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
while (*format) {
|
|
|
|
if (*format == 'p') {
|
|
|
|
format++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
format++;
|
|
|
|
}
|
|
|
|
|
2020-07-03 02:53:50 +08:00
|
|
|
switch (*format) {
|
|
|
|
case 'F':
|
|
|
|
case 'f':
|
|
|
|
case 'S':
|
|
|
|
case 's':
|
|
|
|
ret += print_function(s, format, data, size, event, arg);
|
|
|
|
break;
|
|
|
|
case 'M':
|
|
|
|
case 'm':
|
|
|
|
ret += print_mac_arg(s, format, data, size, event, arg);
|
|
|
|
break;
|
|
|
|
case 'I':
|
|
|
|
case 'i':
|
|
|
|
ret += print_ip_arg(s, format, data, size, event, arg);
|
|
|
|
break;
|
|
|
|
case 'U':
|
|
|
|
ret += print_uuid_arg(s, format, data, size, event, arg);
|
|
|
|
break;
|
|
|
|
case 'h':
|
|
|
|
ret += print_raw_buff_arg(s, format, data, size, event, arg, plen);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ret = 0;
|
|
|
|
val = eval_num_arg(data, size, event, arg);
|
2020-09-02 18:31:21 +08:00
|
|
|
trace_seq_printf(s, "%p", (void *)(intptr_t)val);
|
2020-07-03 02:53:50 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-07-03 02:53:51 +08:00
|
|
|
static int print_arg_number(struct trace_seq *s, const char *format, int plen,
|
|
|
|
void *data, int size, int ls,
|
|
|
|
struct tep_event *event, struct tep_print_arg *arg)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
|
|
|
unsigned long long val;
|
2020-07-03 02:53:51 +08:00
|
|
|
|
|
|
|
val = eval_num_arg(data, size, event, arg);
|
|
|
|
|
|
|
|
switch (ls) {
|
|
|
|
case -2:
|
|
|
|
if (plen >= 0)
|
|
|
|
trace_seq_printf(s, format, plen, (char)val);
|
|
|
|
else
|
|
|
|
trace_seq_printf(s, format, (char)val);
|
|
|
|
break;
|
|
|
|
case -1:
|
|
|
|
if (plen >= 0)
|
|
|
|
trace_seq_printf(s, format, plen, (short)val);
|
|
|
|
else
|
|
|
|
trace_seq_printf(s, format, (short)val);
|
|
|
|
break;
|
|
|
|
case 0:
|
|
|
|
if (plen >= 0)
|
|
|
|
trace_seq_printf(s, format, plen, (int)val);
|
|
|
|
else
|
|
|
|
trace_seq_printf(s, format, (int)val);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
if (plen >= 0)
|
|
|
|
trace_seq_printf(s, format, plen, (long)val);
|
|
|
|
else
|
|
|
|
trace_seq_printf(s, format, (long)val);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
if (plen >= 0)
|
|
|
|
trace_seq_printf(s, format, plen, (long long)val);
|
|
|
|
else
|
|
|
|
trace_seq_printf(s, format, (long long)val);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
do_warning_event(event, "bad count (%d)", ls);
|
|
|
|
event->flags |= TEP_EVENT_FL_FAILED;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void print_arg_string(struct trace_seq *s, const char *format, int plen,
|
|
|
|
void *data, int size,
|
|
|
|
struct tep_event *event, struct tep_print_arg *arg)
|
|
|
|
{
|
2013-11-20 07:29:37 +08:00
|
|
|
struct trace_seq p;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2020-07-03 02:53:51 +08:00
|
|
|
/* Use helper trace_seq */
|
|
|
|
trace_seq_init(&p);
|
|
|
|
print_str_arg(&p, data, size, event,
|
|
|
|
format, plen, arg);
|
|
|
|
trace_seq_terminate(&p);
|
|
|
|
trace_seq_puts(s, p.buffer);
|
|
|
|
trace_seq_destroy(&p);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int parse_arg_format_pointer(const char *format)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
int index;
|
|
|
|
int loop;
|
|
|
|
|
|
|
|
switch (*format) {
|
|
|
|
case 'F':
|
|
|
|
case 'S':
|
|
|
|
case 'f':
|
|
|
|
case 's':
|
|
|
|
ret++;
|
|
|
|
break;
|
|
|
|
case 'M':
|
|
|
|
case 'm':
|
|
|
|
/* [mM]R , [mM]F */
|
|
|
|
switch (format[1]) {
|
|
|
|
case 'R':
|
|
|
|
case 'F':
|
|
|
|
ret++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ret++;
|
|
|
|
break;
|
|
|
|
case 'I':
|
|
|
|
case 'i':
|
|
|
|
index = 2;
|
|
|
|
loop = 1;
|
|
|
|
switch (format[1]) {
|
|
|
|
case 'S':
|
|
|
|
/*[S][pfs]*/
|
|
|
|
while (loop) {
|
|
|
|
switch (format[index]) {
|
|
|
|
case 'p':
|
|
|
|
case 'f':
|
|
|
|
case 's':
|
|
|
|
ret++;
|
|
|
|
index++;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
loop = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* fall through */
|
|
|
|
case '4':
|
|
|
|
/* [4S][hnbl] */
|
|
|
|
switch (format[index]) {
|
|
|
|
case 'h':
|
|
|
|
case 'n':
|
|
|
|
case 'l':
|
|
|
|
case 'b':
|
|
|
|
ret++;
|
|
|
|
index++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (format[1] == '4') {
|
|
|
|
ret++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* fall through */
|
|
|
|
case '6':
|
|
|
|
/* [6S]c */
|
|
|
|
if (format[index] == 'c')
|
|
|
|
ret++;
|
|
|
|
ret++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ret++;
|
|
|
|
break;
|
|
|
|
case 'U':
|
|
|
|
switch (format[1]) {
|
|
|
|
case 'L':
|
|
|
|
case 'l':
|
|
|
|
case 'B':
|
|
|
|
case 'b':
|
|
|
|
ret++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ret++;
|
|
|
|
break;
|
|
|
|
case 'h':
|
|
|
|
switch (format[1]) {
|
|
|
|
case 'C':
|
|
|
|
case 'D':
|
|
|
|
case 'N':
|
|
|
|
ret++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ret++;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
|
2020-07-03 02:53:51 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void free_parse_args(struct tep_print_parse *arg)
|
|
|
|
{
|
|
|
|
struct tep_print_parse *del;
|
|
|
|
|
|
|
|
while (arg) {
|
|
|
|
del = arg;
|
|
|
|
arg = del->next;
|
|
|
|
free(del->format);
|
|
|
|
free(del);
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
2020-07-03 02:53:51 +08:00
|
|
|
}
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2020-07-03 02:53:51 +08:00
|
|
|
static int parse_arg_add(struct tep_print_parse **parse, char *format,
|
|
|
|
enum tep_print_parse_type type,
|
|
|
|
struct tep_print_arg *arg,
|
|
|
|
struct tep_print_arg *len_as_arg,
|
|
|
|
int ls)
|
|
|
|
{
|
|
|
|
struct tep_print_parse *parg = NULL;
|
|
|
|
|
|
|
|
parg = calloc(1, sizeof(*parg));
|
|
|
|
if (!parg)
|
|
|
|
goto error;
|
|
|
|
parg->format = strdup(format);
|
|
|
|
if (!parg->format)
|
|
|
|
goto error;
|
|
|
|
parg->type = type;
|
|
|
|
parg->arg = arg;
|
|
|
|
parg->len_as_arg = len_as_arg;
|
|
|
|
parg->ls = ls;
|
|
|
|
*parse = parg;
|
|
|
|
return 0;
|
|
|
|
error:
|
|
|
|
if (parg) {
|
|
|
|
free(parg->format);
|
|
|
|
free(parg);
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int parse_arg_format(struct tep_print_parse **parse,
|
|
|
|
struct tep_event *event,
|
|
|
|
const char *format, struct tep_print_arg **arg)
|
|
|
|
{
|
|
|
|
struct tep_print_arg *len_arg = NULL;
|
|
|
|
char print_format[32];
|
|
|
|
const char *start = format;
|
|
|
|
int ret = 0;
|
|
|
|
int ls = 0;
|
|
|
|
int res;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
format++;
|
|
|
|
ret++;
|
|
|
|
for (; *format; format++) {
|
|
|
|
switch (*format) {
|
|
|
|
case '#':
|
|
|
|
/* FIXME: need to handle properly */
|
|
|
|
break;
|
|
|
|
case 'h':
|
|
|
|
ls--;
|
|
|
|
break;
|
|
|
|
case 'l':
|
|
|
|
ls++;
|
|
|
|
break;
|
|
|
|
case 'L':
|
|
|
|
ls = 2;
|
|
|
|
break;
|
|
|
|
case '.':
|
|
|
|
case 'z':
|
|
|
|
case 'Z':
|
|
|
|
case '0' ... '9':
|
|
|
|
case '-':
|
|
|
|
break;
|
|
|
|
case '*':
|
|
|
|
/* The argument is the length. */
|
|
|
|
if (!*arg) {
|
|
|
|
do_warning_event(event, "no argument match");
|
|
|
|
event->flags |= TEP_EVENT_FL_FAILED;
|
|
|
|
goto out_failed;
|
|
|
|
}
|
|
|
|
if (len_arg) {
|
|
|
|
do_warning_event(event, "argument already matched");
|
|
|
|
event->flags |= TEP_EVENT_FL_FAILED;
|
|
|
|
goto out_failed;
|
|
|
|
}
|
|
|
|
len_arg = *arg;
|
|
|
|
*arg = (*arg)->next;
|
|
|
|
break;
|
|
|
|
case 'p':
|
|
|
|
if (!*arg) {
|
|
|
|
do_warning_event(event, "no argument match");
|
|
|
|
event->flags |= TEP_EVENT_FL_FAILED;
|
|
|
|
goto out_failed;
|
|
|
|
}
|
|
|
|
res = parse_arg_format_pointer(format + 1);
|
|
|
|
if (res > 0) {
|
|
|
|
format += res;
|
|
|
|
ret += res;
|
|
|
|
}
|
|
|
|
len = ((unsigned long)format + 1) -
|
|
|
|
(unsigned long)start;
|
|
|
|
/* should never happen */
|
|
|
|
if (len > 31) {
|
|
|
|
do_warning_event(event, "bad format!");
|
|
|
|
event->flags |= TEP_EVENT_FL_FAILED;
|
|
|
|
len = 31;
|
|
|
|
}
|
|
|
|
memcpy(print_format, start, len);
|
|
|
|
print_format[len] = 0;
|
|
|
|
|
|
|
|
parse_arg_add(parse, print_format,
|
|
|
|
PRINT_FMT_ARG_POINTER, *arg, len_arg, ls);
|
|
|
|
*arg = (*arg)->next;
|
|
|
|
ret++;
|
|
|
|
return ret;
|
|
|
|
case 'd':
|
|
|
|
case 'u':
|
|
|
|
case 'i':
|
|
|
|
case 'x':
|
|
|
|
case 'X':
|
|
|
|
case 'o':
|
|
|
|
if (!*arg) {
|
|
|
|
do_warning_event(event, "no argument match");
|
|
|
|
event->flags |= TEP_EVENT_FL_FAILED;
|
|
|
|
goto out_failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
len = ((unsigned long)format + 1) -
|
|
|
|
(unsigned long)start;
|
|
|
|
|
|
|
|
/* should never happen */
|
|
|
|
if (len > 30) {
|
|
|
|
do_warning_event(event, "bad format!");
|
|
|
|
event->flags |= TEP_EVENT_FL_FAILED;
|
|
|
|
len = 31;
|
|
|
|
}
|
|
|
|
memcpy(print_format, start, len);
|
|
|
|
print_format[len] = 0;
|
|
|
|
|
|
|
|
if (event->tep->long_size == 8 && ls == 1 &&
|
|
|
|
sizeof(long) != 8) {
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
/* make %l into %ll */
|
|
|
|
if (ls == 1 && (p = strchr(print_format, 'l')))
|
|
|
|
memmove(p+1, p, strlen(p)+1);
|
|
|
|
ls = 2;
|
|
|
|
}
|
|
|
|
if (ls < -2 || ls > 2) {
|
|
|
|
do_warning_event(event, "bad count (%d)", ls);
|
|
|
|
event->flags |= TEP_EVENT_FL_FAILED;
|
|
|
|
}
|
|
|
|
parse_arg_add(parse, print_format,
|
|
|
|
PRINT_FMT_ARG_DIGIT, *arg, len_arg, ls);
|
|
|
|
*arg = (*arg)->next;
|
|
|
|
ret++;
|
|
|
|
return ret;
|
|
|
|
case 's':
|
|
|
|
if (!*arg) {
|
|
|
|
do_warning_event(event, "no matching argument");
|
|
|
|
event->flags |= TEP_EVENT_FL_FAILED;
|
|
|
|
goto out_failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
len = ((unsigned long)format + 1) -
|
|
|
|
(unsigned long)start;
|
|
|
|
|
|
|
|
/* should never happen */
|
|
|
|
if (len > 31) {
|
|
|
|
do_warning_event(event, "bad format!");
|
|
|
|
event->flags |= TEP_EVENT_FL_FAILED;
|
|
|
|
len = 31;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(print_format, start, len);
|
|
|
|
print_format[len] = 0;
|
|
|
|
|
|
|
|
parse_arg_add(parse, print_format,
|
|
|
|
PRINT_FMT_ARG_STRING, *arg, len_arg, 0);
|
|
|
|
*arg = (*arg)->next;
|
|
|
|
ret++;
|
|
|
|
return ret;
|
|
|
|
default:
|
|
|
|
snprintf(print_format, 32, ">%c<", *format);
|
|
|
|
parse_arg_add(parse, print_format,
|
2020-07-22 09:16:49 +08:00
|
|
|
PRINT_FMT_STRING, NULL, NULL, 0);
|
2020-07-03 02:53:51 +08:00
|
|
|
ret++;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
ret++;
|
|
|
|
}
|
|
|
|
|
|
|
|
out_failed:
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static int parse_arg_string(struct tep_print_parse **parse, const char *format)
|
|
|
|
{
|
|
|
|
struct trace_seq s;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
trace_seq_init(&s);
|
|
|
|
for (; *format; format++) {
|
|
|
|
if (*format == '\\') {
|
|
|
|
format++;
|
|
|
|
ret++;
|
|
|
|
switch (*format) {
|
2012-04-06 06:47:53 +08:00
|
|
|
case 'n':
|
2020-07-03 02:53:51 +08:00
|
|
|
trace_seq_putc(&s, '\n');
|
2012-04-06 06:47:53 +08:00
|
|
|
break;
|
|
|
|
case 't':
|
2020-07-03 02:53:51 +08:00
|
|
|
trace_seq_putc(&s, '\t');
|
2012-04-06 06:47:53 +08:00
|
|
|
break;
|
|
|
|
case 'r':
|
2020-07-03 02:53:51 +08:00
|
|
|
trace_seq_putc(&s, '\r');
|
2012-04-06 06:47:53 +08:00
|
|
|
break;
|
|
|
|
case '\\':
|
2020-07-03 02:53:51 +08:00
|
|
|
trace_seq_putc(&s, '\\');
|
2012-04-06 06:47:53 +08:00
|
|
|
break;
|
|
|
|
default:
|
2020-07-03 02:53:51 +08:00
|
|
|
trace_seq_putc(&s, *format);
|
2012-04-06 06:47:53 +08:00
|
|
|
break;
|
|
|
|
}
|
2020-07-03 02:53:51 +08:00
|
|
|
} else if (*format == '%') {
|
|
|
|
if (*(format + 1) == '%') {
|
|
|
|
trace_seq_putc(&s, '%');
|
|
|
|
format++;
|
|
|
|
ret++;
|
|
|
|
} else
|
2020-07-03 02:53:50 +08:00
|
|
|
break;
|
2020-07-03 02:53:51 +08:00
|
|
|
} else
|
|
|
|
trace_seq_putc(&s, *format);
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2020-07-03 02:53:51 +08:00
|
|
|
ret++;
|
|
|
|
}
|
|
|
|
trace_seq_terminate(&s);
|
2020-07-22 09:16:49 +08:00
|
|
|
parse_arg_add(parse, s.buffer, PRINT_FMT_STRING, NULL, NULL, 0);
|
2020-07-03 02:53:51 +08:00
|
|
|
trace_seq_destroy(&s);
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2020-07-03 02:53:51 +08:00
|
|
|
return ret;
|
|
|
|
}
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2020-07-03 02:53:51 +08:00
|
|
|
static struct tep_print_parse *
|
|
|
|
parse_args(struct tep_event *event, const char *format, struct tep_print_arg *arg)
|
|
|
|
{
|
|
|
|
struct tep_print_parse *parse_ret = NULL;
|
|
|
|
struct tep_print_parse **parse = NULL;
|
|
|
|
int ret;
|
|
|
|
int len;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2020-07-03 02:53:51 +08:00
|
|
|
len = strlen(format);
|
|
|
|
while (*format) {
|
|
|
|
if (!parse_ret)
|
|
|
|
parse = &parse_ret;
|
|
|
|
if (*format == '%' && *(format + 1) != '%')
|
|
|
|
ret = parse_arg_format(parse, event, format, &arg);
|
|
|
|
else
|
|
|
|
ret = parse_arg_string(parse, format);
|
|
|
|
if (*parse)
|
|
|
|
parse = &((*parse)->next);
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2020-07-03 02:53:51 +08:00
|
|
|
len -= ret;
|
|
|
|
if (len > 0)
|
|
|
|
format += ret;
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return parse_ret;
|
|
|
|
}
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2020-07-03 02:53:51 +08:00
|
|
|
static void print_event_cache(struct tep_print_parse *parse, struct trace_seq *s,
|
|
|
|
void *data, int size, struct tep_event *event)
|
|
|
|
{
|
|
|
|
int len_arg;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2020-07-03 02:53:51 +08:00
|
|
|
while (parse) {
|
|
|
|
if (parse->len_as_arg)
|
|
|
|
len_arg = eval_num_arg(data, size, event, parse->len_as_arg);
|
|
|
|
switch (parse->type) {
|
|
|
|
case PRINT_FMT_ARG_DIGIT:
|
|
|
|
print_arg_number(s, parse->format,
|
|
|
|
parse->len_as_arg ? len_arg : -1, data,
|
|
|
|
size, parse->ls, event, parse->arg);
|
|
|
|
break;
|
|
|
|
case PRINT_FMT_ARG_POINTER:
|
|
|
|
print_arg_pointer(s, parse->format,
|
|
|
|
parse->len_as_arg ? len_arg : 1,
|
|
|
|
data, size, event, parse->arg);
|
|
|
|
break;
|
|
|
|
case PRINT_FMT_ARG_STRING:
|
|
|
|
print_arg_string(s, parse->format,
|
|
|
|
parse->len_as_arg ? len_arg : -1,
|
|
|
|
data, size, event, parse->arg);
|
|
|
|
break;
|
2020-07-22 09:16:49 +08:00
|
|
|
case PRINT_FMT_STRING:
|
2020-07-03 02:53:51 +08:00
|
|
|
default:
|
|
|
|
trace_seq_printf(s, "%s", parse->format);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
parse = parse->next;
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
2020-07-03 02:53:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void pretty_print(struct trace_seq *s, void *data, int size, struct tep_event *event)
|
|
|
|
{
|
|
|
|
struct tep_print_parse *parse = event->print_fmt.print_cache;
|
|
|
|
struct tep_print_arg *args = NULL;
|
|
|
|
char *bprint_fmt = NULL;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2018-09-20 02:56:48 +08:00
|
|
|
if (event->flags & TEP_EVENT_FL_FAILED) {
|
2012-09-07 10:49:45 +08:00
|
|
|
trace_seq_printf(s, "[FAILED TO PARSE]");
|
2020-07-03 02:53:51 +08:00
|
|
|
tep_print_fields(s, data, size, event);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (event->flags & TEP_EVENT_FL_ISBPRINT) {
|
|
|
|
bprint_fmt = get_bprint_format(data, size, event);
|
|
|
|
args = make_bprint_args(bprint_fmt, data, size, event);
|
|
|
|
parse = parse_args(event, bprint_fmt, args);
|
2012-09-07 10:49:45 +08:00
|
|
|
}
|
|
|
|
|
2020-07-03 02:53:51 +08:00
|
|
|
print_event_cache(parse, s, data, size, event);
|
|
|
|
|
|
|
|
if (event->flags & TEP_EVENT_FL_ISBPRINT) {
|
|
|
|
free_parse_args(parse);
|
2012-04-06 06:47:53 +08:00
|
|
|
free_args(args);
|
|
|
|
free(bprint_fmt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
libtraceevent, perf tools: Changes in tep_print_event_* APIs
Libtraceevent APIs for printing various trace events information are
complicated, there are complex extra parameters. To control the way
event information is printed, the user should call a set of functions in
a specific sequence.
These APIs are reimplemented to provide a more simple interface for
printing event information.
Removed APIs:
tep_print_event_task()
tep_print_event_time()
tep_print_event_data()
tep_event_info()
tep_is_latency_format()
tep_set_latency_format()
tep_data_latency_format()
tep_set_print_raw()
A new API for printing event information is introduced:
void tep_print_event(struct tep_handle *tep, struct trace_seq *s,
struct tep_record *record, const char *fmt, ...);
where "fmt" is a printf-like format string, followed by the event
fields to be printed. Supported fields:
TEP_PRINT_PID, "%d" - event PID
TEP_PRINT_CPU, "%d" - event CPU
TEP_PRINT_COMM, "%s" - event command string
TEP_PRINT_NAME, "%s" - event name
TEP_PRINT_LATENCY, "%s" - event latency
TEP_PRINT_TIME, %d - event time stamp. A divisor and precision
can be specified as part of this format string:
"%precision.divisord". Example:
"%3.1000d" - divide the time by 1000 and print the first 3 digits
before the dot. Thus, the time stamp "123456000" will be printed as
"123.456"
TEP_PRINT_INFO, "%s" - event information.
TEP_PRINT_INFO_RAW, "%s" - event information, in raw format.
Example:
tep_print_event(tep, s, record, "%16s-%-5d [%03d] %s %6.1000d %s %s",
TEP_PRINT_COMM, TEP_PRINT_PID, TEP_PRINT_CPU,
TEP_PRINT_LATENCY, TEP_PRINT_TIME, TEP_PRINT_NAME, TEP_PRINT_INFO);
Output:
ls-11314 [005] d.h. 185207.366383 function __wake_up
Signed-off-by: Tzvetomir Stoyanov <tstoyanov@vmware.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: linux-trace-devel@vger.kernel.org
Cc: Patrick McLean <chutzpah@gentoo.org>
Link: http://lore.kernel.org/linux-trace-devel/20190801074959.22023-2-tz.stoyanov@gmail.com
Link: http://lore.kernel.org/lkml/20190805204355.041132030@goodmis.org
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2019-08-06 04:43:13 +08:00
|
|
|
/*
|
2012-04-06 06:47:53 +08:00
|
|
|
* This parses out the Latency format (interrupts disabled,
|
|
|
|
* need rescheduling, in hard/soft interrupt, preempt count
|
|
|
|
* and lock depth) and places it into the trace_seq.
|
|
|
|
*/
|
libtraceevent, perf tools: Changes in tep_print_event_* APIs
Libtraceevent APIs for printing various trace events information are
complicated, there are complex extra parameters. To control the way
event information is printed, the user should call a set of functions in
a specific sequence.
These APIs are reimplemented to provide a more simple interface for
printing event information.
Removed APIs:
tep_print_event_task()
tep_print_event_time()
tep_print_event_data()
tep_event_info()
tep_is_latency_format()
tep_set_latency_format()
tep_data_latency_format()
tep_set_print_raw()
A new API for printing event information is introduced:
void tep_print_event(struct tep_handle *tep, struct trace_seq *s,
struct tep_record *record, const char *fmt, ...);
where "fmt" is a printf-like format string, followed by the event
fields to be printed. Supported fields:
TEP_PRINT_PID, "%d" - event PID
TEP_PRINT_CPU, "%d" - event CPU
TEP_PRINT_COMM, "%s" - event command string
TEP_PRINT_NAME, "%s" - event name
TEP_PRINT_LATENCY, "%s" - event latency
TEP_PRINT_TIME, %d - event time stamp. A divisor and precision
can be specified as part of this format string:
"%precision.divisord". Example:
"%3.1000d" - divide the time by 1000 and print the first 3 digits
before the dot. Thus, the time stamp "123456000" will be printed as
"123.456"
TEP_PRINT_INFO, "%s" - event information.
TEP_PRINT_INFO_RAW, "%s" - event information, in raw format.
Example:
tep_print_event(tep, s, record, "%16s-%-5d [%03d] %s %6.1000d %s %s",
TEP_PRINT_COMM, TEP_PRINT_PID, TEP_PRINT_CPU,
TEP_PRINT_LATENCY, TEP_PRINT_TIME, TEP_PRINT_NAME, TEP_PRINT_INFO);
Output:
ls-11314 [005] d.h. 185207.366383 function __wake_up
Signed-off-by: Tzvetomir Stoyanov <tstoyanov@vmware.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: linux-trace-devel@vger.kernel.org
Cc: Patrick McLean <chutzpah@gentoo.org>
Link: http://lore.kernel.org/linux-trace-devel/20190801074959.22023-2-tz.stoyanov@gmail.com
Link: http://lore.kernel.org/lkml/20190805204355.041132030@goodmis.org
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2019-08-06 04:43:13 +08:00
|
|
|
static void data_latency_format(struct tep_handle *tep, struct trace_seq *s,
|
|
|
|
char *format, struct tep_record *record)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
|
|
|
static int check_lock_depth = 1;
|
2012-05-22 13:52:40 +08:00
|
|
|
static int check_migrate_disable = 1;
|
2012-04-06 06:47:53 +08:00
|
|
|
static int lock_depth_exists;
|
2012-05-22 13:52:40 +08:00
|
|
|
static int migrate_disable_exists;
|
2012-04-06 06:47:53 +08:00
|
|
|
unsigned int lat_flags;
|
libtraceevent, perf tools: Changes in tep_print_event_* APIs
Libtraceevent APIs for printing various trace events information are
complicated, there are complex extra parameters. To control the way
event information is printed, the user should call a set of functions in
a specific sequence.
These APIs are reimplemented to provide a more simple interface for
printing event information.
Removed APIs:
tep_print_event_task()
tep_print_event_time()
tep_print_event_data()
tep_event_info()
tep_is_latency_format()
tep_set_latency_format()
tep_data_latency_format()
tep_set_print_raw()
A new API for printing event information is introduced:
void tep_print_event(struct tep_handle *tep, struct trace_seq *s,
struct tep_record *record, const char *fmt, ...);
where "fmt" is a printf-like format string, followed by the event
fields to be printed. Supported fields:
TEP_PRINT_PID, "%d" - event PID
TEP_PRINT_CPU, "%d" - event CPU
TEP_PRINT_COMM, "%s" - event command string
TEP_PRINT_NAME, "%s" - event name
TEP_PRINT_LATENCY, "%s" - event latency
TEP_PRINT_TIME, %d - event time stamp. A divisor and precision
can be specified as part of this format string:
"%precision.divisord". Example:
"%3.1000d" - divide the time by 1000 and print the first 3 digits
before the dot. Thus, the time stamp "123456000" will be printed as
"123.456"
TEP_PRINT_INFO, "%s" - event information.
TEP_PRINT_INFO_RAW, "%s" - event information, in raw format.
Example:
tep_print_event(tep, s, record, "%16s-%-5d [%03d] %s %6.1000d %s %s",
TEP_PRINT_COMM, TEP_PRINT_PID, TEP_PRINT_CPU,
TEP_PRINT_LATENCY, TEP_PRINT_TIME, TEP_PRINT_NAME, TEP_PRINT_INFO);
Output:
ls-11314 [005] d.h. 185207.366383 function __wake_up
Signed-off-by: Tzvetomir Stoyanov <tstoyanov@vmware.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: linux-trace-devel@vger.kernel.org
Cc: Patrick McLean <chutzpah@gentoo.org>
Link: http://lore.kernel.org/linux-trace-devel/20190801074959.22023-2-tz.stoyanov@gmail.com
Link: http://lore.kernel.org/lkml/20190805204355.041132030@goodmis.org
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2019-08-06 04:43:13 +08:00
|
|
|
struct trace_seq sq;
|
2012-04-06 06:47:53 +08:00
|
|
|
unsigned int pc;
|
2018-11-22 19:29:37 +08:00
|
|
|
int lock_depth = 0;
|
|
|
|
int migrate_disable = 0;
|
2012-04-06 06:47:53 +08:00
|
|
|
int hardirq;
|
|
|
|
int softirq;
|
|
|
|
void *data = record->data;
|
|
|
|
|
libtraceevent, perf tools: Changes in tep_print_event_* APIs
Libtraceevent APIs for printing various trace events information are
complicated, there are complex extra parameters. To control the way
event information is printed, the user should call a set of functions in
a specific sequence.
These APIs are reimplemented to provide a more simple interface for
printing event information.
Removed APIs:
tep_print_event_task()
tep_print_event_time()
tep_print_event_data()
tep_event_info()
tep_is_latency_format()
tep_set_latency_format()
tep_data_latency_format()
tep_set_print_raw()
A new API for printing event information is introduced:
void tep_print_event(struct tep_handle *tep, struct trace_seq *s,
struct tep_record *record, const char *fmt, ...);
where "fmt" is a printf-like format string, followed by the event
fields to be printed. Supported fields:
TEP_PRINT_PID, "%d" - event PID
TEP_PRINT_CPU, "%d" - event CPU
TEP_PRINT_COMM, "%s" - event command string
TEP_PRINT_NAME, "%s" - event name
TEP_PRINT_LATENCY, "%s" - event latency
TEP_PRINT_TIME, %d - event time stamp. A divisor and precision
can be specified as part of this format string:
"%precision.divisord". Example:
"%3.1000d" - divide the time by 1000 and print the first 3 digits
before the dot. Thus, the time stamp "123456000" will be printed as
"123.456"
TEP_PRINT_INFO, "%s" - event information.
TEP_PRINT_INFO_RAW, "%s" - event information, in raw format.
Example:
tep_print_event(tep, s, record, "%16s-%-5d [%03d] %s %6.1000d %s %s",
TEP_PRINT_COMM, TEP_PRINT_PID, TEP_PRINT_CPU,
TEP_PRINT_LATENCY, TEP_PRINT_TIME, TEP_PRINT_NAME, TEP_PRINT_INFO);
Output:
ls-11314 [005] d.h. 185207.366383 function __wake_up
Signed-off-by: Tzvetomir Stoyanov <tstoyanov@vmware.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: linux-trace-devel@vger.kernel.org
Cc: Patrick McLean <chutzpah@gentoo.org>
Link: http://lore.kernel.org/linux-trace-devel/20190801074959.22023-2-tz.stoyanov@gmail.com
Link: http://lore.kernel.org/lkml/20190805204355.041132030@goodmis.org
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2019-08-06 04:43:13 +08:00
|
|
|
trace_seq_init(&sq);
|
2019-04-02 00:43:17 +08:00
|
|
|
lat_flags = parse_common_flags(tep, data);
|
|
|
|
pc = parse_common_pc(tep, data);
|
2012-04-06 06:47:53 +08:00
|
|
|
/* lock_depth may not always exist */
|
|
|
|
if (lock_depth_exists)
|
2019-04-02 00:43:17 +08:00
|
|
|
lock_depth = parse_common_lock_depth(tep, data);
|
2012-05-22 13:52:40 +08:00
|
|
|
else if (check_lock_depth) {
|
2019-04-02 00:43:17 +08:00
|
|
|
lock_depth = parse_common_lock_depth(tep, data);
|
2012-05-22 13:52:40 +08:00
|
|
|
if (lock_depth < 0)
|
|
|
|
check_lock_depth = 0;
|
|
|
|
else
|
|
|
|
lock_depth_exists = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* migrate_disable may not always exist */
|
|
|
|
if (migrate_disable_exists)
|
2019-04-02 00:43:17 +08:00
|
|
|
migrate_disable = parse_common_migrate_disable(tep, data);
|
2012-05-22 13:52:40 +08:00
|
|
|
else if (check_migrate_disable) {
|
2019-04-02 00:43:17 +08:00
|
|
|
migrate_disable = parse_common_migrate_disable(tep, data);
|
2012-05-22 13:52:40 +08:00
|
|
|
if (migrate_disable < 0)
|
|
|
|
check_migrate_disable = 0;
|
|
|
|
else
|
|
|
|
migrate_disable_exists = 1;
|
|
|
|
}
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
hardirq = lat_flags & TRACE_FLAG_HARDIRQ;
|
|
|
|
softirq = lat_flags & TRACE_FLAG_SOFTIRQ;
|
|
|
|
|
libtraceevent, perf tools: Changes in tep_print_event_* APIs
Libtraceevent APIs for printing various trace events information are
complicated, there are complex extra parameters. To control the way
event information is printed, the user should call a set of functions in
a specific sequence.
These APIs are reimplemented to provide a more simple interface for
printing event information.
Removed APIs:
tep_print_event_task()
tep_print_event_time()
tep_print_event_data()
tep_event_info()
tep_is_latency_format()
tep_set_latency_format()
tep_data_latency_format()
tep_set_print_raw()
A new API for printing event information is introduced:
void tep_print_event(struct tep_handle *tep, struct trace_seq *s,
struct tep_record *record, const char *fmt, ...);
where "fmt" is a printf-like format string, followed by the event
fields to be printed. Supported fields:
TEP_PRINT_PID, "%d" - event PID
TEP_PRINT_CPU, "%d" - event CPU
TEP_PRINT_COMM, "%s" - event command string
TEP_PRINT_NAME, "%s" - event name
TEP_PRINT_LATENCY, "%s" - event latency
TEP_PRINT_TIME, %d - event time stamp. A divisor and precision
can be specified as part of this format string:
"%precision.divisord". Example:
"%3.1000d" - divide the time by 1000 and print the first 3 digits
before the dot. Thus, the time stamp "123456000" will be printed as
"123.456"
TEP_PRINT_INFO, "%s" - event information.
TEP_PRINT_INFO_RAW, "%s" - event information, in raw format.
Example:
tep_print_event(tep, s, record, "%16s-%-5d [%03d] %s %6.1000d %s %s",
TEP_PRINT_COMM, TEP_PRINT_PID, TEP_PRINT_CPU,
TEP_PRINT_LATENCY, TEP_PRINT_TIME, TEP_PRINT_NAME, TEP_PRINT_INFO);
Output:
ls-11314 [005] d.h. 185207.366383 function __wake_up
Signed-off-by: Tzvetomir Stoyanov <tstoyanov@vmware.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: linux-trace-devel@vger.kernel.org
Cc: Patrick McLean <chutzpah@gentoo.org>
Link: http://lore.kernel.org/linux-trace-devel/20190801074959.22023-2-tz.stoyanov@gmail.com
Link: http://lore.kernel.org/lkml/20190805204355.041132030@goodmis.org
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2019-08-06 04:43:13 +08:00
|
|
|
trace_seq_printf(&sq, "%c%c%c",
|
2012-04-06 06:47:53 +08:00
|
|
|
(lat_flags & TRACE_FLAG_IRQS_OFF) ? 'd' :
|
|
|
|
(lat_flags & TRACE_FLAG_IRQS_NOSUPPORT) ?
|
|
|
|
'X' : '.',
|
|
|
|
(lat_flags & TRACE_FLAG_NEED_RESCHED) ?
|
|
|
|
'N' : '.',
|
|
|
|
(hardirq && softirq) ? 'H' :
|
|
|
|
hardirq ? 'h' : softirq ? 's' : '.');
|
|
|
|
|
|
|
|
if (pc)
|
libtraceevent, perf tools: Changes in tep_print_event_* APIs
Libtraceevent APIs for printing various trace events information are
complicated, there are complex extra parameters. To control the way
event information is printed, the user should call a set of functions in
a specific sequence.
These APIs are reimplemented to provide a more simple interface for
printing event information.
Removed APIs:
tep_print_event_task()
tep_print_event_time()
tep_print_event_data()
tep_event_info()
tep_is_latency_format()
tep_set_latency_format()
tep_data_latency_format()
tep_set_print_raw()
A new API for printing event information is introduced:
void tep_print_event(struct tep_handle *tep, struct trace_seq *s,
struct tep_record *record, const char *fmt, ...);
where "fmt" is a printf-like format string, followed by the event
fields to be printed. Supported fields:
TEP_PRINT_PID, "%d" - event PID
TEP_PRINT_CPU, "%d" - event CPU
TEP_PRINT_COMM, "%s" - event command string
TEP_PRINT_NAME, "%s" - event name
TEP_PRINT_LATENCY, "%s" - event latency
TEP_PRINT_TIME, %d - event time stamp. A divisor and precision
can be specified as part of this format string:
"%precision.divisord". Example:
"%3.1000d" - divide the time by 1000 and print the first 3 digits
before the dot. Thus, the time stamp "123456000" will be printed as
"123.456"
TEP_PRINT_INFO, "%s" - event information.
TEP_PRINT_INFO_RAW, "%s" - event information, in raw format.
Example:
tep_print_event(tep, s, record, "%16s-%-5d [%03d] %s %6.1000d %s %s",
TEP_PRINT_COMM, TEP_PRINT_PID, TEP_PRINT_CPU,
TEP_PRINT_LATENCY, TEP_PRINT_TIME, TEP_PRINT_NAME, TEP_PRINT_INFO);
Output:
ls-11314 [005] d.h. 185207.366383 function __wake_up
Signed-off-by: Tzvetomir Stoyanov <tstoyanov@vmware.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: linux-trace-devel@vger.kernel.org
Cc: Patrick McLean <chutzpah@gentoo.org>
Link: http://lore.kernel.org/linux-trace-devel/20190801074959.22023-2-tz.stoyanov@gmail.com
Link: http://lore.kernel.org/lkml/20190805204355.041132030@goodmis.org
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2019-08-06 04:43:13 +08:00
|
|
|
trace_seq_printf(&sq, "%x", pc);
|
2012-04-06 06:47:53 +08:00
|
|
|
else
|
libtraceevent, perf tools: Changes in tep_print_event_* APIs
Libtraceevent APIs for printing various trace events information are
complicated, there are complex extra parameters. To control the way
event information is printed, the user should call a set of functions in
a specific sequence.
These APIs are reimplemented to provide a more simple interface for
printing event information.
Removed APIs:
tep_print_event_task()
tep_print_event_time()
tep_print_event_data()
tep_event_info()
tep_is_latency_format()
tep_set_latency_format()
tep_data_latency_format()
tep_set_print_raw()
A new API for printing event information is introduced:
void tep_print_event(struct tep_handle *tep, struct trace_seq *s,
struct tep_record *record, const char *fmt, ...);
where "fmt" is a printf-like format string, followed by the event
fields to be printed. Supported fields:
TEP_PRINT_PID, "%d" - event PID
TEP_PRINT_CPU, "%d" - event CPU
TEP_PRINT_COMM, "%s" - event command string
TEP_PRINT_NAME, "%s" - event name
TEP_PRINT_LATENCY, "%s" - event latency
TEP_PRINT_TIME, %d - event time stamp. A divisor and precision
can be specified as part of this format string:
"%precision.divisord". Example:
"%3.1000d" - divide the time by 1000 and print the first 3 digits
before the dot. Thus, the time stamp "123456000" will be printed as
"123.456"
TEP_PRINT_INFO, "%s" - event information.
TEP_PRINT_INFO_RAW, "%s" - event information, in raw format.
Example:
tep_print_event(tep, s, record, "%16s-%-5d [%03d] %s %6.1000d %s %s",
TEP_PRINT_COMM, TEP_PRINT_PID, TEP_PRINT_CPU,
TEP_PRINT_LATENCY, TEP_PRINT_TIME, TEP_PRINT_NAME, TEP_PRINT_INFO);
Output:
ls-11314 [005] d.h. 185207.366383 function __wake_up
Signed-off-by: Tzvetomir Stoyanov <tstoyanov@vmware.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: linux-trace-devel@vger.kernel.org
Cc: Patrick McLean <chutzpah@gentoo.org>
Link: http://lore.kernel.org/linux-trace-devel/20190801074959.22023-2-tz.stoyanov@gmail.com
Link: http://lore.kernel.org/lkml/20190805204355.041132030@goodmis.org
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2019-08-06 04:43:13 +08:00
|
|
|
trace_seq_printf(&sq, ".");
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2012-05-22 13:52:40 +08:00
|
|
|
if (migrate_disable_exists) {
|
|
|
|
if (migrate_disable < 0)
|
libtraceevent, perf tools: Changes in tep_print_event_* APIs
Libtraceevent APIs for printing various trace events information are
complicated, there are complex extra parameters. To control the way
event information is printed, the user should call a set of functions in
a specific sequence.
These APIs are reimplemented to provide a more simple interface for
printing event information.
Removed APIs:
tep_print_event_task()
tep_print_event_time()
tep_print_event_data()
tep_event_info()
tep_is_latency_format()
tep_set_latency_format()
tep_data_latency_format()
tep_set_print_raw()
A new API for printing event information is introduced:
void tep_print_event(struct tep_handle *tep, struct trace_seq *s,
struct tep_record *record, const char *fmt, ...);
where "fmt" is a printf-like format string, followed by the event
fields to be printed. Supported fields:
TEP_PRINT_PID, "%d" - event PID
TEP_PRINT_CPU, "%d" - event CPU
TEP_PRINT_COMM, "%s" - event command string
TEP_PRINT_NAME, "%s" - event name
TEP_PRINT_LATENCY, "%s" - event latency
TEP_PRINT_TIME, %d - event time stamp. A divisor and precision
can be specified as part of this format string:
"%precision.divisord". Example:
"%3.1000d" - divide the time by 1000 and print the first 3 digits
before the dot. Thus, the time stamp "123456000" will be printed as
"123.456"
TEP_PRINT_INFO, "%s" - event information.
TEP_PRINT_INFO_RAW, "%s" - event information, in raw format.
Example:
tep_print_event(tep, s, record, "%16s-%-5d [%03d] %s %6.1000d %s %s",
TEP_PRINT_COMM, TEP_PRINT_PID, TEP_PRINT_CPU,
TEP_PRINT_LATENCY, TEP_PRINT_TIME, TEP_PRINT_NAME, TEP_PRINT_INFO);
Output:
ls-11314 [005] d.h. 185207.366383 function __wake_up
Signed-off-by: Tzvetomir Stoyanov <tstoyanov@vmware.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: linux-trace-devel@vger.kernel.org
Cc: Patrick McLean <chutzpah@gentoo.org>
Link: http://lore.kernel.org/linux-trace-devel/20190801074959.22023-2-tz.stoyanov@gmail.com
Link: http://lore.kernel.org/lkml/20190805204355.041132030@goodmis.org
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2019-08-06 04:43:13 +08:00
|
|
|
trace_seq_printf(&sq, ".");
|
2012-05-22 13:52:40 +08:00
|
|
|
else
|
libtraceevent, perf tools: Changes in tep_print_event_* APIs
Libtraceevent APIs for printing various trace events information are
complicated, there are complex extra parameters. To control the way
event information is printed, the user should call a set of functions in
a specific sequence.
These APIs are reimplemented to provide a more simple interface for
printing event information.
Removed APIs:
tep_print_event_task()
tep_print_event_time()
tep_print_event_data()
tep_event_info()
tep_is_latency_format()
tep_set_latency_format()
tep_data_latency_format()
tep_set_print_raw()
A new API for printing event information is introduced:
void tep_print_event(struct tep_handle *tep, struct trace_seq *s,
struct tep_record *record, const char *fmt, ...);
where "fmt" is a printf-like format string, followed by the event
fields to be printed. Supported fields:
TEP_PRINT_PID, "%d" - event PID
TEP_PRINT_CPU, "%d" - event CPU
TEP_PRINT_COMM, "%s" - event command string
TEP_PRINT_NAME, "%s" - event name
TEP_PRINT_LATENCY, "%s" - event latency
TEP_PRINT_TIME, %d - event time stamp. A divisor and precision
can be specified as part of this format string:
"%precision.divisord". Example:
"%3.1000d" - divide the time by 1000 and print the first 3 digits
before the dot. Thus, the time stamp "123456000" will be printed as
"123.456"
TEP_PRINT_INFO, "%s" - event information.
TEP_PRINT_INFO_RAW, "%s" - event information, in raw format.
Example:
tep_print_event(tep, s, record, "%16s-%-5d [%03d] %s %6.1000d %s %s",
TEP_PRINT_COMM, TEP_PRINT_PID, TEP_PRINT_CPU,
TEP_PRINT_LATENCY, TEP_PRINT_TIME, TEP_PRINT_NAME, TEP_PRINT_INFO);
Output:
ls-11314 [005] d.h. 185207.366383 function __wake_up
Signed-off-by: Tzvetomir Stoyanov <tstoyanov@vmware.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: linux-trace-devel@vger.kernel.org
Cc: Patrick McLean <chutzpah@gentoo.org>
Link: http://lore.kernel.org/linux-trace-devel/20190801074959.22023-2-tz.stoyanov@gmail.com
Link: http://lore.kernel.org/lkml/20190805204355.041132030@goodmis.org
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2019-08-06 04:43:13 +08:00
|
|
|
trace_seq_printf(&sq, "%d", migrate_disable);
|
2012-05-22 13:52:40 +08:00
|
|
|
}
|
|
|
|
|
2012-04-06 06:47:53 +08:00
|
|
|
if (lock_depth_exists) {
|
|
|
|
if (lock_depth < 0)
|
libtraceevent, perf tools: Changes in tep_print_event_* APIs
Libtraceevent APIs for printing various trace events information are
complicated, there are complex extra parameters. To control the way
event information is printed, the user should call a set of functions in
a specific sequence.
These APIs are reimplemented to provide a more simple interface for
printing event information.
Removed APIs:
tep_print_event_task()
tep_print_event_time()
tep_print_event_data()
tep_event_info()
tep_is_latency_format()
tep_set_latency_format()
tep_data_latency_format()
tep_set_print_raw()
A new API for printing event information is introduced:
void tep_print_event(struct tep_handle *tep, struct trace_seq *s,
struct tep_record *record, const char *fmt, ...);
where "fmt" is a printf-like format string, followed by the event
fields to be printed. Supported fields:
TEP_PRINT_PID, "%d" - event PID
TEP_PRINT_CPU, "%d" - event CPU
TEP_PRINT_COMM, "%s" - event command string
TEP_PRINT_NAME, "%s" - event name
TEP_PRINT_LATENCY, "%s" - event latency
TEP_PRINT_TIME, %d - event time stamp. A divisor and precision
can be specified as part of this format string:
"%precision.divisord". Example:
"%3.1000d" - divide the time by 1000 and print the first 3 digits
before the dot. Thus, the time stamp "123456000" will be printed as
"123.456"
TEP_PRINT_INFO, "%s" - event information.
TEP_PRINT_INFO_RAW, "%s" - event information, in raw format.
Example:
tep_print_event(tep, s, record, "%16s-%-5d [%03d] %s %6.1000d %s %s",
TEP_PRINT_COMM, TEP_PRINT_PID, TEP_PRINT_CPU,
TEP_PRINT_LATENCY, TEP_PRINT_TIME, TEP_PRINT_NAME, TEP_PRINT_INFO);
Output:
ls-11314 [005] d.h. 185207.366383 function __wake_up
Signed-off-by: Tzvetomir Stoyanov <tstoyanov@vmware.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: linux-trace-devel@vger.kernel.org
Cc: Patrick McLean <chutzpah@gentoo.org>
Link: http://lore.kernel.org/linux-trace-devel/20190801074959.22023-2-tz.stoyanov@gmail.com
Link: http://lore.kernel.org/lkml/20190805204355.041132030@goodmis.org
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2019-08-06 04:43:13 +08:00
|
|
|
trace_seq_printf(&sq, ".");
|
2012-04-06 06:47:53 +08:00
|
|
|
else
|
libtraceevent, perf tools: Changes in tep_print_event_* APIs
Libtraceevent APIs for printing various trace events information are
complicated, there are complex extra parameters. To control the way
event information is printed, the user should call a set of functions in
a specific sequence.
These APIs are reimplemented to provide a more simple interface for
printing event information.
Removed APIs:
tep_print_event_task()
tep_print_event_time()
tep_print_event_data()
tep_event_info()
tep_is_latency_format()
tep_set_latency_format()
tep_data_latency_format()
tep_set_print_raw()
A new API for printing event information is introduced:
void tep_print_event(struct tep_handle *tep, struct trace_seq *s,
struct tep_record *record, const char *fmt, ...);
where "fmt" is a printf-like format string, followed by the event
fields to be printed. Supported fields:
TEP_PRINT_PID, "%d" - event PID
TEP_PRINT_CPU, "%d" - event CPU
TEP_PRINT_COMM, "%s" - event command string
TEP_PRINT_NAME, "%s" - event name
TEP_PRINT_LATENCY, "%s" - event latency
TEP_PRINT_TIME, %d - event time stamp. A divisor and precision
can be specified as part of this format string:
"%precision.divisord". Example:
"%3.1000d" - divide the time by 1000 and print the first 3 digits
before the dot. Thus, the time stamp "123456000" will be printed as
"123.456"
TEP_PRINT_INFO, "%s" - event information.
TEP_PRINT_INFO_RAW, "%s" - event information, in raw format.
Example:
tep_print_event(tep, s, record, "%16s-%-5d [%03d] %s %6.1000d %s %s",
TEP_PRINT_COMM, TEP_PRINT_PID, TEP_PRINT_CPU,
TEP_PRINT_LATENCY, TEP_PRINT_TIME, TEP_PRINT_NAME, TEP_PRINT_INFO);
Output:
ls-11314 [005] d.h. 185207.366383 function __wake_up
Signed-off-by: Tzvetomir Stoyanov <tstoyanov@vmware.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: linux-trace-devel@vger.kernel.org
Cc: Patrick McLean <chutzpah@gentoo.org>
Link: http://lore.kernel.org/linux-trace-devel/20190801074959.22023-2-tz.stoyanov@gmail.com
Link: http://lore.kernel.org/lkml/20190805204355.041132030@goodmis.org
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2019-08-06 04:43:13 +08:00
|
|
|
trace_seq_printf(&sq, "%d", lock_depth);
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
|
libtraceevent, perf tools: Changes in tep_print_event_* APIs
Libtraceevent APIs for printing various trace events information are
complicated, there are complex extra parameters. To control the way
event information is printed, the user should call a set of functions in
a specific sequence.
These APIs are reimplemented to provide a more simple interface for
printing event information.
Removed APIs:
tep_print_event_task()
tep_print_event_time()
tep_print_event_data()
tep_event_info()
tep_is_latency_format()
tep_set_latency_format()
tep_data_latency_format()
tep_set_print_raw()
A new API for printing event information is introduced:
void tep_print_event(struct tep_handle *tep, struct trace_seq *s,
struct tep_record *record, const char *fmt, ...);
where "fmt" is a printf-like format string, followed by the event
fields to be printed. Supported fields:
TEP_PRINT_PID, "%d" - event PID
TEP_PRINT_CPU, "%d" - event CPU
TEP_PRINT_COMM, "%s" - event command string
TEP_PRINT_NAME, "%s" - event name
TEP_PRINT_LATENCY, "%s" - event latency
TEP_PRINT_TIME, %d - event time stamp. A divisor and precision
can be specified as part of this format string:
"%precision.divisord". Example:
"%3.1000d" - divide the time by 1000 and print the first 3 digits
before the dot. Thus, the time stamp "123456000" will be printed as
"123.456"
TEP_PRINT_INFO, "%s" - event information.
TEP_PRINT_INFO_RAW, "%s" - event information, in raw format.
Example:
tep_print_event(tep, s, record, "%16s-%-5d [%03d] %s %6.1000d %s %s",
TEP_PRINT_COMM, TEP_PRINT_PID, TEP_PRINT_CPU,
TEP_PRINT_LATENCY, TEP_PRINT_TIME, TEP_PRINT_NAME, TEP_PRINT_INFO);
Output:
ls-11314 [005] d.h. 185207.366383 function __wake_up
Signed-off-by: Tzvetomir Stoyanov <tstoyanov@vmware.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: linux-trace-devel@vger.kernel.org
Cc: Patrick McLean <chutzpah@gentoo.org>
Link: http://lore.kernel.org/linux-trace-devel/20190801074959.22023-2-tz.stoyanov@gmail.com
Link: http://lore.kernel.org/lkml/20190805204355.041132030@goodmis.org
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2019-08-06 04:43:13 +08:00
|
|
|
if (sq.state == TRACE_SEQ__MEM_ALLOC_FAILED) {
|
|
|
|
s->state = TRACE_SEQ__MEM_ALLOC_FAILED;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
trace_seq_terminate(&sq);
|
|
|
|
trace_seq_puts(s, sq.buffer);
|
|
|
|
trace_seq_destroy(&sq);
|
2012-04-06 06:47:53 +08:00
|
|
|
trace_seq_terminate(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
tools lib traceevent: Rename pevent_data_ APIs
In order to make libtraceevent into a proper library, variables, data
structures and functions require a unique prefix to prevent name space
conflicts. That prefix will be "tep_" and not "pevent_". This changes
APIs: pevent_data_lat_fmt, pevent_data_type, pevent_data_event_from_type,
pevent_data_pid, pevent_data_preempt_count, pevent_data_flags,
pevent_data_comm_from_pid, pevent_data_pid_from_comm, pevent_cmdline_pid
Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
Cc: linux-trace-devel@vger.kernel.org
Link: http://lkml.kernel.org/r/20180808180702.678020020@goodmis.org
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2018-08-09 02:03:03 +08:00
|
|
|
* tep_data_type - parse out the given event type
|
2019-04-02 00:43:17 +08:00
|
|
|
* @tep: a handle to the trace event parser context
|
2012-04-06 06:47:53 +08:00
|
|
|
* @rec: the record to read from
|
|
|
|
*
|
|
|
|
* This returns the event id from the @rec.
|
|
|
|
*/
|
2019-04-02 00:43:17 +08:00
|
|
|
int tep_data_type(struct tep_handle *tep, struct tep_record *rec)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
2019-04-02 00:43:17 +08:00
|
|
|
return trace_parse_common_type(tep, rec->data);
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
tools lib traceevent: Rename pevent_data_ APIs
In order to make libtraceevent into a proper library, variables, data
structures and functions require a unique prefix to prevent name space
conflicts. That prefix will be "tep_" and not "pevent_". This changes
APIs: pevent_data_lat_fmt, pevent_data_type, pevent_data_event_from_type,
pevent_data_pid, pevent_data_preempt_count, pevent_data_flags,
pevent_data_comm_from_pid, pevent_data_pid_from_comm, pevent_cmdline_pid
Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
Cc: linux-trace-devel@vger.kernel.org
Link: http://lkml.kernel.org/r/20180808180702.678020020@goodmis.org
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2018-08-09 02:03:03 +08:00
|
|
|
* tep_data_pid - parse the PID from record
|
2019-04-02 00:43:17 +08:00
|
|
|
* @tep: a handle to the trace event parser context
|
2012-04-06 06:47:53 +08:00
|
|
|
* @rec: the record to parse
|
|
|
|
*
|
2016-11-23 00:31:58 +08:00
|
|
|
* This returns the PID from a record.
|
2012-04-06 06:47:53 +08:00
|
|
|
*/
|
2019-04-02 00:43:17 +08:00
|
|
|
int tep_data_pid(struct tep_handle *tep, struct tep_record *rec)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
2019-04-02 00:43:17 +08:00
|
|
|
return parse_common_pid(tep, rec->data);
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
|
2016-11-23 00:31:58 +08:00
|
|
|
/**
|
tools lib traceevent: Rename pevent_data_ APIs
In order to make libtraceevent into a proper library, variables, data
structures and functions require a unique prefix to prevent name space
conflicts. That prefix will be "tep_" and not "pevent_". This changes
APIs: pevent_data_lat_fmt, pevent_data_type, pevent_data_event_from_type,
pevent_data_pid, pevent_data_preempt_count, pevent_data_flags,
pevent_data_comm_from_pid, pevent_data_pid_from_comm, pevent_cmdline_pid
Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
Cc: linux-trace-devel@vger.kernel.org
Link: http://lkml.kernel.org/r/20180808180702.678020020@goodmis.org
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2018-08-09 02:03:03 +08:00
|
|
|
* tep_data_preempt_count - parse the preempt count from the record
|
2019-04-02 00:43:17 +08:00
|
|
|
* @tep: a handle to the trace event parser context
|
2016-11-23 00:31:58 +08:00
|
|
|
* @rec: the record to parse
|
|
|
|
*
|
|
|
|
* This returns the preempt count from a record.
|
|
|
|
*/
|
2019-04-02 00:43:17 +08:00
|
|
|
int tep_data_preempt_count(struct tep_handle *tep, struct tep_record *rec)
|
2016-11-23 00:31:58 +08:00
|
|
|
{
|
2019-04-02 00:43:17 +08:00
|
|
|
return parse_common_pc(tep, rec->data);
|
2016-11-23 00:31:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
tools lib traceevent: Rename pevent_data_ APIs
In order to make libtraceevent into a proper library, variables, data
structures and functions require a unique prefix to prevent name space
conflicts. That prefix will be "tep_" and not "pevent_". This changes
APIs: pevent_data_lat_fmt, pevent_data_type, pevent_data_event_from_type,
pevent_data_pid, pevent_data_preempt_count, pevent_data_flags,
pevent_data_comm_from_pid, pevent_data_pid_from_comm, pevent_cmdline_pid
Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
Cc: linux-trace-devel@vger.kernel.org
Link: http://lkml.kernel.org/r/20180808180702.678020020@goodmis.org
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2018-08-09 02:03:03 +08:00
|
|
|
* tep_data_flags - parse the latency flags from the record
|
2019-04-02 00:43:17 +08:00
|
|
|
* @tep: a handle to the trace event parser context
|
2016-11-23 00:31:58 +08:00
|
|
|
* @rec: the record to parse
|
|
|
|
*
|
|
|
|
* This returns the latency flags from a record.
|
|
|
|
*
|
|
|
|
* Use trace_flag_type enum for the flags (see event-parse.h).
|
|
|
|
*/
|
2019-04-02 00:43:17 +08:00
|
|
|
int tep_data_flags(struct tep_handle *tep, struct tep_record *rec)
|
2016-11-23 00:31:58 +08:00
|
|
|
{
|
2019-04-02 00:43:17 +08:00
|
|
|
return parse_common_flags(tep, rec->data);
|
2016-11-23 00:31:58 +08:00
|
|
|
}
|
|
|
|
|
2012-04-06 06:47:53 +08:00
|
|
|
/**
|
tools lib traceevent: Rename pevent_data_ APIs
In order to make libtraceevent into a proper library, variables, data
structures and functions require a unique prefix to prevent name space
conflicts. That prefix will be "tep_" and not "pevent_". This changes
APIs: pevent_data_lat_fmt, pevent_data_type, pevent_data_event_from_type,
pevent_data_pid, pevent_data_preempt_count, pevent_data_flags,
pevent_data_comm_from_pid, pevent_data_pid_from_comm, pevent_cmdline_pid
Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
Cc: linux-trace-devel@vger.kernel.org
Link: http://lkml.kernel.org/r/20180808180702.678020020@goodmis.org
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2018-08-09 02:03:03 +08:00
|
|
|
* tep_data_comm_from_pid - return the command line from PID
|
2019-04-02 00:43:17 +08:00
|
|
|
* @tep: a handle to the trace event parser context
|
2012-04-06 06:47:53 +08:00
|
|
|
* @pid: the PID of the task to search for
|
|
|
|
*
|
|
|
|
* This returns a pointer to the command line that has the given
|
|
|
|
* @pid.
|
|
|
|
*/
|
2019-04-02 00:43:17 +08:00
|
|
|
const char *tep_data_comm_from_pid(struct tep_handle *tep, int pid)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
|
|
|
const char *comm;
|
|
|
|
|
2019-04-02 00:43:17 +08:00
|
|
|
comm = find_cmdline(tep, pid);
|
2012-04-06 06:47:53 +08:00
|
|
|
return comm;
|
|
|
|
}
|
|
|
|
|
2018-12-01 12:08:09 +08:00
|
|
|
static struct tep_cmdline *
|
2019-04-02 00:43:20 +08:00
|
|
|
pid_from_cmdlist(struct tep_handle *tep, const char *comm, struct tep_cmdline *next)
|
2015-03-24 21:57:52 +08:00
|
|
|
{
|
|
|
|
struct cmdline_list *cmdlist = (struct cmdline_list *)next;
|
|
|
|
|
|
|
|
if (cmdlist)
|
|
|
|
cmdlist = cmdlist->next;
|
|
|
|
else
|
2019-04-02 00:43:20 +08:00
|
|
|
cmdlist = tep->cmdlist;
|
2015-03-24 21:57:52 +08:00
|
|
|
|
|
|
|
while (cmdlist && strcmp(cmdlist->comm, comm) != 0)
|
|
|
|
cmdlist = cmdlist->next;
|
|
|
|
|
2018-12-01 12:08:09 +08:00
|
|
|
return (struct tep_cmdline *)cmdlist;
|
2015-03-24 21:57:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
tools lib traceevent: Rename pevent_data_ APIs
In order to make libtraceevent into a proper library, variables, data
structures and functions require a unique prefix to prevent name space
conflicts. That prefix will be "tep_" and not "pevent_". This changes
APIs: pevent_data_lat_fmt, pevent_data_type, pevent_data_event_from_type,
pevent_data_pid, pevent_data_preempt_count, pevent_data_flags,
pevent_data_comm_from_pid, pevent_data_pid_from_comm, pevent_cmdline_pid
Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
Cc: linux-trace-devel@vger.kernel.org
Link: http://lkml.kernel.org/r/20180808180702.678020020@goodmis.org
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2018-08-09 02:03:03 +08:00
|
|
|
* tep_data_pid_from_comm - return the pid from a given comm
|
2019-04-02 00:43:17 +08:00
|
|
|
* @tep: a handle to the trace event parser context
|
2015-03-24 21:57:52 +08:00
|
|
|
* @comm: the cmdline to find the pid from
|
|
|
|
* @next: the cmdline structure to find the next comm
|
|
|
|
*
|
|
|
|
* This returns the cmdline structure that holds a pid for a given
|
|
|
|
* comm, or NULL if none found. As there may be more than one pid for
|
|
|
|
* a given comm, the result of this call can be passed back into
|
2018-12-03 18:22:00 +08:00
|
|
|
* a recurring call in the @next parameter, and then it will find the
|
2015-03-24 21:57:52 +08:00
|
|
|
* next pid.
|
2018-12-03 18:22:00 +08:00
|
|
|
* Also, it does a linear search, so it may be slow.
|
2015-03-24 21:57:52 +08:00
|
|
|
*/
|
2019-04-02 00:43:17 +08:00
|
|
|
struct tep_cmdline *tep_data_pid_from_comm(struct tep_handle *tep, const char *comm,
|
2018-12-01 12:08:09 +08:00
|
|
|
struct tep_cmdline *next)
|
2015-03-24 21:57:52 +08:00
|
|
|
{
|
2018-12-01 12:08:09 +08:00
|
|
|
struct tep_cmdline *cmdline;
|
2015-03-24 21:57:52 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If the cmdlines have not been converted yet, then use
|
|
|
|
* the list.
|
|
|
|
*/
|
2019-04-02 00:43:17 +08:00
|
|
|
if (!tep->cmdlines)
|
|
|
|
return pid_from_cmdlist(tep, comm, next);
|
2015-03-24 21:57:52 +08:00
|
|
|
|
|
|
|
if (next) {
|
|
|
|
/*
|
|
|
|
* The next pointer could have been still from
|
|
|
|
* a previous call before cmdlines were created
|
|
|
|
*/
|
2019-04-02 00:43:17 +08:00
|
|
|
if (next < tep->cmdlines ||
|
|
|
|
next >= tep->cmdlines + tep->cmdline_count)
|
2015-03-24 21:57:52 +08:00
|
|
|
next = NULL;
|
|
|
|
else
|
|
|
|
cmdline = next++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!next)
|
2019-04-02 00:43:17 +08:00
|
|
|
cmdline = tep->cmdlines;
|
2015-03-24 21:57:52 +08:00
|
|
|
|
2019-04-02 00:43:17 +08:00
|
|
|
while (cmdline < tep->cmdlines + tep->cmdline_count) {
|
2015-03-24 21:57:52 +08:00
|
|
|
if (strcmp(cmdline->comm, comm) == 0)
|
|
|
|
return cmdline;
|
|
|
|
cmdline++;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
tools lib traceevent: Rename pevent_data_ APIs
In order to make libtraceevent into a proper library, variables, data
structures and functions require a unique prefix to prevent name space
conflicts. That prefix will be "tep_" and not "pevent_". This changes
APIs: pevent_data_lat_fmt, pevent_data_type, pevent_data_event_from_type,
pevent_data_pid, pevent_data_preempt_count, pevent_data_flags,
pevent_data_comm_from_pid, pevent_data_pid_from_comm, pevent_cmdline_pid
Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
Cc: linux-trace-devel@vger.kernel.org
Link: http://lkml.kernel.org/r/20180808180702.678020020@goodmis.org
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2018-08-09 02:03:03 +08:00
|
|
|
* tep_cmdline_pid - return the pid associated to a given cmdline
|
2019-04-02 00:43:17 +08:00
|
|
|
* @tep: a handle to the trace event parser context
|
2015-03-24 21:57:52 +08:00
|
|
|
* @cmdline: The cmdline structure to get the pid from
|
|
|
|
*
|
|
|
|
* Returns the pid for a give cmdline. If @cmdline is NULL, then
|
|
|
|
* -1 is returned.
|
|
|
|
*/
|
2019-04-02 00:43:17 +08:00
|
|
|
int tep_cmdline_pid(struct tep_handle *tep, struct tep_cmdline *cmdline)
|
2015-03-24 21:57:52 +08:00
|
|
|
{
|
|
|
|
struct cmdline_list *cmdlist = (struct cmdline_list *)cmdline;
|
|
|
|
|
|
|
|
if (!cmdline)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If cmdlines have not been created yet, or cmdline is
|
|
|
|
* not part of the array, then treat it as a cmdlist instead.
|
|
|
|
*/
|
2019-04-02 00:43:17 +08:00
|
|
|
if (!tep->cmdlines ||
|
|
|
|
cmdline < tep->cmdlines ||
|
|
|
|
cmdline >= tep->cmdlines + tep->cmdline_count)
|
2015-03-24 21:57:52 +08:00
|
|
|
return cmdlist->pid;
|
|
|
|
|
|
|
|
return cmdline->pid;
|
|
|
|
}
|
|
|
|
|
libtraceevent, perf tools: Changes in tep_print_event_* APIs
Libtraceevent APIs for printing various trace events information are
complicated, there are complex extra parameters. To control the way
event information is printed, the user should call a set of functions in
a specific sequence.
These APIs are reimplemented to provide a more simple interface for
printing event information.
Removed APIs:
tep_print_event_task()
tep_print_event_time()
tep_print_event_data()
tep_event_info()
tep_is_latency_format()
tep_set_latency_format()
tep_data_latency_format()
tep_set_print_raw()
A new API for printing event information is introduced:
void tep_print_event(struct tep_handle *tep, struct trace_seq *s,
struct tep_record *record, const char *fmt, ...);
where "fmt" is a printf-like format string, followed by the event
fields to be printed. Supported fields:
TEP_PRINT_PID, "%d" - event PID
TEP_PRINT_CPU, "%d" - event CPU
TEP_PRINT_COMM, "%s" - event command string
TEP_PRINT_NAME, "%s" - event name
TEP_PRINT_LATENCY, "%s" - event latency
TEP_PRINT_TIME, %d - event time stamp. A divisor and precision
can be specified as part of this format string:
"%precision.divisord". Example:
"%3.1000d" - divide the time by 1000 and print the first 3 digits
before the dot. Thus, the time stamp "123456000" will be printed as
"123.456"
TEP_PRINT_INFO, "%s" - event information.
TEP_PRINT_INFO_RAW, "%s" - event information, in raw format.
Example:
tep_print_event(tep, s, record, "%16s-%-5d [%03d] %s %6.1000d %s %s",
TEP_PRINT_COMM, TEP_PRINT_PID, TEP_PRINT_CPU,
TEP_PRINT_LATENCY, TEP_PRINT_TIME, TEP_PRINT_NAME, TEP_PRINT_INFO);
Output:
ls-11314 [005] d.h. 185207.366383 function __wake_up
Signed-off-by: Tzvetomir Stoyanov <tstoyanov@vmware.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: linux-trace-devel@vger.kernel.org
Cc: Patrick McLean <chutzpah@gentoo.org>
Link: http://lore.kernel.org/linux-trace-devel/20190801074959.22023-2-tz.stoyanov@gmail.com
Link: http://lore.kernel.org/lkml/20190805204355.041132030@goodmis.org
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2019-08-06 04:43:13 +08:00
|
|
|
/*
|
2012-04-06 06:47:53 +08:00
|
|
|
* This parses the raw @data using the given @event information and
|
|
|
|
* writes the print format into the trace_seq.
|
|
|
|
*/
|
libtraceevent, perf tools: Changes in tep_print_event_* APIs
Libtraceevent APIs for printing various trace events information are
complicated, there are complex extra parameters. To control the way
event information is printed, the user should call a set of functions in
a specific sequence.
These APIs are reimplemented to provide a more simple interface for
printing event information.
Removed APIs:
tep_print_event_task()
tep_print_event_time()
tep_print_event_data()
tep_event_info()
tep_is_latency_format()
tep_set_latency_format()
tep_data_latency_format()
tep_set_print_raw()
A new API for printing event information is introduced:
void tep_print_event(struct tep_handle *tep, struct trace_seq *s,
struct tep_record *record, const char *fmt, ...);
where "fmt" is a printf-like format string, followed by the event
fields to be printed. Supported fields:
TEP_PRINT_PID, "%d" - event PID
TEP_PRINT_CPU, "%d" - event CPU
TEP_PRINT_COMM, "%s" - event command string
TEP_PRINT_NAME, "%s" - event name
TEP_PRINT_LATENCY, "%s" - event latency
TEP_PRINT_TIME, %d - event time stamp. A divisor and precision
can be specified as part of this format string:
"%precision.divisord". Example:
"%3.1000d" - divide the time by 1000 and print the first 3 digits
before the dot. Thus, the time stamp "123456000" will be printed as
"123.456"
TEP_PRINT_INFO, "%s" - event information.
TEP_PRINT_INFO_RAW, "%s" - event information, in raw format.
Example:
tep_print_event(tep, s, record, "%16s-%-5d [%03d] %s %6.1000d %s %s",
TEP_PRINT_COMM, TEP_PRINT_PID, TEP_PRINT_CPU,
TEP_PRINT_LATENCY, TEP_PRINT_TIME, TEP_PRINT_NAME, TEP_PRINT_INFO);
Output:
ls-11314 [005] d.h. 185207.366383 function __wake_up
Signed-off-by: Tzvetomir Stoyanov <tstoyanov@vmware.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: linux-trace-devel@vger.kernel.org
Cc: Patrick McLean <chutzpah@gentoo.org>
Link: http://lore.kernel.org/linux-trace-devel/20190801074959.22023-2-tz.stoyanov@gmail.com
Link: http://lore.kernel.org/lkml/20190805204355.041132030@goodmis.org
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2019-08-06 04:43:13 +08:00
|
|
|
static void print_event_info(struct trace_seq *s, char *format, bool raw,
|
|
|
|
struct tep_event *event, struct tep_record *record)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
|
|
|
int print_pretty = 1;
|
|
|
|
|
libtraceevent, perf tools: Changes in tep_print_event_* APIs
Libtraceevent APIs for printing various trace events information are
complicated, there are complex extra parameters. To control the way
event information is printed, the user should call a set of functions in
a specific sequence.
These APIs are reimplemented to provide a more simple interface for
printing event information.
Removed APIs:
tep_print_event_task()
tep_print_event_time()
tep_print_event_data()
tep_event_info()
tep_is_latency_format()
tep_set_latency_format()
tep_data_latency_format()
tep_set_print_raw()
A new API for printing event information is introduced:
void tep_print_event(struct tep_handle *tep, struct trace_seq *s,
struct tep_record *record, const char *fmt, ...);
where "fmt" is a printf-like format string, followed by the event
fields to be printed. Supported fields:
TEP_PRINT_PID, "%d" - event PID
TEP_PRINT_CPU, "%d" - event CPU
TEP_PRINT_COMM, "%s" - event command string
TEP_PRINT_NAME, "%s" - event name
TEP_PRINT_LATENCY, "%s" - event latency
TEP_PRINT_TIME, %d - event time stamp. A divisor and precision
can be specified as part of this format string:
"%precision.divisord". Example:
"%3.1000d" - divide the time by 1000 and print the first 3 digits
before the dot. Thus, the time stamp "123456000" will be printed as
"123.456"
TEP_PRINT_INFO, "%s" - event information.
TEP_PRINT_INFO_RAW, "%s" - event information, in raw format.
Example:
tep_print_event(tep, s, record, "%16s-%-5d [%03d] %s %6.1000d %s %s",
TEP_PRINT_COMM, TEP_PRINT_PID, TEP_PRINT_CPU,
TEP_PRINT_LATENCY, TEP_PRINT_TIME, TEP_PRINT_NAME, TEP_PRINT_INFO);
Output:
ls-11314 [005] d.h. 185207.366383 function __wake_up
Signed-off-by: Tzvetomir Stoyanov <tstoyanov@vmware.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: linux-trace-devel@vger.kernel.org
Cc: Patrick McLean <chutzpah@gentoo.org>
Link: http://lore.kernel.org/linux-trace-devel/20190801074959.22023-2-tz.stoyanov@gmail.com
Link: http://lore.kernel.org/lkml/20190805204355.041132030@goodmis.org
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2019-08-06 04:43:13 +08:00
|
|
|
if (raw || (event->flags & TEP_EVENT_FL_PRINTRAW))
|
2018-08-09 02:02:52 +08:00
|
|
|
tep_print_fields(s, record->data, record->size, event);
|
2012-04-06 06:47:53 +08:00
|
|
|
else {
|
|
|
|
|
2018-09-20 02:56:48 +08:00
|
|
|
if (event->handler && !(event->flags & TEP_EVENT_FL_NOHANDLE))
|
2012-04-06 06:47:53 +08:00
|
|
|
print_pretty = event->handler(s, record, event,
|
|
|
|
event->context);
|
|
|
|
|
|
|
|
if (print_pretty)
|
|
|
|
pretty_print(s, record->data, record->size, event);
|
|
|
|
}
|
|
|
|
|
|
|
|
trace_seq_terminate(s);
|
|
|
|
}
|
|
|
|
|
2016-02-29 22:01:28 +08:00
|
|
|
/**
|
2018-08-09 02:03:05 +08:00
|
|
|
* tep_find_event_by_record - return the event from a given record
|
2019-04-02 00:43:17 +08:00
|
|
|
* @tep: a handle to the trace event parser context
|
2016-02-29 22:01:28 +08:00
|
|
|
* @record: The record to get the event from
|
|
|
|
*
|
|
|
|
* Returns the associated event for a given record, or NULL if non is
|
|
|
|
* is found.
|
|
|
|
*/
|
2018-11-30 23:44:07 +08:00
|
|
|
struct tep_event *
|
2019-04-02 00:43:17 +08:00
|
|
|
tep_find_event_by_record(struct tep_handle *tep, struct tep_record *record)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
|
|
|
int type;
|
|
|
|
|
|
|
|
if (record->size < 0) {
|
|
|
|
do_warning("ug! negative record size %d", record->size);
|
2016-02-29 22:01:28 +08:00
|
|
|
return NULL;
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
|
2019-04-02 00:43:17 +08:00
|
|
|
type = trace_parse_common_type(tep, record->data);
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2019-04-02 00:43:17 +08:00
|
|
|
return tep_find_event(tep, type);
|
2016-02-29 22:01:28 +08:00
|
|
|
}
|
|
|
|
|
libtraceevent, perf tools: Changes in tep_print_event_* APIs
Libtraceevent APIs for printing various trace events information are
complicated, there are complex extra parameters. To control the way
event information is printed, the user should call a set of functions in
a specific sequence.
These APIs are reimplemented to provide a more simple interface for
printing event information.
Removed APIs:
tep_print_event_task()
tep_print_event_time()
tep_print_event_data()
tep_event_info()
tep_is_latency_format()
tep_set_latency_format()
tep_data_latency_format()
tep_set_print_raw()
A new API for printing event information is introduced:
void tep_print_event(struct tep_handle *tep, struct trace_seq *s,
struct tep_record *record, const char *fmt, ...);
where "fmt" is a printf-like format string, followed by the event
fields to be printed. Supported fields:
TEP_PRINT_PID, "%d" - event PID
TEP_PRINT_CPU, "%d" - event CPU
TEP_PRINT_COMM, "%s" - event command string
TEP_PRINT_NAME, "%s" - event name
TEP_PRINT_LATENCY, "%s" - event latency
TEP_PRINT_TIME, %d - event time stamp. A divisor and precision
can be specified as part of this format string:
"%precision.divisord". Example:
"%3.1000d" - divide the time by 1000 and print the first 3 digits
before the dot. Thus, the time stamp "123456000" will be printed as
"123.456"
TEP_PRINT_INFO, "%s" - event information.
TEP_PRINT_INFO_RAW, "%s" - event information, in raw format.
Example:
tep_print_event(tep, s, record, "%16s-%-5d [%03d] %s %6.1000d %s %s",
TEP_PRINT_COMM, TEP_PRINT_PID, TEP_PRINT_CPU,
TEP_PRINT_LATENCY, TEP_PRINT_TIME, TEP_PRINT_NAME, TEP_PRINT_INFO);
Output:
ls-11314 [005] d.h. 185207.366383 function __wake_up
Signed-off-by: Tzvetomir Stoyanov <tstoyanov@vmware.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: linux-trace-devel@vger.kernel.org
Cc: Patrick McLean <chutzpah@gentoo.org>
Link: http://lore.kernel.org/linux-trace-devel/20190801074959.22023-2-tz.stoyanov@gmail.com
Link: http://lore.kernel.org/lkml/20190805204355.041132030@goodmis.org
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2019-08-06 04:43:13 +08:00
|
|
|
/*
|
|
|
|
* Writes the timestamp of the record into @s. Time divisor and precision can be
|
|
|
|
* specified as part of printf @format string. Example:
|
|
|
|
* "%3.1000d" - divide the time by 1000 and print the first 3 digits
|
|
|
|
* before the dot. Thus, the timestamp "123456000" will be printed as
|
|
|
|
* "123.456"
|
2016-02-29 22:01:28 +08:00
|
|
|
*/
|
libtraceevent, perf tools: Changes in tep_print_event_* APIs
Libtraceevent APIs for printing various trace events information are
complicated, there are complex extra parameters. To control the way
event information is printed, the user should call a set of functions in
a specific sequence.
These APIs are reimplemented to provide a more simple interface for
printing event information.
Removed APIs:
tep_print_event_task()
tep_print_event_time()
tep_print_event_data()
tep_event_info()
tep_is_latency_format()
tep_set_latency_format()
tep_data_latency_format()
tep_set_print_raw()
A new API for printing event information is introduced:
void tep_print_event(struct tep_handle *tep, struct trace_seq *s,
struct tep_record *record, const char *fmt, ...);
where "fmt" is a printf-like format string, followed by the event
fields to be printed. Supported fields:
TEP_PRINT_PID, "%d" - event PID
TEP_PRINT_CPU, "%d" - event CPU
TEP_PRINT_COMM, "%s" - event command string
TEP_PRINT_NAME, "%s" - event name
TEP_PRINT_LATENCY, "%s" - event latency
TEP_PRINT_TIME, %d - event time stamp. A divisor and precision
can be specified as part of this format string:
"%precision.divisord". Example:
"%3.1000d" - divide the time by 1000 and print the first 3 digits
before the dot. Thus, the time stamp "123456000" will be printed as
"123.456"
TEP_PRINT_INFO, "%s" - event information.
TEP_PRINT_INFO_RAW, "%s" - event information, in raw format.
Example:
tep_print_event(tep, s, record, "%16s-%-5d [%03d] %s %6.1000d %s %s",
TEP_PRINT_COMM, TEP_PRINT_PID, TEP_PRINT_CPU,
TEP_PRINT_LATENCY, TEP_PRINT_TIME, TEP_PRINT_NAME, TEP_PRINT_INFO);
Output:
ls-11314 [005] d.h. 185207.366383 function __wake_up
Signed-off-by: Tzvetomir Stoyanov <tstoyanov@vmware.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: linux-trace-devel@vger.kernel.org
Cc: Patrick McLean <chutzpah@gentoo.org>
Link: http://lore.kernel.org/linux-trace-devel/20190801074959.22023-2-tz.stoyanov@gmail.com
Link: http://lore.kernel.org/lkml/20190805204355.041132030@goodmis.org
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2019-08-06 04:43:13 +08:00
|
|
|
static void print_event_time(struct tep_handle *tep, struct trace_seq *s,
|
|
|
|
char *format, struct tep_event *event,
|
|
|
|
struct tep_record *record)
|
|
|
|
{
|
|
|
|
unsigned long long time;
|
|
|
|
char *divstr;
|
|
|
|
int prec = 0, pr;
|
|
|
|
int div = 0;
|
|
|
|
int p10 = 1;
|
|
|
|
|
|
|
|
if (isdigit(*(format + 1)))
|
|
|
|
prec = atoi(format + 1);
|
|
|
|
divstr = strchr(format, '.');
|
|
|
|
if (divstr && isdigit(*(divstr + 1)))
|
|
|
|
div = atoi(divstr + 1);
|
|
|
|
time = record->ts;
|
2019-09-20 04:51:19 +08:00
|
|
|
if (div) {
|
|
|
|
time += div / 2;
|
libtraceevent, perf tools: Changes in tep_print_event_* APIs
Libtraceevent APIs for printing various trace events information are
complicated, there are complex extra parameters. To control the way
event information is printed, the user should call a set of functions in
a specific sequence.
These APIs are reimplemented to provide a more simple interface for
printing event information.
Removed APIs:
tep_print_event_task()
tep_print_event_time()
tep_print_event_data()
tep_event_info()
tep_is_latency_format()
tep_set_latency_format()
tep_data_latency_format()
tep_set_print_raw()
A new API for printing event information is introduced:
void tep_print_event(struct tep_handle *tep, struct trace_seq *s,
struct tep_record *record, const char *fmt, ...);
where "fmt" is a printf-like format string, followed by the event
fields to be printed. Supported fields:
TEP_PRINT_PID, "%d" - event PID
TEP_PRINT_CPU, "%d" - event CPU
TEP_PRINT_COMM, "%s" - event command string
TEP_PRINT_NAME, "%s" - event name
TEP_PRINT_LATENCY, "%s" - event latency
TEP_PRINT_TIME, %d - event time stamp. A divisor and precision
can be specified as part of this format string:
"%precision.divisord". Example:
"%3.1000d" - divide the time by 1000 and print the first 3 digits
before the dot. Thus, the time stamp "123456000" will be printed as
"123.456"
TEP_PRINT_INFO, "%s" - event information.
TEP_PRINT_INFO_RAW, "%s" - event information, in raw format.
Example:
tep_print_event(tep, s, record, "%16s-%-5d [%03d] %s %6.1000d %s %s",
TEP_PRINT_COMM, TEP_PRINT_PID, TEP_PRINT_CPU,
TEP_PRINT_LATENCY, TEP_PRINT_TIME, TEP_PRINT_NAME, TEP_PRINT_INFO);
Output:
ls-11314 [005] d.h. 185207.366383 function __wake_up
Signed-off-by: Tzvetomir Stoyanov <tstoyanov@vmware.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: linux-trace-devel@vger.kernel.org
Cc: Patrick McLean <chutzpah@gentoo.org>
Link: http://lore.kernel.org/linux-trace-devel/20190801074959.22023-2-tz.stoyanov@gmail.com
Link: http://lore.kernel.org/lkml/20190805204355.041132030@goodmis.org
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2019-08-06 04:43:13 +08:00
|
|
|
time /= div;
|
2019-09-20 04:51:19 +08:00
|
|
|
}
|
libtraceevent, perf tools: Changes in tep_print_event_* APIs
Libtraceevent APIs for printing various trace events information are
complicated, there are complex extra parameters. To control the way
event information is printed, the user should call a set of functions in
a specific sequence.
These APIs are reimplemented to provide a more simple interface for
printing event information.
Removed APIs:
tep_print_event_task()
tep_print_event_time()
tep_print_event_data()
tep_event_info()
tep_is_latency_format()
tep_set_latency_format()
tep_data_latency_format()
tep_set_print_raw()
A new API for printing event information is introduced:
void tep_print_event(struct tep_handle *tep, struct trace_seq *s,
struct tep_record *record, const char *fmt, ...);
where "fmt" is a printf-like format string, followed by the event
fields to be printed. Supported fields:
TEP_PRINT_PID, "%d" - event PID
TEP_PRINT_CPU, "%d" - event CPU
TEP_PRINT_COMM, "%s" - event command string
TEP_PRINT_NAME, "%s" - event name
TEP_PRINT_LATENCY, "%s" - event latency
TEP_PRINT_TIME, %d - event time stamp. A divisor and precision
can be specified as part of this format string:
"%precision.divisord". Example:
"%3.1000d" - divide the time by 1000 and print the first 3 digits
before the dot. Thus, the time stamp "123456000" will be printed as
"123.456"
TEP_PRINT_INFO, "%s" - event information.
TEP_PRINT_INFO_RAW, "%s" - event information, in raw format.
Example:
tep_print_event(tep, s, record, "%16s-%-5d [%03d] %s %6.1000d %s %s",
TEP_PRINT_COMM, TEP_PRINT_PID, TEP_PRINT_CPU,
TEP_PRINT_LATENCY, TEP_PRINT_TIME, TEP_PRINT_NAME, TEP_PRINT_INFO);
Output:
ls-11314 [005] d.h. 185207.366383 function __wake_up
Signed-off-by: Tzvetomir Stoyanov <tstoyanov@vmware.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: linux-trace-devel@vger.kernel.org
Cc: Patrick McLean <chutzpah@gentoo.org>
Link: http://lore.kernel.org/linux-trace-devel/20190801074959.22023-2-tz.stoyanov@gmail.com
Link: http://lore.kernel.org/lkml/20190805204355.041132030@goodmis.org
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2019-08-06 04:43:13 +08:00
|
|
|
pr = prec;
|
|
|
|
while (pr--)
|
|
|
|
p10 *= 10;
|
|
|
|
|
|
|
|
if (p10 > 1 && p10 < time)
|
|
|
|
trace_seq_printf(s, "%5llu.%0*llu", time / p10, prec, time % p10);
|
|
|
|
else
|
2020-03-04 12:18:52 +08:00
|
|
|
trace_seq_printf(s, "%12llu", time);
|
libtraceevent, perf tools: Changes in tep_print_event_* APIs
Libtraceevent APIs for printing various trace events information are
complicated, there are complex extra parameters. To control the way
event information is printed, the user should call a set of functions in
a specific sequence.
These APIs are reimplemented to provide a more simple interface for
printing event information.
Removed APIs:
tep_print_event_task()
tep_print_event_time()
tep_print_event_data()
tep_event_info()
tep_is_latency_format()
tep_set_latency_format()
tep_data_latency_format()
tep_set_print_raw()
A new API for printing event information is introduced:
void tep_print_event(struct tep_handle *tep, struct trace_seq *s,
struct tep_record *record, const char *fmt, ...);
where "fmt" is a printf-like format string, followed by the event
fields to be printed. Supported fields:
TEP_PRINT_PID, "%d" - event PID
TEP_PRINT_CPU, "%d" - event CPU
TEP_PRINT_COMM, "%s" - event command string
TEP_PRINT_NAME, "%s" - event name
TEP_PRINT_LATENCY, "%s" - event latency
TEP_PRINT_TIME, %d - event time stamp. A divisor and precision
can be specified as part of this format string:
"%precision.divisord". Example:
"%3.1000d" - divide the time by 1000 and print the first 3 digits
before the dot. Thus, the time stamp "123456000" will be printed as
"123.456"
TEP_PRINT_INFO, "%s" - event information.
TEP_PRINT_INFO_RAW, "%s" - event information, in raw format.
Example:
tep_print_event(tep, s, record, "%16s-%-5d [%03d] %s %6.1000d %s %s",
TEP_PRINT_COMM, TEP_PRINT_PID, TEP_PRINT_CPU,
TEP_PRINT_LATENCY, TEP_PRINT_TIME, TEP_PRINT_NAME, TEP_PRINT_INFO);
Output:
ls-11314 [005] d.h. 185207.366383 function __wake_up
Signed-off-by: Tzvetomir Stoyanov <tstoyanov@vmware.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: linux-trace-devel@vger.kernel.org
Cc: Patrick McLean <chutzpah@gentoo.org>
Link: http://lore.kernel.org/linux-trace-devel/20190801074959.22023-2-tz.stoyanov@gmail.com
Link: http://lore.kernel.org/lkml/20190805204355.041132030@goodmis.org
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2019-08-06 04:43:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
struct print_event_type {
|
|
|
|
enum {
|
|
|
|
EVENT_TYPE_INT = 1,
|
|
|
|
EVENT_TYPE_STRING,
|
|
|
|
EVENT_TYPE_UNKNOWN,
|
|
|
|
} type;
|
|
|
|
char format[32];
|
|
|
|
};
|
|
|
|
|
|
|
|
static void print_string(struct tep_handle *tep, struct trace_seq *s,
|
|
|
|
struct tep_record *record, struct tep_event *event,
|
|
|
|
const char *arg, struct print_event_type *type)
|
2016-02-29 22:01:28 +08:00
|
|
|
{
|
|
|
|
const char *comm;
|
|
|
|
int pid;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
libtraceevent, perf tools: Changes in tep_print_event_* APIs
Libtraceevent APIs for printing various trace events information are
complicated, there are complex extra parameters. To control the way
event information is printed, the user should call a set of functions in
a specific sequence.
These APIs are reimplemented to provide a more simple interface for
printing event information.
Removed APIs:
tep_print_event_task()
tep_print_event_time()
tep_print_event_data()
tep_event_info()
tep_is_latency_format()
tep_set_latency_format()
tep_data_latency_format()
tep_set_print_raw()
A new API for printing event information is introduced:
void tep_print_event(struct tep_handle *tep, struct trace_seq *s,
struct tep_record *record, const char *fmt, ...);
where "fmt" is a printf-like format string, followed by the event
fields to be printed. Supported fields:
TEP_PRINT_PID, "%d" - event PID
TEP_PRINT_CPU, "%d" - event CPU
TEP_PRINT_COMM, "%s" - event command string
TEP_PRINT_NAME, "%s" - event name
TEP_PRINT_LATENCY, "%s" - event latency
TEP_PRINT_TIME, %d - event time stamp. A divisor and precision
can be specified as part of this format string:
"%precision.divisord". Example:
"%3.1000d" - divide the time by 1000 and print the first 3 digits
before the dot. Thus, the time stamp "123456000" will be printed as
"123.456"
TEP_PRINT_INFO, "%s" - event information.
TEP_PRINT_INFO_RAW, "%s" - event information, in raw format.
Example:
tep_print_event(tep, s, record, "%16s-%-5d [%03d] %s %6.1000d %s %s",
TEP_PRINT_COMM, TEP_PRINT_PID, TEP_PRINT_CPU,
TEP_PRINT_LATENCY, TEP_PRINT_TIME, TEP_PRINT_NAME, TEP_PRINT_INFO);
Output:
ls-11314 [005] d.h. 185207.366383 function __wake_up
Signed-off-by: Tzvetomir Stoyanov <tstoyanov@vmware.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: linux-trace-devel@vger.kernel.org
Cc: Patrick McLean <chutzpah@gentoo.org>
Link: http://lore.kernel.org/linux-trace-devel/20190801074959.22023-2-tz.stoyanov@gmail.com
Link: http://lore.kernel.org/lkml/20190805204355.041132030@goodmis.org
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2019-08-06 04:43:13 +08:00
|
|
|
if (strncmp(arg, TEP_PRINT_LATENCY, strlen(TEP_PRINT_LATENCY)) == 0) {
|
|
|
|
data_latency_format(tep, s, type->format, record);
|
|
|
|
} else if (strncmp(arg, TEP_PRINT_COMM, strlen(TEP_PRINT_COMM)) == 0) {
|
|
|
|
pid = parse_common_pid(tep, record->data);
|
|
|
|
comm = find_cmdline(tep, pid);
|
|
|
|
trace_seq_printf(s, type->format, comm);
|
|
|
|
} else if (strncmp(arg, TEP_PRINT_INFO_RAW, strlen(TEP_PRINT_INFO_RAW)) == 0) {
|
|
|
|
print_event_info(s, type->format, true, event, record);
|
|
|
|
} else if (strncmp(arg, TEP_PRINT_INFO, strlen(TEP_PRINT_INFO)) == 0) {
|
|
|
|
print_event_info(s, type->format, false, event, record);
|
|
|
|
} else if (strncmp(arg, TEP_PRINT_NAME, strlen(TEP_PRINT_NAME)) == 0) {
|
|
|
|
trace_seq_printf(s, type->format, event->name);
|
|
|
|
} else {
|
|
|
|
trace_seq_printf(s, "[UNKNOWN TEP TYPE %s]", arg);
|
|
|
|
}
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2016-02-29 22:01:28 +08:00
|
|
|
}
|
|
|
|
|
libtraceevent, perf tools: Changes in tep_print_event_* APIs
Libtraceevent APIs for printing various trace events information are
complicated, there are complex extra parameters. To control the way
event information is printed, the user should call a set of functions in
a specific sequence.
These APIs are reimplemented to provide a more simple interface for
printing event information.
Removed APIs:
tep_print_event_task()
tep_print_event_time()
tep_print_event_data()
tep_event_info()
tep_is_latency_format()
tep_set_latency_format()
tep_data_latency_format()
tep_set_print_raw()
A new API for printing event information is introduced:
void tep_print_event(struct tep_handle *tep, struct trace_seq *s,
struct tep_record *record, const char *fmt, ...);
where "fmt" is a printf-like format string, followed by the event
fields to be printed. Supported fields:
TEP_PRINT_PID, "%d" - event PID
TEP_PRINT_CPU, "%d" - event CPU
TEP_PRINT_COMM, "%s" - event command string
TEP_PRINT_NAME, "%s" - event name
TEP_PRINT_LATENCY, "%s" - event latency
TEP_PRINT_TIME, %d - event time stamp. A divisor and precision
can be specified as part of this format string:
"%precision.divisord". Example:
"%3.1000d" - divide the time by 1000 and print the first 3 digits
before the dot. Thus, the time stamp "123456000" will be printed as
"123.456"
TEP_PRINT_INFO, "%s" - event information.
TEP_PRINT_INFO_RAW, "%s" - event information, in raw format.
Example:
tep_print_event(tep, s, record, "%16s-%-5d [%03d] %s %6.1000d %s %s",
TEP_PRINT_COMM, TEP_PRINT_PID, TEP_PRINT_CPU,
TEP_PRINT_LATENCY, TEP_PRINT_TIME, TEP_PRINT_NAME, TEP_PRINT_INFO);
Output:
ls-11314 [005] d.h. 185207.366383 function __wake_up
Signed-off-by: Tzvetomir Stoyanov <tstoyanov@vmware.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: linux-trace-devel@vger.kernel.org
Cc: Patrick McLean <chutzpah@gentoo.org>
Link: http://lore.kernel.org/linux-trace-devel/20190801074959.22023-2-tz.stoyanov@gmail.com
Link: http://lore.kernel.org/lkml/20190805204355.041132030@goodmis.org
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2019-08-06 04:43:13 +08:00
|
|
|
static void print_int(struct tep_handle *tep, struct trace_seq *s,
|
|
|
|
struct tep_record *record, struct tep_event *event,
|
|
|
|
int arg, struct print_event_type *type)
|
2016-02-29 22:01:28 +08:00
|
|
|
{
|
libtraceevent, perf tools: Changes in tep_print_event_* APIs
Libtraceevent APIs for printing various trace events information are
complicated, there are complex extra parameters. To control the way
event information is printed, the user should call a set of functions in
a specific sequence.
These APIs are reimplemented to provide a more simple interface for
printing event information.
Removed APIs:
tep_print_event_task()
tep_print_event_time()
tep_print_event_data()
tep_event_info()
tep_is_latency_format()
tep_set_latency_format()
tep_data_latency_format()
tep_set_print_raw()
A new API for printing event information is introduced:
void tep_print_event(struct tep_handle *tep, struct trace_seq *s,
struct tep_record *record, const char *fmt, ...);
where "fmt" is a printf-like format string, followed by the event
fields to be printed. Supported fields:
TEP_PRINT_PID, "%d" - event PID
TEP_PRINT_CPU, "%d" - event CPU
TEP_PRINT_COMM, "%s" - event command string
TEP_PRINT_NAME, "%s" - event name
TEP_PRINT_LATENCY, "%s" - event latency
TEP_PRINT_TIME, %d - event time stamp. A divisor and precision
can be specified as part of this format string:
"%precision.divisord". Example:
"%3.1000d" - divide the time by 1000 and print the first 3 digits
before the dot. Thus, the time stamp "123456000" will be printed as
"123.456"
TEP_PRINT_INFO, "%s" - event information.
TEP_PRINT_INFO_RAW, "%s" - event information, in raw format.
Example:
tep_print_event(tep, s, record, "%16s-%-5d [%03d] %s %6.1000d %s %s",
TEP_PRINT_COMM, TEP_PRINT_PID, TEP_PRINT_CPU,
TEP_PRINT_LATENCY, TEP_PRINT_TIME, TEP_PRINT_NAME, TEP_PRINT_INFO);
Output:
ls-11314 [005] d.h. 185207.366383 function __wake_up
Signed-off-by: Tzvetomir Stoyanov <tstoyanov@vmware.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: linux-trace-devel@vger.kernel.org
Cc: Patrick McLean <chutzpah@gentoo.org>
Link: http://lore.kernel.org/linux-trace-devel/20190801074959.22023-2-tz.stoyanov@gmail.com
Link: http://lore.kernel.org/lkml/20190805204355.041132030@goodmis.org
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2019-08-06 04:43:13 +08:00
|
|
|
int param;
|
2016-02-29 22:01:28 +08:00
|
|
|
|
libtraceevent, perf tools: Changes in tep_print_event_* APIs
Libtraceevent APIs for printing various trace events information are
complicated, there are complex extra parameters. To control the way
event information is printed, the user should call a set of functions in
a specific sequence.
These APIs are reimplemented to provide a more simple interface for
printing event information.
Removed APIs:
tep_print_event_task()
tep_print_event_time()
tep_print_event_data()
tep_event_info()
tep_is_latency_format()
tep_set_latency_format()
tep_data_latency_format()
tep_set_print_raw()
A new API for printing event information is introduced:
void tep_print_event(struct tep_handle *tep, struct trace_seq *s,
struct tep_record *record, const char *fmt, ...);
where "fmt" is a printf-like format string, followed by the event
fields to be printed. Supported fields:
TEP_PRINT_PID, "%d" - event PID
TEP_PRINT_CPU, "%d" - event CPU
TEP_PRINT_COMM, "%s" - event command string
TEP_PRINT_NAME, "%s" - event name
TEP_PRINT_LATENCY, "%s" - event latency
TEP_PRINT_TIME, %d - event time stamp. A divisor and precision
can be specified as part of this format string:
"%precision.divisord". Example:
"%3.1000d" - divide the time by 1000 and print the first 3 digits
before the dot. Thus, the time stamp "123456000" will be printed as
"123.456"
TEP_PRINT_INFO, "%s" - event information.
TEP_PRINT_INFO_RAW, "%s" - event information, in raw format.
Example:
tep_print_event(tep, s, record, "%16s-%-5d [%03d] %s %6.1000d %s %s",
TEP_PRINT_COMM, TEP_PRINT_PID, TEP_PRINT_CPU,
TEP_PRINT_LATENCY, TEP_PRINT_TIME, TEP_PRINT_NAME, TEP_PRINT_INFO);
Output:
ls-11314 [005] d.h. 185207.366383 function __wake_up
Signed-off-by: Tzvetomir Stoyanov <tstoyanov@vmware.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: linux-trace-devel@vger.kernel.org
Cc: Patrick McLean <chutzpah@gentoo.org>
Link: http://lore.kernel.org/linux-trace-devel/20190801074959.22023-2-tz.stoyanov@gmail.com
Link: http://lore.kernel.org/lkml/20190805204355.041132030@goodmis.org
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2019-08-06 04:43:13 +08:00
|
|
|
switch (arg) {
|
|
|
|
case TEP_PRINT_CPU:
|
|
|
|
param = record->cpu;
|
|
|
|
break;
|
|
|
|
case TEP_PRINT_PID:
|
|
|
|
param = parse_common_pid(tep, record->data);
|
|
|
|
break;
|
|
|
|
case TEP_PRINT_TIME:
|
|
|
|
return print_event_time(tep, s, type->format, event, record);
|
|
|
|
default:
|
|
|
|
return;
|
2016-02-29 22:01:28 +08:00
|
|
|
}
|
libtraceevent, perf tools: Changes in tep_print_event_* APIs
Libtraceevent APIs for printing various trace events information are
complicated, there are complex extra parameters. To control the way
event information is printed, the user should call a set of functions in
a specific sequence.
These APIs are reimplemented to provide a more simple interface for
printing event information.
Removed APIs:
tep_print_event_task()
tep_print_event_time()
tep_print_event_data()
tep_event_info()
tep_is_latency_format()
tep_set_latency_format()
tep_data_latency_format()
tep_set_print_raw()
A new API for printing event information is introduced:
void tep_print_event(struct tep_handle *tep, struct trace_seq *s,
struct tep_record *record, const char *fmt, ...);
where "fmt" is a printf-like format string, followed by the event
fields to be printed. Supported fields:
TEP_PRINT_PID, "%d" - event PID
TEP_PRINT_CPU, "%d" - event CPU
TEP_PRINT_COMM, "%s" - event command string
TEP_PRINT_NAME, "%s" - event name
TEP_PRINT_LATENCY, "%s" - event latency
TEP_PRINT_TIME, %d - event time stamp. A divisor and precision
can be specified as part of this format string:
"%precision.divisord". Example:
"%3.1000d" - divide the time by 1000 and print the first 3 digits
before the dot. Thus, the time stamp "123456000" will be printed as
"123.456"
TEP_PRINT_INFO, "%s" - event information.
TEP_PRINT_INFO_RAW, "%s" - event information, in raw format.
Example:
tep_print_event(tep, s, record, "%16s-%-5d [%03d] %s %6.1000d %s %s",
TEP_PRINT_COMM, TEP_PRINT_PID, TEP_PRINT_CPU,
TEP_PRINT_LATENCY, TEP_PRINT_TIME, TEP_PRINT_NAME, TEP_PRINT_INFO);
Output:
ls-11314 [005] d.h. 185207.366383 function __wake_up
Signed-off-by: Tzvetomir Stoyanov <tstoyanov@vmware.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: linux-trace-devel@vger.kernel.org
Cc: Patrick McLean <chutzpah@gentoo.org>
Link: http://lore.kernel.org/linux-trace-devel/20190801074959.22023-2-tz.stoyanov@gmail.com
Link: http://lore.kernel.org/lkml/20190805204355.041132030@goodmis.org
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2019-08-06 04:43:13 +08:00
|
|
|
trace_seq_printf(s, type->format, param);
|
|
|
|
}
|
2016-02-29 22:01:28 +08:00
|
|
|
|
libtraceevent, perf tools: Changes in tep_print_event_* APIs
Libtraceevent APIs for printing various trace events information are
complicated, there are complex extra parameters. To control the way
event information is printed, the user should call a set of functions in
a specific sequence.
These APIs are reimplemented to provide a more simple interface for
printing event information.
Removed APIs:
tep_print_event_task()
tep_print_event_time()
tep_print_event_data()
tep_event_info()
tep_is_latency_format()
tep_set_latency_format()
tep_data_latency_format()
tep_set_print_raw()
A new API for printing event information is introduced:
void tep_print_event(struct tep_handle *tep, struct trace_seq *s,
struct tep_record *record, const char *fmt, ...);
where "fmt" is a printf-like format string, followed by the event
fields to be printed. Supported fields:
TEP_PRINT_PID, "%d" - event PID
TEP_PRINT_CPU, "%d" - event CPU
TEP_PRINT_COMM, "%s" - event command string
TEP_PRINT_NAME, "%s" - event name
TEP_PRINT_LATENCY, "%s" - event latency
TEP_PRINT_TIME, %d - event time stamp. A divisor and precision
can be specified as part of this format string:
"%precision.divisord". Example:
"%3.1000d" - divide the time by 1000 and print the first 3 digits
before the dot. Thus, the time stamp "123456000" will be printed as
"123.456"
TEP_PRINT_INFO, "%s" - event information.
TEP_PRINT_INFO_RAW, "%s" - event information, in raw format.
Example:
tep_print_event(tep, s, record, "%16s-%-5d [%03d] %s %6.1000d %s %s",
TEP_PRINT_COMM, TEP_PRINT_PID, TEP_PRINT_CPU,
TEP_PRINT_LATENCY, TEP_PRINT_TIME, TEP_PRINT_NAME, TEP_PRINT_INFO);
Output:
ls-11314 [005] d.h. 185207.366383 function __wake_up
Signed-off-by: Tzvetomir Stoyanov <tstoyanov@vmware.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: linux-trace-devel@vger.kernel.org
Cc: Patrick McLean <chutzpah@gentoo.org>
Link: http://lore.kernel.org/linux-trace-devel/20190801074959.22023-2-tz.stoyanov@gmail.com
Link: http://lore.kernel.org/lkml/20190805204355.041132030@goodmis.org
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2019-08-06 04:43:13 +08:00
|
|
|
static int tep_print_event_param_type(char *format,
|
|
|
|
struct print_event_type *type)
|
|
|
|
{
|
|
|
|
char *str = format + 1;
|
|
|
|
int i = 1;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
libtraceevent, perf tools: Changes in tep_print_event_* APIs
Libtraceevent APIs for printing various trace events information are
complicated, there are complex extra parameters. To control the way
event information is printed, the user should call a set of functions in
a specific sequence.
These APIs are reimplemented to provide a more simple interface for
printing event information.
Removed APIs:
tep_print_event_task()
tep_print_event_time()
tep_print_event_data()
tep_event_info()
tep_is_latency_format()
tep_set_latency_format()
tep_data_latency_format()
tep_set_print_raw()
A new API for printing event information is introduced:
void tep_print_event(struct tep_handle *tep, struct trace_seq *s,
struct tep_record *record, const char *fmt, ...);
where "fmt" is a printf-like format string, followed by the event
fields to be printed. Supported fields:
TEP_PRINT_PID, "%d" - event PID
TEP_PRINT_CPU, "%d" - event CPU
TEP_PRINT_COMM, "%s" - event command string
TEP_PRINT_NAME, "%s" - event name
TEP_PRINT_LATENCY, "%s" - event latency
TEP_PRINT_TIME, %d - event time stamp. A divisor and precision
can be specified as part of this format string:
"%precision.divisord". Example:
"%3.1000d" - divide the time by 1000 and print the first 3 digits
before the dot. Thus, the time stamp "123456000" will be printed as
"123.456"
TEP_PRINT_INFO, "%s" - event information.
TEP_PRINT_INFO_RAW, "%s" - event information, in raw format.
Example:
tep_print_event(tep, s, record, "%16s-%-5d [%03d] %s %6.1000d %s %s",
TEP_PRINT_COMM, TEP_PRINT_PID, TEP_PRINT_CPU,
TEP_PRINT_LATENCY, TEP_PRINT_TIME, TEP_PRINT_NAME, TEP_PRINT_INFO);
Output:
ls-11314 [005] d.h. 185207.366383 function __wake_up
Signed-off-by: Tzvetomir Stoyanov <tstoyanov@vmware.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: linux-trace-devel@vger.kernel.org
Cc: Patrick McLean <chutzpah@gentoo.org>
Link: http://lore.kernel.org/linux-trace-devel/20190801074959.22023-2-tz.stoyanov@gmail.com
Link: http://lore.kernel.org/lkml/20190805204355.041132030@goodmis.org
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2019-08-06 04:43:13 +08:00
|
|
|
type->type = EVENT_TYPE_UNKNOWN;
|
|
|
|
while (*str) {
|
|
|
|
switch (*str) {
|
|
|
|
case 'd':
|
|
|
|
case 'u':
|
|
|
|
case 'i':
|
|
|
|
case 'x':
|
|
|
|
case 'X':
|
|
|
|
case 'o':
|
|
|
|
type->type = EVENT_TYPE_INT;
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
type->type = EVENT_TYPE_STRING;
|
|
|
|
break;
|
2013-11-02 05:53:53 +08:00
|
|
|
}
|
libtraceevent, perf tools: Changes in tep_print_event_* APIs
Libtraceevent APIs for printing various trace events information are
complicated, there are complex extra parameters. To control the way
event information is printed, the user should call a set of functions in
a specific sequence.
These APIs are reimplemented to provide a more simple interface for
printing event information.
Removed APIs:
tep_print_event_task()
tep_print_event_time()
tep_print_event_data()
tep_event_info()
tep_is_latency_format()
tep_set_latency_format()
tep_data_latency_format()
tep_set_print_raw()
A new API for printing event information is introduced:
void tep_print_event(struct tep_handle *tep, struct trace_seq *s,
struct tep_record *record, const char *fmt, ...);
where "fmt" is a printf-like format string, followed by the event
fields to be printed. Supported fields:
TEP_PRINT_PID, "%d" - event PID
TEP_PRINT_CPU, "%d" - event CPU
TEP_PRINT_COMM, "%s" - event command string
TEP_PRINT_NAME, "%s" - event name
TEP_PRINT_LATENCY, "%s" - event latency
TEP_PRINT_TIME, %d - event time stamp. A divisor and precision
can be specified as part of this format string:
"%precision.divisord". Example:
"%3.1000d" - divide the time by 1000 and print the first 3 digits
before the dot. Thus, the time stamp "123456000" will be printed as
"123.456"
TEP_PRINT_INFO, "%s" - event information.
TEP_PRINT_INFO_RAW, "%s" - event information, in raw format.
Example:
tep_print_event(tep, s, record, "%16s-%-5d [%03d] %s %6.1000d %s %s",
TEP_PRINT_COMM, TEP_PRINT_PID, TEP_PRINT_CPU,
TEP_PRINT_LATENCY, TEP_PRINT_TIME, TEP_PRINT_NAME, TEP_PRINT_INFO);
Output:
ls-11314 [005] d.h. 185207.366383 function __wake_up
Signed-off-by: Tzvetomir Stoyanov <tstoyanov@vmware.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: linux-trace-devel@vger.kernel.org
Cc: Patrick McLean <chutzpah@gentoo.org>
Link: http://lore.kernel.org/linux-trace-devel/20190801074959.22023-2-tz.stoyanov@gmail.com
Link: http://lore.kernel.org/lkml/20190805204355.041132030@goodmis.org
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2019-08-06 04:43:13 +08:00
|
|
|
str++;
|
|
|
|
i++;
|
|
|
|
if (type->type != EVENT_TYPE_UNKNOWN)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
memset(type->format, 0, 32);
|
|
|
|
memcpy(type->format, format, i < 32 ? i : 31);
|
|
|
|
return i;
|
2016-02-29 22:01:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
libtraceevent, perf tools: Changes in tep_print_event_* APIs
Libtraceevent APIs for printing various trace events information are
complicated, there are complex extra parameters. To control the way
event information is printed, the user should call a set of functions in
a specific sequence.
These APIs are reimplemented to provide a more simple interface for
printing event information.
Removed APIs:
tep_print_event_task()
tep_print_event_time()
tep_print_event_data()
tep_event_info()
tep_is_latency_format()
tep_set_latency_format()
tep_data_latency_format()
tep_set_print_raw()
A new API for printing event information is introduced:
void tep_print_event(struct tep_handle *tep, struct trace_seq *s,
struct tep_record *record, const char *fmt, ...);
where "fmt" is a printf-like format string, followed by the event
fields to be printed. Supported fields:
TEP_PRINT_PID, "%d" - event PID
TEP_PRINT_CPU, "%d" - event CPU
TEP_PRINT_COMM, "%s" - event command string
TEP_PRINT_NAME, "%s" - event name
TEP_PRINT_LATENCY, "%s" - event latency
TEP_PRINT_TIME, %d - event time stamp. A divisor and precision
can be specified as part of this format string:
"%precision.divisord". Example:
"%3.1000d" - divide the time by 1000 and print the first 3 digits
before the dot. Thus, the time stamp "123456000" will be printed as
"123.456"
TEP_PRINT_INFO, "%s" - event information.
TEP_PRINT_INFO_RAW, "%s" - event information, in raw format.
Example:
tep_print_event(tep, s, record, "%16s-%-5d [%03d] %s %6.1000d %s %s",
TEP_PRINT_COMM, TEP_PRINT_PID, TEP_PRINT_CPU,
TEP_PRINT_LATENCY, TEP_PRINT_TIME, TEP_PRINT_NAME, TEP_PRINT_INFO);
Output:
ls-11314 [005] d.h. 185207.366383 function __wake_up
Signed-off-by: Tzvetomir Stoyanov <tstoyanov@vmware.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: linux-trace-devel@vger.kernel.org
Cc: Patrick McLean <chutzpah@gentoo.org>
Link: http://lore.kernel.org/linux-trace-devel/20190801074959.22023-2-tz.stoyanov@gmail.com
Link: http://lore.kernel.org/lkml/20190805204355.041132030@goodmis.org
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2019-08-06 04:43:13 +08:00
|
|
|
* tep_print_event - Write various event information
|
2019-04-02 00:43:17 +08:00
|
|
|
* @tep: a handle to the trace event parser context
|
2016-02-29 22:01:28 +08:00
|
|
|
* @s: the trace_seq to write to
|
|
|
|
* @record: The record to get the event from
|
libtraceevent, perf tools: Changes in tep_print_event_* APIs
Libtraceevent APIs for printing various trace events information are
complicated, there are complex extra parameters. To control the way
event information is printed, the user should call a set of functions in
a specific sequence.
These APIs are reimplemented to provide a more simple interface for
printing event information.
Removed APIs:
tep_print_event_task()
tep_print_event_time()
tep_print_event_data()
tep_event_info()
tep_is_latency_format()
tep_set_latency_format()
tep_data_latency_format()
tep_set_print_raw()
A new API for printing event information is introduced:
void tep_print_event(struct tep_handle *tep, struct trace_seq *s,
struct tep_record *record, const char *fmt, ...);
where "fmt" is a printf-like format string, followed by the event
fields to be printed. Supported fields:
TEP_PRINT_PID, "%d" - event PID
TEP_PRINT_CPU, "%d" - event CPU
TEP_PRINT_COMM, "%s" - event command string
TEP_PRINT_NAME, "%s" - event name
TEP_PRINT_LATENCY, "%s" - event latency
TEP_PRINT_TIME, %d - event time stamp. A divisor and precision
can be specified as part of this format string:
"%precision.divisord". Example:
"%3.1000d" - divide the time by 1000 and print the first 3 digits
before the dot. Thus, the time stamp "123456000" will be printed as
"123.456"
TEP_PRINT_INFO, "%s" - event information.
TEP_PRINT_INFO_RAW, "%s" - event information, in raw format.
Example:
tep_print_event(tep, s, record, "%16s-%-5d [%03d] %s %6.1000d %s %s",
TEP_PRINT_COMM, TEP_PRINT_PID, TEP_PRINT_CPU,
TEP_PRINT_LATENCY, TEP_PRINT_TIME, TEP_PRINT_NAME, TEP_PRINT_INFO);
Output:
ls-11314 [005] d.h. 185207.366383 function __wake_up
Signed-off-by: Tzvetomir Stoyanov <tstoyanov@vmware.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: linux-trace-devel@vger.kernel.org
Cc: Patrick McLean <chutzpah@gentoo.org>
Link: http://lore.kernel.org/linux-trace-devel/20190801074959.22023-2-tz.stoyanov@gmail.com
Link: http://lore.kernel.org/lkml/20190805204355.041132030@goodmis.org
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2019-08-06 04:43:13 +08:00
|
|
|
* @format: a printf format string. Supported event fileds:
|
|
|
|
* TEP_PRINT_PID, "%d" - event PID
|
|
|
|
* TEP_PRINT_CPU, "%d" - event CPU
|
|
|
|
* TEP_PRINT_COMM, "%s" - event command string
|
|
|
|
* TEP_PRINT_NAME, "%s" - event name
|
|
|
|
* TEP_PRINT_LATENCY, "%s" - event latency
|
|
|
|
* TEP_PRINT_TIME, %d - event time stamp. A divisor and precision
|
|
|
|
* can be specified as part of this format string:
|
|
|
|
* "%precision.divisord". Example:
|
|
|
|
* "%3.1000d" - divide the time by 1000 and print the first
|
|
|
|
* 3 digits before the dot. Thus, the time stamp
|
|
|
|
* "123456000" will be printed as "123.456"
|
|
|
|
* TEP_PRINT_INFO, "%s" - event information. If any width is specified in
|
|
|
|
* the format string, the event information will be printed
|
|
|
|
* in raw format.
|
|
|
|
* Writes the specified event information into @s.
|
2016-02-29 22:01:28 +08:00
|
|
|
*/
|
2019-04-02 00:43:17 +08:00
|
|
|
void tep_print_event(struct tep_handle *tep, struct trace_seq *s,
|
libtraceevent, perf tools: Changes in tep_print_event_* APIs
Libtraceevent APIs for printing various trace events information are
complicated, there are complex extra parameters. To control the way
event information is printed, the user should call a set of functions in
a specific sequence.
These APIs are reimplemented to provide a more simple interface for
printing event information.
Removed APIs:
tep_print_event_task()
tep_print_event_time()
tep_print_event_data()
tep_event_info()
tep_is_latency_format()
tep_set_latency_format()
tep_data_latency_format()
tep_set_print_raw()
A new API for printing event information is introduced:
void tep_print_event(struct tep_handle *tep, struct trace_seq *s,
struct tep_record *record, const char *fmt, ...);
where "fmt" is a printf-like format string, followed by the event
fields to be printed. Supported fields:
TEP_PRINT_PID, "%d" - event PID
TEP_PRINT_CPU, "%d" - event CPU
TEP_PRINT_COMM, "%s" - event command string
TEP_PRINT_NAME, "%s" - event name
TEP_PRINT_LATENCY, "%s" - event latency
TEP_PRINT_TIME, %d - event time stamp. A divisor and precision
can be specified as part of this format string:
"%precision.divisord". Example:
"%3.1000d" - divide the time by 1000 and print the first 3 digits
before the dot. Thus, the time stamp "123456000" will be printed as
"123.456"
TEP_PRINT_INFO, "%s" - event information.
TEP_PRINT_INFO_RAW, "%s" - event information, in raw format.
Example:
tep_print_event(tep, s, record, "%16s-%-5d [%03d] %s %6.1000d %s %s",
TEP_PRINT_COMM, TEP_PRINT_PID, TEP_PRINT_CPU,
TEP_PRINT_LATENCY, TEP_PRINT_TIME, TEP_PRINT_NAME, TEP_PRINT_INFO);
Output:
ls-11314 [005] d.h. 185207.366383 function __wake_up
Signed-off-by: Tzvetomir Stoyanov <tstoyanov@vmware.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: linux-trace-devel@vger.kernel.org
Cc: Patrick McLean <chutzpah@gentoo.org>
Link: http://lore.kernel.org/linux-trace-devel/20190801074959.22023-2-tz.stoyanov@gmail.com
Link: http://lore.kernel.org/lkml/20190805204355.041132030@goodmis.org
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2019-08-06 04:43:13 +08:00
|
|
|
struct tep_record *record, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
struct print_event_type type;
|
|
|
|
char *format = strdup(fmt);
|
|
|
|
char *current = format;
|
|
|
|
char *str = format;
|
|
|
|
int offset;
|
|
|
|
va_list args;
|
2018-11-30 23:44:07 +08:00
|
|
|
struct tep_event *event;
|
2016-02-29 22:01:28 +08:00
|
|
|
|
libtraceevent, perf tools: Changes in tep_print_event_* APIs
Libtraceevent APIs for printing various trace events information are
complicated, there are complex extra parameters. To control the way
event information is printed, the user should call a set of functions in
a specific sequence.
These APIs are reimplemented to provide a more simple interface for
printing event information.
Removed APIs:
tep_print_event_task()
tep_print_event_time()
tep_print_event_data()
tep_event_info()
tep_is_latency_format()
tep_set_latency_format()
tep_data_latency_format()
tep_set_print_raw()
A new API for printing event information is introduced:
void tep_print_event(struct tep_handle *tep, struct trace_seq *s,
struct tep_record *record, const char *fmt, ...);
where "fmt" is a printf-like format string, followed by the event
fields to be printed. Supported fields:
TEP_PRINT_PID, "%d" - event PID
TEP_PRINT_CPU, "%d" - event CPU
TEP_PRINT_COMM, "%s" - event command string
TEP_PRINT_NAME, "%s" - event name
TEP_PRINT_LATENCY, "%s" - event latency
TEP_PRINT_TIME, %d - event time stamp. A divisor and precision
can be specified as part of this format string:
"%precision.divisord". Example:
"%3.1000d" - divide the time by 1000 and print the first 3 digits
before the dot. Thus, the time stamp "123456000" will be printed as
"123.456"
TEP_PRINT_INFO, "%s" - event information.
TEP_PRINT_INFO_RAW, "%s" - event information, in raw format.
Example:
tep_print_event(tep, s, record, "%16s-%-5d [%03d] %s %6.1000d %s %s",
TEP_PRINT_COMM, TEP_PRINT_PID, TEP_PRINT_CPU,
TEP_PRINT_LATENCY, TEP_PRINT_TIME, TEP_PRINT_NAME, TEP_PRINT_INFO);
Output:
ls-11314 [005] d.h. 185207.366383 function __wake_up
Signed-off-by: Tzvetomir Stoyanov <tstoyanov@vmware.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: linux-trace-devel@vger.kernel.org
Cc: Patrick McLean <chutzpah@gentoo.org>
Link: http://lore.kernel.org/linux-trace-devel/20190801074959.22023-2-tz.stoyanov@gmail.com
Link: http://lore.kernel.org/lkml/20190805204355.041132030@goodmis.org
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2019-08-06 04:43:13 +08:00
|
|
|
if (!format)
|
2016-02-29 22:01:28 +08:00
|
|
|
return;
|
|
|
|
|
libtraceevent, perf tools: Changes in tep_print_event_* APIs
Libtraceevent APIs for printing various trace events information are
complicated, there are complex extra parameters. To control the way
event information is printed, the user should call a set of functions in
a specific sequence.
These APIs are reimplemented to provide a more simple interface for
printing event information.
Removed APIs:
tep_print_event_task()
tep_print_event_time()
tep_print_event_data()
tep_event_info()
tep_is_latency_format()
tep_set_latency_format()
tep_data_latency_format()
tep_set_print_raw()
A new API for printing event information is introduced:
void tep_print_event(struct tep_handle *tep, struct trace_seq *s,
struct tep_record *record, const char *fmt, ...);
where "fmt" is a printf-like format string, followed by the event
fields to be printed. Supported fields:
TEP_PRINT_PID, "%d" - event PID
TEP_PRINT_CPU, "%d" - event CPU
TEP_PRINT_COMM, "%s" - event command string
TEP_PRINT_NAME, "%s" - event name
TEP_PRINT_LATENCY, "%s" - event latency
TEP_PRINT_TIME, %d - event time stamp. A divisor and precision
can be specified as part of this format string:
"%precision.divisord". Example:
"%3.1000d" - divide the time by 1000 and print the first 3 digits
before the dot. Thus, the time stamp "123456000" will be printed as
"123.456"
TEP_PRINT_INFO, "%s" - event information.
TEP_PRINT_INFO_RAW, "%s" - event information, in raw format.
Example:
tep_print_event(tep, s, record, "%16s-%-5d [%03d] %s %6.1000d %s %s",
TEP_PRINT_COMM, TEP_PRINT_PID, TEP_PRINT_CPU,
TEP_PRINT_LATENCY, TEP_PRINT_TIME, TEP_PRINT_NAME, TEP_PRINT_INFO);
Output:
ls-11314 [005] d.h. 185207.366383 function __wake_up
Signed-off-by: Tzvetomir Stoyanov <tstoyanov@vmware.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: linux-trace-devel@vger.kernel.org
Cc: Patrick McLean <chutzpah@gentoo.org>
Link: http://lore.kernel.org/linux-trace-devel/20190801074959.22023-2-tz.stoyanov@gmail.com
Link: http://lore.kernel.org/lkml/20190805204355.041132030@goodmis.org
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2019-08-06 04:43:13 +08:00
|
|
|
event = tep_find_event_by_record(tep, record);
|
|
|
|
va_start(args, fmt);
|
|
|
|
while (*current) {
|
|
|
|
current = strchr(str, '%');
|
|
|
|
if (!current) {
|
|
|
|
trace_seq_puts(s, str);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
memset(&type, 0, sizeof(type));
|
|
|
|
offset = tep_print_event_param_type(current, &type);
|
|
|
|
*current = '\0';
|
|
|
|
trace_seq_puts(s, str);
|
|
|
|
current += offset;
|
|
|
|
switch (type.type) {
|
|
|
|
case EVENT_TYPE_STRING:
|
|
|
|
print_string(tep, s, record, event,
|
|
|
|
va_arg(args, char*), &type);
|
|
|
|
break;
|
|
|
|
case EVENT_TYPE_INT:
|
|
|
|
print_int(tep, s, record, event,
|
|
|
|
va_arg(args, int), &type);
|
|
|
|
break;
|
|
|
|
case EVENT_TYPE_UNKNOWN:
|
|
|
|
default:
|
|
|
|
trace_seq_printf(s, "[UNKNOWN TYPE]");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
str = current;
|
|
|
|
|
|
|
|
}
|
|
|
|
va_end(args);
|
|
|
|
free(format);
|
2016-02-29 22:01:28 +08:00
|
|
|
}
|
|
|
|
|
2012-04-06 06:47:53 +08:00
|
|
|
static int events_id_cmp(const void *a, const void *b)
|
|
|
|
{
|
2018-11-30 23:44:07 +08:00
|
|
|
struct tep_event * const * ea = a;
|
|
|
|
struct tep_event * const * eb = b;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
if ((*ea)->id < (*eb)->id)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if ((*ea)->id > (*eb)->id)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int events_name_cmp(const void *a, const void *b)
|
|
|
|
{
|
2018-11-30 23:44:07 +08:00
|
|
|
struct tep_event * const * ea = a;
|
|
|
|
struct tep_event * const * eb = b;
|
2012-04-06 06:47:53 +08:00
|
|
|
int res;
|
|
|
|
|
|
|
|
res = strcmp((*ea)->name, (*eb)->name);
|
|
|
|
if (res)
|
|
|
|
return res;
|
|
|
|
|
|
|
|
res = strcmp((*ea)->system, (*eb)->system);
|
|
|
|
if (res)
|
|
|
|
return res;
|
|
|
|
|
|
|
|
return events_id_cmp(a, b);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int events_system_cmp(const void *a, const void *b)
|
|
|
|
{
|
2018-11-30 23:44:07 +08:00
|
|
|
struct tep_event * const * ea = a;
|
|
|
|
struct tep_event * const * eb = b;
|
2012-04-06 06:47:53 +08:00
|
|
|
int res;
|
|
|
|
|
|
|
|
res = strcmp((*ea)->system, (*eb)->system);
|
|
|
|
if (res)
|
|
|
|
return res;
|
|
|
|
|
|
|
|
res = strcmp((*ea)->name, (*eb)->name);
|
|
|
|
if (res)
|
|
|
|
return res;
|
|
|
|
|
|
|
|
return events_id_cmp(a, b);
|
|
|
|
}
|
|
|
|
|
2019-04-02 00:43:08 +08:00
|
|
|
static struct tep_event **list_events_copy(struct tep_handle *tep)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
2018-11-30 23:44:07 +08:00
|
|
|
struct tep_event **events;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2019-04-02 00:43:08 +08:00
|
|
|
if (!tep)
|
|
|
|
return NULL;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2019-04-02 00:43:08 +08:00
|
|
|
events = malloc(sizeof(*events) * (tep->nr_events + 1));
|
|
|
|
if (!events)
|
|
|
|
return NULL;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2019-04-02 00:43:08 +08:00
|
|
|
memcpy(events, tep->events, sizeof(*events) * tep->nr_events);
|
|
|
|
events[tep->nr_events] = NULL;
|
|
|
|
return events;
|
|
|
|
}
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2019-04-02 00:43:08 +08:00
|
|
|
static void list_events_sort(struct tep_event **events, int nr_events,
|
|
|
|
enum tep_event_sort_type sort_type)
|
|
|
|
{
|
|
|
|
int (*sort)(const void *a, const void *b);
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
switch (sort_type) {
|
2018-09-20 02:56:47 +08:00
|
|
|
case TEP_EVENT_SORT_ID:
|
2012-04-06 06:47:53 +08:00
|
|
|
sort = events_id_cmp;
|
|
|
|
break;
|
2018-09-20 02:56:47 +08:00
|
|
|
case TEP_EVENT_SORT_NAME:
|
2012-04-06 06:47:53 +08:00
|
|
|
sort = events_name_cmp;
|
|
|
|
break;
|
2018-09-20 02:56:47 +08:00
|
|
|
case TEP_EVENT_SORT_SYSTEM:
|
2012-04-06 06:47:53 +08:00
|
|
|
sort = events_system_cmp;
|
|
|
|
break;
|
|
|
|
default:
|
2019-04-02 00:43:08 +08:00
|
|
|
sort = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sort)
|
|
|
|
qsort(events, nr_events, sizeof(*events), sort);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* tep_list_events - Get events, sorted by given criteria.
|
|
|
|
* @tep: a handle to the tep context
|
|
|
|
* @sort_type: desired sort order of the events in the array
|
|
|
|
*
|
|
|
|
* Returns an array of pointers to all events, sorted by the given
|
|
|
|
* @sort_type criteria. The last element of the array is NULL. The returned
|
|
|
|
* memory must not be freed, it is managed by the library.
|
|
|
|
* The function is not thread safe.
|
|
|
|
*/
|
|
|
|
struct tep_event **tep_list_events(struct tep_handle *tep,
|
|
|
|
enum tep_event_sort_type sort_type)
|
|
|
|
{
|
|
|
|
struct tep_event **events;
|
|
|
|
|
|
|
|
if (!tep)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
events = tep->sort_events;
|
|
|
|
if (events && tep->last_type == sort_type)
|
2012-04-06 06:47:53 +08:00
|
|
|
return events;
|
2019-04-02 00:43:08 +08:00
|
|
|
|
|
|
|
if (!events) {
|
|
|
|
events = list_events_copy(tep);
|
|
|
|
if (!events)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
tep->sort_events = events;
|
|
|
|
|
|
|
|
/* the internal events are sorted by id */
|
|
|
|
if (sort_type == TEP_EVENT_SORT_ID) {
|
|
|
|
tep->last_type = sort_type;
|
|
|
|
return events;
|
|
|
|
}
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
|
2019-04-02 00:43:08 +08:00
|
|
|
list_events_sort(events, tep->nr_events, sort_type);
|
|
|
|
tep->last_type = sort_type;
|
|
|
|
|
|
|
|
return events;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* tep_list_events_copy - Thread safe version of tep_list_events()
|
|
|
|
* @tep: a handle to the tep context
|
|
|
|
* @sort_type: desired sort order of the events in the array
|
|
|
|
*
|
|
|
|
* Returns an array of pointers to all events, sorted by the given
|
|
|
|
* @sort_type criteria. The last element of the array is NULL. The returned
|
|
|
|
* array is newly allocated inside the function and must be freed by the caller
|
|
|
|
*/
|
|
|
|
struct tep_event **tep_list_events_copy(struct tep_handle *tep,
|
|
|
|
enum tep_event_sort_type sort_type)
|
|
|
|
{
|
|
|
|
struct tep_event **events;
|
|
|
|
|
|
|
|
if (!tep)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
events = list_events_copy(tep);
|
|
|
|
if (!events)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* the internal events are sorted by id */
|
|
|
|
if (sort_type == TEP_EVENT_SORT_ID)
|
|
|
|
return events;
|
|
|
|
|
|
|
|
list_events_sort(events, tep->nr_events, sort_type);
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
return events;
|
|
|
|
}
|
|
|
|
|
2018-09-20 02:56:45 +08:00
|
|
|
static struct tep_format_field **
|
2012-04-06 06:47:53 +08:00
|
|
|
get_event_fields(const char *type, const char *name,
|
2018-09-20 02:56:45 +08:00
|
|
|
int count, struct tep_format_field *list)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
2018-09-20 02:56:45 +08:00
|
|
|
struct tep_format_field **fields;
|
|
|
|
struct tep_format_field *field;
|
2012-04-06 06:47:53 +08:00
|
|
|
int i = 0;
|
|
|
|
|
2012-09-13 04:30:50 +08:00
|
|
|
fields = malloc(sizeof(*fields) * (count + 1));
|
|
|
|
if (!fields)
|
|
|
|
return NULL;
|
|
|
|
|
2012-04-06 06:47:53 +08:00
|
|
|
for (field = list; field; field = field->next) {
|
|
|
|
fields[i++] = field;
|
|
|
|
if (i == count + 1) {
|
|
|
|
do_warning("event %s has more %s fields than specified",
|
|
|
|
name, type);
|
|
|
|
i--;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i != count)
|
|
|
|
do_warning("event %s has less %s fields than specified",
|
|
|
|
name, type);
|
|
|
|
|
|
|
|
fields[i] = NULL;
|
|
|
|
|
|
|
|
return fields;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-09 02:03:08 +08:00
|
|
|
* tep_event_common_fields - return a list of common fields for an event
|
2012-04-06 06:47:53 +08:00
|
|
|
* @event: the event to return the common fields of.
|
|
|
|
*
|
|
|
|
* Returns an allocated array of fields. The last item in the array is NULL.
|
|
|
|
* The array must be freed with free().
|
|
|
|
*/
|
2018-11-30 23:44:07 +08:00
|
|
|
struct tep_format_field **tep_event_common_fields(struct tep_event *event)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
|
|
|
return get_event_fields("common", event->name,
|
|
|
|
event->format.nr_common,
|
|
|
|
event->format.common_fields);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-09 02:03:08 +08:00
|
|
|
* tep_event_fields - return a list of event specific fields for an event
|
2012-04-06 06:47:53 +08:00
|
|
|
* @event: the event to return the fields of.
|
|
|
|
*
|
|
|
|
* Returns an allocated array of fields. The last item in the array is NULL.
|
|
|
|
* The array must be freed with free().
|
|
|
|
*/
|
2018-11-30 23:44:07 +08:00
|
|
|
struct tep_format_field **tep_event_fields(struct tep_event *event)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
|
|
|
return get_event_fields("event", event->name,
|
|
|
|
event->format.nr_fields,
|
|
|
|
event->format.fields);
|
|
|
|
}
|
|
|
|
|
2018-09-20 02:56:49 +08:00
|
|
|
static void print_fields(struct trace_seq *s, struct tep_print_flag_sym *field)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
|
|
|
trace_seq_printf(s, "{ %s, %s }", field->value, field->str);
|
|
|
|
if (field->next) {
|
|
|
|
trace_seq_puts(s, ", ");
|
|
|
|
print_fields(s, field->next);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* for debugging */
|
2018-09-20 02:56:49 +08:00
|
|
|
static void print_args(struct tep_print_arg *args)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
|
|
|
int print_paren = 1;
|
|
|
|
struct trace_seq s;
|
|
|
|
|
|
|
|
switch (args->type) {
|
2018-09-20 02:56:50 +08:00
|
|
|
case TEP_PRINT_NULL:
|
2012-04-06 06:47:53 +08:00
|
|
|
printf("null");
|
|
|
|
break;
|
2018-09-20 02:56:50 +08:00
|
|
|
case TEP_PRINT_ATOM:
|
2012-04-06 06:47:53 +08:00
|
|
|
printf("%s", args->atom.atom);
|
|
|
|
break;
|
2018-09-20 02:56:50 +08:00
|
|
|
case TEP_PRINT_FIELD:
|
2012-04-06 06:47:53 +08:00
|
|
|
printf("REC->%s", args->field.name);
|
|
|
|
break;
|
2018-09-20 02:56:50 +08:00
|
|
|
case TEP_PRINT_FLAGS:
|
2012-04-06 06:47:53 +08:00
|
|
|
printf("__print_flags(");
|
|
|
|
print_args(args->flags.field);
|
|
|
|
printf(", %s, ", args->flags.delim);
|
|
|
|
trace_seq_init(&s);
|
|
|
|
print_fields(&s, args->flags.flags);
|
|
|
|
trace_seq_do_printf(&s);
|
|
|
|
trace_seq_destroy(&s);
|
|
|
|
printf(")");
|
|
|
|
break;
|
2018-09-20 02:56:50 +08:00
|
|
|
case TEP_PRINT_SYMBOL:
|
2012-04-06 06:47:53 +08:00
|
|
|
printf("__print_symbolic(");
|
|
|
|
print_args(args->symbol.field);
|
|
|
|
printf(", ");
|
|
|
|
trace_seq_init(&s);
|
|
|
|
print_fields(&s, args->symbol.symbols);
|
|
|
|
trace_seq_do_printf(&s);
|
|
|
|
trace_seq_destroy(&s);
|
|
|
|
printf(")");
|
|
|
|
break;
|
2018-09-20 02:56:50 +08:00
|
|
|
case TEP_PRINT_HEX:
|
2012-06-27 08:41:41 +08:00
|
|
|
printf("__print_hex(");
|
|
|
|
print_args(args->hex.field);
|
|
|
|
printf(", ");
|
|
|
|
print_args(args->hex.size);
|
|
|
|
printf(")");
|
|
|
|
break;
|
2018-09-20 02:56:50 +08:00
|
|
|
case TEP_PRINT_HEX_STR:
|
2017-01-25 09:28:17 +08:00
|
|
|
printf("__print_hex_str(");
|
|
|
|
print_args(args->hex.field);
|
|
|
|
printf(", ");
|
|
|
|
print_args(args->hex.size);
|
|
|
|
printf(")");
|
|
|
|
break;
|
2018-09-20 02:56:50 +08:00
|
|
|
case TEP_PRINT_INT_ARRAY:
|
2015-03-24 19:07:19 +08:00
|
|
|
printf("__print_array(");
|
|
|
|
print_args(args->int_array.field);
|
|
|
|
printf(", ");
|
|
|
|
print_args(args->int_array.count);
|
|
|
|
printf(", ");
|
|
|
|
print_args(args->int_array.el_size);
|
|
|
|
printf(")");
|
|
|
|
break;
|
2018-09-20 02:56:50 +08:00
|
|
|
case TEP_PRINT_STRING:
|
|
|
|
case TEP_PRINT_BSTRING:
|
2012-04-06 06:47:53 +08:00
|
|
|
printf("__get_str(%s)", args->string.string);
|
|
|
|
break;
|
2018-09-20 02:56:50 +08:00
|
|
|
case TEP_PRINT_BITMASK:
|
2014-06-03 11:20:16 +08:00
|
|
|
printf("__get_bitmask(%s)", args->bitmask.bitmask);
|
|
|
|
break;
|
2018-09-20 02:56:50 +08:00
|
|
|
case TEP_PRINT_TYPE:
|
2012-04-06 06:47:53 +08:00
|
|
|
printf("(%s)", args->typecast.type);
|
|
|
|
print_args(args->typecast.item);
|
|
|
|
break;
|
2018-09-20 02:56:50 +08:00
|
|
|
case TEP_PRINT_OP:
|
2012-04-06 06:47:53 +08:00
|
|
|
if (strcmp(args->op.op, ":") == 0)
|
|
|
|
print_paren = 0;
|
|
|
|
if (print_paren)
|
|
|
|
printf("(");
|
|
|
|
print_args(args->op.left);
|
|
|
|
printf(" %s ", args->op.op);
|
|
|
|
print_args(args->op.right);
|
|
|
|
if (print_paren)
|
|
|
|
printf(")");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* we should warn... */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (args->next) {
|
|
|
|
printf("\n");
|
|
|
|
print_args(args->next);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void parse_header_field(const char *field,
|
|
|
|
int *offset, int *size, int mandatory)
|
|
|
|
{
|
|
|
|
unsigned long long save_input_buf_ptr;
|
|
|
|
unsigned long long save_input_buf_siz;
|
|
|
|
char *token;
|
|
|
|
int type;
|
|
|
|
|
|
|
|
save_input_buf_ptr = input_buf_ptr;
|
|
|
|
save_input_buf_siz = input_buf_siz;
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
if (read_expected(TEP_EVENT_ITEM, "field") < 0)
|
2012-04-06 06:47:53 +08:00
|
|
|
return;
|
2018-09-20 02:56:47 +08:00
|
|
|
if (read_expected(TEP_EVENT_OP, ":") < 0)
|
2012-04-06 06:47:53 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* type */
|
2018-09-20 02:56:47 +08:00
|
|
|
if (read_expect_type(TEP_EVENT_ITEM, &token) < 0)
|
2012-04-06 06:47:53 +08:00
|
|
|
goto fail;
|
|
|
|
free_token(token);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If this is not a mandatory field, then test it first.
|
|
|
|
*/
|
|
|
|
if (mandatory) {
|
2018-09-20 02:56:47 +08:00
|
|
|
if (read_expected(TEP_EVENT_ITEM, field) < 0)
|
2012-04-06 06:47:53 +08:00
|
|
|
return;
|
|
|
|
} else {
|
2018-09-20 02:56:47 +08:00
|
|
|
if (read_expect_type(TEP_EVENT_ITEM, &token) < 0)
|
2012-04-06 06:47:53 +08:00
|
|
|
goto fail;
|
|
|
|
if (strcmp(token, field) != 0)
|
|
|
|
goto discard;
|
|
|
|
free_token(token);
|
|
|
|
}
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
if (read_expected(TEP_EVENT_OP, ";") < 0)
|
2012-04-06 06:47:53 +08:00
|
|
|
return;
|
2018-09-20 02:56:47 +08:00
|
|
|
if (read_expected(TEP_EVENT_ITEM, "offset") < 0)
|
2012-04-06 06:47:53 +08:00
|
|
|
return;
|
2018-09-20 02:56:47 +08:00
|
|
|
if (read_expected(TEP_EVENT_OP, ":") < 0)
|
2012-04-06 06:47:53 +08:00
|
|
|
return;
|
2018-09-20 02:56:47 +08:00
|
|
|
if (read_expect_type(TEP_EVENT_ITEM, &token) < 0)
|
2012-04-06 06:47:53 +08:00
|
|
|
goto fail;
|
|
|
|
*offset = atoi(token);
|
|
|
|
free_token(token);
|
2018-09-20 02:56:47 +08:00
|
|
|
if (read_expected(TEP_EVENT_OP, ";") < 0)
|
2012-04-06 06:47:53 +08:00
|
|
|
return;
|
2018-09-20 02:56:47 +08:00
|
|
|
if (read_expected(TEP_EVENT_ITEM, "size") < 0)
|
2012-04-06 06:47:53 +08:00
|
|
|
return;
|
2018-09-20 02:56:47 +08:00
|
|
|
if (read_expected(TEP_EVENT_OP, ":") < 0)
|
2012-04-06 06:47:53 +08:00
|
|
|
return;
|
2018-09-20 02:56:47 +08:00
|
|
|
if (read_expect_type(TEP_EVENT_ITEM, &token) < 0)
|
2012-04-06 06:47:53 +08:00
|
|
|
goto fail;
|
|
|
|
*size = atoi(token);
|
|
|
|
free_token(token);
|
2018-09-20 02:56:47 +08:00
|
|
|
if (read_expected(TEP_EVENT_OP, ";") < 0)
|
2012-04-06 06:47:53 +08:00
|
|
|
return;
|
|
|
|
type = read_token(&token);
|
2018-09-20 02:56:47 +08:00
|
|
|
if (type != TEP_EVENT_NEWLINE) {
|
2012-04-06 06:47:53 +08:00
|
|
|
/* newer versions of the kernel have a "signed" type */
|
2018-09-20 02:56:47 +08:00
|
|
|
if (type != TEP_EVENT_ITEM)
|
2012-04-06 06:47:53 +08:00
|
|
|
goto fail;
|
|
|
|
|
|
|
|
if (strcmp(token, "signed") != 0)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
free_token(token);
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
if (read_expected(TEP_EVENT_OP, ":") < 0)
|
2012-04-06 06:47:53 +08:00
|
|
|
return;
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
if (read_expect_type(TEP_EVENT_ITEM, &token))
|
2012-04-06 06:47:53 +08:00
|
|
|
goto fail;
|
|
|
|
|
|
|
|
free_token(token);
|
2018-09-20 02:56:47 +08:00
|
|
|
if (read_expected(TEP_EVENT_OP, ";") < 0)
|
2012-04-06 06:47:53 +08:00
|
|
|
return;
|
|
|
|
|
2018-09-20 02:56:47 +08:00
|
|
|
if (read_expect_type(TEP_EVENT_NEWLINE, &token))
|
2012-04-06 06:47:53 +08:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
fail:
|
|
|
|
free_token(token);
|
|
|
|
return;
|
|
|
|
|
|
|
|
discard:
|
|
|
|
input_buf_ptr = save_input_buf_ptr;
|
|
|
|
input_buf_siz = save_input_buf_siz;
|
|
|
|
*offset = 0;
|
|
|
|
*size = 0;
|
|
|
|
free_token(token);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-09 02:02:51 +08:00
|
|
|
* tep_parse_header_page - parse the data stored in the header page
|
2019-04-02 00:43:17 +08:00
|
|
|
* @tep: a handle to the trace event parser context
|
2012-04-06 06:47:53 +08:00
|
|
|
* @buf: the buffer storing the header page format string
|
|
|
|
* @size: the size of @buf
|
|
|
|
* @long_size: the long size to use if there is no header
|
|
|
|
*
|
|
|
|
* This parses the header page format for information on the
|
|
|
|
* ring buffer used. The @buf should be copied from
|
|
|
|
*
|
|
|
|
* /sys/kernel/debug/tracing/events/header_page
|
|
|
|
*/
|
2019-04-02 00:43:17 +08:00
|
|
|
int tep_parse_header_page(struct tep_handle *tep, char *buf, unsigned long size,
|
2018-08-09 02:02:51 +08:00
|
|
|
int long_size)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
|
|
|
int ignore;
|
|
|
|
|
|
|
|
if (!size) {
|
|
|
|
/*
|
|
|
|
* Old kernels did not have header page info.
|
|
|
|
* Sorry but we just use what we find here in user space.
|
|
|
|
*/
|
2019-04-02 00:43:17 +08:00
|
|
|
tep->header_page_ts_size = sizeof(long long);
|
|
|
|
tep->header_page_size_size = long_size;
|
|
|
|
tep->header_page_data_offset = sizeof(long long) + long_size;
|
|
|
|
tep->old_format = 1;
|
2012-04-06 06:47:53 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
init_input_buf(buf, size);
|
|
|
|
|
2019-04-02 00:43:17 +08:00
|
|
|
parse_header_field("timestamp", &tep->header_page_ts_offset,
|
|
|
|
&tep->header_page_ts_size, 1);
|
|
|
|
parse_header_field("commit", &tep->header_page_size_offset,
|
|
|
|
&tep->header_page_size_size, 1);
|
|
|
|
parse_header_field("overwrite", &tep->header_page_overwrite,
|
2012-04-06 06:47:53 +08:00
|
|
|
&ignore, 0);
|
2019-04-02 00:43:17 +08:00
|
|
|
parse_header_field("data", &tep->header_page_data_offset,
|
|
|
|
&tep->header_page_data_size, 1);
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-11-30 23:44:07 +08:00
|
|
|
static int event_matches(struct tep_event *event,
|
2012-04-06 06:47:53 +08:00
|
|
|
int id, const char *sys_name,
|
|
|
|
const char *event_name)
|
|
|
|
{
|
|
|
|
if (id >= 0 && id != event->id)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (event_name && (strcmp(event_name, event->name) != 0))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (sys_name && (strcmp(sys_name, event->system) != 0))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void free_handler(struct event_handler *handle)
|
|
|
|
{
|
|
|
|
free((void *)handle->sys_name);
|
|
|
|
free((void *)handle->event_name);
|
|
|
|
free(handle);
|
|
|
|
}
|
|
|
|
|
2019-04-02 00:43:20 +08:00
|
|
|
static int find_event_handle(struct tep_handle *tep, struct tep_event *event)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
|
|
|
struct event_handler *handle, **next;
|
|
|
|
|
2019-04-02 00:43:20 +08:00
|
|
|
for (next = &tep->handlers; *next;
|
2012-04-06 06:47:53 +08:00
|
|
|
next = &(*next)->next) {
|
|
|
|
handle = *next;
|
|
|
|
if (event_matches(event, handle->id,
|
|
|
|
handle->sys_name,
|
|
|
|
handle->event_name))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(*next))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
pr_stat("overriding event (%d) %s:%s with new print handler",
|
|
|
|
event->id, event->system, event->name);
|
|
|
|
|
|
|
|
event->handler = handle->func;
|
|
|
|
event->context = handle->context;
|
|
|
|
|
|
|
|
*next = handle->next;
|
|
|
|
free_handler(handle);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-09-30 19:07:33 +08:00
|
|
|
* parse_format - parse the event format
|
2012-04-06 06:47:53 +08:00
|
|
|
* @buf: the buffer storing the event format string
|
|
|
|
* @size: the size of @buf
|
|
|
|
* @sys: the system the event belongs to
|
|
|
|
*
|
|
|
|
* This parses the event format and creates an event structure
|
|
|
|
* to quickly parse raw data for a given event.
|
|
|
|
*
|
|
|
|
* These files currently come from:
|
|
|
|
*
|
|
|
|
* /sys/kernel/debug/tracing/events/.../.../format
|
|
|
|
*/
|
2020-09-30 19:07:33 +08:00
|
|
|
static enum tep_errno parse_format(struct tep_event **eventp,
|
|
|
|
struct tep_handle *tep, const char *buf,
|
|
|
|
unsigned long size, const char *sys)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
2018-11-30 23:44:07 +08:00
|
|
|
struct tep_event *event;
|
2012-04-06 06:47:53 +08:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
init_input_buf(buf, size);
|
|
|
|
|
2012-09-18 22:13:15 +08:00
|
|
|
*eventp = event = alloc_event();
|
2012-04-06 06:47:53 +08:00
|
|
|
if (!event)
|
2018-08-09 02:02:58 +08:00
|
|
|
return TEP_ERRNO__MEM_ALLOC_FAILED;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
event->name = event_read_name();
|
|
|
|
if (!event->name) {
|
|
|
|
/* Bad event? */
|
2018-08-09 02:02:58 +08:00
|
|
|
ret = TEP_ERRNO__MEM_ALLOC_FAILED;
|
2012-08-22 15:00:29 +08:00
|
|
|
goto event_alloc_failed;
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (strcmp(sys, "ftrace") == 0) {
|
2018-09-20 02:56:48 +08:00
|
|
|
event->flags |= TEP_EVENT_FL_ISFTRACE;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
if (strcmp(event->name, "bprint") == 0)
|
2018-09-20 02:56:48 +08:00
|
|
|
event->flags |= TEP_EVENT_FL_ISBPRINT;
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
event->id = event_read_id();
|
2012-08-22 15:00:29 +08:00
|
|
|
if (event->id < 0) {
|
2018-08-09 02:02:58 +08:00
|
|
|
ret = TEP_ERRNO__READ_ID_FAILED;
|
2012-08-22 15:00:29 +08:00
|
|
|
/*
|
|
|
|
* This isn't an allocation error actually.
|
|
|
|
* But as the ID is critical, just bail out.
|
|
|
|
*/
|
|
|
|
goto event_alloc_failed;
|
|
|
|
}
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
event->system = strdup(sys);
|
2012-08-22 15:00:29 +08:00
|
|
|
if (!event->system) {
|
2018-08-09 02:02:58 +08:00
|
|
|
ret = TEP_ERRNO__MEM_ALLOC_FAILED;
|
2012-08-22 15:00:29 +08:00
|
|
|
goto event_alloc_failed;
|
|
|
|
}
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2019-04-02 00:43:20 +08:00
|
|
|
/* Add tep to event so that it can be referenced */
|
|
|
|
event->tep = tep;
|
2012-10-02 08:13:51 +08:00
|
|
|
|
2012-04-06 06:47:53 +08:00
|
|
|
ret = event_read_format(event);
|
|
|
|
if (ret < 0) {
|
2018-08-09 02:02:58 +08:00
|
|
|
ret = TEP_ERRNO__READ_FORMAT_FAILED;
|
2012-08-22 15:00:29 +08:00
|
|
|
goto event_parse_failed;
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the event has an override, don't print warnings if the event
|
|
|
|
* print format fails to parse.
|
|
|
|
*/
|
2019-04-02 00:43:20 +08:00
|
|
|
if (tep && find_event_handle(tep, event))
|
2012-04-06 06:47:53 +08:00
|
|
|
show_warning = 0;
|
|
|
|
|
|
|
|
ret = event_read_print(event);
|
2012-09-18 22:13:15 +08:00
|
|
|
show_warning = 1;
|
|
|
|
|
2012-04-06 06:47:53 +08:00
|
|
|
if (ret < 0) {
|
2018-08-09 02:02:58 +08:00
|
|
|
ret = TEP_ERRNO__READ_PRINT_FAILED;
|
2012-08-22 15:00:29 +08:00
|
|
|
goto event_parse_failed;
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
|
2018-09-20 02:56:48 +08:00
|
|
|
if (!ret && (event->flags & TEP_EVENT_FL_ISFTRACE)) {
|
2018-09-20 02:56:45 +08:00
|
|
|
struct tep_format_field *field;
|
2018-09-20 02:56:49 +08:00
|
|
|
struct tep_print_arg *arg, **list;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
/* old ftrace had no args */
|
|
|
|
list = &event->print_fmt.args;
|
|
|
|
for (field = event->format.fields; field; field = field->next) {
|
|
|
|
arg = alloc_arg();
|
2012-09-20 10:09:19 +08:00
|
|
|
if (!arg) {
|
2018-09-20 02:56:48 +08:00
|
|
|
event->flags |= TEP_EVENT_FL_FAILED;
|
2018-08-09 02:02:58 +08:00
|
|
|
return TEP_ERRNO__OLD_FTRACE_ARG_FAILED;
|
2012-09-20 10:09:19 +08:00
|
|
|
}
|
2018-09-20 02:56:50 +08:00
|
|
|
arg->type = TEP_PRINT_FIELD;
|
2012-04-06 06:47:53 +08:00
|
|
|
arg->field.name = strdup(field->name);
|
2012-04-09 10:54:31 +08:00
|
|
|
if (!arg->field.name) {
|
2018-09-20 02:56:48 +08:00
|
|
|
event->flags |= TEP_EVENT_FL_FAILED;
|
2012-08-22 15:00:28 +08:00
|
|
|
free_arg(arg);
|
2018-08-09 02:02:58 +08:00
|
|
|
return TEP_ERRNO__OLD_FTRACE_ARG_FAILED;
|
2012-04-09 10:54:31 +08:00
|
|
|
}
|
2012-04-06 06:47:53 +08:00
|
|
|
arg->field.field = field;
|
2012-08-22 15:00:28 +08:00
|
|
|
*list = arg;
|
|
|
|
list = &arg->next;
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-03 02:53:51 +08:00
|
|
|
if (!(event->flags & TEP_EVENT_FL_ISBPRINT))
|
|
|
|
event->print_fmt.print_cache = parse_args(event,
|
|
|
|
event->print_fmt.format,
|
|
|
|
event->print_fmt.args);
|
|
|
|
|
2012-04-06 06:47:53 +08:00
|
|
|
return 0;
|
|
|
|
|
2012-08-22 15:00:29 +08:00
|
|
|
event_parse_failed:
|
2018-09-20 02:56:48 +08:00
|
|
|
event->flags |= TEP_EVENT_FL_FAILED;
|
2012-08-22 15:00:29 +08:00
|
|
|
return ret;
|
|
|
|
|
|
|
|
event_alloc_failed:
|
2012-09-18 22:13:15 +08:00
|
|
|
free(event->system);
|
|
|
|
free(event->name);
|
|
|
|
free(event);
|
|
|
|
*eventp = NULL;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-08-09 02:02:58 +08:00
|
|
|
static enum tep_errno
|
2019-04-02 00:43:20 +08:00
|
|
|
__parse_event(struct tep_handle *tep,
|
2018-11-30 23:44:07 +08:00
|
|
|
struct tep_event **eventp,
|
2018-08-09 02:03:09 +08:00
|
|
|
const char *buf, unsigned long size,
|
|
|
|
const char *sys)
|
2013-12-03 21:09:19 +08:00
|
|
|
{
|
2020-09-30 19:07:33 +08:00
|
|
|
int ret = parse_format(eventp, tep, buf, size, sys);
|
2018-11-30 23:44:07 +08:00
|
|
|
struct tep_event *event = *eventp;
|
2013-12-03 21:09:19 +08:00
|
|
|
|
|
|
|
if (event == NULL)
|
|
|
|
return ret;
|
|
|
|
|
2019-04-02 00:43:20 +08:00
|
|
|
if (tep && add_event(tep, event)) {
|
2018-08-09 02:02:58 +08:00
|
|
|
ret = TEP_ERRNO__MEM_ALLOC_FAILED;
|
2013-12-03 21:09:19 +08:00
|
|
|
goto event_add_failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define PRINT_ARGS 0
|
|
|
|
if (PRINT_ARGS && event->print_fmt.args)
|
|
|
|
print_args(event->print_fmt.args);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
event_add_failed:
|
2020-09-30 19:07:33 +08:00
|
|
|
free_tep_event(event);
|
2013-12-03 21:09:19 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-09-18 22:13:15 +08:00
|
|
|
/**
|
2018-08-09 02:02:51 +08:00
|
|
|
* tep_parse_format - parse the event format
|
2019-04-02 00:43:17 +08:00
|
|
|
* @tep: a handle to the trace event parser context
|
2013-12-03 21:09:19 +08:00
|
|
|
* @eventp: returned format
|
2012-09-18 22:13:15 +08:00
|
|
|
* @buf: the buffer storing the event format string
|
|
|
|
* @size: the size of @buf
|
|
|
|
* @sys: the system the event belongs to
|
|
|
|
*
|
|
|
|
* This parses the event format and creates an event structure
|
|
|
|
* to quickly parse raw data for a given event.
|
|
|
|
*
|
|
|
|
* These files currently come from:
|
|
|
|
*
|
|
|
|
* /sys/kernel/debug/tracing/events/.../.../format
|
|
|
|
*/
|
2019-04-02 00:43:17 +08:00
|
|
|
enum tep_errno tep_parse_format(struct tep_handle *tep,
|
2018-11-30 23:44:07 +08:00
|
|
|
struct tep_event **eventp,
|
2018-08-09 02:02:58 +08:00
|
|
|
const char *buf,
|
|
|
|
unsigned long size, const char *sys)
|
2012-09-18 22:13:15 +08:00
|
|
|
{
|
2019-04-02 00:43:17 +08:00
|
|
|
return __parse_event(tep, eventp, buf, size, sys);
|
2012-09-18 22:13:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-09 02:02:51 +08:00
|
|
|
* tep_parse_event - parse the event format
|
2019-04-02 00:43:17 +08:00
|
|
|
* @tep: a handle to the trace event parser context
|
2012-09-18 22:13:15 +08:00
|
|
|
* @buf: the buffer storing the event format string
|
|
|
|
* @size: the size of @buf
|
|
|
|
* @sys: the system the event belongs to
|
|
|
|
*
|
|
|
|
* This parses the event format and creates an event structure
|
|
|
|
* to quickly parse raw data for a given event.
|
|
|
|
*
|
|
|
|
* These files currently come from:
|
|
|
|
*
|
|
|
|
* /sys/kernel/debug/tracing/events/.../.../format
|
|
|
|
*/
|
2019-04-02 00:43:17 +08:00
|
|
|
enum tep_errno tep_parse_event(struct tep_handle *tep, const char *buf,
|
2018-08-09 02:02:58 +08:00
|
|
|
unsigned long size, const char *sys)
|
2012-09-18 22:13:15 +08:00
|
|
|
{
|
2018-11-30 23:44:07 +08:00
|
|
|
struct tep_event *event = NULL;
|
2019-04-02 00:43:17 +08:00
|
|
|
return __parse_event(tep, &event, buf, size, sys);
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
|
2018-09-20 02:56:45 +08:00
|
|
|
int get_field_val(struct trace_seq *s, struct tep_format_field *field,
|
2018-08-09 02:02:47 +08:00
|
|
|
const char *name, struct tep_record *record,
|
2012-04-06 06:47:53 +08:00
|
|
|
unsigned long long *val, int err)
|
|
|
|
{
|
|
|
|
if (!field) {
|
|
|
|
if (err)
|
|
|
|
trace_seq_printf(s, "<CANT FIND FIELD %s>", name);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-08-09 02:02:53 +08:00
|
|
|
if (tep_read_number_field(field, record->data, val)) {
|
2012-04-06 06:47:53 +08:00
|
|
|
if (err)
|
|
|
|
trace_seq_printf(s, " %s=INVALID", name);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-09 02:03:04 +08:00
|
|
|
* tep_get_field_raw - return the raw pointer into the data field
|
2012-04-06 06:47:53 +08:00
|
|
|
* @s: The seq to print to on error
|
|
|
|
* @event: the event that the field is for
|
|
|
|
* @name: The name of the field
|
|
|
|
* @record: The record with the field name.
|
|
|
|
* @len: place to store the field length.
|
|
|
|
* @err: print default error if failed.
|
|
|
|
*
|
|
|
|
* Returns a pointer into record->data of the field and places
|
|
|
|
* the length of the field in @len.
|
|
|
|
*
|
|
|
|
* On failure, it returns NULL.
|
|
|
|
*/
|
2018-11-30 23:44:07 +08:00
|
|
|
void *tep_get_field_raw(struct trace_seq *s, struct tep_event *event,
|
2018-08-09 02:03:04 +08:00
|
|
|
const char *name, struct tep_record *record,
|
|
|
|
int *len, int err)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
2018-09-20 02:56:45 +08:00
|
|
|
struct tep_format_field *field;
|
2012-04-06 06:47:53 +08:00
|
|
|
void *data = record->data;
|
|
|
|
unsigned offset;
|
|
|
|
int dummy;
|
|
|
|
|
|
|
|
if (!event)
|
|
|
|
return NULL;
|
|
|
|
|
2018-08-09 02:02:50 +08:00
|
|
|
field = tep_find_field(event, name);
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
if (!field) {
|
|
|
|
if (err)
|
|
|
|
trace_seq_printf(s, "<CANT FIND FIELD %s>", name);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allow @len to be NULL */
|
|
|
|
if (!len)
|
|
|
|
len = &dummy;
|
|
|
|
|
|
|
|
offset = field->offset;
|
2018-09-20 02:56:46 +08:00
|
|
|
if (field->flags & TEP_FIELD_IS_DYNAMIC) {
|
2019-04-02 00:43:18 +08:00
|
|
|
offset = tep_read_number(event->tep,
|
|
|
|
data + offset, field->size);
|
2012-04-06 06:47:53 +08:00
|
|
|
*len = offset >> 16;
|
|
|
|
offset &= 0xffff;
|
2021-11-22 17:30:40 +08:00
|
|
|
if (field->flags & TEP_FIELD_IS_RELATIVE)
|
|
|
|
offset += field->offset + field->size;
|
2012-04-06 06:47:53 +08:00
|
|
|
} else
|
|
|
|
*len = field->size;
|
|
|
|
|
|
|
|
return data + offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-09 02:03:04 +08:00
|
|
|
* tep_get_field_val - find a field and return its value
|
2012-04-06 06:47:53 +08:00
|
|
|
* @s: The seq to print to on error
|
|
|
|
* @event: the event that the field is for
|
|
|
|
* @name: The name of the field
|
|
|
|
* @record: The record with the field name.
|
|
|
|
* @val: place to store the value of the field.
|
|
|
|
* @err: print default error if failed.
|
|
|
|
*
|
|
|
|
* Returns 0 on success -1 on field not found.
|
|
|
|
*/
|
2018-11-30 23:44:07 +08:00
|
|
|
int tep_get_field_val(struct trace_seq *s, struct tep_event *event,
|
2018-08-09 02:03:04 +08:00
|
|
|
const char *name, struct tep_record *record,
|
|
|
|
unsigned long long *val, int err)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
2018-09-20 02:56:45 +08:00
|
|
|
struct tep_format_field *field;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
if (!event)
|
|
|
|
return -1;
|
|
|
|
|
2018-08-09 02:02:50 +08:00
|
|
|
field = tep_find_field(event, name);
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
return get_field_val(s, field, name, record, val, err);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-09 02:03:04 +08:00
|
|
|
* tep_get_common_field_val - find a common field and return its value
|
2012-04-06 06:47:53 +08:00
|
|
|
* @s: The seq to print to on error
|
|
|
|
* @event: the event that the field is for
|
|
|
|
* @name: The name of the field
|
|
|
|
* @record: The record with the field name.
|
|
|
|
* @val: place to store the value of the field.
|
|
|
|
* @err: print default error if failed.
|
|
|
|
*
|
|
|
|
* Returns 0 on success -1 on field not found.
|
|
|
|
*/
|
2018-11-30 23:44:07 +08:00
|
|
|
int tep_get_common_field_val(struct trace_seq *s, struct tep_event *event,
|
2018-08-09 02:03:04 +08:00
|
|
|
const char *name, struct tep_record *record,
|
|
|
|
unsigned long long *val, int err)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
2018-09-20 02:56:45 +08:00
|
|
|
struct tep_format_field *field;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
if (!event)
|
|
|
|
return -1;
|
|
|
|
|
2018-08-09 02:02:50 +08:00
|
|
|
field = tep_find_common_field(event, name);
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
return get_field_val(s, field, name, record, val, err);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-09 02:03:04 +08:00
|
|
|
* tep_get_any_field_val - find a any field and return its value
|
2012-04-06 06:47:53 +08:00
|
|
|
* @s: The seq to print to on error
|
|
|
|
* @event: the event that the field is for
|
|
|
|
* @name: The name of the field
|
|
|
|
* @record: The record with the field name.
|
|
|
|
* @val: place to store the value of the field.
|
|
|
|
* @err: print default error if failed.
|
|
|
|
*
|
|
|
|
* Returns 0 on success -1 on field not found.
|
|
|
|
*/
|
2018-11-30 23:44:07 +08:00
|
|
|
int tep_get_any_field_val(struct trace_seq *s, struct tep_event *event,
|
2018-08-09 02:03:04 +08:00
|
|
|
const char *name, struct tep_record *record,
|
|
|
|
unsigned long long *val, int err)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
2018-09-20 02:56:45 +08:00
|
|
|
struct tep_format_field *field;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
if (!event)
|
|
|
|
return -1;
|
|
|
|
|
2018-08-09 02:02:50 +08:00
|
|
|
field = tep_find_any_field(event, name);
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
return get_field_val(s, field, name, record, val, err);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-09 02:02:52 +08:00
|
|
|
* tep_print_num_field - print a field and a format
|
2012-04-06 06:47:53 +08:00
|
|
|
* @s: The seq to print to
|
|
|
|
* @fmt: The printf format to print the field with.
|
|
|
|
* @event: the event that the field is for
|
|
|
|
* @name: The name of the field
|
|
|
|
* @record: The record with the field name.
|
|
|
|
* @err: print default error if failed.
|
|
|
|
*
|
2019-04-02 00:43:10 +08:00
|
|
|
* Returns positive value on success, negative in case of an error,
|
|
|
|
* or 0 if buffer is full.
|
2012-04-06 06:47:53 +08:00
|
|
|
*/
|
2018-08-09 02:02:52 +08:00
|
|
|
int tep_print_num_field(struct trace_seq *s, const char *fmt,
|
2018-11-30 23:44:07 +08:00
|
|
|
struct tep_event *event, const char *name,
|
2018-08-09 02:02:52 +08:00
|
|
|
struct tep_record *record, int err)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
2018-09-20 02:56:45 +08:00
|
|
|
struct tep_format_field *field = tep_find_field(event, name);
|
2012-04-06 06:47:53 +08:00
|
|
|
unsigned long long val;
|
|
|
|
|
|
|
|
if (!field)
|
|
|
|
goto failed;
|
|
|
|
|
2018-08-09 02:02:53 +08:00
|
|
|
if (tep_read_number_field(field, record->data, &val))
|
2012-04-06 06:47:53 +08:00
|
|
|
goto failed;
|
|
|
|
|
|
|
|
return trace_seq_printf(s, fmt, val);
|
|
|
|
|
|
|
|
failed:
|
|
|
|
if (err)
|
|
|
|
trace_seq_printf(s, "CAN'T FIND FIELD \"%s\"", name);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-11-02 05:54:00 +08:00
|
|
|
/**
|
2018-08-09 02:02:52 +08:00
|
|
|
* tep_print_func_field - print a field and a format for function pointers
|
2013-11-02 05:54:00 +08:00
|
|
|
* @s: The seq to print to
|
|
|
|
* @fmt: The printf format to print the field with.
|
|
|
|
* @event: the event that the field is for
|
|
|
|
* @name: The name of the field
|
|
|
|
* @record: The record with the field name.
|
|
|
|
* @err: print default error if failed.
|
|
|
|
*
|
2019-04-02 00:43:10 +08:00
|
|
|
* Returns positive value on success, negative in case of an error,
|
|
|
|
* or 0 if buffer is full.
|
2013-11-02 05:54:00 +08:00
|
|
|
*/
|
2018-08-09 02:02:52 +08:00
|
|
|
int tep_print_func_field(struct trace_seq *s, const char *fmt,
|
2018-11-30 23:44:07 +08:00
|
|
|
struct tep_event *event, const char *name,
|
2018-08-09 02:02:52 +08:00
|
|
|
struct tep_record *record, int err)
|
2013-11-02 05:54:00 +08:00
|
|
|
{
|
2018-09-20 02:56:45 +08:00
|
|
|
struct tep_format_field *field = tep_find_field(event, name);
|
2019-04-02 00:43:20 +08:00
|
|
|
struct tep_handle *tep = event->tep;
|
2013-11-02 05:54:00 +08:00
|
|
|
unsigned long long val;
|
|
|
|
struct func_map *func;
|
|
|
|
char tmp[128];
|
|
|
|
|
|
|
|
if (!field)
|
|
|
|
goto failed;
|
|
|
|
|
2018-08-09 02:02:53 +08:00
|
|
|
if (tep_read_number_field(field, record->data, &val))
|
2013-11-02 05:54:00 +08:00
|
|
|
goto failed;
|
|
|
|
|
2019-04-02 00:43:20 +08:00
|
|
|
func = find_func(tep, val);
|
2013-11-02 05:54:00 +08:00
|
|
|
|
|
|
|
if (func)
|
|
|
|
snprintf(tmp, 128, "%s/0x%llx", func->func, func->addr - val);
|
|
|
|
else
|
|
|
|
sprintf(tmp, "0x%08llx", val);
|
|
|
|
|
|
|
|
return trace_seq_printf(s, fmt, tmp);
|
|
|
|
|
|
|
|
failed:
|
|
|
|
if (err)
|
|
|
|
trace_seq_printf(s, "CAN'T FIND FIELD \"%s\"", name);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
tools lib traceevent: Rename pevent_function* APIs
In order to make libtraceevent into a proper library, variables, data
structures and functions require a unique prefix to prevent name space
conflicts. That prefix will be "tep_" and not "pevent_". This changes
APIs: pevent_function_handler, pevent_func_handler,
pevent_func_arg_type, PEVENT_FUNC_ARG_VOID, PEVENT_FUNC_ARG_INT,
PEVENT_FUNC_ARG_LONG, PEVENT_FUNC_ARG_STRING, PEVENT_FUNC_ARG_PTRS,
PEVENT_FUNC_ARG_MAX_TYPES
Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
Cc: linux-trace-devel@vger.kernel.org
Link: http://lkml.kernel.org/r/20180808180701.935881193@goodmis.org
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2018-08-09 02:02:59 +08:00
|
|
|
static void free_func_handle(struct tep_function_handler *func)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
2018-08-09 02:03:09 +08:00
|
|
|
struct func_params *params;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
free(func->name);
|
|
|
|
|
|
|
|
while (func->params) {
|
|
|
|
params = func->params;
|
|
|
|
func->params = params->next;
|
|
|
|
free(params);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(func);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-09 02:03:02 +08:00
|
|
|
* tep_register_print_function - register a helper function
|
2019-04-02 00:43:17 +08:00
|
|
|
* @tep: a handle to the trace event parser context
|
2012-04-06 06:47:53 +08:00
|
|
|
* @func: the function to process the helper function
|
2012-04-23 12:58:35 +08:00
|
|
|
* @ret_type: the return type of the helper function
|
2012-04-06 06:47:53 +08:00
|
|
|
* @name: the name of the helper function
|
tools lib traceevent: Rename pevent_function* APIs
In order to make libtraceevent into a proper library, variables, data
structures and functions require a unique prefix to prevent name space
conflicts. That prefix will be "tep_" and not "pevent_". This changes
APIs: pevent_function_handler, pevent_func_handler,
pevent_func_arg_type, PEVENT_FUNC_ARG_VOID, PEVENT_FUNC_ARG_INT,
PEVENT_FUNC_ARG_LONG, PEVENT_FUNC_ARG_STRING, PEVENT_FUNC_ARG_PTRS,
PEVENT_FUNC_ARG_MAX_TYPES
Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
Cc: linux-trace-devel@vger.kernel.org
Link: http://lkml.kernel.org/r/20180808180701.935881193@goodmis.org
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2018-08-09 02:02:59 +08:00
|
|
|
* @parameters: A list of enum tep_func_arg_type
|
2012-04-06 06:47:53 +08:00
|
|
|
*
|
|
|
|
* Some events may have helper functions in the print format arguments.
|
2012-04-23 12:58:35 +08:00
|
|
|
* This allows a plugin to dynamically create a way to process one
|
2012-04-06 06:47:53 +08:00
|
|
|
* of these functions.
|
|
|
|
*
|
tools lib traceevent: Rename pevent_function* APIs
In order to make libtraceevent into a proper library, variables, data
structures and functions require a unique prefix to prevent name space
conflicts. That prefix will be "tep_" and not "pevent_". This changes
APIs: pevent_function_handler, pevent_func_handler,
pevent_func_arg_type, PEVENT_FUNC_ARG_VOID, PEVENT_FUNC_ARG_INT,
PEVENT_FUNC_ARG_LONG, PEVENT_FUNC_ARG_STRING, PEVENT_FUNC_ARG_PTRS,
PEVENT_FUNC_ARG_MAX_TYPES
Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
Cc: linux-trace-devel@vger.kernel.org
Link: http://lkml.kernel.org/r/20180808180701.935881193@goodmis.org
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2018-08-09 02:02:59 +08:00
|
|
|
* The @parameters is a variable list of tep_func_arg_type enums that
|
|
|
|
* must end with TEP_FUNC_ARG_VOID.
|
2012-04-06 06:47:53 +08:00
|
|
|
*/
|
2019-04-02 00:43:17 +08:00
|
|
|
int tep_register_print_function(struct tep_handle *tep,
|
2018-08-09 02:03:02 +08:00
|
|
|
tep_func_handler func,
|
|
|
|
enum tep_func_arg_type ret_type,
|
|
|
|
char *name, ...)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
tools lib traceevent: Rename pevent_function* APIs
In order to make libtraceevent into a proper library, variables, data
structures and functions require a unique prefix to prevent name space
conflicts. That prefix will be "tep_" and not "pevent_". This changes
APIs: pevent_function_handler, pevent_func_handler,
pevent_func_arg_type, PEVENT_FUNC_ARG_VOID, PEVENT_FUNC_ARG_INT,
PEVENT_FUNC_ARG_LONG, PEVENT_FUNC_ARG_STRING, PEVENT_FUNC_ARG_PTRS,
PEVENT_FUNC_ARG_MAX_TYPES
Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
Cc: linux-trace-devel@vger.kernel.org
Link: http://lkml.kernel.org/r/20180808180701.935881193@goodmis.org
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2018-08-09 02:02:59 +08:00
|
|
|
struct tep_function_handler *func_handle;
|
2018-08-09 02:03:09 +08:00
|
|
|
struct func_params **next_param;
|
|
|
|
struct func_params *param;
|
tools lib traceevent: Rename pevent_function* APIs
In order to make libtraceevent into a proper library, variables, data
structures and functions require a unique prefix to prevent name space
conflicts. That prefix will be "tep_" and not "pevent_". This changes
APIs: pevent_function_handler, pevent_func_handler,
pevent_func_arg_type, PEVENT_FUNC_ARG_VOID, PEVENT_FUNC_ARG_INT,
PEVENT_FUNC_ARG_LONG, PEVENT_FUNC_ARG_STRING, PEVENT_FUNC_ARG_PTRS,
PEVENT_FUNC_ARG_MAX_TYPES
Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
Cc: linux-trace-devel@vger.kernel.org
Link: http://lkml.kernel.org/r/20180808180701.935881193@goodmis.org
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2018-08-09 02:02:59 +08:00
|
|
|
enum tep_func_arg_type type;
|
2012-04-06 06:47:53 +08:00
|
|
|
va_list ap;
|
2012-09-07 10:49:47 +08:00
|
|
|
int ret;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2019-04-02 00:43:17 +08:00
|
|
|
func_handle = find_func_handler(tep, name);
|
2012-04-06 06:47:53 +08:00
|
|
|
if (func_handle) {
|
|
|
|
/*
|
|
|
|
* This is most like caused by the users own
|
|
|
|
* plugins updating the function. This overrides the
|
|
|
|
* system defaults.
|
|
|
|
*/
|
|
|
|
pr_stat("override of function helper '%s'", name);
|
2019-04-02 00:43:17 +08:00
|
|
|
remove_func_handler(tep, name);
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
|
2012-09-13 02:39:59 +08:00
|
|
|
func_handle = calloc(1, sizeof(*func_handle));
|
2012-09-07 10:49:47 +08:00
|
|
|
if (!func_handle) {
|
|
|
|
do_warning("Failed to allocate function handler");
|
2018-08-09 02:02:58 +08:00
|
|
|
return TEP_ERRNO__MEM_ALLOC_FAILED;
|
2012-09-07 10:49:47 +08:00
|
|
|
}
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
func_handle->ret_type = ret_type;
|
|
|
|
func_handle->name = strdup(name);
|
|
|
|
func_handle->func = func;
|
2012-09-07 10:49:47 +08:00
|
|
|
if (!func_handle->name) {
|
|
|
|
do_warning("Failed to allocate function name");
|
|
|
|
free(func_handle);
|
2018-08-09 02:02:58 +08:00
|
|
|
return TEP_ERRNO__MEM_ALLOC_FAILED;
|
2012-09-07 10:49:47 +08:00
|
|
|
}
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
next_param = &(func_handle->params);
|
|
|
|
va_start(ap, name);
|
|
|
|
for (;;) {
|
tools lib traceevent: Rename pevent_function* APIs
In order to make libtraceevent into a proper library, variables, data
structures and functions require a unique prefix to prevent name space
conflicts. That prefix will be "tep_" and not "pevent_". This changes
APIs: pevent_function_handler, pevent_func_handler,
pevent_func_arg_type, PEVENT_FUNC_ARG_VOID, PEVENT_FUNC_ARG_INT,
PEVENT_FUNC_ARG_LONG, PEVENT_FUNC_ARG_STRING, PEVENT_FUNC_ARG_PTRS,
PEVENT_FUNC_ARG_MAX_TYPES
Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
Cc: linux-trace-devel@vger.kernel.org
Link: http://lkml.kernel.org/r/20180808180701.935881193@goodmis.org
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2018-08-09 02:02:59 +08:00
|
|
|
type = va_arg(ap, enum tep_func_arg_type);
|
|
|
|
if (type == TEP_FUNC_ARG_VOID)
|
2012-04-06 06:47:53 +08:00
|
|
|
break;
|
|
|
|
|
tools lib traceevent: Rename pevent_function* APIs
In order to make libtraceevent into a proper library, variables, data
structures and functions require a unique prefix to prevent name space
conflicts. That prefix will be "tep_" and not "pevent_". This changes
APIs: pevent_function_handler, pevent_func_handler,
pevent_func_arg_type, PEVENT_FUNC_ARG_VOID, PEVENT_FUNC_ARG_INT,
PEVENT_FUNC_ARG_LONG, PEVENT_FUNC_ARG_STRING, PEVENT_FUNC_ARG_PTRS,
PEVENT_FUNC_ARG_MAX_TYPES
Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
Cc: linux-trace-devel@vger.kernel.org
Link: http://lkml.kernel.org/r/20180808180701.935881193@goodmis.org
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2018-08-09 02:02:59 +08:00
|
|
|
if (type >= TEP_FUNC_ARG_MAX_TYPES) {
|
2012-09-07 10:49:47 +08:00
|
|
|
do_warning("Invalid argument type %d", type);
|
2018-08-09 02:02:58 +08:00
|
|
|
ret = TEP_ERRNO__INVALID_ARG_TYPE;
|
2012-04-06 06:47:53 +08:00
|
|
|
goto out_free;
|
|
|
|
}
|
|
|
|
|
2012-09-07 10:49:47 +08:00
|
|
|
param = malloc(sizeof(*param));
|
|
|
|
if (!param) {
|
|
|
|
do_warning("Failed to allocate function param");
|
2018-08-09 02:02:58 +08:00
|
|
|
ret = TEP_ERRNO__MEM_ALLOC_FAILED;
|
2012-09-07 10:49:47 +08:00
|
|
|
goto out_free;
|
|
|
|
}
|
2012-04-06 06:47:53 +08:00
|
|
|
param->type = type;
|
|
|
|
param->next = NULL;
|
|
|
|
|
|
|
|
*next_param = param;
|
|
|
|
next_param = &(param->next);
|
|
|
|
|
|
|
|
func_handle->nr_args++;
|
|
|
|
}
|
|
|
|
va_end(ap);
|
|
|
|
|
2019-04-02 00:43:17 +08:00
|
|
|
func_handle->next = tep->func_handlers;
|
|
|
|
tep->func_handlers = func_handle;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
out_free:
|
|
|
|
va_end(ap);
|
|
|
|
free_func_handle(func_handle);
|
2012-09-07 10:49:47 +08:00
|
|
|
return ret;
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
|
2014-01-16 10:31:08 +08:00
|
|
|
/**
|
2018-08-09 02:03:02 +08:00
|
|
|
* tep_unregister_print_function - unregister a helper function
|
2019-04-02 00:43:17 +08:00
|
|
|
* @tep: a handle to the trace event parser context
|
2014-01-16 10:31:08 +08:00
|
|
|
* @func: the function to process the helper function
|
|
|
|
* @name: the name of the helper function
|
|
|
|
*
|
|
|
|
* This function removes existing print handler for function @name.
|
|
|
|
*
|
|
|
|
* Returns 0 if the handler was removed successully, -1 otherwise.
|
|
|
|
*/
|
2019-04-02 00:43:17 +08:00
|
|
|
int tep_unregister_print_function(struct tep_handle *tep,
|
2018-08-09 02:03:02 +08:00
|
|
|
tep_func_handler func, char *name)
|
2014-01-16 10:31:08 +08:00
|
|
|
{
|
tools lib traceevent: Rename pevent_function* APIs
In order to make libtraceevent into a proper library, variables, data
structures and functions require a unique prefix to prevent name space
conflicts. That prefix will be "tep_" and not "pevent_". This changes
APIs: pevent_function_handler, pevent_func_handler,
pevent_func_arg_type, PEVENT_FUNC_ARG_VOID, PEVENT_FUNC_ARG_INT,
PEVENT_FUNC_ARG_LONG, PEVENT_FUNC_ARG_STRING, PEVENT_FUNC_ARG_PTRS,
PEVENT_FUNC_ARG_MAX_TYPES
Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
Cc: linux-trace-devel@vger.kernel.org
Link: http://lkml.kernel.org/r/20180808180701.935881193@goodmis.org
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2018-08-09 02:02:59 +08:00
|
|
|
struct tep_function_handler *func_handle;
|
2014-01-16 10:31:08 +08:00
|
|
|
|
2019-04-02 00:43:17 +08:00
|
|
|
func_handle = find_func_handler(tep, name);
|
2014-01-16 10:31:08 +08:00
|
|
|
if (func_handle && func_handle->func == func) {
|
2019-04-02 00:43:17 +08:00
|
|
|
remove_func_handler(tep, name);
|
2014-01-16 10:31:08 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2019-04-02 00:43:20 +08:00
|
|
|
static struct tep_event *search_event(struct tep_handle *tep, int id,
|
2018-11-30 23:44:07 +08:00
|
|
|
const char *sys_name,
|
|
|
|
const char *event_name)
|
2014-01-16 10:31:07 +08:00
|
|
|
{
|
2018-11-30 23:44:07 +08:00
|
|
|
struct tep_event *event;
|
2014-01-16 10:31:07 +08:00
|
|
|
|
|
|
|
if (id >= 0) {
|
|
|
|
/* search by id */
|
2019-04-02 00:43:20 +08:00
|
|
|
event = tep_find_event(tep, id);
|
2014-01-16 10:31:07 +08:00
|
|
|
if (!event)
|
|
|
|
return NULL;
|
|
|
|
if (event_name && (strcmp(event_name, event->name) != 0))
|
|
|
|
return NULL;
|
|
|
|
if (sys_name && (strcmp(sys_name, event->system) != 0))
|
|
|
|
return NULL;
|
|
|
|
} else {
|
2019-04-02 00:43:20 +08:00
|
|
|
event = tep_find_event_by_name(tep, sys_name, event_name);
|
2014-01-16 10:31:07 +08:00
|
|
|
if (!event)
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
2012-04-06 06:47:53 +08:00
|
|
|
/**
|
2018-08-09 02:03:02 +08:00
|
|
|
* tep_register_event_handler - register a way to parse an event
|
2019-04-02 00:43:17 +08:00
|
|
|
* @tep: a handle to the trace event parser context
|
2012-04-06 06:47:53 +08:00
|
|
|
* @id: the id of the event to register
|
|
|
|
* @sys_name: the system name the event belongs to
|
|
|
|
* @event_name: the name of the event
|
|
|
|
* @func: the function to call to parse the event information
|
2012-04-23 12:58:35 +08:00
|
|
|
* @context: the data to be passed to @func
|
2012-04-06 06:47:53 +08:00
|
|
|
*
|
|
|
|
* This function allows a developer to override the parsing of
|
|
|
|
* a given event. If for some reason the default print format
|
|
|
|
* is not sufficient, this function will register a function
|
|
|
|
* for an event to be used to parse the data instead.
|
|
|
|
*
|
|
|
|
* If @id is >= 0, then it is used to find the event.
|
|
|
|
* else @sys_name and @event_name are used.
|
2018-12-01 12:08:11 +08:00
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* TEP_REGISTER_SUCCESS_OVERWRITE if an existing handler is overwritten
|
|
|
|
* TEP_REGISTER_SUCCESS if a new handler is registered successfully
|
|
|
|
* negative TEP_ERRNO_... in case of an error
|
|
|
|
*
|
2012-04-06 06:47:53 +08:00
|
|
|
*/
|
2019-04-02 00:43:17 +08:00
|
|
|
int tep_register_event_handler(struct tep_handle *tep, int id,
|
2018-08-09 02:03:02 +08:00
|
|
|
const char *sys_name, const char *event_name,
|
|
|
|
tep_event_handler_func func, void *context)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
2018-11-30 23:44:07 +08:00
|
|
|
struct tep_event *event;
|
2012-04-06 06:47:53 +08:00
|
|
|
struct event_handler *handle;
|
|
|
|
|
2019-04-02 00:43:17 +08:00
|
|
|
event = search_event(tep, id, sys_name, event_name);
|
2014-01-16 10:31:07 +08:00
|
|
|
if (event == NULL)
|
|
|
|
goto not_found;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
pr_stat("overriding event (%d) %s:%s with new print handler",
|
|
|
|
event->id, event->system, event->name);
|
|
|
|
|
|
|
|
event->handler = func;
|
|
|
|
event->context = context;
|
2018-12-01 12:08:11 +08:00
|
|
|
return TEP_REGISTER_SUCCESS_OVERWRITE;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
not_found:
|
|
|
|
/* Save for later use. */
|
2012-09-13 02:39:59 +08:00
|
|
|
handle = calloc(1, sizeof(*handle));
|
2012-09-07 10:49:46 +08:00
|
|
|
if (!handle) {
|
|
|
|
do_warning("Failed to allocate event handler");
|
2018-08-09 02:02:58 +08:00
|
|
|
return TEP_ERRNO__MEM_ALLOC_FAILED;
|
2012-09-07 10:49:46 +08:00
|
|
|
}
|
|
|
|
|
2012-04-06 06:47:53 +08:00
|
|
|
handle->id = id;
|
|
|
|
if (event_name)
|
|
|
|
handle->event_name = strdup(event_name);
|
|
|
|
if (sys_name)
|
|
|
|
handle->sys_name = strdup(sys_name);
|
|
|
|
|
2012-04-09 10:54:31 +08:00
|
|
|
if ((event_name && !handle->event_name) ||
|
|
|
|
(sys_name && !handle->sys_name)) {
|
2012-09-07 10:49:46 +08:00
|
|
|
do_warning("Failed to allocate event/sys name");
|
|
|
|
free((void *)handle->event_name);
|
|
|
|
free((void *)handle->sys_name);
|
|
|
|
free(handle);
|
2018-08-09 02:02:58 +08:00
|
|
|
return TEP_ERRNO__MEM_ALLOC_FAILED;
|
2012-04-09 10:54:31 +08:00
|
|
|
}
|
|
|
|
|
2012-04-06 06:47:53 +08:00
|
|
|
handle->func = func;
|
2019-04-02 00:43:17 +08:00
|
|
|
handle->next = tep->handlers;
|
|
|
|
tep->handlers = handle;
|
2012-04-06 06:47:53 +08:00
|
|
|
handle->context = context;
|
|
|
|
|
2018-12-01 12:08:11 +08:00
|
|
|
return TEP_REGISTER_SUCCESS;
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
|
2014-01-16 10:31:07 +08:00
|
|
|
static int handle_matches(struct event_handler *handler, int id,
|
|
|
|
const char *sys_name, const char *event_name,
|
2018-08-09 02:02:48 +08:00
|
|
|
tep_event_handler_func func, void *context)
|
2014-01-16 10:31:07 +08:00
|
|
|
{
|
|
|
|
if (id >= 0 && id != handler->id)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (event_name && (strcmp(event_name, handler->event_name) != 0))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (sys_name && (strcmp(sys_name, handler->sys_name) != 0))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (func != handler->func || context != handler->context)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-09 02:03:02 +08:00
|
|
|
* tep_unregister_event_handler - unregister an existing event handler
|
2019-04-02 00:43:17 +08:00
|
|
|
* @tep: a handle to the trace event parser context
|
2014-01-16 10:31:07 +08:00
|
|
|
* @id: the id of the event to unregister
|
|
|
|
* @sys_name: the system name the handler belongs to
|
|
|
|
* @event_name: the name of the event handler
|
|
|
|
* @func: the function to call to parse the event information
|
|
|
|
* @context: the data to be passed to @func
|
|
|
|
*
|
|
|
|
* This function removes existing event handler (parser).
|
|
|
|
*
|
|
|
|
* If @id is >= 0, then it is used to find the event.
|
|
|
|
* else @sys_name and @event_name are used.
|
|
|
|
*
|
|
|
|
* Returns 0 if handler was removed successfully, -1 if event was not found.
|
|
|
|
*/
|
2019-04-02 00:43:17 +08:00
|
|
|
int tep_unregister_event_handler(struct tep_handle *tep, int id,
|
2018-08-09 02:03:02 +08:00
|
|
|
const char *sys_name, const char *event_name,
|
|
|
|
tep_event_handler_func func, void *context)
|
2014-01-16 10:31:07 +08:00
|
|
|
{
|
2018-11-30 23:44:07 +08:00
|
|
|
struct tep_event *event;
|
2014-01-16 10:31:07 +08:00
|
|
|
struct event_handler *handle;
|
|
|
|
struct event_handler **next;
|
|
|
|
|
2019-04-02 00:43:17 +08:00
|
|
|
event = search_event(tep, id, sys_name, event_name);
|
2014-01-16 10:31:07 +08:00
|
|
|
if (event == NULL)
|
|
|
|
goto not_found;
|
|
|
|
|
|
|
|
if (event->handler == func && event->context == context) {
|
|
|
|
pr_stat("removing override handler for event (%d) %s:%s. Going back to default handler.",
|
|
|
|
event->id, event->system, event->name);
|
|
|
|
|
|
|
|
event->handler = NULL;
|
|
|
|
event->context = NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
not_found:
|
2019-04-02 00:43:17 +08:00
|
|
|
for (next = &tep->handlers; *next; next = &(*next)->next) {
|
2014-01-16 10:31:07 +08:00
|
|
|
handle = *next;
|
|
|
|
if (handle_matches(handle, id, sys_name, event_name,
|
|
|
|
func, context))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(*next))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
*next = handle->next;
|
|
|
|
free_handler(handle);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-04-06 06:47:53 +08:00
|
|
|
/**
|
2019-04-02 00:43:17 +08:00
|
|
|
* tep_alloc - create a tep handle
|
2012-04-06 06:47:53 +08:00
|
|
|
*/
|
2018-08-09 02:02:49 +08:00
|
|
|
struct tep_handle *tep_alloc(void)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
2019-04-02 00:43:20 +08:00
|
|
|
struct tep_handle *tep = calloc(1, sizeof(*tep));
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2019-04-02 00:43:20 +08:00
|
|
|
if (tep) {
|
|
|
|
tep->ref_count = 1;
|
|
|
|
tep->host_bigendian = tep_is_bigendian();
|
2018-12-01 12:08:08 +08:00
|
|
|
}
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2019-04-02 00:43:20 +08:00
|
|
|
return tep;
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
|
2019-04-02 00:43:17 +08:00
|
|
|
void tep_ref(struct tep_handle *tep)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
2019-04-02 00:43:17 +08:00
|
|
|
tep->ref_count++;
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
|
2018-11-30 23:44:04 +08:00
|
|
|
int tep_get_ref(struct tep_handle *tep)
|
|
|
|
{
|
|
|
|
if (tep)
|
|
|
|
return tep->ref_count;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-09-30 19:07:33 +08:00
|
|
|
__hidden void free_tep_format_field(struct tep_format_field *field)
|
2015-03-20 02:36:21 +08:00
|
|
|
{
|
|
|
|
free(field->type);
|
2015-04-18 23:50:18 +08:00
|
|
|
if (field->alias != field->name)
|
|
|
|
free(field->alias);
|
2015-03-20 02:36:21 +08:00
|
|
|
free(field->name);
|
|
|
|
free(field);
|
|
|
|
}
|
|
|
|
|
2018-09-20 02:56:45 +08:00
|
|
|
static void free_format_fields(struct tep_format_field *field)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
2018-09-20 02:56:45 +08:00
|
|
|
struct tep_format_field *next;
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
while (field) {
|
|
|
|
next = field->next;
|
2020-09-30 19:07:33 +08:00
|
|
|
free_tep_format_field(field);
|
2012-04-06 06:47:53 +08:00
|
|
|
field = next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-20 02:56:45 +08:00
|
|
|
static void free_formats(struct tep_format *format)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
|
|
|
free_format_fields(format->common_fields);
|
|
|
|
free_format_fields(format->fields);
|
|
|
|
}
|
|
|
|
|
2020-09-30 19:07:33 +08:00
|
|
|
__hidden void free_tep_event(struct tep_event *event)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
|
|
|
free(event->name);
|
|
|
|
free(event->system);
|
|
|
|
|
|
|
|
free_formats(&event->format);
|
|
|
|
|
|
|
|
free(event->print_fmt.format);
|
|
|
|
free_args(event->print_fmt.args);
|
2020-07-03 02:53:51 +08:00
|
|
|
free_parse_args(event->print_fmt.print_cache);
|
2012-04-06 06:47:53 +08:00
|
|
|
free(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-04-02 00:43:17 +08:00
|
|
|
* tep_free - free a tep handle
|
|
|
|
* @tep: the tep handle to free
|
2012-04-06 06:47:53 +08:00
|
|
|
*/
|
2019-04-02 00:43:17 +08:00
|
|
|
void tep_free(struct tep_handle *tep)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
2012-04-06 06:48:02 +08:00
|
|
|
struct cmdline_list *cmdlist, *cmdnext;
|
|
|
|
struct func_list *funclist, *funcnext;
|
|
|
|
struct printk_list *printklist, *printknext;
|
tools lib traceevent: Rename pevent_function* APIs
In order to make libtraceevent into a proper library, variables, data
structures and functions require a unique prefix to prevent name space
conflicts. That prefix will be "tep_" and not "pevent_". This changes
APIs: pevent_function_handler, pevent_func_handler,
pevent_func_arg_type, PEVENT_FUNC_ARG_VOID, PEVENT_FUNC_ARG_INT,
PEVENT_FUNC_ARG_LONG, PEVENT_FUNC_ARG_STRING, PEVENT_FUNC_ARG_PTRS,
PEVENT_FUNC_ARG_MAX_TYPES
Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
Cc: linux-trace-devel@vger.kernel.org
Link: http://lkml.kernel.org/r/20180808180701.935881193@goodmis.org
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2018-08-09 02:02:59 +08:00
|
|
|
struct tep_function_handler *func_handler;
|
2012-04-06 06:47:53 +08:00
|
|
|
struct event_handler *handle;
|
|
|
|
int i;
|
|
|
|
|
2019-04-02 00:43:17 +08:00
|
|
|
if (!tep)
|
2012-04-06 06:48:02 +08:00
|
|
|
return;
|
|
|
|
|
2019-04-02 00:43:17 +08:00
|
|
|
cmdlist = tep->cmdlist;
|
|
|
|
funclist = tep->funclist;
|
|
|
|
printklist = tep->printklist;
|
2012-04-06 06:48:02 +08:00
|
|
|
|
2019-04-02 00:43:17 +08:00
|
|
|
tep->ref_count--;
|
|
|
|
if (tep->ref_count)
|
2012-04-06 06:47:53 +08:00
|
|
|
return;
|
|
|
|
|
2019-04-02 00:43:17 +08:00
|
|
|
if (tep->cmdlines) {
|
|
|
|
for (i = 0; i < tep->cmdline_count; i++)
|
|
|
|
free(tep->cmdlines[i].comm);
|
|
|
|
free(tep->cmdlines);
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
while (cmdlist) {
|
|
|
|
cmdnext = cmdlist->next;
|
|
|
|
free(cmdlist->comm);
|
|
|
|
free(cmdlist);
|
|
|
|
cmdlist = cmdnext;
|
|
|
|
}
|
|
|
|
|
2019-04-02 00:43:17 +08:00
|
|
|
if (tep->func_map) {
|
|
|
|
for (i = 0; i < (int)tep->func_count; i++) {
|
|
|
|
free(tep->func_map[i].func);
|
|
|
|
free(tep->func_map[i].mod);
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
2019-04-02 00:43:17 +08:00
|
|
|
free(tep->func_map);
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
while (funclist) {
|
|
|
|
funcnext = funclist->next;
|
|
|
|
free(funclist->func);
|
|
|
|
free(funclist->mod);
|
|
|
|
free(funclist);
|
|
|
|
funclist = funcnext;
|
|
|
|
}
|
|
|
|
|
2019-04-02 00:43:17 +08:00
|
|
|
while (tep->func_handlers) {
|
|
|
|
func_handler = tep->func_handlers;
|
|
|
|
tep->func_handlers = func_handler->next;
|
2012-04-06 06:47:53 +08:00
|
|
|
free_func_handle(func_handler);
|
|
|
|
}
|
|
|
|
|
2019-04-02 00:43:17 +08:00
|
|
|
if (tep->printk_map) {
|
|
|
|
for (i = 0; i < (int)tep->printk_count; i++)
|
|
|
|
free(tep->printk_map[i].printk);
|
|
|
|
free(tep->printk_map);
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
while (printklist) {
|
|
|
|
printknext = printklist->next;
|
|
|
|
free(printklist->printk);
|
|
|
|
free(printklist);
|
|
|
|
printklist = printknext;
|
|
|
|
}
|
|
|
|
|
2019-04-02 00:43:17 +08:00
|
|
|
for (i = 0; i < tep->nr_events; i++)
|
2020-09-30 19:07:33 +08:00
|
|
|
free_tep_event(tep->events[i]);
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2019-04-02 00:43:17 +08:00
|
|
|
while (tep->handlers) {
|
|
|
|
handle = tep->handlers;
|
|
|
|
tep->handlers = handle->next;
|
2012-04-06 06:47:53 +08:00
|
|
|
free_handler(handle);
|
|
|
|
}
|
|
|
|
|
2019-04-02 00:43:17 +08:00
|
|
|
free(tep->events);
|
|
|
|
free(tep->sort_events);
|
|
|
|
free(tep->func_resolver);
|
2020-09-30 19:07:33 +08:00
|
|
|
free_tep_plugin_paths(tep);
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2019-04-02 00:43:17 +08:00
|
|
|
free(tep);
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|
|
|
|
|
2019-04-02 00:43:17 +08:00
|
|
|
void tep_unref(struct tep_handle *tep)
|
2012-04-06 06:47:53 +08:00
|
|
|
{
|
2019-04-02 00:43:17 +08:00
|
|
|
tep_free(tep);
|
2012-04-06 06:47:53 +08:00
|
|
|
}
|