Main Page | Packages | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | Related Pages

test_db.py

00001 #!/usr/local/bin/python
00002 #
00003 #                               Copyright 2004
00004 #                                     by
00005 #                        The Board of Trustees of the
00006 #                     Leland Stanford Junior University.
00007 #                            All rights reserved.
00008 #
00009 
00010 """Test script for commanding
00011 Contents:
00012 Sample script for testing commanding throughput
00013 """
00014 __facility__ = "Online"
00015 __abstract__ = "GLAST Test command database"
00016 __author__   = "Ric Claus <claus@slac.stanford.edu> SLAC - GLAST LAT I&T/Online"
00017 __date__     = "Sun Aug 08 18:14:33 2004"
00018 __version__  = "$Revision: 1.6 $"
00019 __release__  = "$Name: R04-12-00 $"
00020 __credits__  = "SLAC"
00021 
00022 import LATTE.copyright_SLAC
00023 
00024 import struct
00025 import time
00026 import gc
00027 from   LATTE.client.gOptions   import Options
00028 from   LATTE.client.gCmdCli    import CmdCli
00029 import LATTE.database.gDb      as gDb
00030 import LATTE.database.gAttr    as gAttr
00031 import LATTE.client.gRegister  as gRegister
00032 import LATTE.client.gException as gException
00033 
00034 class GTest(gDb.Gdb):
00035   """
00036   """
00037 
00038   __attrs = [
00039     gAttr.GattrRaw('raw', 0, 4),
00040     gAttr.GattrReg('reg', 1, 4),
00041     gAttr.GattrDlc('dlc', 2),
00042     gAttr.GattrBF('bf1', 0,  0,  4),
00043     gAttr.GattrBF('bf2', 0,  4,  8),
00044     gAttr.GattrBF('bf3', 0,  8, 12),
00045     gAttr.GattrBF('bf4', 0, 12, 16),
00046     ]
00047 
00048   def __init__(self, client):
00049     """
00050     """
00051     gDb.Gdb.__init__(self, client, None, 0, self.__attrs)
00052 
00053   def read(self, reg):
00054     return self.cmdrsp('TEM_read', self.addr(), reg, '!I')
00055 
00056   def load(self, reg, value):
00057     return self.cmdrsp('TEM_load', self.addr(), reg, value)
00058 
00059   def send(self, cmd):
00060     return self.cmdrsp('TEM_cmd', self.addr(), cmd)
00061 
00062 
00063 def test(cmd=None, disconnectOnExit=True):
00064   global tst, cmdCli
00065 
00066   options = Options(['server'])
00067   try:
00068     options.parse()
00069   except Exception, msg:
00070     options.usage(str(msg))
00071     return
00072 
00073   if cmd == None:
00074     cmd = CmdCli()
00075     cmd.connect(options.server)
00076 
00077   tst = GTest(cmd)
00078 
00079   # The following rates were measured on a D600 laptop (1.7 GHz, 600 MHz bus,
00080   # 1 GB memory) in local mode with prints commented out
00081   # 2nd rate column is for optimized set/getattr in which lower is called once
00082   cmdStrs = [                                             #   Hz
00083     "cmd.cmdrsp('TEM_load', 0, 3, 4567L)", # Garbage - Why? GC?
00084     "cmd.cmdrsp('TEM_load', 0, 3, 4567L)", # 11098.8 10858
00085     "tst.cmdrsp('TEM_load', 0, 3, 7654L)", # 10741.1 10515
00086     "tst.dlc = 1",                                        #  9242.1  9606
00087     "tst.dlc",                                            #  9416.2  9506
00088     "tst.raw = 1234",                                     #  9000.9  9416
00089     "tst.raw",                                            #  8605.9  8764
00090     "tst.reg = 4321",                                     #  8841.7  9158
00091     "tst.reg",                                            #  8460.2  8532
00092     "tst.bf4",                                            #  8460.2  8613
00093     "tst.bf4 = 5",                                        #  4560.0  4645
00094     "tst.regs['reg'].set(3145)" ,                         #  9242.1  9328
00095     "tst.regs['reg'].set(9876, 1)",                       #  9425.1  9606
00096     "tst.regs['REG'].set(3145)" ,                         #  9157.5
00097     "tst.regs['REG'].set(9876, 1)",                       #  9425.1
00098     "tst.regs['reg'].get()" ,                             #  8680.6
00099     "tst.regs['reg'].get(1)",                             #  8841.7
00100     "tst.regs['REG'].get()" ,                             #  8605.9
00101     "tst.regs['REG'].get(1)",                             #  8833.9
00102     "tst.regs['reg'].set(3145, 0, tst)" ,                 #  9337.1  9328
00103     "tst.regs['reg'].set(9876, 1, tst)",                  #  9505.7  9606
00104     "tst.regs['REG'].set(3145, 0, tst)" ,                 #  9250.7
00105     "tst.regs['REG'].set(9876, 1, tst)",                  #  9416.2
00106     "tst.regs['reg'].get(0, tst)" ,                       #  8680.6
00107     "tst.regs['reg'].get(1, tst)",                        #  8841.7
00108     "tst.regs['REG'].get(0, tst)" ,                       #  8680.6
00109     "tst.regs['REG'].get(1, tst)",                        #  8833.9
00110     #"cmd.gTEMload(0, 3, 1234)",                           # ~18500 writes/sec
00111     ]
00112 
00113   commands = []
00114   for cmdStr in cmdStrs:
00115     commands.append((cmdStr, compile(cmdStr, '', 'exec')))
00116 
00117   cnt = 10000
00118   for cmdTuple in commands:
00119     command = cmdTuple[1]
00120     print 23*' ', cmdTuple[0],
00121     gc.collect()
00122     start = time.time()
00123     for i in xrange(cnt):
00124       exec(command)
00125     end = time.time()
00126     et = end-start
00127     if et == 0: et = 0.000001
00128     rate = cnt/et
00129     print "\r%4.2f sec (%7.1f Hz)   %s" % (et, rate, cmdTuple[0])
00130 
00131   if disconnectOnExit:
00132     cmd.disconnect()
00133   else:
00134     cmdCli = cmd
00135 
00136 if __name__ == '__main__':
00137   test()

Generated on Fri Jul 21 13:26:32 2006 for LATTE R04-12-00 by doxygen 1.4.3