void print_fields(struct bt_ctf_event *event, const char *procname, int pid) { unsigned int cnt, i; const struct bt_definition *const * list; const struct bt_declaration *l; const struct bt_definition *scope; enum ctf_type_id type; const char *str; struct processtop *current_proc; struct files *current_file; int fd, fd_value = -1; scope = bt_ctf_get_top_level_scope(event, BT_EVENT_FIELDS); bt_ctf_get_field_list(event, scope, &list, &cnt); for (i = 0; i < cnt; i++) { if (i != 0) fprintf(output, ", "); fprintf(output, "%s = ", bt_ctf_field_name(list[i])); l = bt_ctf_get_decl_from_def(list[i]); if (strncmp(bt_ctf_field_name(list[i]), "fd", 2) == 0) fd = 1; else fd = 0; type = bt_ctf_field_type(l); if (type == CTF_TYPE_INTEGER) { if (bt_ctf_get_int_signedness(l) == 0) { fd_value = bt_ctf_get_uint64(list[i]); fprintf(output, "%" PRIu64, bt_ctf_get_uint64(list[i])); } else { fd_value = bt_ctf_get_int64(list[i]); fprintf(output, "%" PRId64, bt_ctf_get_int64(list[i])); } } else if (type == CTF_TYPE_STRING) { fprintf(output, "%s", bt_ctf_get_string(list[i])); } else if (type == CTF_TYPE_ARRAY) { str = bt_ctf_get_char_array(list[i]); if (!bt_ctf_field_get_error() && str) fprintf(output, "%s", str); } if (fd) { current_proc = find_process_tid(<tngtop, pid, procname); if (!current_proc) continue; current_file = get_file(current_proc, fd_value); if (!current_file || !current_file->name) continue; fprintf(output, "<%s>", current_file->name); } } }
int getFieldsFromEvent(struct bt_ctf_event *ctf_event, GString* fields, gboolean field_names) { struct bt_definition const * const *list = NULL; unsigned int count; int i = 0, ret = 0; gboolean noError = TRUE; const struct bt_definition *scope; scope = bt_ctf_get_top_level_scope(ctf_event, BT_EVENT_FIELDS); if (!scope) { noError = FALSE; } if (noError) { ret = bt_ctf_get_field_list(ctf_event, scope, &list, &count); if (ret < 0) { noError = TRUE; } else { for (i = 0; i < count; i++) { if (i > 0) { g_string_append_printf(fields, ", "); } const char *name = bt_ctf_field_name(list[i]); if (field_names) { g_string_append_printf(fields, "%s = ", name); } getFields(ctf_event, list[i] ,fields); if (bt_ctf_field_get_error()) { continue; } } } } if (!noError) { ret = -1; } return ret; }