Skip to content

Commit

Permalink
allow to pass in class path of a BenchRunner as a cli arg
Browse files Browse the repository at this point in the history
  • Loading branch information
anentropic committed Mar 14, 2013
1 parent 57bdf1f commit 1b58f17
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions doc/source/usage-fl-run-bench.rst
Expand Up @@ -52,6 +52,8 @@ Options
--as-fast-as-possible, -f
Remove sleep times between requests and between tests,
shortcut for -m0 -M0 -t0
--runner-class=BENCH_RUNNER_CLASS, -r BENCH_RUNNER_CLASS
Python dotted import path to BenchRunner class to use.
--no-color Monochrome output.
--accept-invalid-links Do not fail if css/image links are not reachable.
--simple-fetch Don't load additional links like css or images when
Expand Down
17 changes: 16 additions & 1 deletion src/funkload/BenchRunner.py
Expand Up @@ -636,6 +636,15 @@ def shutdown(*args):
trace('Aborted')
sys.exit(0)

def get_runner_class(class_path):
try:
module_path, class_name = class_path.rsplit('.', 1)
except ValueError:
raise Exception('Invalid class path {0}'.format(class_path))

_module = __import__(module_path, globals(), locals(), class_name, -1)
return getattr(_module, class_name)


def main(args=sys.argv[1:]):
"""Default main."""
Expand Down Expand Up @@ -684,6 +693,11 @@ def main(args=sys.argv[1:]):
action="store_true",
help="Remove sleep times between requests and between "
"tests, shortcut for -m0 -M0 -t0")
parser.add_option("-r", "--runner-class",
type="string",
dest="bench_runner_class",
default="funkload.BenchRunner.BenchRunner",
help="Python dotted import path to BenchRunner class to use.")
parser.add_option("", "--no-color",
action="store_true",
help="Monochrome output.")
Expand Down Expand Up @@ -821,7 +835,8 @@ def main(args=sys.argv[1:]):
_manager = None
return ret
else:
bench = BenchRunner(module_name, klass, method, options)
RunnerClass = get_runner_class(options.bench_runner_class)
bench = RunnerClass(module_name, klass, method, options)

# Start a HTTP server optionally
if options.debugserver:
Expand Down

0 comments on commit 1b58f17

Please sign in to comment.