?? dbinit.py
字號:
# Copyright (c) 2003, 2004# The Regents of The University of Michigan# All Rights Reserved## This code is part of the M5 simulator, developed by Nathan Binkert,# Erik Hallnor, Steve Raasch, and Steve Reinhardt, with contributions# from Ron Dreslinski, Dave Greene, Lisa Hsu, Kevin Lim, Ali Saidi,# and Andrew Schultz.## Permission is granted to use, copy, create derivative works and# redistribute this software and such derivative works for any purpose,# so long as the copyright notice above, this grant of permission, and# the disclaimer below appear in all copies made; and so long as the# name of The University of Michigan is not used in any advertising or# publicity pertaining to the use or distribution of this software# without specific, written prior authorization.## THIS SOFTWARE IS PROVIDED AS IS, WITHOUT REPRESENTATION FROM THE# UNIVERSITY OF MICHIGAN AS TO ITS FITNESS FOR ANY PURPOSE, AND WITHOUT# WARRANTY BY THE UNIVERSITY OF MICHIGAN OF ANY KIND, EITHER EXPRESS OR# IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE REGENTS OF# THE UNIVERSITY OF MICHIGAN SHALL NOT BE LIABLE FOR ANY DAMAGES,# INCLUDING DIRECT, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL# DAMAGES, WITH RESPECT TO ANY CLAIM ARISING OUT OF OR IN CONNECTION# WITH THE USE OF THE SOFTWARE, EVEN IF IT HAS BEEN OR IS HEREAFTER# ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.import MySQLdbclass MyDB(object): def __init__(self, options): self.name = options.db self.host = options.host self.user = options.user self.passwd = options.passwd self.mydb = None self.cursor = None def admin(self): self.close() self.mydb = MySQLdb.connect(db='mysql', host=self.host, user=self.user, passwd=self.passwd) self.cursor = self.mydb.cursor() def connect(self): self.close() self.mydb = MySQLdb.connect(db=self.name, host=self.host, user=self.user, passwd=self.passwd) self.cursor = self.mydb.cursor() def close(self): if self.mydb is not None: self.mydb.close() self.cursor = None def query(self, sql): self.cursor.execute(sql) def drop(self): self.query('DROP DATABASE IF EXISTS %s' % self.name) def create(self): self.query('CREATE DATABASE %s' % self.name) def populate(self): # # Each run (or simulation) gets its own entry in the runs table to # group stats by where they were generated # # COLUMNS: # 'id' is a unique identifier for each run to be used in other # tables. # 'name' is the user designated name for the data generated. It is # configured in the simulator. # 'user' identifies the user that generated the data for the given # run. # 'project' another name to identify runs for a specific goal # 'date' is a timestamp for when the data was generated. It can be # used to easily expire data that was generated in the past. # 'expire' is a timestamp for when the data should be removed from # the database so we don't have years worth of junk. # # INDEXES: # 'run' is indexed so you can find out details of a run if the run # was retreived from the data table. # 'name' is indexed so that two all run names are forced to be unique # self.query(''' CREATE TABLE runs( rn_id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT, rn_name VARCHAR(200) NOT NULL, rn_sample VARCHAR(32) NOT NULL, rn_user VARCHAR(32) NOT NULL, rn_project VARCHAR(100) NOT NULL, rn_date TIMESTAMP NOT NULL, rn_expire TIMESTAMP NOT NULL, PRIMARY KEY (rn_id), UNIQUE (rn_name,rn_sample) ) TYPE=InnoDB''') # # We keep the bin names separate so that the data table doesn't get # huge since bin names are frequently repeated. # # COLUMNS: # 'id' is the unique bin identifer. # 'name' is the string name for the bin. # # INDEXES: # 'bin' is indexed to get the name of a bin when data is retrieved # via the data table. # 'name' is indexed to get the bin id for a named bin when you want # to search the data table based on a specific bin. # self.query(''' CREATE TABLE bins( bn_id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT, bn_name VARCHAR(255) NOT NULL, PRIMARY KEY(bn_id), UNIQUE (bn_name) ) TYPE=InnoDB''') # # The stat table gives us all of the data for a particular stat. # # COLUMNS: # 'stat' is a unique identifier for each stat to be used in other # tables for references. # 'name' is simply the simulator derived name for a given # statistic. # 'descr' is the description of the statistic and what it tells # you. # 'type' defines what the stat tells you. Types are: # SCALAR: A simple scalar statistic that holds one value # VECTOR: An array of statistic values. Such a something that # is generated per-thread. Vectors exist to give averages, # pdfs, cdfs, means, standard deviations, etc across the # stat values. # DIST: Is a distribution of data. When the statistic value is # sampled, its value is counted in a particular bucket. # Useful for keeping track of utilization of a resource. # (e.g. fraction of time it is 25% used vs. 50% vs. 100%) # VECTORDIST: Can be used when the distribution needs to be # factored out into a per-thread distribution of data for # example. It can still be summed across threads to find # the total distribution. # VECTOR2D: Can be used when you have a stat that is not only # per-thread, but it is per-something else. Like # per-message type. # FORMULA: This statistic is a formula, and its data must be # looked up in the formula table, for indicating how to # present its values. # 'subdata' is potentially used by any of the vector types to # give a specific name to all of the data elements within a # stat. # 'print' indicates whether this stat should be printed ever. # (Unnamed stats don't usually get printed) # 'prereq' only print the stat if the prereq is not zero. # 'prec' number of decimal places to print # 'nozero' don't print zero values # 'nonan' don't print NaN values # 'total' for vector type stats, print the total. # 'pdf' for vector type stats, print the pdf. # 'cdf' for vector type stats, print the cdf. # # The Following are for dist type stats: # 'min' is the minimum bucket value. Anything less is an underflow. # 'max' is the maximum bucket value. Anything more is an overflow. # 'bktsize' is the approximate number of entries in each bucket. # 'size' is the number of buckets. equal to (min/max)/bktsize. # # INDEXES: # 'stat' is indexed so that you can find out details about a stat # if the stat id was retrieved from the data table. # 'name' is indexed so that you can simply look up data about a # named stat. # self.query(''' CREATE TABLE stats( st_id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT, st_name VARCHAR(255) NOT NULL, st_descr TEXT NOT NULL, st_type ENUM("SCALAR", "VECTOR", "DIST", "VECTORDIST", "VECTOR2D", "FORMULA") NOT NULL, st_print BOOL NOT NULL, st_prereq SMALLINT UNSIGNED NOT NULL, st_prec TINYINT NOT NULL, st_nozero BOOL NOT NULL, st_nonan BOOL NOT NULL, st_total BOOL NOT NULL, st_pdf BOOL NOT NULL, st_cdf BOOL NOT NULL, st_min DOUBLE NOT NULL, st_max DOUBLE NOT NULL, st_bktsize DOUBLE NOT NULL, st_size SMALLINT UNSIGNED NOT NULL, PRIMARY KEY (st_id), UNIQUE (st_name) ) TYPE=InnoDB''') # # This is the main table of data for stats. # # COLUMNS: # 'stat' refers to the stat field given in the stat table. # # 'x' referrs to the first dimension of a multi-dimensional stat. For # a vector, x will start at 0 and increase for each vector
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -