trappy.stats.grammar module¶
Grammar module allows the user to easily define relations between data events and perform basic logical and arithmetic operations on the data. The parser also handles super-indexing and variable forwarding.
-
class
trappy.stats.grammar.
Parser
(data, pvars=None, window=(0, None), filters=None, **kwargs)[source]¶ Bases:
object
A parser class for solving simple data accesses and super-indexing data
Parameters: - data (instance of
trappy.ftrace.BareTrace
or a child class (liketrappy.ftrace.FTrace
)) – Trace Object - pvars (dict) – A dictionary of variables that need to be accessed from within the grammar
- method (str) – The method to be used for reindexing data
This can be one of the standas
pandas.DataFrame
methods (eg. pad, bfill, nearest). The default is pad or use the last valid observation. - limit (int) – The number of indices a value will be propagated when reindexing. The default is None
- fill (bool) – Whether to fill the NaNs in the data. The default value is True.
- window (tuple) – A window of time in which to apply the data accesses. By default the data accesses happen accross the whole trace. With the window parameter you can limit it to a window of time inside the trace. The first element of the tuple is the starting time and the second the ending time (set to None for end of trace).
- filters (dict) –
Restrict the parsing to the rows that match the specified criteria. For Example:
filters = { "pid": 3338, "cpu": [0, 2, 4], }
will only consider rows whose pid column is 3338 and cpu is either 0, 2 or 4.
Operators
Operation operator Associativity Exponentiation ** Left Unary - Right Multiply/Divide *, /, //, % Left Add/Subtract +, -, Left Comparison >, <, >=, <=, ==, != Left Logical &&, ||, |, & Left Data Accessors
Since the goal of the grammar is to provide an easy language to access and compare data from a
trappy.trace.FTrace
object. The parser provides a simple notation to access this data.Statically Defined Events
import trappy from trappy.stats.grammar import Parser trace = trappy.FTrace("path/to/trace/file") parser = Parser(trace) parser.solve("trappy.thermal.Thermal:temp * 2")
Aliasing
import trappy from trappy.stats.grammar import Parser pvars = {"THERMAL": trappy.thermal.Thermal} trace = trappy.FTrace("path/to/trace/file") parser = Parser(trace, pvars=pvars) parser.solve("THERMAL:temp * 2")
Using Event Name
import trappy from trappy.stats.grammar import Parser trace = trappy.FTrace("path/to/trace/file") parser = Parser(trace) parser.solve("thermal:temp * 2")
The event
trappy.thermal.Thermal
is aliased as thermal in the grammarDynamic Events
import trappy from trappy.stats.grammar import Parser # Register Dynamic Event cls = trappy.register_dynamic_ftrace("my_unique_word", "event_name") pvars = {"CUSTOM": cls} trace = trappy.FTrace("path/to/trace/file") parser = Parser(trace, pvars=pvars) parser.solve("CUSTOM:col * 2")
-
inspect
(accessor)[source]¶ A function to inspect the accessor for information
Parameters: accessor (str) – A data accessor of the format <event>:<column> Returns: A dictionary of information
-
ref
(mask)[source]¶ Reference super indexed data with a boolean mask
Parameters: mask ( pandas.Series
) – A booleanpandas.Series
that can be used to reference the aggregated data in the parserReturns: aggregated_data[mask]
-
solve
(expr)[source]¶ Parses and solves the input expression
Parameters: expr (str) – The input expression Returns: The return type may vary depending on the expression. For example: Vector
import trappy from trappy.stats.grammar import Parser trace = trappy.FTrace("path/to/trace/file") parser = Parser(trace) parser.solve("trappy.thermal.Thermal:temp * 2")
Scalar
import trappy from trappy.stats.grammar import Parser trace = trappy.FTrace("path/to/trace/file") parser = Parser(trace) parser.solve("numpy.mean(trappy.thermal.Thermal:temp)")
Vector Mask
import trappy from trappy.stats.grammar import Parser trace = trappy.FTrace("path/to/trace/file") parser = Parser(trace) parser.solve("trappy.thermal.Thermal:temp > 65000")
- data (instance of
-
trappy.stats.grammar.
eval_binary_op
(tokens)[source]¶ Evaluate Binary operators
Parameters: tokens (list) – The grammar tokens
-
trappy.stats.grammar.
eval_unary_op
(tokens)[source]¶ Unary Op Evaluation
Parameters: tokens (list) – The grammar tokens
-
trappy.stats.grammar.
get_parse_expression
(parse_func, parse_var_id)[source]¶ return a parse expression with for the input parseActions
-
trappy.stats.grammar.
iterate_binary_ops
(tokens)[source]¶ An iterator for Binary Operation tokens
Parameters: tokens (list) – The grammar tokens