Esempio n. 1
0
    def execute(self, hardware):
        hardware.sanity_check()
        self._schedule_hardware_poll()

        commandline = self.ARGV + [
            '--config', self.config, '--skp', self.skp, '--suppressHeader',
            'true'
        ]
        if FLAGS.write_path:
            pngfile = _path.join(FLAGS.write_path, self.config,
                                 _path.basename(self.skp) + '.png')
            commandline.extend(['--png', pngfile])
        if (FLAGS.verbosity >= 4):
            quoted = [
                '\'%s\'' % re.sub(r'([\\\'])', r'\\\1', x) for x in commandline
            ]
            print(' '.join(quoted), file=sys.stderr)
        self._proc = subprocess.Popen(commandline, stdout=subprocess.PIPE)
        self._monitor = SubprocessMonitor(self._queue, self._proc)
        self._monitor.start()

        while True:
            message = self._queue.get()
            if message.message == Message.READLINE:
                result = BenchResult.match(message.value)
                if result:
                    hardware.sanity_check()
                    self._process_result(result)
                else:
                    print(message.value)
                sys.stdout.flush()
                continue
            if message.message == Message.POLL_HARDWARE:
                hardware.sanity_check()
                self._schedule_hardware_poll()
                continue
            if message.message == Message.EXIT:
                self._monitor.join()
                self._proc.wait()
                if self._proc.returncode != 0:
                    raise Exception(
                        "skpbench exited with nonzero exit code %i" %
                        self._proc.returncode)
                self._proc = None
                break
Esempio n. 2
0
    def execute(self, hardware):
        hardware.sanity_check()
        self._schedule_hardware_poll()

        commandline = self.ARGV + [
            '--config', self.config, '--src', self.src, '--suppressHeader',
            'true'
        ]
        if FLAGS.write_path:
            pngfile = _path.join(FLAGS.write_path, self.config,
                                 _path.basename(self.src) + '.png')
            commandline.extend(['--png', pngfile])
        dump_commandline_if_verbose(commandline)
        self._proc = subprocess.Popen(commandline,
                                      stdout=subprocess.PIPE,
                                      stderr=subprocess.STDOUT)
        self._monitor = SubprocessMonitor(self._queue, self._proc)
        self._monitor.start()

        while True:
            message = self._queue.get()
            if message.message == Message.READLINE:
                result = BenchResult.match(message.value)
                if result:
                    hardware.sanity_check()
                    self._process_result(result)
                elif hardware.filter_line(message.value):
                    print(message.value, file=sys.stderr)
                continue
            if message.message == Message.POLL_HARDWARE:
                hardware.sanity_check()
                self._schedule_hardware_poll()
                continue
            if message.message == Message.EXIT:
                self._monitor.join()
                self._proc.wait()
                if self._proc.returncode != 0:
                    raise Exception(
                        "skpbench exited with nonzero exit code %i" %
                        self._proc.returncode)
                self._proc = None
                break
Esempio n. 3
0
  def run(self):
    """Called on the background thread.

    Launches and reads output from an skpbench process.

    """
    commandline = self.ARGV + ['--config', self.config,
                               '--skp', self.skp,
                               '--suppressHeader', 'true']
    if (FLAGS.write_path):
      pngfile = _path.join(FLAGS.write_path, self.config,
                           _path.basename(self.skp) + '.png')
      commandline.extend(['--png', pngfile])
    if (FLAGS.verbosity >= 3):
      print(' '.join(commandline), file=sys.stderr)
    proc = subprocess.Popen(commandline, stdout=subprocess.PIPE)
    for line in iter(proc.stdout.readline, b''):
      self._queue.put(Message(Message.READLINE, line.decode('utf-8').rstrip()))
    proc.wait()
    self._queue.put(Message(Message.EXIT, proc.returncode))
Esempio n. 4
0
  def execute(self, hardware):
    hardware.sanity_check()
    self._schedule_hardware_poll()

    commandline = self.ARGV + ['--config', self.config,
                               '--skp', self.skp,
                               '--suppressHeader', 'true']
    if FLAGS.write_path:
      pngfile = _path.join(FLAGS.write_path, self.config,
                           _path.basename(self.skp) + '.png')
      commandline.extend(['--png', pngfile])
    dump_commandline_if_verbose(commandline)
    self._proc = subprocess.Popen(commandline, stdout=subprocess.PIPE)
    self._monitor = SubprocessMonitor(self._queue, self._proc)
    self._monitor.start()

    while True:
      message = self._queue.get()
      if message.message == Message.READLINE:
        result = BenchResult.match(message.value)
        if result:
          hardware.sanity_check()
          self._process_result(result)
        else:
          print(message.value, file=sys.stderr)
        sys.stdout.flush()
        continue
      if message.message == Message.POLL_HARDWARE:
        hardware.sanity_check()
        self._schedule_hardware_poll()
        continue
      if message.message == Message.EXIT:
        self._monitor.join()
        self._proc.wait()
        if self._proc.returncode != 0:
          raise Exception("skpbench exited with nonzero exit code %i" %
                          self._proc.returncode)
        self._proc = None
        break
Esempio n. 5
0
class SKPBench:
    ARGV = ['skpbench', '--verbosity', str(FLAGS.verbosity)]
    if FLAGS.duration:
        ARGV.extend(['--duration', str(FLAGS.duration)])
    if FLAGS.sample_ms:
        ARGV.extend(['--sampleMs', str(FLAGS.sample_ms)])
    if FLAGS.gpu:
        ARGV.extend(['--gpuClock', 'true'])
    if FLAGS.fps:
        ARGV.extend(['--fps', 'true'])
    if FLAGS.path:
        ARGV[0] = _path.join(FLAGS.path, ARGV[0])
    if FLAGS.adb:
        if FLAGS.device_serial is None:
            ARGV = ['adb', 'shell'] + ARGV
        else:
            ARGV = ['adb', '-s', FLAGS.device_serial, 'shell'] + ARGV

    @classmethod
    def print_header(cls):
        subprocess.call(cls.ARGV + ['--duration', '0'])

    def __init__(self, skp, config, max_stddev, best_result=None):
        self.skp = skp
        self.config = config
        self.max_stddev = max_stddev
        self.best_result = best_result
        self._queue = Queue()
        self._proc = None
        self._monitor = None
        self._hw_poll_timer = None

    def __enter__(self):
        return self

    def __exit__(self, exception_type, exception_value, traceback):
        if self._proc:
            self.terminate()
        if self._hw_poll_timer:
            self._hw_poll_timer.cancel()

    def execute(self, hardware):
        hardware.sanity_check()
        self._schedule_hardware_poll()

        commandline = self.ARGV + [
            '--config', self.config, '--skp', self.skp, '--suppressHeader',
            'true'
        ]
        if FLAGS.write_path:
            pngfile = _path.join(FLAGS.write_path, self.config,
                                 _path.basename(self.skp) + '.png')
            commandline.extend(['--png', pngfile])
        if (FLAGS.verbosity >= 4):
            quoted = [
                '\'%s\'' % re.sub(r'([\\\'])', r'\\\1', x) for x in commandline
            ]
            print(' '.join(quoted), file=sys.stderr)
        self._proc = subprocess.Popen(commandline, stdout=subprocess.PIPE)
        self._monitor = SubprocessMonitor(self._queue, self._proc)
        self._monitor.start()

        while True:
            message = self._queue.get()
            if message.message == Message.READLINE:
                result = BenchResult.match(message.value)
                if result:
                    hardware.sanity_check()
                    self._process_result(result)
                else:
                    print(message.value)
                sys.stdout.flush()
                continue
            if message.message == Message.POLL_HARDWARE:
                hardware.sanity_check()
                self._schedule_hardware_poll()
                continue
            if message.message == Message.EXIT:
                self._monitor.join()
                self._proc.wait()
                if self._proc.returncode != 0:
                    raise Exception(
                        "skpbench exited with nonzero exit code %i" %
                        self._proc.returncode)
                self._proc = None
                break

    def _schedule_hardware_poll(self):
        if self._hw_poll_timer:
            self._hw_poll_timer.cancel()
        self._hw_poll_timer = \
          Timer(1, lambda: self._queue.put(Message(Message.POLL_HARDWARE)))
        self._hw_poll_timer.start()

    def _process_result(self, result):
        if not self.best_result or result.stddev <= self.best_result.stddev:
            self.best_result = result
        elif FLAGS.verbosity >= 2:
            print("reusing previous result for %s/%s with lower stddev "
                  "(%s%% instead of %s%%)." %
                  (result.config, result.bench, self.best_result.stddev,
                   result.stddev),
                  file=sys.stderr)
        if self.max_stddev and self.best_result.stddev > self.max_stddev:
            raise StddevException()

    def terminate(self):
        if self._proc:
            self._proc.terminate()
            self._monitor.join()
            self._proc.wait()
            self._proc = None
