AUTHOR = "Eric Whitney (eric.whitney@hp.com)"
NAME = "fsscale_ffsb_lockstats"
TEST_CATEGORY = "Performance"
TEST_CLASS = "General"
TEST_TYPE = "client"
TIME = 'MEDIUM'
DOC='''
Runs all boxacle-derived tests serially with selected perf monitoring tools
'''
import ConfigParser
from autotest_lib.client.bin.partition import FsOptions

config = ConfigParser.SafeConfigParser()
config.read(os.path.join(job.configdir, 'boxacle-tests.cfg'))
scenarios = config.sections()

for scenario in scenarios:

    name = (config.get(scenario, 'name'))
    base_profiles = (config.get(scenario, 'base_profiles')).split()
    thread_counts = (config.get(scenario, 'thread_counts')).split()
    devices = (config.get(scenario, 'devices')).split()
    filesystem = (config.get(scenario, 'filesystem_type'))
    mkfs_flags = (config.get(scenario, 'mkfs_options'))
    mopt = (config.get(scenario, 'mount_options'))

    job.fs = job.partition(devices[0])
    for base_profile in base_profiles:
        # we assume mkfs for ext4 is in /usr/local/sbin and in $PATH
        # autotest unfortunately hardwires acceptable mkfs.ext4 locations
        fs_options = FsOptions(filesystem, base_profile, mkfs_flags,
                               mount_options = mopt)
        job.fs.set_fs_options(fs_options)
        if base_profile in ['large_file_sequential_reads', 'random_reads']:
            job.fs.mkfs()
            job.run_test('ffsb_init', iterations = 1,
                         tag = '%s.%s' % (name, base_profile),
                         workload = base_profile)	   
        for thread_count in thread_counts:
            # job.fs.mkfs()
            # fs.mkfs(fstype = filesystem, args = '-F')
            # system('mkfs.%s -F -q %s' % (filesystem, ' '.join(devices)))
            # default mount point is /usr/local/autotest/tmp
            # fs.mount(None)
            try:
#                job.profilers.add('vmstat', 10)
                job.profilers.add('lock_stat')
                profile = '%s_threads=%u' % (base_profile, int(thread_count))
                job.run_test('ffsb_fsscale', profile_only = True,
                             tag = '%s.%s' % (name, profile),
                             workload = profile)
                job.profilers.delete('lock_stat')
#                job.profilers.delete('vmstat')
            finally:
                # system('umount %s' % job.tmpdir)
                if job.fs.get_mountpoint():
                    job.fs.unmount()

