Ejemplo n.º 1
0
    def run(self):
        """
        - create 'concurrency' number of threads
        - per thread call pre()
        - sync threads, start timer
        - per thread call core() 'iteration' number of times', tic()
        - stop timer
        - per thread, call post, close threads
        - eval once
        """

        threads = []
        concurrency = int(self.bench_cfg['concurrency'])

        self._start()

        for tid in range(0, concurrency):

            self.events[tid] = {}
            self.events[tid]['event_1'] = rut.Event()
            self.events[tid]['event_2'] = rut.Event()
            self.events[tid]['event_3'] = rut.Event()
            self.events[tid]['event_4'] = rut.Event()
            self.events[tid]['event_5'] = rut.Event()
            self.start[tid] = time.time()
            self.times[tid] = list()

            t = rut.Thread(self._thread, tid)
            threads.append(t)

        for t in threads:
            t.start()

        # wait for all threads to start up and initialize
        self.t_init = time.time()
        rut.lout("\n> " + "=" * concurrency)
        rut.lout("\n> ")
        for tid in range(0, concurrency):
            self.events[tid]['event_1'].wait()

        # start workload in all threads
        self.t_start = time.time()
        for tid in range(0, concurrency):
            self.events[tid]['event_2'].set()

        # wait for all threads to finish core test
        for tid in range(0, concurrency):
            self.events[tid]['event_3'].wait()
        self.t_stop = time.time()

        # start shut down
        rut.lout("\n< " + "-" * concurrency)
        rut.lout("\n< ")
        for tid in range(0, concurrency):
            self.events[tid]['event_4'].set()

        # wait for all threads to finish shut down
        for tid in range(0, concurrency):
            self.events[tid]['event_5'].wait()
Ejemplo n.º 2
0
 def _start (self) :
 
     self.start = dict()
     self.times = dict()
     self.idx   = 0
 
     rut.lout ("\n")
     rut.lout ("benchmark   : %s (%s)\n" % (self.name, self.bench_cfg['tags']))
     rut.lout ("concurrency : %s\n"      %  self.bench_cfg['concurrency'])
     rut.lout ("iterations  : %s\n"      %  self.bench_cfg['iterations'])
 
     sys.stdout.flush ()
Ejemplo n.º 3
0
    def _start(self):

        self.start = dict()
        self.times = dict()
        self.idx = 0

        rut.lout("\n")
        rut.lout("benchmark   : %s (%s)\n" %
                 (self.name, self.bench_cfg['tags']))
        rut.lout("concurrency : %s\n" % self.bench_cfg['concurrency'])
        rut.lout("iterations  : %s\n" % self.bench_cfg['iterations'])

        sys.stdout.flush()
Ejemplo n.º 4
0
    def eval(self, error=None):

        import numpy

        times = list()

        for tid in self.times:
            times += self.times[tid][1:]

    # import pprint
    # pprint.pprint (times)

        if len(times) < 1:
            raise ValueError(
                "min 1 timing value required for benchmark evaluation (%d)" %
                len(times))

        concurrency = int(self.bench_cfg['concurrency'])
        tags = ' '.join(self.bench_cfg['tags'])

        out = "\n"
        top = ""
        tab = ""
        num = ""

        out += "Results :\n"

        numpy_times = numpy.array(times)

        vtot = self.t_stop - self.t_start
        vini = self.t_start - self.t_init
        vn = len(times)
        vsum = sum(times)
        vmin = min(times)
        vmax = max(times)

        if len(times):
            vmean = numpy_times.mean()
            vsdev = numpy_times.std()
        else:
            vmean = 0.0
            vsdev = 0.0
        vrate = vn / vtot

        bdat = "benchmark.%s.dat" % (self.name)

        out += "  name    : %s\n" % (self.name)
        out += "  tags    : %s\n" % (tags)
        out += "  threads : %8d        iters   : %8d\n" % (concurrency, vn)
        out += "  init    : %8.2fs       min     : %8.2fs\n" % (vini, vmin)
        out += "  total   : %8.2fs       max     : %8.2fs\n" % (vtot, vmax)
        out += "  rate    : %8.2f/s      mean    : %8.2fs\n" % (vrate, vmean)
        out += "                            sdev    : %8.2fs\n" % (vsdev)

        num = "# %7s  %7s  %7s  %7s  %7s  %7s  %8s  %8s  %9s  %10s  %10s" \
            % (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)
        top = "# %7s  %7s  %7s  %7s  %7s  %7s  %8s  %8s  %9s  %10s  %10s" \
            % ('n', 'threads', 'init', 'tot', 'min',  'max', 'mean', \
               'std-dev', 'rate', 'name', 'tags')

        tab = "  "      \
              "%7d  "   \
              "%7d  "   \
              "%7.2f  " \
              "%7.2f  " \
              "%7.2f  " \
              "%7.2f  " \
              "%8.3f  " \
              "%8.3f  " \
              "%9.3f  " \
              "%10s  "  \
              "%10s  "  \
            % (vn,
               concurrency,
               vini,
               vtot,
               vmin,
               vmax,
               vmean,
               vsdev,
               vrate,
               self.name,
               tags)

        rut.lout("\n%s" % out)

        create_top = True
        try:
            statinfo = os.stat(bdat)
            if statinfo.st_size > 0:
                create_top = False
        except:
            pass

        f = open(bdat, "a+")

        if create_top:
            f.write("%s\n" % num)
            f.write("%s\n" % top)
        f.write("%s\n" % tab)
