const struct bt_ctf_field_decl *field);
%rename("_bt_ctf_get_decl_from_def") bt_ctf_get_decl_from_def(
const struct bt_definition *field);
+%rename("_bt_array_index") bt_array_index(struct definition_array *array, uint64_t i);
const struct bt_definition *bt_ctf_get_top_level_scope(const struct bt_ctf_event *ctf_event,
enum bt_ctf_scope scope);
const char *bt_ctf_get_enum_str(const struct bt_definition *field);
enum ctf_string_encoding bt_ctf_get_encoding(const struct bt_declaration *field);
int bt_ctf_get_array_len(const struct bt_declaration *field);
+struct bt_definition *bt_array_index(struct definition_array *array, uint64_t i);
uint64_t bt_ctf_get_uint64(const struct bt_definition *field);
int64_t bt_ctf_get_int64(const struct bt_definition *field);
char *bt_ctf_get_char_array(const struct bt_definition *field);
"""
return _bt_ctf_get_array_len(_bt_ctf_get_decl_from_def(self._d))
+ def get_array_element_at(self, index):
+ """
+ Return the array's element at position index.
+ Return None on error
+ """
+ array = _bt_python_get_array_from_def(self._d)
+ if array is None:
+ return None
+
+ element = ctf.Definition.__new__(ctf.Definition)
+ element._d = _bt_array_index(array, index)
+ if element._d is None:
+ return None
+ return element
+
def get_uint64(self):
"""
Return the value associated with the field.
"""
return _bt_ctf_get_string(self._d)
+ def get_value(self):
+ """
+ Return the value associated with the field according to its type.
+ Return None on error.
+ """
+ id = self.field_type()
+ if id == ctf.type_id.STRING:
+ return self.get_str()
+ if id == ctf.type_id.ARRAY:
+ array = []
+ for i in range(self.get_array_len()):
+ element = self.get_array_element_at(i)
+ array.append(element.get_value())
+ return array
+ if id == ctf.type_id.INTEGER:
+ if self.get_int_signedness() == 0:
+ return self.get_uint64()
+ else:
+ return self.get_int64()
+ if id == ctf.type_id.ENUM:
+ return self.get_enum_str()
+ return None
+
def get_scope(self):
"""Return the scope of a field or None on error."""
return self._s
if prev_field is None:
print("ERROR: Missing prev_comm context info")
else:
- prev_comm = prev_field[0].get_char_array()
- print("sched_switch prev_comm: {}".format(prev_comm))
+ prev_comm = prev_field[0].get_value()
+ if prev_comm is not None:
+ print("sched_switch prev_comm: {}".format(prev_comm))
if event.get_name() == "exit_syscall":
ret_field = event.get_field("ret")
if ret_field is None:
print("ERROR: Unable to extract ret")
else:
- ret_code = ret_field[0].get_int64()
- print("exit_syscall ret: {}".format(ret_code))
+ ret_code = ret_field[0].get_value()
+ if ret_code is not None:
+ print("exit_syscall ret: {}".format(ret_code))
ret = ctf_it.next()
if ret < 0:
# Getting PID
pid_field = event.get_field_with_scope(sco, "pid")
- pid = pid_field.get_int64()
-
- if ctf.field_error():
+ if pid_field is None:
print("ERROR: Missing PID info for sched_switch")
break # Next event
-
+ pid = pid_field.get_value()
if usePID and (pid != long(sys.argv[1])):
break # Next event
# prev_comm
field = event.get_field_with_scope(sco, "prev_comm")
- prev_comm = field.get_char_array()
- if ctf.field_error():
+ if field is None:
print("ERROR: Missing prev_comm context info")
+ prev_comm = field.get_value()
# prev_tid
field = event.get_field_with_scope(sco, "prev_tid")
- prev_tid = field.get_int64()
- if ctf.field_error():
+ if field is None:
print("ERROR: Missing prev_tid context info")
+ prev_tid = field.get_value()
# prev_prio
field = event.get_field_with_scope(sco, "prev_prio")
- prev_prio = field.get_int64()
- if ctf.field_error():
+ if field is None:
print("ERROR: Missing prev_prio context info")
+ prev_prio = field.get_value()
# prev_state
field = event.get_field_with_scope(sco, "prev_state")
- prev_state = field.get_int64()
- if ctf.field_error():
+ if field is None:
print("ERROR: Missing prev_state context info")
+ prev_state = field.get_value()
# next_comm
field = event.get_field_with_scope(sco, "next_comm")
- next_comm = field.get_char_array()
- if ctf.field_error():
+ if field is None:
print("ERROR: Missing next_comm context info")
+ next_comm = field.get_value()
# next_tid
field = event.get_field_with_scope(sco, "next_tid")
- next_tid = field.get_int64()
- if ctf.field_error():
+ if field is None:
print("ERROR: Missing next_tid context info")
+ next_tid = field.get_value()
# next_prio
field = event.get_field_with_scope(sco, "next_prio")
- next_prio = field.get_int64()
- if ctf.field_error():
+ if field is None:
print("ERROR: Missing next_prio context info")
+ next_prio = field.get_value()
# Output
print("sched_switch, pid = {}, TS = {}, prev_comm = {},\n\t"
{
return list[index];
}
+
+struct definition_array *_bt_python_get_array_from_def(
+ struct bt_definition *field)
+{
+ const struct bt_declaration *array_decl;
+ struct definition_array *array = NULL;
+
+ if (!field) {
+ goto end;
+ }
+
+ array_decl = bt_ctf_get_decl_from_def(field);
+ if (bt_ctf_field_type(array_decl) == CTF_TYPE_ARRAY) {
+ array = container_of(field, struct definition_array, p);
+ }
+end:
+ return array;
+}
enum bt_ctf_scope scope);
struct bt_ctf_field_decl *_bt_python_field_decl_one_from_list(
struct bt_ctf_field_decl **list, int index);
+
+/* definitions */
+struct definition_array *_bt_python_get_array_from_def(
+ struct bt_definition *field);