您的位置:首页 > 编程语言 > C语言/C++

生成结果以及处理结果代码段(c++和python)

2016-06-06 00:00 281 查看
生成结果文件(c++)

static void WriteOutput() {
// Create output directory
struct stat st;
if (stat("./ycsb-output", &st) == -1) {
mkdir("./ycsb-output", 0700);
}

// Create file under output directory
time_t tt;
time(&tt);
struct tm *p;
p = localtime(&tt);
std::stringstream oss;
oss << "./ycsb-output/"
<< "output" << p->tm_year + 1900 << p->tm_mon + 1 << p->tm_mday
<< p->tm_hour << p->tm_min << p->tm_sec << ".summary";
std::ofstream out(oss.str(), std::ofstream::out);

LOG_INFO("----------------------------------------------------------");
LOG_INFO(
"%lf %d %d :: %lf tps, %lf abort, %lf delay_ave, %lf delay_max, %lf "
"delay_min, "
"%lf generate/s",
state.update_ratio, state.scale_factor, state.column_count,
state.throughput, state.abort_rate, state.delay_ave, state.delay_max,
state.delay_min, state.generate_rate);

out << state.update_ratio << " ";
out << state.scale_factor << " ";
out << state.column_count << "\n";

for (size_t round_id = 0; round_id < state.snapshot_throughput.size();
++round_id) {
out << "[" << std::setw(3) << std::left
<< state.snapshot_duration * round_id << " - " << std::setw(3)
<< std::left << state.snapshot_duration * (round_id + 1)
<< " s]: " << state.snapshot_throughput[round_id] << " "
<< state.snapshot_abort_rate[round_id] << "\n";
}

out << state.throughput << " ";
out << state.abort_rate << " ";
out << state.delay_ave << " ";
out << state.delay_max << " ";
out << state.delay_min << " ";
out << state.backend_count << " ";
out << state.generate_count << " ";
out << state.scheduler << " ";
out << state.zipf_theta << " ";
out << state.generate_rate << "\n";
out.flush();
out.close();
}


自动运行shell脚本以及处理结果(python)

#!/usr/bin/python2.4
#
# Small script to show PostgreSQL and Pyscopg together
#

#from subprocess import call
import subprocess
import os

for i in range(1, 8):
    cmd = "./src/ycsb -b" + " " + str(i) + " " + "-z 0.99 -p occ -g co -d 5 -w 1 -q queue"
    pid = subprocess.Popen(cmd, shell=True)
    pid.wait()

for i in range(1, 8):
    cmd = "./src/ycsb -b" + " " + str(i) + " " + "-z 0.99 -p occ -g co -d 5 -w 1 -q detect"
    pid = subprocess.Popen(cmd, shell=True)
    pid.wait()

search_dir = "./ycsb-output"

result = open("./ycsb.summary", "a")
files = os.listdir(search_dir)
files = [os.path.join(search_dir, f) for f in files]
files.sort(key=lambda x: os.path.getmtime(x))

for filename in files:
    fl = filename
    with open(fl, "rb") as f:
        first = f.readline()
        f.seek(-2, 2)
        while f.read(1) != b"\n":
            f.seek(-2, 1)
        last = f.readline()
        print last
        result.write(last)
result.close()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: