blob: 400b89f31f11b4962b7c94b3250d597163617789 [file] [log] [blame]
# Copyright 2015 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.
import imp
import inspect
import os
import sys
from core import perf_benchmark
def GetClassFilePath(clazz):
""" Return the absolute file path to |clazz|. """
assert inspect.isclass(clazz)
path = os.path.abspath(inspect.getfile(clazz))
if path.endswith('.pyc'):
return path[:-1]
return path
def GetBenchmarkNamesForFile(top_level_dir, benchmark_file_dir):
""" Return the list of all benchmark names of benchmarks defined in
original_sys_path = sys.path[:]
top_level_dir = os.path.abspath(top_level_dir)
original_sys_path = sys.path[:]
if top_level_dir not in sys.path:
module = imp.load_source('_tmp_module_name_', benchmark_file_dir)
benchmark_names = []
for _, obj in inspect.getmembers(module):
if (inspect.isclass(obj) and issubclass(obj, perf_benchmark.PerfBenchmark)
and GetClassFilePath(obj) == benchmark_file_dir):
return sorted(benchmark_names)
sys.path = original_sys_path