def run_sysbench_cpu(hw_, max_time, cpu_count, processor_num=-1):
    taskset = ''
    if (processor_num < 0):
        sys.stderr.write('Benchmarking all CPUs for '
                         '%d seconds (%d threads)\n' % (max_time, cpu_count))
    else:
        sys.stderr.write('Benchmarking CPU %d for %d seconds (%d threads)\n' %
                         (processor_num, max_time, cpu_count))
        taskset = 'taskset %s' % hex(1 << processor_num)

    cmds = '%s sysbench --max-time=%d --max-requests=10000000' \
           ' --num-threads=%d --test=cpu --cpu-max-prime=15000 run' \
           % (taskset, max_time, cpu_count)
    sysbench_cmd = subprocess.Popen(cmds, shell=True, stdout=subprocess.PIPE)

    for line in sysbench_cmd.stdout:
        if "total number of events" in line.decode():
            title, perf = line.decode().rstrip('\n').replace(' ', '').split(':')
            if processor_num == -1:
                hw_.append(('cpu', 'logical', 'loops_per_sec',
                            str(int(perf) / max_time)))
            else:
                hw_.append(('cpu', 'logical_%d' % processor_num,
                            'loops_per_sec', str(int(perf) / max_time)))
Running sysbench cpu stress of a give amount of logical cpu
dataset/ETHPy150Open redhat-cip/edeploy/src/health_libs.py/run_sysbench_cpu