Esempio n. 6
0
class SKPBench(Thread):
  ARGV = ['skpbench', '--verbosity', str(FLAGS.verbosity)]
  if FLAGS.samples:
    ARGV.extend(['--samples', str(FLAGS.samples)])
  if FLAGS.sample_ms:
    ARGV.extend(['--sampleMs', str(FLAGS.sample_ms)])
  if FLAGS.fps:
    ARGV.extend(['--fps', 'true'])
  if FLAGS.path:
    ARGV[0] = _path.join(FLAGS.path, ARGV[0])
  if FLAGS.adb:
    if FLAGS.device_serial is None:
      ARGV = ['adb', 'shell'] + ARGV
    else:
      ARGV = ['adb', '-s', FLAGS.device_serial, 'shell'] + ARGV

  @classmethod
  def print_header(cls):
    subprocess.call(cls.ARGV + ['--samples', '0'])

  def __init__(self, skp, config, max_stddev, best_result=None):
    self.skp = skp
    self.config = config
    self.max_stddev = max_stddev
    self.best_result = best_result
    self._queue = Queue()
    Thread.__init__(self)

  def execute(self):
    self.start()
    while True:
      message = self._queue.get()
      if message.message == Message.READLINE:
        result = BenchResult.match(message.value)
        if result:
          self.__process_result(result)
        else:
          print(message.value)
        sys.stdout.flush()
        continue
      if message.message == Message.EXIT:
        self.join()
        break

  def __process_result(self, result):
    if not self.best_result or result.stddev <= self.best_result.stddev:
      self.best_result = result
    elif FLAGS.verbosity >= 1:
      print('NOTE: reusing previous result for %s/%s with lower stddev '
            '(%s%% instead of %s%%).' %
            (result.config, result.bench, self.best_result.stddev,
             result.stddev), file=sys.stderr)
    if self.max_stddev and self.best_result.stddev > self.max_stddev:
      raise StddevException()
    self.best_result.print_values(config_suffix=FLAGS.suffix)

  def run(self):
    """Called on the background thread.

    Launches and reads output from an skpbench process.

    """
    commandline = self.ARGV + ['--config', self.config,
                               '--skp', self.skp,
                               '--suppressHeader', 'true']
    if (FLAGS.write_path):
      pngfile = _path.join(FLAGS.write_path, self.config,
                           _path.basename(self.skp) + '.png')
      commandline.extend(['--png', pngfile])
    if (FLAGS.verbosity >= 3):
      print(' '.join(commandline), file=sys.stderr)
    proc = subprocess.Popen(commandline, stdout=subprocess.PIPE)
    for line in iter(proc.stdout.readline, b''):
      self._queue.put(Message(Message.READLINE, line.decode('utf-8').rstrip()))
    proc.wait()
    self._queue.put(Message(Message.EXIT, proc.returncode))
