Lines Matching +full:cs +full:- +full:setup
1 // SPDX-License-Identifier: GPL-2.0-only
14 #include <babeltrace/ctf-writer/writer.h>
15 #include <babeltrace/ctf-writer/clock.h>
16 #include <babeltrace/ctf-writer/stream.h>
17 #include <babeltrace/ctf-writer/event.h>
18 #include <babeltrace/ctf-writer/event-types.h>
19 #include <babeltrace/ctf-writer/event-fields.h>
20 #include <babeltrace/ctf-ir/utils.h>
22 #include <traceevent/event-parse.h>
24 #include "data-convert.h"
109 return -1; in value_set()
145 struct bt_ctf_field_type *type = cw->data._name; \
162 struct bt_ctf_field_type *type = cw->data.string; in value_set_string()
169 return -1; in value_set_string()
190 unsigned long flags = field->flags; in get_tracepoint_field_type()
193 return cw->data.string; in get_tracepoint_field_type()
198 return cw->data.u64_hex; in get_tracepoint_field_type()
202 if (field->size == 8) in get_tracepoint_field_type()
203 return cw->data.s64; in get_tracepoint_field_type()
205 return cw->data.s32; in get_tracepoint_field_type()
208 if (field->size == 8) in get_tracepoint_field_type()
209 return cw->data.u64; in get_tracepoint_field_type()
211 return cw->data.u32; in get_tracepoint_field_type()
219 * value_mask = (1 << (size * 8 - 1)) - 1. in adjust_signedness()
244 if ((value_int & (~0ULL - value_mask)) == 0) in adjust_signedness()
269 buffer = zalloc(i + (len - i) * 4 + 2); in string_set_value()
272 return bt_ctf_field_string_set_value(field, "UNPRINTABLE-STRING"); in string_set_value()
298 const char *name = fmtf->name; in add_tracepoint_field_value()
299 void *data = sample->raw_data; in add_tracepoint_field_value()
300 unsigned long flags = fmtf->flags; in add_tracepoint_field_value()
307 name = fmtf->alias; in add_tracepoint_field_value()
308 offset = fmtf->offset; in add_tracepoint_field_value()
309 len = fmtf->size; in add_tracepoint_field_value()
316 tmp_val = tep_read_number(fmtf->event->tep, in add_tracepoint_field_value()
322 offset += fmtf->offset + fmtf->size; in add_tracepoint_field_value()
333 return -1; in add_tracepoint_field_value()
336 len = fmtf->size / fmtf->arraylen; in add_tracepoint_field_value()
337 n_items = fmtf->arraylen; in add_tracepoint_field_value()
353 return -1; in add_tracepoint_field_value()
362 fmtf->event->tep, in add_tracepoint_field_value()
390 return -1; in add_tracepoint_field_value()
398 return -1; in add_tracepoint_field_value()
410 for (field = fields; field; field = field->next) { in add_tracepoint_fields_values()
414 return -1; in add_tracepoint_fields_values()
425 struct tep_format_field *common_fields = evsel->tp_format->format.common_fields; in add_tracepoint_values()
426 struct tep_format_field *fields = evsel->tp_format->format.fields; in add_tracepoint_values()
445 unsigned int raw_size = sample->raw_size; in add_bpf_output_values()
452 raw_size, nr_elements * sizeof(u32) - raw_size); in add_bpf_output_values()
458 ret = -1; in add_bpf_output_values()
477 ret = -1; in add_bpf_output_values()
492 ((u32 *)(sample->raw_data))[i]); in add_bpf_output_values()
523 unsigned int nr_elements = callchain->nr; in add_callchain_output_values()
532 ret = -1; in add_callchain_output_values()
552 ret = -1; in add_callchain_output_values()
567 ((u64 *)(callchain->ips))[i]); in add_callchain_output_values()
596 u64 type = evsel->core.attr.sample_type; in add_generic_values()
601 * PERF_SAMPLE_TIME - not needed as we have it in in add_generic_values()
603 * PERF_SAMPLE_READ - TODO in add_generic_values()
604 * PERF_SAMPLE_RAW - tracepoint fields are handled separately in add_generic_values()
605 * PERF_SAMPLE_BRANCH_STACK - TODO in add_generic_values()
606 * PERF_SAMPLE_REGS_USER - TODO in add_generic_values()
607 * PERF_SAMPLE_STACK_USER - TODO in add_generic_values()
611 ret = value_set_u64_hex(cw, event, "perf_ip", sample->ip); in add_generic_values()
613 return -1; in add_generic_values()
617 ret = value_set_s32(cw, event, "perf_tid", sample->tid); in add_generic_values()
619 return -1; in add_generic_values()
621 ret = value_set_s32(cw, event, "perf_pid", sample->pid); in add_generic_values()
623 return -1; in add_generic_values()
628 ret = value_set_u64(cw, event, "perf_id", sample->id); in add_generic_values()
630 return -1; in add_generic_values()
634 ret = value_set_u64(cw, event, "perf_stream_id", sample->stream_id); in add_generic_values()
636 return -1; in add_generic_values()
640 ret = value_set_u64(cw, event, "perf_period", sample->period); in add_generic_values()
642 return -1; in add_generic_values()
646 ret = value_set_u64(cw, event, "perf_weight", sample->weight); in add_generic_values()
648 return -1; in add_generic_values()
653 sample->data_src); in add_generic_values()
655 return -1; in add_generic_values()
660 sample->transaction); in add_generic_values()
662 return -1; in add_generic_values()
668 static int ctf_stream__flush(struct ctf_stream *cs) in ctf_stream__flush() argument
672 if (cs) { in ctf_stream__flush()
673 err = bt_ctf_stream_flush(cs->stream); in ctf_stream__flush()
675 pr_err("CTF stream %d flush failed\n", cs->cpu); in ctf_stream__flush()
678 cs->cpu, cs->count); in ctf_stream__flush()
680 cs->count = 0; in ctf_stream__flush()
688 struct ctf_stream *cs; in ctf_stream__create() local
694 cs = zalloc(sizeof(*cs)); in ctf_stream__create()
695 if (!cs) { in ctf_stream__create()
700 stream = bt_ctf_writer_create_stream(cw->writer, cw->stream_class); in ctf_stream__create()
727 cs->cpu = cpu; in ctf_stream__create()
728 cs->stream = stream; in ctf_stream__create()
729 return cs; in ctf_stream__create()
737 free(cs); in ctf_stream__create()
741 static void ctf_stream__delete(struct ctf_stream *cs) in ctf_stream__delete() argument
743 if (cs) { in ctf_stream__delete()
744 bt_ctf_stream_put(cs->stream); in ctf_stream__delete()
745 free(cs); in ctf_stream__delete()
751 struct ctf_stream *cs = cw->stream[cpu]; in ctf_stream() local
753 if (!cs) { in ctf_stream()
754 cs = ctf_stream__create(cw, cpu); in ctf_stream()
755 cw->stream[cpu] = cs; in ctf_stream()
758 return cs; in ctf_stream()
766 if (evsel->core.attr.sample_type & PERF_SAMPLE_CPU) in get_sample_cpu()
767 cpu = sample->cpu; in get_sample_cpu()
769 if (cpu > cw->stream_cnt) { in get_sample_cpu()
771 cpu, cw->stream_cnt); in get_sample_cpu()
786 static bool is_flush_needed(struct ctf_stream *cs) in is_flush_needed() argument
788 return cs->count >= STREAM_FLUSH_COUNT; in is_flush_needed()
798 struct evsel_priv *priv = evsel->priv; in process_sample_event()
799 struct ctf_writer *cw = &c->writer; in process_sample_event()
800 struct ctf_stream *cs; in process_sample_event() local
804 unsigned long type = evsel->core.attr.sample_type; in process_sample_event()
806 if (WARN_ONCE(!priv, "Failed to setup all events.\n")) in process_sample_event()
809 event_class = priv->event_class; in process_sample_event()
812 c->events_count++; in process_sample_event()
813 c->events_size += _event->header.size; in process_sample_event()
815 pr_time2(sample->time, "sample %" PRIu64 "\n", c->events_count); in process_sample_event()
820 return -1; in process_sample_event()
823 bt_ctf_clock_set_time(cw->clock, sample->time); in process_sample_event()
827 return -1; in process_sample_event()
829 if (evsel->core.attr.type == PERF_TYPE_TRACEPOINT) { in process_sample_event()
833 return -1; in process_sample_event()
838 event, sample->callchain); in process_sample_event()
840 return -1; in process_sample_event()
846 return -1; in process_sample_event()
849 cs = ctf_stream(cw, get_sample_cpu(cw, sample, evsel)); in process_sample_event()
850 if (cs) { in process_sample_event()
851 if (is_flush_needed(cs)) in process_sample_event()
852 ctf_stream__flush(cs); in process_sample_event()
854 cs->count++; in process_sample_event()
855 bt_ctf_stream_append_event(cs->stream, event); in process_sample_event()
859 return cs ? 0 : -1; in process_sample_event()
864 ret = value_set_##_type(cw, event, #_field, _event->_name._field);\
866 return -1; \
876 struct ctf_writer *cw = &c->writer; \
877 struct bt_ctf_event_class *event_class = cw->_name##_class;\
879 struct ctf_stream *cs; \
882 c->non_sample_count++; \
883 c->events_size += _event->header.size; \
887 return -1; \
890 bt_ctf_clock_set_time(cw->clock, sample->time); \
892 cs = ctf_stream(cw, 0); \
893 if (cs) { \
894 if (is_flush_needed(cs)) \
895 ctf_stream__flush(cs); \
897 cs->count++; \
898 bt_ctf_stream_append_event(cs->stream, event); \
986 if (field->alias != field->name) in event_class_add_field()
988 (char *)field->alias); in event_class_add_field()
990 name = field->name; in event_class_add_field()
994 name = change_name(name, field->name, -1); in event_class_add_field()
998 return -1; in event_class_add_field()
1002 name = change_name(name, field->name, dup++); in event_class_add_field()
1004 pr_err("Failed to create dup name for '%s'\n", field->name); in event_class_add_field()
1005 return -1; in event_class_add_field()
1011 field->alias = name; in event_class_add_field()
1023 for (field = fields; field; field = field->next) { in add_tracepoint_fields_types()
1025 unsigned long flags = field->flags; in add_tracepoint_fields_types()
1027 pr2(" field '%s'\n", field->name); in add_tracepoint_fields_types()
1031 return -1; in add_tracepoint_fields_types()
1042 type = bt_ctf_field_type_array_create(type, field->arraylen); in add_tracepoint_fields_types()
1051 field->name, ret); in add_tracepoint_fields_types()
1052 return -1; in add_tracepoint_fields_types()
1063 struct tep_format_field *common_fields = evsel->tp_format->format.common_fields; in add_tracepoint_types()
1064 struct tep_format_field *fields = evsel->tp_format->format.fields; in add_tracepoint_types()
1077 struct bt_ctf_field_type *len_type = cw->data.u32; in add_bpf_output_types()
1078 struct bt_ctf_field_type *seq_base_type = cw->data.u32_hex; in add_bpf_output_types()
1088 return -1; in add_bpf_output_types()
1096 u64 type = evsel->core.attr.sample_type; in add_generic_types()
1100 * PERF_SAMPLE_TIME - not needed as we have it in in add_generic_types()
1102 * PERF_SAMPLE_READ - TODO in add_generic_types()
1103 * PERF_SAMPLE_CALLCHAIN - TODO in add_generic_types()
1104 * PERF_SAMPLE_RAW - tracepoint fields and BPF output in add_generic_types()
1106 * PERF_SAMPLE_BRANCH_STACK - TODO in add_generic_types()
1107 * PERF_SAMPLE_REGS_USER - TODO in add_generic_types()
1108 * PERF_SAMPLE_STACK_USER - TODO in add_generic_types()
1116 return -1; \ in add_generic_types()
1121 ADD_FIELD(event_class, cw->data.u64_hex, "perf_ip"); in add_generic_types()
1124 ADD_FIELD(event_class, cw->data.s32, "perf_tid"); in add_generic_types()
1125 ADD_FIELD(event_class, cw->data.s32, "perf_pid"); in add_generic_types()
1130 ADD_FIELD(event_class, cw->data.u64, "perf_id"); in add_generic_types()
1133 ADD_FIELD(event_class, cw->data.u64, "perf_stream_id"); in add_generic_types()
1136 ADD_FIELD(event_class, cw->data.u64, "perf_period"); in add_generic_types()
1139 ADD_FIELD(event_class, cw->data.u64, "perf_weight"); in add_generic_types()
1142 ADD_FIELD(event_class, cw->data.u64, "perf_data_src"); in add_generic_types()
1145 ADD_FIELD(event_class, cw->data.u64, "perf_transaction"); in add_generic_types()
1148 ADD_FIELD(event_class, cw->data.u32, "perf_callchain_size"); in add_generic_types()
1151 cw->data.u64_hex, "perf_callchain_size"), in add_generic_types()
1166 pr("Adding event '%s' (type %d)\n", name, evsel->core.attr.type); in add_event()
1170 return -1; in add_event()
1176 if (evsel->core.attr.type == PERF_TYPE_TRACEPOINT) { in add_event()
1188 ret = bt_ctf_stream_class_add_event_class(cw->stream_class, event_class); in add_event()
1198 priv->event_class = event_class; in add_event()
1199 evsel->priv = priv; in add_event()
1205 return -1; in add_event()
1210 struct evlist *evlist = session->evlist; in setup_events()
1225 if (bt_ctf_event_class_add_field(event_class, cw->data.t, #n)) {\
1227 return -1; \
1240 return -1; \
1243 ret = bt_ctf_stream_class_add_event_class(cw->stream_class, event_class);\
1249 cw->_name##_class = event_class; \
1317 struct evlist *evlist = session->evlist; in cleanup_events()
1323 priv = evsel->priv; in cleanup_events()
1324 bt_ctf_event_class_put(priv->event_class); in cleanup_events()
1325 zfree(&evsel->priv); in cleanup_events()
1329 session->evlist = NULL; in cleanup_events()
1335 struct perf_header *ph = &session->header; in setup_streams()
1342 ncpus = ph->env.nr_cpus_avail ?: MAX_CPUS; in setup_streams()
1347 return -ENOMEM; in setup_streams()
1350 cw->stream = stream; in setup_streams()
1351 cw->stream_cnt = ncpus; in setup_streams()
1359 for (cpu = 0; cpu < cw->stream_cnt; cpu++) in free_streams()
1360 ctf_stream__delete(cw->stream[cpu]); in free_streams()
1362 zfree(&cw->stream); in free_streams()
1368 struct perf_header *header = &session->header; in ctf_writer__setup_env()
1369 struct bt_ctf_writer *writer = cw->writer; in ctf_writer__setup_env()
1374 return -1; \ in ctf_writer__setup_env()
1377 ADD("host", header->env.hostname); in ctf_writer__setup_env()
1379 ADD("release", header->env.os_release); in ctf_writer__setup_env()
1380 ADD("version", header->env.version); in ctf_writer__setup_env()
1381 ADD("machine", header->env.arch); in ctf_writer__setup_env()
1393 struct bt_ctf_clock *clock = cw->clock; in ctf_writer__setup_clock()
1398 struct perf_env *env = &session->header.env; in ctf_writer__setup_clock()
1400 if (!env->clock.enabled) { in ctf_writer__setup_clock()
1401 pr_err("Can't provide --tod time, missing clock data. " in ctf_writer__setup_clock()
1402 "Please record with -k/--clockid option.\n"); in ctf_writer__setup_clock()
1403 return -1; in ctf_writer__setup_clock()
1406 desc = clockid_name(env->clock.clockid); in ctf_writer__setup_clock()
1407 offset = env->clock.tod_ns - env->clock.clockid_ns; in ctf_writer__setup_clock()
1413 return -1; \ in ctf_writer__setup_clock()
1448 pr2("Created type: INTEGER %d-bit %ssigned %s\n", in create_int_type()
1461 for (i = 0; i < ARRAY_SIZE(cw->data.array); i++) in ctf_writer__cleanup_data()
1462 bt_ctf_field_type_put(cw->data.array[i]); in ctf_writer__cleanup_data()
1474 CREATE_INT_TYPE(cw->data.s64, 64, true, false); in ctf_writer__init_data()
1475 CREATE_INT_TYPE(cw->data.u64, 64, false, false); in ctf_writer__init_data()
1476 CREATE_INT_TYPE(cw->data.s32, 32, true, false); in ctf_writer__init_data()
1477 CREATE_INT_TYPE(cw->data.u32, 32, false, false); in ctf_writer__init_data()
1478 CREATE_INT_TYPE(cw->data.u32_hex, 32, false, true); in ctf_writer__init_data()
1479 CREATE_INT_TYPE(cw->data.u64_hex, 64, false, true); in ctf_writer__init_data()
1481 cw->data.string = bt_ctf_field_type_string_create(); in ctf_writer__init_data()
1482 if (cw->data.string) in ctf_writer__init_data()
1488 return -1; in ctf_writer__init_data()
1495 bt_ctf_clock_put(cw->clock); in ctf_writer__cleanup()
1497 bt_ctf_stream_class_put(cw->stream_class); in ctf_writer__cleanup()
1498 bt_ctf_writer_put(cw->writer); in ctf_writer__cleanup()
1518 cw->writer = writer; in ctf_writer__init()
1527 cw->clock = clock; in ctf_writer__init()
1530 pr("Failed to setup CTF clock.\n"); in ctf_writer__init()
1541 cw->stream_class = stream_class; in ctf_writer__init()
1543 /* CTF clock stream setup */ in ctf_writer__init()
1557 ret = bt_ctf_field_type_structure_add_field(pkt_ctx_type, cw->data.u32, "cpu_id"); in ctf_writer__init()
1562 /* CTF clock writer setup */ in ctf_writer__init()
1573 pr_err("Failed to setup CTF writer.\n"); in ctf_writer__init()
1574 return -1; in ctf_writer__init()
1581 for (cpu = 0; cpu < cw->stream_cnt && !ret; cpu++) in ctf_writer__flush_streams()
1582 ret = ctf_stream__flush(cw->stream[cpu]); in ctf_writer__flush_streams()
1591 if (!strcmp(var, "convert.queue-size")) in convert__config()
1592 return perf_config_u64(&c->queue_size, var, value); in convert__config()
1604 .force = opts->force, in bt_convert__perf2ctf()
1625 if (opts->all) { in bt_convert__perf2ctf()
1637 err = -1; in bt_convert__perf2ctf()
1644 if (ctf_writer__init(cw, path, session, opts->tod)) in bt_convert__perf2ctf()
1648 ordered_events__set_alloc_size(&session->ordered_events, in bt_convert__perf2ctf()
1652 /* CTF writer env/clock setup */ in bt_convert__perf2ctf()
1656 /* CTF events setup */ in bt_convert__perf2ctf()
1660 if (opts->all && setup_non_sample_events(cw, session)) in bt_convert__perf2ctf()
1684 fprintf(stderr, ", %" PRIu64 " non-samples) ]\n", c.non_sample_count); in bt_convert__perf2ctf()
1696 pr_err("Error during conversion setup.\n"); in bt_convert__perf2ctf()