-
-%pythoncode%{
-
-class IterPos:
- """This class represents the position where to set an iterator."""
-
- __can_access = False
-
- def __init__(self, seek_type, seek_time = None):
- """
- seek_type represents the type of seek to use.
- seek_time is the timestamp to seek to when using SEEK_TIME, it
- is expressed in nanoseconds
- Only use SEEK_RESTORE on IterPos obtained from the get_pos function
- in Iter class.
- """
-
- self._pos = _bt_iter_pos()
- self._pos.type = seek_type
- if seek_time and seek_type == SEEK_TIME:
- self._pos.u.seek_time = seek_time
- self.__can_access = True
-
- def __del__(self):
- if not self.__can_access:
- _bt_iter_free_pos(self._pos)
-
- def _get_type(self):
- if not __can_access:
- raise AttributeError("seek_type is not available")
- return self._pos.type
-
- def _set_type(self, seek_type):
- if not __can_access:
- raise AttributeError("seek_type is not available")
- self._pos.type = seek_type
-
- def _get_time(self):
- if not __can_access:
- raise AttributeError("seek_time is not available")
-
- elif self._pos.type is not SEEK_TIME:
- raise TypeError("seek_type is not SEEK_TIME")
-
- return self._pos.u.seek_time
-
- def _set_time(self, time):
- if not __can_access:
- raise AttributeError("seek_time is not available")
-
- elif self._pos.type is not SEEK_TIME:
- raise TypeError("seek_type is not SEEK_TIME")
-
- self._pos.u.seek_time = time
-
- def _get_pos(self):
- return self._pos
-
-
- seek_type = property(_get_type, _set_type)
- seek_time = property(_get_time, _set_time)
-
-
-class Iterator:
-
- __with_init = False
-
- def __init__(self, context, begin_pos = None, end_pos = None, _no_init = None):
- """
- Allocate a trace collection iterator.
-
- begin_pos and end_pos are optional parameters to specify the
- position at which the trace collection should be seeked upon
- iterator creation, and the position at which iteration will
- start returning "EOF".
-
- By default, if begin_pos is None, a BT_SEEK_CUR is performed at
- creation. By default, if end_pos is None, a BT_SEEK_END (end of
- trace) is the EOF criterion.
- """
- if _no_init is None:
- if begin_pos is None:
- bp = None
- else:
- try:
- bp = begin_pos._pos
- except AttributeError:
- raise TypeError("in __init__, "
- "argument 3 must be a IterPos instance")
-
- if end_pos is None:
- ep = None
- else:
- try:
- ep = end_pos._pos
- except AttributeError:
- raise TypeError("in __init__, "
- "argument 4 must be a IterPos instance")
-
- try:
- self._bi = _bt_iter_create(context._c, bp, ep)
- except AttributeError:
- raise TypeError("in __init__, "
- "argument 2 must be a Context instance")
-
- self.__with_init = True
-
- else:
- self._bi = _no_init
-
- def __del__(self):
- if self.__with_init:
- _bt_iter_destroy(self._bi)
-
- def next(self):
- """
- Move trace collection position to the next event.
- Returns 0 on success, a negative value on error.
- """
- return _bt_iter_next(self._bi)
-
- def get_pos(self):
- """Return a IterPos class of the current iterator position."""
- ret = IterPos(0)
- ret.__can_access = False
- ret._pos = _bt_iter_get_pos(self._bi)
- return ret
-
- def set_pos(self, pos):
- """
- Move the iterator to a given position.
-
- On error, the stream_heap is reinitialized and returned empty.
- Return 0 for success.
- Return EOF if the position requested is after the last event of the
- trace collection.
- Return -EINVAL when called with invalid parameter.
- Return -ENOMEM if the stream_heap could not be properly initialized.
- """
- try:
- return _bt_iter_set_pos(self._bi, pos._pos)
- except AttributeError:
- raise TypeError("in set_pos, "
- "argument 2 must be a IterPos instance")
-
- def create_time_pos(self, timestamp):
- """
- Create a position based on time
- This function allocates and returns a new IterPos to be able to
- restore an iterator position based on a timestamp.
- """
-
- if timestamp < 0:
- raise TypeError("timestamp must be an unsigned int")
-
- ret = IterPos(0)
- ret.__can_access = False
- ret._pos = _bt_iter_create_time_pos(self._bi, timestamp)
- return ret
-%}
-
-
-/* =================================================================
- CLOCK-TYPE.H
- ¯¯¯¯¯¯¯¯¯¯¯¯
- *** Enum copied from clock-type.h
- All changes must also be made here
-*/
-%rename("CLOCK_CYCLES") BT_CLOCK_CYCLES;
-%rename("CLOCK_REAL") BT_CLOCK_REAL;
-
-enum bt_clock_type {
- BT_CLOCK_CYCLES = 0,
- BT_CLOCK_REAL
-};
-