hc
2023-12-09 958e46acc8e900e8569dd467c1af9b8d2d019394
kernel/tools/perf/util/scripting-engines/trace-event-perl.c
....@@ -34,9 +34,11 @@
3434 #include <EXTERN.h>
3535 #include <perl.h>
3636
37
-#include "../../perf.h"
3837 #include "../callchain.h"
38
+#include "../dso.h"
3939 #include "../machine.h"
40
+#include "../map.h"
41
+#include "../symbol.h"
4042 #include "../thread.h"
4143 #include "../event.h"
4244 #include "../trace-event.h"
....@@ -99,7 +101,7 @@
99101 LEAVE;
100102 }
101103
102
-static void define_symbolic_values(struct print_flag_sym *field,
104
+static void define_symbolic_values(struct tep_print_flag_sym *field,
103105 const char *ev_name,
104106 const char *field_name)
105107 {
....@@ -157,7 +159,7 @@
157159 LEAVE;
158160 }
159161
160
-static void define_flag_values(struct print_flag_sym *field,
162
+static void define_flag_values(struct tep_print_flag_sym *field,
161163 const char *ev_name,
162164 const char *field_name)
163165 {
....@@ -189,62 +191,62 @@
189191 LEAVE;
190192 }
191193
192
-static void define_event_symbols(struct event_format *event,
194
+static void define_event_symbols(struct tep_event *event,
193195 const char *ev_name,
194
- struct print_arg *args)
196
+ struct tep_print_arg *args)
195197 {
196198 if (args == NULL)
197199 return;
198200
199201 switch (args->type) {
200
- case PRINT_NULL:
202
+ case TEP_PRINT_NULL:
201203 break;
202
- case PRINT_ATOM:
204
+ case TEP_PRINT_ATOM:
203205 define_flag_value(ev_name, cur_field_name, "0",
204206 args->atom.atom);
205207 zero_flag_atom = 0;
206208 break;
207
- case PRINT_FIELD:
209
+ case TEP_PRINT_FIELD:
208210 free(cur_field_name);
209211 cur_field_name = strdup(args->field.name);
210212 break;
211
- case PRINT_FLAGS:
213
+ case TEP_PRINT_FLAGS:
212214 define_event_symbols(event, ev_name, args->flags.field);
213215 define_flag_field(ev_name, cur_field_name, args->flags.delim);
214216 define_flag_values(args->flags.flags, ev_name, cur_field_name);
215217 break;
216
- case PRINT_SYMBOL:
218
+ case TEP_PRINT_SYMBOL:
217219 define_event_symbols(event, ev_name, args->symbol.field);
218220 define_symbolic_field(ev_name, cur_field_name);
219221 define_symbolic_values(args->symbol.symbols, ev_name,
220222 cur_field_name);
221223 break;
222
- case PRINT_HEX:
223
- case PRINT_HEX_STR:
224
+ case TEP_PRINT_HEX:
225
+ case TEP_PRINT_HEX_STR:
224226 define_event_symbols(event, ev_name, args->hex.field);
225227 define_event_symbols(event, ev_name, args->hex.size);
226228 break;
227
- case PRINT_INT_ARRAY:
229
+ case TEP_PRINT_INT_ARRAY:
228230 define_event_symbols(event, ev_name, args->int_array.field);
229231 define_event_symbols(event, ev_name, args->int_array.count);
230232 define_event_symbols(event, ev_name, args->int_array.el_size);
231233 break;
232
- case PRINT_BSTRING:
233
- case PRINT_DYNAMIC_ARRAY:
234
- case PRINT_DYNAMIC_ARRAY_LEN:
235
- case PRINT_STRING:
236
- case PRINT_BITMASK:
234
+ case TEP_PRINT_BSTRING:
235
+ case TEP_PRINT_DYNAMIC_ARRAY:
236
+ case TEP_PRINT_DYNAMIC_ARRAY_LEN:
237
+ case TEP_PRINT_STRING:
238
+ case TEP_PRINT_BITMASK:
237239 break;
238
- case PRINT_TYPE:
240
+ case TEP_PRINT_TYPE:
239241 define_event_symbols(event, ev_name, args->typecast.item);
240242 break;
241
- case PRINT_OP:
243
+ case TEP_PRINT_OP:
242244 if (strcmp(args->op.op, ":") == 0)
243245 zero_flag_atom = 1;
244246 define_event_symbols(event, ev_name, args->op.left);
245247 define_event_symbols(event, ev_name, args->op.right);
246248 break;
247
- case PRINT_FUNC:
249
+ case TEP_PRINT_FUNC:
248250 default:
249251 pr_err("Unsupported print arg type\n");
250252 /* we should warn... */
....@@ -256,7 +258,7 @@
256258 }
257259
258260 static SV *perl_process_callchain(struct perf_sample *sample,
259
- struct perf_evsel *evsel,
261
+ struct evsel *evsel,
260262 struct addr_location *al)
261263 {
262264 AV *list;
....@@ -292,17 +294,17 @@
292294 goto exit;
293295 }
294296
295
- if (node->sym) {
297
+ if (node->ms.sym) {
296298 HV *sym = newHV();
297299 if (!sym) {
298300 hv_undef(elem);
299301 goto exit;
300302 }
301
- if (!hv_stores(sym, "start", newSVuv(node->sym->start)) ||
302
- !hv_stores(sym, "end", newSVuv(node->sym->end)) ||
303
- !hv_stores(sym, "binding", newSVuv(node->sym->binding)) ||
304
- !hv_stores(sym, "name", newSVpvn(node->sym->name,
305
- node->sym->namelen)) ||
303
+ if (!hv_stores(sym, "start", newSVuv(node->ms.sym->start)) ||
304
+ !hv_stores(sym, "end", newSVuv(node->ms.sym->end)) ||
305
+ !hv_stores(sym, "binding", newSVuv(node->ms.sym->binding)) ||
306
+ !hv_stores(sym, "name", newSVpvn(node->ms.sym->name,
307
+ node->ms.sym->namelen)) ||
306308 !hv_stores(elem, "sym", newRV_noinc((SV*)sym))) {
307309 hv_undef(sym);
308310 hv_undef(elem);
....@@ -310,8 +312,8 @@
310312 }
311313 }
312314
313
- if (node->map) {
314
- struct map *map = node->map;
315
+ if (node->ms.map) {
316
+ struct map *map = node->ms.map;
315317 const char *dsoname = "[unknown]";
316318 if (map && map->dso) {
317319 if (symbol_conf.show_kernel_path && map->dso->long_name)
....@@ -334,12 +336,12 @@
334336 }
335337
336338 static void perl_process_tracepoint(struct perf_sample *sample,
337
- struct perf_evsel *evsel,
339
+ struct evsel *evsel,
338340 struct addr_location *al)
339341 {
340342 struct thread *thread = al->thread;
341
- struct event_format *event = evsel->tp_format;
342
- struct format_field *field;
343
+ struct tep_event *event = evsel->tp_format;
344
+ struct tep_format_field *field;
343345 static char handler[256];
344346 unsigned long long val;
345347 unsigned long s, ns;
....@@ -351,11 +353,11 @@
351353
352354 dSP;
353355
354
- if (evsel->attr.type != PERF_TYPE_TRACEPOINT)
356
+ if (evsel->core.attr.type != PERF_TYPE_TRACEPOINT)
355357 return;
356358
357359 if (!event) {
358
- pr_debug("ug! no event found for type %" PRIu64, (u64)evsel->attr.config);
360
+ pr_debug("ug! no event found for type %" PRIu64, (u64)evsel->core.attr.config);
359361 return;
360362 }
361363
....@@ -370,7 +372,7 @@
370372 ns = nsecs - s * NSEC_PER_SEC;
371373
372374 scripting_context->event_data = data;
373
- scripting_context->pevent = evsel->tp_format->pevent;
375
+ scripting_context->pevent = evsel->tp_format->tep;
374376
375377 ENTER;
376378 SAVETMPS;
....@@ -388,9 +390,9 @@
388390 /* common fields other than pid can be accessed via xsub fns */
389391
390392 for (field = event->format.fields; field; field = field->next) {
391
- if (field->flags & FIELD_IS_STRING) {
393
+ if (field->flags & TEP_FIELD_IS_STRING) {
392394 int offset;
393
- if (field->flags & FIELD_IS_DYNAMIC) {
395
+ if (field->flags & TEP_FIELD_IS_DYNAMIC) {
394396 offset = *(int *)(data + field->offset);
395397 offset &= 0xffff;
396398 } else
....@@ -399,7 +401,7 @@
399401 } else { /* FIELD_IS_NUMERIC */
400402 val = read_size(event, data + field->offset,
401403 field->size);
402
- if (field->flags & FIELD_IS_SIGNED) {
404
+ if (field->flags & TEP_FIELD_IS_SIGNED) {
403405 XPUSHs(sv_2mortal(newSViv(val)));
404406 } else {
405407 XPUSHs(sv_2mortal(newSVuv(val)));
....@@ -429,7 +431,7 @@
429431
430432 static void perl_process_event_generic(union perf_event *event,
431433 struct perf_sample *sample,
432
- struct perf_evsel *evsel)
434
+ struct evsel *evsel)
433435 {
434436 dSP;
435437
....@@ -440,7 +442,7 @@
440442 SAVETMPS;
441443 PUSHMARK(SP);
442444 XPUSHs(sv_2mortal(newSVpvn((const char *)event, event->header.size)));
443
- XPUSHs(sv_2mortal(newSVpvn((const char *)&evsel->attr, sizeof(evsel->attr))));
445
+ XPUSHs(sv_2mortal(newSVpvn((const char *)&evsel->core.attr, sizeof(evsel->core.attr))));
444446 XPUSHs(sv_2mortal(newSVpvn((const char *)sample, sizeof(*sample))));
445447 XPUSHs(sv_2mortal(newSVpvn((const char *)sample->raw_data, sample->raw_size)));
446448 PUTBACK;
....@@ -453,7 +455,7 @@
453455
454456 static void perl_process_event(union perf_event *event,
455457 struct perf_sample *sample,
456
- struct perf_evsel *evsel,
458
+ struct evsel *evsel,
457459 struct addr_location *al)
458460 {
459461 perl_process_tracepoint(sample, evsel, al);
....@@ -537,10 +539,11 @@
537539
538540 static int perl_generate_script(struct tep_handle *pevent, const char *outfile)
539541 {
540
- struct event_format *event = NULL;
541
- struct format_field *f;
542
+ int i, not_first, count, nr_events;
543
+ struct tep_event **all_events;
544
+ struct tep_event *event = NULL;
545
+ struct tep_format_field *f;
542546 char fname[PATH_MAX];
543
- int not_first, count;
544547 FILE *ofp;
545548
546549 sprintf(fname, "%s.pl", outfile);
....@@ -601,8 +604,11 @@
601604 }\n\n\
602605 ");
603606
607
+ nr_events = tep_get_events_count(pevent);
608
+ all_events = tep_list_events(pevent, TEP_EVENT_SORT_ID);
604609
605
- while ((event = trace_find_next_event(pevent, event))) {
610
+ for (i = 0; all_events && i < nr_events; i++) {
611
+ event = all_events[i];
606612 fprintf(ofp, "sub %s::%s\n{\n", event->system, event->name);
607613 fprintf(ofp, "\tmy (");
608614
....@@ -646,11 +652,11 @@
646652 count++;
647653
648654 fprintf(ofp, "%s=", f->name);
649
- if (f->flags & FIELD_IS_STRING ||
650
- f->flags & FIELD_IS_FLAG ||
651
- f->flags & FIELD_IS_SYMBOLIC)
655
+ if (f->flags & TEP_FIELD_IS_STRING ||
656
+ f->flags & TEP_FIELD_IS_FLAG ||
657
+ f->flags & TEP_FIELD_IS_SYMBOLIC)
652658 fprintf(ofp, "%%s");
653
- else if (f->flags & FIELD_IS_SIGNED)
659
+ else if (f->flags & TEP_FIELD_IS_SIGNED)
654660 fprintf(ofp, "%%d");
655661 else
656662 fprintf(ofp, "%%u");
....@@ -668,7 +674,7 @@
668674 if (++count % 5 == 0)
669675 fprintf(ofp, "\n\t ");
670676
671
- if (f->flags & FIELD_IS_FLAG) {
677
+ if (f->flags & TEP_FIELD_IS_FLAG) {
672678 if ((count - 1) % 5 != 0) {
673679 fprintf(ofp, "\n\t ");
674680 count = 4;
....@@ -678,7 +684,7 @@
678684 event->name);
679685 fprintf(ofp, "\"%s\", $%s)", f->name,
680686 f->name);
681
- } else if (f->flags & FIELD_IS_SYMBOLIC) {
687
+ } else if (f->flags & TEP_FIELD_IS_SYMBOLIC) {
682688 if ((count - 1) % 5 != 0) {
683689 fprintf(ofp, "\n\t ");
684690 count = 4;