| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Copyright (C) 2009, Steven Rostedt <srostedt@redhat.com> |
|---|
| 3 | | - * |
|---|
| 4 | | - * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 5 | | - * |
|---|
| 6 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 7 | | - * it under the terms of the GNU General Public License as published by |
|---|
| 8 | | - * the Free Software Foundation; version 2 of the License (not later!) |
|---|
| 9 | | - * |
|---|
| 10 | | - * This program is distributed in the hope that it will be useful, |
|---|
| 11 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 12 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 13 | | - * GNU General Public License for more details. |
|---|
| 14 | | - * |
|---|
| 15 | | - * You should have received a copy of the GNU General Public License |
|---|
| 16 | | - * along with this program; if not, write to the Free Software |
|---|
| 17 | | - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 18 | | - * |
|---|
| 19 | | - * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 20 | 4 | */ |
|---|
| 21 | 5 | #include <stdio.h> |
|---|
| 22 | 6 | #include <stdlib.h> |
|---|
| 23 | 7 | #include <string.h> |
|---|
| 24 | 8 | #include <errno.h> |
|---|
| 25 | 9 | |
|---|
| 26 | | -#include "../perf.h" |
|---|
| 27 | 10 | #include "debug.h" |
|---|
| 28 | 11 | #include "trace-event.h" |
|---|
| 29 | 12 | |
|---|
| 30 | | -#include "sane_ctype.h" |
|---|
| 13 | +#include <linux/ctype.h> |
|---|
| 31 | 14 | |
|---|
| 32 | 15 | static int get_common_field(struct scripting_context *context, |
|---|
| 33 | 16 | int *offset, int *size, const char *type) |
|---|
| 34 | 17 | { |
|---|
| 35 | 18 | struct tep_handle *pevent = context->pevent; |
|---|
| 36 | | - struct event_format *event; |
|---|
| 37 | | - struct format_field *field; |
|---|
| 19 | + struct tep_event *event; |
|---|
| 20 | + struct tep_format_field *field; |
|---|
| 38 | 21 | |
|---|
| 39 | 22 | if (!*size) { |
|---|
| 40 | | - if (!pevent->events) |
|---|
| 23 | + |
|---|
| 24 | + event = tep_get_first_event(pevent); |
|---|
| 25 | + if (!event) |
|---|
| 41 | 26 | return 0; |
|---|
| 42 | 27 | |
|---|
| 43 | | - event = pevent->events[0]; |
|---|
| 44 | 28 | field = tep_find_common_field(event, type); |
|---|
| 45 | 29 | if (!field) |
|---|
| 46 | 30 | return 0; |
|---|
| .. | .. |
|---|
| 94 | 78 | } |
|---|
| 95 | 79 | |
|---|
| 96 | 80 | unsigned long long |
|---|
| 97 | | -raw_field_value(struct event_format *event, const char *name, void *data) |
|---|
| 81 | +raw_field_value(struct tep_event *event, const char *name, void *data) |
|---|
| 98 | 82 | { |
|---|
| 99 | | - struct format_field *field; |
|---|
| 83 | + struct tep_format_field *field; |
|---|
| 100 | 84 | unsigned long long val; |
|---|
| 101 | 85 | |
|---|
| 102 | 86 | field = tep_find_any_field(event, name); |
|---|
| .. | .. |
|---|
| 108 | 92 | return val; |
|---|
| 109 | 93 | } |
|---|
| 110 | 94 | |
|---|
| 111 | | -unsigned long long read_size(struct event_format *event, void *ptr, int size) |
|---|
| 95 | +unsigned long long read_size(struct tep_event *event, void *ptr, int size) |
|---|
| 112 | 96 | { |
|---|
| 113 | | - return tep_read_number(event->pevent, ptr, size); |
|---|
| 97 | + return tep_read_number(event->tep, ptr, size); |
|---|
| 114 | 98 | } |
|---|
| 115 | 99 | |
|---|
| 116 | | -void event_format__fprintf(struct event_format *event, |
|---|
| 100 | +void event_format__fprintf(struct tep_event *event, |
|---|
| 117 | 101 | int cpu, void *data, int size, FILE *fp) |
|---|
| 118 | 102 | { |
|---|
| 119 | 103 | struct tep_record record; |
|---|
| .. | .. |
|---|
| 125 | 109 | record.data = data; |
|---|
| 126 | 110 | |
|---|
| 127 | 111 | trace_seq_init(&s); |
|---|
| 128 | | - tep_event_info(&s, event, &record); |
|---|
| 112 | + tep_print_event(event->tep, &s, &record, "%s", TEP_PRINT_INFO); |
|---|
| 129 | 113 | trace_seq_do_fprintf(&s, fp); |
|---|
| 130 | 114 | trace_seq_destroy(&s); |
|---|
| 131 | 115 | } |
|---|
| 132 | 116 | |
|---|
| 133 | | -void event_format__print(struct event_format *event, |
|---|
| 117 | +void event_format__print(struct tep_event *event, |
|---|
| 134 | 118 | int cpu, void *data, int size) |
|---|
| 135 | 119 | { |
|---|
| 136 | 120 | return event_format__fprintf(event, cpu, data, size, stdout); |
|---|
| .. | .. |
|---|
| 187 | 171 | char *buf, unsigned long size, char *sys) |
|---|
| 188 | 172 | { |
|---|
| 189 | 173 | return tep_parse_event(pevent, buf, size, sys); |
|---|
| 190 | | -} |
|---|
| 191 | | - |
|---|
| 192 | | -struct event_format *trace_find_next_event(struct tep_handle *pevent, |
|---|
| 193 | | - struct event_format *event) |
|---|
| 194 | | -{ |
|---|
| 195 | | - static int idx; |
|---|
| 196 | | - |
|---|
| 197 | | - if (!pevent || !pevent->events) |
|---|
| 198 | | - return NULL; |
|---|
| 199 | | - |
|---|
| 200 | | - if (!event) { |
|---|
| 201 | | - idx = 0; |
|---|
| 202 | | - return pevent->events[0]; |
|---|
| 203 | | - } |
|---|
| 204 | | - |
|---|
| 205 | | - if (idx < pevent->nr_events && event == pevent->events[idx]) { |
|---|
| 206 | | - idx++; |
|---|
| 207 | | - if (idx == pevent->nr_events) |
|---|
| 208 | | - return NULL; |
|---|
| 209 | | - return pevent->events[idx]; |
|---|
| 210 | | - } |
|---|
| 211 | | - |
|---|
| 212 | | - for (idx = 1; idx < pevent->nr_events; idx++) { |
|---|
| 213 | | - if (event == pevent->events[idx - 1]) |
|---|
| 214 | | - return pevent->events[idx]; |
|---|
| 215 | | - } |
|---|
| 216 | | - return NULL; |
|---|
| 217 | 174 | } |
|---|
| 218 | 175 | |
|---|
| 219 | 176 | struct flag { |
|---|