#!/usr/bin/env python
# Copyright (c) 2013 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

""" Run the Skia benchmarking executable. """

from build_step import BuildStep
from utils import shell_utils
import os
import re
import sys


GIT = 'git.bat' if os.name == 'nt' else 'git'
GIT_SVN_ID_MATCH_STR = 'git-svn-id: http://skia.googlecode.com/svn/trunk@(\d+)'


def BenchArgs(data_file):
  """ Builds a list containing arguments to pass to bench.

  data_file: filepath to store the log output
  """
  return ['--timers', 'wcg', '--logFile', data_file]


class RunBench(BuildStep):
  def __init__(self, timeout=9600, no_output_timeout=9600, **kwargs):
    super(RunBench, self).__init__(timeout=timeout,
                                   no_output_timeout=no_output_timeout,
                                   **kwargs)

  def _BuildDataFile(self):
    return os.path.join(self._device_dirs.PerfDir(),
                        'bench_%s_data' % self._got_revision)

  def _Run(self):
    args = ['-i', self._device_dirs.ResourceDir()]
    if self._perf_data_dir:
      args.extend(BenchArgs(self._BuildDataFile()))
    if 'Nexus4' in self._builder_name:
      args.extend(['--config', 'defaults', 'MSAA4'])
    self._flavor_utils.RunFlavoredCmd('bench', args + self._bench_args)


if '__main__' == __name__:
  sys.exit(BuildStep.RunBuildStep(RunBench))

@@ -185,17 +185,16 @@
 le.%0A%0A%22%22%22
- 
 Run the 
@@ -226,14 +226,35 @@
 ble.
- 
 %22%22%22%0A%0A
+import os%0Aimport sys%0A%0A
 from
@@ -285,70 +285,8 @@
 Step
-%0Afrom utils import shell_utils%0Aimport os%0Aimport re%0Aimport sys%0A
 %0A%0AGI
@@ -352,16 +352,17 @@
 H_STR = 
+r
 'git-svn
@@ -443,17 +443,16 @@
 ):%0A  %22%22%22
- 
 Builds a
@@ -497,16 +497,26 @@
 bench.%0A%0A
+  Args:%0A  
   data_f
@@ -559,93 +559,345 @@
 t%0A  
-%22%22%22%0A  return %5B'--timers', 'wcg', '--logFile', data_file%5D%0A%0A%0Aclass RunBench(BuildStep):
+Returns:%0A    list containing arguments to pass to bench%0A  %22%22%22%0A  return %5B'--timers', 'wcg', '--logFile', data_file%5D%0A%0A# Device name -%3E extra arguments%0AEXTRA_ARGS = %7B%0A    'GalaxyNexus': %5B'--match', '~DeferredSurfaceCopy'%5D,%0A    'Nexus4': %5B'--config', 'defaults', 'MSAA4'%5D,%0A%7D%0A%0A%0Aclass RunBench(BuildStep):%0A  %22%22%22A BuildStep that runs bench.%22%22%22%0A
 %0A  d
@@ -1434,19 +1434,49 @@
     
-if 'Nexus4'
+for device in EXTRA_ARGS:%0A      if device
  in 
@@ -1493,32 +1493,34 @@
 der_name:%0A      
+ 
+ 
 args.extend(%5B'--
@@ -1519,40 +1519,25 @@
 end(
-%5B'--config', 'defaults', 'MSAA4'
+EXTRA_ARGS%5Bdevice
 %5D)%0A 

Disable tests that crash bench on GalaxyNeuxs/NexusS, and lint.