Esempio n. 7
0
class SKPBench:
    ARGV = ['skpbench', '--verbosity', str(FLAGS.verbosity)]
    if FLAGS.duration:
        ARGV.extend(['--duration', str(FLAGS.duration)])
    if FLAGS.sample_ms:
        ARGV.extend(['--sampleMs', str(FLAGS.sample_ms)])
    if FLAGS.gpu:
        ARGV.extend(['--gpuClock', 'true'])
    if FLAGS.fps:
        ARGV.extend(['--fps', 'true'])
    if FLAGS.path:
        ARGV[0] = _path.join(FLAGS.path, ARGV[0])
    if FLAGS.adb:
        if FLAGS.device_serial is None:
            ARGV = ['adb', 'shell'] + ARGV
        else:
            ARGV = ['adb', '-s', FLAGS.device_serial, 'shell'] + ARGV

    @classmethod
    def print_header(cls):
        commandline = cls.ARGV + ['--duration', '0']
        dump_commandline_if_verbose(commandline)
        subprocess.call(commandline)

    @classmethod
    def run_warmup(cls, warmup_time):
        if not warmup_time:
            return
        print('running %i second warmup...' % warmup_time, file=sys.stderr)
        commandline = cls.ARGV + [
            '--duration',
            str(warmup_time * 1000), '--config', 'gpu', '--skp', 'warmup'
        ]
        dump_commandline_if_verbose(commandline)
        output = subprocess.check_output(commandline).decode('utf-8')
        # validate the warmup run output.
        for line in output.split('\n'):
            match = BenchResult.match(line.rstrip())
            if match and match.bench == 'warmup':
                return
        raise Exception('Invalid warmup output:\n%s' % output)

    def __init__(self, skp, config, max_stddev, best_result=None):
        self.skp = skp
        self.config = config
        self.max_stddev = max_stddev
        self.best_result = best_result
        self._queue = Queue()
        self._proc = None
        self._monitor = None
        self._hw_poll_timer = None

    def __enter__(self):
        return self

    def __exit__(self, exception_type, exception_value, traceback):
        if self._proc:
            self.terminate()
        if self._hw_poll_timer:
            self._hw_poll_timer.cancel()

    def execute(self, hardware):
        hardware.sanity_check()
        self._schedule_hardware_poll()

        commandline = self.ARGV + [
            '--config', self.config, '--skp', self.skp, '--suppressHeader',
            'true'
        ]
        if FLAGS.write_path:
            pngfile = _path.join(FLAGS.write_path, self.config,
                                 _path.basename(self.skp) + '.png')
            commandline.extend(['--png', pngfile])
        dump_commandline_if_verbose(commandline)
        self._proc = subprocess.Popen(commandline, stdout=subprocess.PIPE)
        self._monitor = SubprocessMonitor(self._queue, self._proc)
        self._monitor.start()

        while True:
            message = self._queue.get()
            if message.message == Message.READLINE:
                result = BenchResult.match(message.value)
                if result:
                    hardware.sanity_check()
                    self._process_result(result)
                else:
                    print(message.value, file=sys.stderr)
                sys.stdout.flush()
                continue
            if message.message == Message.POLL_HARDWARE:
                hardware.sanity_check()
                self._schedule_hardware_poll()
                continue
            if message.message == Message.EXIT:
                self._monitor.join()
                self._proc.wait()
                if self._proc.returncode != 0:
                    raise Exception(
                        "skpbench exited with nonzero exit code %i" %
                        self._proc.returncode)
                self._proc = None
                break

    def _schedule_hardware_poll(self):
        if self._hw_poll_timer:
            self._hw_poll_timer.cancel()
        self._hw_poll_timer = \
          Timer(1, lambda: self._queue.put(Message(Message.POLL_HARDWARE)))
        self._hw_poll_timer.start()

    def _process_result(self, result):
        if not self.best_result or result.stddev <= self.best_result.stddev:
            self.best_result = result
        elif FLAGS.verbosity >= 2:
            print("reusing previous result for %s/%s with lower stddev "
                  "(%s%% instead of %s%%)." %
                  (result.config, result.bench, self.best_result.stddev,
                   result.stddev),
                  file=sys.stderr)
        if self.max_stddev and self.best_result.stddev > self.max_stddev:
            raise StddevException()

    def terminate(self):
        if self._proc:
            self._proc.terminate()
            self._monitor.join()
            self._proc.wait()
            self._proc = None