Ejemplo n.º 5
0
    def eval (self, error=None) :
    
        import numpy

        times = list()
    
        for tid in self.times :
            times += self.times[tid][1:]

      # import pprint
      # pprint.pprint (times)
    
        if  len(times) < 1 :
            raise ValueError ("min 1 timing value required for benchmark evaluation (%d)" % len(times))
    
        concurrency = int(self.bench_cfg['concurrency'])
        tags        = ' '.join (self.bench_cfg['tags'])
    
        out = "\n"
        top = ""
        tab = ""
        num = ""
    
        out += "Results :\n"

        numpy_times = numpy.array (times)
    
        vtot  = self.t_stop  - self.t_start
        vini  = self.t_start - self.t_init
        vn    = len (times)
        vsum  = sum (times)
        vmin  = min (times)
        vmax  = max (times)

        if len (times) :
            vmean = numpy_times.mean ()
            vsdev = numpy_times.std  ()
        else :
            vmean = 0.0
            vsdev = 0.0
        vrate = vn / vtot
    
        bdat  = "benchmark.%s.dat" % (self.name)
    
        out += "  name    : %s\n"                               % (self.name)
        out += "  tags    : %s\n"                               % (tags)
        out += "  threads : %8d        iters   : %8d\n"        % (concurrency, vn)
        out += "  init    : %8.2fs       min     : %8.2fs\n"    % (vini,        vmin )
        out += "  total   : %8.2fs       max     : %8.2fs\n"    % (vtot,        vmax )
        out += "  rate    : %8.2f/s      mean    : %8.2fs\n"    % (vrate,       vmean)
        out += "                            sdev    : %8.2fs\n" % (             vsdev)
    
        num = "# %7s  %7s  %7s  %7s  %7s  %7s  %8s  %8s  %9s  %10s  %10s" \
            % (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)
        top = "# %7s  %7s  %7s  %7s  %7s  %7s  %8s  %8s  %9s  %10s  %10s" \
            % ('n', 'threads', 'init', 'tot', 'min',  'max', 'mean', \
               'std-dev', 'rate', 'name', 'tags')
    
        tab = "  "      \
              "%7d  "   \
              "%7d  "   \
              "%7.2f  " \
              "%7.2f  " \
              "%7.2f  " \
              "%7.2f  " \
              "%8.3f  " \
              "%8.3f  " \
              "%9.3f  " \
              "%10s  "  \
              "%10s  "  \
            % (vn, 
               concurrency, 
               vini,
               vtot,   
               vmin,  
               vmax, 
               vmean, 
               vsdev, 
               vrate, 
               self.name, 
               tags) 
    
        rut.lout ("\n%s" % out)
    
        create_top = True
        try :
            statinfo = os.stat (bdat)
            if  statinfo.st_size > 0 :
                create_top = False
        except :
            pass
    
        f = open (bdat, "a+")
    
        if  create_top :
            f.write ("%s\n" % num)
            f.write ("%s\n" % top)
        f.write ("%s\n" % tab)
Ejemplo n.º 6
0
 def run (self) :
     """
     - create 'concurrency' number of threads
     - per thread call pre()
     - sync threads, start timer
     - per thread call core() 'iteration' number of times', tic()
     - stop timer
     - per thread, call post, close threads
     - eval once
     """
 
     threads     = []
     concurrency = int(self.bench_cfg['concurrency'])
 
     self._start ()
 
     for tid in range (0, concurrency) :
 
         self.events[tid] = {}
         self.events[tid]['event_1'] = rut.Event ()
         self.events[tid]['event_2'] = rut.Event ()
         self.events[tid]['event_3'] = rut.Event ()
         self.events[tid]['event_4'] = rut.Event ()
         self.events[tid]['event_5'] = rut.Event ()
         self.start [tid] = time.time ()
         self.times [tid] = list()
 
         t = rut.Thread (self._thread, tid)
         threads.append (t)
 
 
     for t in threads :
         t.start ()
 
     
     # wait for all threads to start up and initialize
     self.t_init = time.time ()
     rut.lout ("\n> " + "="*concurrency)
     rut.lout ("\n> ")
     for tid in range (0, concurrency) :
         self.events[tid]['event_1'].wait ()
 
     # start workload in all threads
     self.t_start = time.time ()
     for tid in range (0, concurrency) :
         self.events[tid]['event_2'].set ()
 
     # wait for all threads to finish core test
     for tid in range (0, concurrency) :
         self.events[tid]['event_3'].wait ()
     self.t_stop = time.time ()
 
     # start shut down
     rut.lout ("\n< " + "-"*concurrency)
     rut.lout ("\n< ")
     for tid in range (0, concurrency) :
         self.events[tid]['event_4'].set ()
 
     # wait for all threads to finish shut down
     for tid in range (0, concurrency) :
         self.events[tid]['event_5'].wait ()