lisa.trace.TxtTraceParserBase#
- class lisa.trace.TxtTraceParserBase(*args, **kwargs)[source]#
Bases:
TraceParserBase
Text trace parser base class.
- Parameters:
lines (collections.abc.Iterable(bytes)) – Iterable of text lines as
bytes
.events (list(str)) – List of events that will be available using
parse_event()
. If not provided, all events will be considered. .. note:: Restricting the set of events can speed up some operations.event_parsers (list(EventParserBase)) –
Pre-built event parsers. Missing event parsers will be inferred from the fields parsed in the trace, which is costly and can lead to using larger dtypes than necessary (e.g.
int64
rather thanuint16
).See also
default_event_parser_cls (type) – Class used to build event parsers inferred from the trace.
pre_filled_metadata (dict(str, object) or None) – Metadata pre-filled by the caller of the constructor.
Attributes
Class used to create event parsers when inferred from the trace.
When the dtype of a field is not provided by a user-defined parser, these dtypes will be tried in order to convert the column from string to something more appropriate.
Mapping of event names to parser description as a dict.
Pandas dtype of the header fields.
METADATA_KEYS
inheritedPossible metadata keys.
Properties
logger
inheritedConvenience short-hand for
self.get_logger()
.Methods
Build an instance from a single multiline string.
Build an instance from a path to a text file.
Return the metadata value.
Parse the given event from the trace and return a
pandas.DataFrame
with the following columns:.__enter__()
inherited__exit__()
inheritedfactory()
inheritedDecorator to use on alternative constructors, i.e. classmethods that return instances of the class.
get_all_metadata()
inheritedCollect all available metadata.
get_logger()
inheritedProvides a
logging.Logger
named aftercls
.get_parser_id()
inheritedGet the unique ID of that parser. Any parameter affecting the output dataframes or metadata must be somehow part of that ID, so that the cache is not accidentally hit with stale data.
log_locals()
inheritedDebugging aid: log the local variables of the calling function.
parse_all_events()
inheritedParse all available events.
parse_events()
inheritedSame as
parse_event()
but taking a list of events as input, and returning a mapping of event names topandas.DataFrame
for each.
Attributes#
- TxtTraceParserBase.DEFAULT_EVENT_PARSER_CLS = None#
Class used to create event parsers when inferred from the trace.
- TxtTraceParserBase.DTYPE_INFERENCE_ORDER = ['int64', 'uint64', 'float64']#
When the dtype of a field is not provided by a user-defined parser, these dtypes will be tried in order to convert the column from string to something more appropriate.
Note
uint64
allows testing for hexadecimal formatting of numbers.
- TxtTraceParserBase.EVENT_DESCS = {}#
Mapping of event names to parser description as a dict.
Each event description can include the constructor parameters of the class used as
DEFAULT_EVENT_PARSER_CLS
, which will be used to build event parsers from the descriptions.If an instance of
EventParserBase
is passed instead of a dict, it will be used as is.
- TxtTraceParserBase.HEADER_FIELDS = {'__comm': 'string', '__cpu': 'uint32', '__event': 'string', '__pid': 'uint32', '__timestamp': 'float64'}#
Pandas dtype of the header fields.
- TxtTraceParserBase.METADATA_KEYS = ['time-range', 'symbols-address', 'cpus-count', 'available-events', 'trace-id']#
Inherited attribute, see
lisa.trace.TraceParserBase.METADATA_KEYS
Possible metadata keys.
Properties#
- property TxtTraceParserBase.logger#
Inherited property, see
lisa.utils.Loggable.logger
Convenience short-hand for
self.get_logger()
.
Methods#
- classmethod TxtTraceParserBase.from_string(txt, path=None, *, events=None, needed_metadata=None, event_parsers=None, default_event_parser_cls=None, pre_filled_metadata=None, temp_dir)[source]#
Build an instance from a single multiline string.
- classmethod TxtTraceParserBase.from_txt_file(path, *, events=None, needed_metadata=None, event_parsers=None, default_event_parser_cls=None, pre_filled_metadata=None, temp_dir)[source]#
Build an instance from a path to a text file.
- Variable keyword arguments:
Forwarded to
__init__
- TxtTraceParserBase.get_metadata(key)[source]#
Return the metadata value.
- Parameters:
key (str) –
Name of the metadata. Can be one of:
time-range
: tuple(start, end)
of the timestamps in the trace. This must be the first timestamp to appear in the trace, regardless of what events is being parsed. Otherwise, it would be impossible to use the time range of a parser in the motherTraceBase
when requesting specific events.symbols-address
: Dictionnary of address (int) to symbol names in the kernel (str) that was used to create the trace. This allows resolving the fields of events that recorded addresses rather than function names.cpus-count
: Number of CPUs on the system the trace was collected on.available-events
: List of all available events stored in the trace. The list must be exhaustive, not limited to the events that were requested. If an exhaustive list cannot be gathered, this metadata should not be implemented.trace-id
: Unique identifier for that trace file used tovalidate the cache. If not available, a checksum will be used.
- Raises:
MissingMetadataError
if the metadata is not available on that parser.
Note
A given metadata can only be expected to be available if asked for in the constructor, but bear in mind that there is no promise on the availability of any except for the following that must be provided if asked for:
time-range
Metadata may still be made available if not asked for, but only if it’s a very cheap byproduct of parsing that incurs no extra cost.
- TxtTraceParserBase.parse_event(event)[source]#
Parse the given event from the trace and return a
pandas.DataFrame
with the following columns:Time
index: floating point absolute timestamp in seconds. The index must not have any duplicated values.One column per event field, with the appropriate dtype.
Columns prefixed with
__
: Header of each event, usually containing the following fields:__cpu
: CPU number the event was emitted from__pid
: PID of the current process scheduled at the time the event was emitted__comm
: Task command name going with__pid
at the point the event was emitted
- Parameters:
event (str) – name of the event to parse
- Raises:
MissingTraceEventError – If the event cannot be parsed.
Note
The caller is free to modify the index of the data, and it must not affect other dataframes.
- TxtTraceParserBase.__enter__()#
Inherited method, see
lisa.trace.TraceParserBase.__enter__()
- TxtTraceParserBase.__exit__(*args, **kwargs)#
Inherited method, see
lisa.trace.TraceParserBase.__exit__()
- classmethod TxtTraceParserBase.factory(f)#
Inherited method, see
lisa.utils.PartialInit.factory()
Decorator to use on alternative constructors, i.e. classmethods that return instances of the class.
- TxtTraceParserBase.get_all_metadata()#
Inherited method, see
lisa.trace.TraceParserBase.get_all_metadata()
Collect all available metadata.
- classmethod TxtTraceParserBase.get_logger(suffix=None)#
Inherited method, see
lisa.utils.Loggable.get_logger()
Provides a
logging.Logger
named aftercls
.
- TxtTraceParserBase.get_parser_id()#
Inherited method, see
lisa.trace.TraceParserBase.get_parser_id()
Get the unique ID of that parser. Any parameter affecting the output dataframes or metadata must be somehow part of that ID, so that the cache is not accidentally hit with stale data.
- classmethod TxtTraceParserBase.log_locals(var_names=None, level='debug')#
Inherited method, see
lisa.utils.Loggable.log_locals()
Debugging aid: log the local variables of the calling function.
- TxtTraceParserBase.parse_all_events()#
Inherited method, see
lisa.trace.TraceParserBase.parse_all_events()
Parse all available events.
- TxtTraceParserBase.parse_events(events, best_effort=False, **kwargs)#
Inherited method, see
lisa.trace.TraceParserBase.parse_events()
Same as
parse_event()
but taking a list of events as input, and returning a mapping of event names topandas.DataFrame
for each.