#!/usr/bin/env python3 # SPDX-License-Identifier: GPL-2.0-only # # Copyright (C) 2019-2022 Red Hat, Inc. Daniel Bristot de Oliveira <bristot@kernel.org> # # Automata object: parse an automata in dot file digraph format into a python object # # For further information, see: # Documentation/trace/rv/deterministic_automata.rst
import ntpath
class Automata: """Automata class: Reads a dot file and part it as an automata.
Attributes:
dot_file: A dot file with an state_automaton definition. """
def __get_event_variables(self): # here we are at the begin of transitions, take a note, we will return later.
cursor = self.__get_cursor_begin_events()
events = [] while self.__dot_lines[cursor].lstrip()[0] == '"': # transitions have the format: # "all_fired" -> "both_fired" [ label = "disable_irq" ]; # ------------ event is here ------------^^^^^ if self.__dot_lines[cursor].split()[1] == "->":
line = self.__dot_lines[cursor].split()
event = line[-2].replace('"','')
# when a transition has more than one lables, they are like this # "local_irq_enable\nhw_local_irq_enable_n" # so split them.
event = event.replace("\\n", " ") for i in event.split():
events.append(i)
cursor += 1
return sorted(set(events))
def __create_matrix(self): # transform the array into a dictionary
events = self.events
states = self.states
events_dict = {}
states_dict = {}
nr_event = 0 for event in events:
events_dict[event] = nr_event
nr_event += 1
nr_state = 0 for state in states:
states_dict[state] = nr_state
nr_state += 1
# declare the matrix....
matrix = [[ self.invalid_state_str for x in range(nr_event)] for y in range(nr_state)]
# and we are back! Let's fill the matrix
cursor = self.__get_cursor_begin_events()
while self.__dot_lines[cursor].lstrip()[0] == '"': if self.__dot_lines[cursor].split()[1] == "->":
line = self.__dot_lines[cursor].split()
origin_state = line[0].replace('"','').replace(',','_')
dest_state = line[2].replace('"','').replace(',','_')
possible_events = line[-2].replace('"','').replace("\\n", " ") for event in possible_events.split():
matrix[states_dict[origin_state]][events_dict[event]] = dest_state
cursor += 1
return matrix
def __store_init_events(self):
events_start = [False] * len(self.events)
events_start_run = [False] * len(self.events) for i, _ in enumerate(self.events):
curr_event_will_init = 0
curr_event_from_init = False
curr_event_used = 0 for j, _ in enumerate(self.states): if self.function[j][i] != self.invalid_state_str:
curr_event_used += 1 if self.function[j][i] == self.initial_state:
curr_event_will_init += 1 if self.function[0][i] != self.invalid_state_str:
curr_event_from_init = True # this event always leads to init if curr_event_will_init and curr_event_used == curr_event_will_init:
events_start[i] = True # this event is only called from init if curr_event_from_init and curr_event_used == 1:
events_start_run[i] = True return events_start, events_start_run
def is_start_run_event(self, event): # prefer handle_start_event if there if any(self.events_start): returnFalse return self.events_start_run[self.events.index(event)]
Messung V0.5
¤ Dauer der Verarbeitung: 0.11 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.