dbinit.py

来自「linux下基于c++的处理器仿真平台。具有处理器流水线」· Python 代码 · 共 417 行 · 第 1/2 页

PY
417
字号
        #       element.        #       For a distribution:        #       -1: sum (for calculating standard deviation)        #       -2: sum of squares (for calculating standard deviation)        #       -3: total number of samples taken (for calculating        #           standard deviation)        #       -4: minimum value        #       -5: maximum value        #       -6: underflow        #       -7: overflow        #   'y' is used by a VECTORDIST and the VECTOR2D to describe the second        #       dimension.        #   'run' is the run that the data was generated from.  Details up in        #       the run table        #   'tick' is a timestamp generated by the simulator.        #   'bin' is the name of the bin that the data was generated in, if        #       any.        #   'data' is the actual stat value.        #        # INDEXES:        #   'stat' is indexed so that a user can find all of the data for a        #       particular stat. It is not unique, because that specific stat        #       can be found in many runs, bins, and samples, in addition to        #       having entries for the mulidimensional cases.         #   'run' is indexed to allow a user to remove all of the data for a        #       particular execution run.  It can also be used to allow the        #       user to print out all of the data for a given run.        #        self.query('''        CREATE TABLE data(            dt_stat	SMALLINT UNSIGNED	NOT NULL,            dt_x	SMALLINT		NOT NULL,            dt_y	SMALLINT		NOT NULL,            dt_run	SMALLINT UNSIGNED	NOT NULL,            dt_tick	BIGINT UNSIGNED		NOT NULL,            dt_bin	SMALLINT UNSIGNED	NOT NULL,            dt_data	DOUBLE			NOT NULL,             INDEX (dt_stat),            INDEX (dt_run),            UNIQUE (dt_stat,dt_x,dt_y,dt_run,dt_tick,dt_bin)        ) TYPE=InnoDB;''')        #        # Names and descriptions for multi-dimensional stats (vectors, etc.)        # are stored here instead of having their own entry in the statistics        # table. This allows all parts of a single stat to easily share a        # single id.         #        # COLUMNS:        #   'stat' is the unique stat identifier from the stat table.        #   'x' is the first dimension for multi-dimensional stats        #       corresponding to the data table above.        #   'y' is the second dimension for multi-dimensional stats        #       corresponding to the data table above.        #   'name' is the specific subname for the unique stat,x,y combination.        #   'descr' is the specific description for the uniqe stat,x,y        #        combination.        #        # INDEXES:        #   'stat' is indexed so you can get the subdata for a specific stat.        #        self.query('''        CREATE TABLE subdata(            sd_stat	SMALLINT UNSIGNED	NOT NULL,            sd_x	SMALLINT		NOT NULL,            sd_y	SMALLINT		NOT NULL,            sd_name	VARCHAR(255)		NOT NULL,            sd_descr	TEXT,            UNIQUE (sd_stat,sd_x,sd_y)        ) TYPE=InnoDB''')        #        # The formula table is maintained separately from the data table        # because formula data, unlike other stat data cannot be represented        # there.        #        # COLUMNS:        #   'stat' refers to the stat field generated in the stat table.        #   'formula' is the actual string representation of the formula        #       itself.        #        # INDEXES:        #   'stat' is indexed so that you can just look up a formula.        #        self.query('''        CREATE TABLE formulas(            fm_stat	SMALLINT UNSIGNED	NOT NULL,            fm_formula	BLOB			NOT NULL,            PRIMARY KEY(fm_stat)        ) TYPE=InnoDB''')        #        # Each stat used in each formula is kept in this table.  This way, if        # you want to print out a particular formula, you can simply find out        # which stats you need by looking in this table.  Additionally, when        # you remove a stat from the stats table and data table, you remove        # any references to the formula in this table.  When a formula is no        # longer referred to, you remove its entry.        #        # COLUMNS:        #   'stat' is the stat id from the stat table above.        #   'child' is the stat id of a stat that is used for this formula.        #       There may be many children for any given 'stat' (formula)        #        # INDEXES:        #   'stat' is indexed so you can look up all of the children for a        #       particular stat.        #   'child' is indexed so that you can remove an entry when a stat is        #       removed.        #        self.query('''        CREATE TABLE formula_ref(            fr_stat	SMALLINT UNSIGNED	NOT NULL,            fr_run	SMALLINT UNSIGNED	NOT NULL,            UNIQUE (fr_stat,fr_run),            INDEX (fr_stat),            INDEX (fr_run)        ) TYPE=InnoDB''')        # COLUMNS:        #   'event' is the unique event id from the event_desc table        #   'run' is simulation run id that this event took place in        #   'tick' is the tick when the event happened        #        # INDEXES:        #   'event' is indexed so you can look up all occurences of a        #       specific event        #   'run' is indexed so you can find all events in a run        #   'tick' is indexed because we want the unique thing anyway        #   'event,run,tick' is unique combination        self.query('''        CREATE TABLE events(            ev_event	SMALLINT UNSIGNED	NOT NULL,            ev_run	SMALLINT UNSIGNED	NOT NULL,            ev_tick	BIGINT   UNSIGNED       NOT NULL,            INDEX(ev_event),            INDEX(ev_run),            INDEX(ev_tick),            UNIQUE(ev_event,ev_run,ev_tick)        ) TYPE=InnoDB''')        # COLUMNS:        #   'id' is the unique description id        #   'name' is the name of the event that occurred        #        # INDEXES:        #   'id' is indexed because it is the primary key and is what you use        #       to look up the descriptions        #   'name' is indexed so one can find the event based on name        #        self.query('''        CREATE TABLE event_names(            en_id	SMALLINT UNSIGNED	NOT NULL AUTO_INCREMENT,            en_name	VARCHAR(255)		NOT NULL,            PRIMARY KEY (en_id),            UNIQUE (en_name)        ) TYPE=InnoDB''')    def clean(self):        self.query('''        DELETE data        FROM data        LEFT JOIN runs ON dt_run=rn_id        WHERE rn_id IS NULL''')        self.query('''        DELETE formula_ref        FROM formula_ref        LEFT JOIN runs ON fr_run=rn_id        WHERE rn_id IS NULL''')        self.query('''        DELETE formulas        FROM formulas        LEFT JOIN formula_ref ON fm_stat=fr_stat        WHERE fr_stat IS NULL''')        self.query('''        DELETE stats        FROM stats        LEFT JOIN data ON st_id=dt_stat        WHERE dt_stat IS NULL''')        self.query('''        DELETE subdata        FROM subdata        LEFT JOIN data ON sd_stat=dt_stat        WHERE dt_stat IS NULL''')        self.query('''        DELETE bins        FROM bins        LEFT JOIN data ON bn_id=dt_bin        WHERE dt_bin IS NULL''')        self.query('''        DELETE events        FROM events        LEFT JOIN runs ON ev_run=rn_id        WHERE rn_id IS NULL''')        self.query('''        DELETE event_names        FROM event_names        LEFT JOIN events ON en_id=ev_event        WHERE ev_event IS NULL''')

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?