mkdir like test_case1, copy three files below in it:
test_case1/test.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | #!/bin/python3 import os def shell_run(name, cmd): os.system('mkdir result') os.system(cmd + '> ./result/' + name) def run_cmds(cmds): for name, cmd in cmds.items(): shell_run(name, cmd) cmds = { '1_small_read' : 'fio -name iops -rw=read -bs=4k -runtime=60 -iodepth 32 -filename /dev/sda6 -ioengine libaio -direct=1', '1_small_randread' : 'fio -name iops -rw=randread -bs=4k -runtime=60 -iodepth 32 -filename /dev/sda6 -ioengine libaio -direct=1', '1_small_write' : 'fio -name iops -rw=write -bs=4k -runtime=60 -iodepth 32 -filename /dev/sda6 -ioengine libaio -direct=1', '1_small_randwrite' : 'fio -name iops -rw=randwrite -bs=4k -runtime=60 -iodepth 32 -filename /dev/sda6 -ioengine libaio -direct=1', '1_big_read' : 'fio -name iops -rw=read -bs=10M -runtime=60 -iodepth 32 -filename /dev/sda6 -ioengine libaio -direct=1', '1_big_randread' : 'fio -name iops -rw=randread -bs=10M -runtime=60 -iodepth 32 -filename /dev/sda6 -ioengine libaio -direct=1', '1_big_write' : 'fio -name iops -rw=write -bs=10M -runtime=60 -iodepth 32 -filename /dev/sda6 -ioengine libaio -direct=1', '1_big_randwrite' : 'fio -name iops -rw=randwrite -bs=10M -runtime=60 -iodepth 32 -filename /dev/sda6 -ioengine libaio -direct=1', '4_small_read' : 'fio -name iops -rw=read -bs=4k -runtime=60 -iodepth 32 -filename /dev/sda6 -ioengine libaio -direct=1 -numjobs=4', '4_small_randread' : 'fio -name iops -rw=randread -bs=4k -runtime=60 -iodepth 32 -filename /dev/sda6 -ioengine libaio -direct=1 -numjobs=4', '4_small_write' : 'fio -name iops -rw=write -bs=4k -runtime=60 -iodepth 32 -filename /dev/sda6 -ioengine libaio -direct=1 -numjobs=4', '4_small_randwrite' : 'fio -name iops -rw=randwrite -bs=4k -runtime=60 -iodepth 32 -filename /dev/sda6 -ioengine libaio -direct=1 -numjobs=4', '4_big_read' : 'fio -name iops -rw=read -bs=10M -runtime=60 -iodepth 32 -filename /dev/sda6 -ioengine libaio -direct=1 -numjobs=4', '4_big_randread' : 'fio -name iops -rw=randread -bs=10M -runtime=60 -iodepth 32 -filename /dev/sda6 -ioengine libaio -direct=1 -numjobs=4', '4_big_write' : 'fio -name iops -rw=write -bs=10M -runtime=60 -iodepth 32 -filename /dev/sda6 -ioengine libaio -direct=1 -numjobs=4', '4_big_randwrite' : 'fio -name iops -rw=randwrite -bs=10M -runtime=60 -iodepth 32 -filename /dev/sda6 -ioengine libaio -direct=1 -numjobs=4' } run_cmds(cmds) |
test_case1/parse.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 | #include <vector> #include <list> #include <string> #include <stdlib.h> #include <stdio.h> #include <string.h> using namespace std; #define DBG(...) printf(__VA_ARGS__) #define op_strdup strdup int read_lines_from_file(const char *file_path, list<string>& lines) { FILE *fp = fopen(file_path, "r"); if (NULL == fp) return 0; char buf[2048]; while (fgets(buf, 2048 - 1, fp) != NULL) { char *retLine = strstr(buf, "\n"); if (NULL != retLine) retLine[0] = 0; lines.push_back(buf); } fclose(fp); return 1; } void split_token_string(const char* str, char split_ch, vector<string>& out) { if (NULL == str) return; char* newStr = op_strdup(str); char* pStart = newStr; char* pEnd = newStr; for (; ; pEnd++) { if (*pEnd == split_ch) { *pEnd = 0; out.push_back(pStart); pStart = pEnd + 1; } else if (*pEnd == 0) { out.push_back(pStart); break; } } free(newStr); } typedef enum file_type { FILE_TYPE_READ, FILE_TYPE_RAND_READ, FILE_TYPE_WRITE, FILE_TYPE_RAND_WRITE } file_type_t; #define IOPS_READ_START_STR " read: IOPS=" #define BW_READ_START_STR " READ: bw=" #define IOPS_WRITE_START_STR " write: IOPS=" #define BW_WRITE_START_STR " WRITE: bw=" typedef struct file_desc { const char* name; int thread_count; int is_big_file; file_type_t type; int iops; int bw; const char* iops_start_str; const char* bw_start_str; } file_desc_t; int parse_file_name(file_desc_t* desc, char* filepath) { vector<string> tokens; split_token_string(filepath, '_', tokens); desc->name = filepath; desc->thread_count = atoi(tokens[0].c_str()); desc->is_big_file = tokens[1] == "big"; if (tokens[2] == "read") { desc->type = FILE_TYPE_READ; desc->iops_start_str = IOPS_READ_START_STR; desc->bw_start_str = BW_READ_START_STR; } else if (tokens[2] == "randread") { desc->type = FILE_TYPE_RAND_READ; desc->iops_start_str = IOPS_READ_START_STR; desc->bw_start_str = BW_READ_START_STR; } else if (tokens[2] == "write") { desc->type = FILE_TYPE_WRITE; desc->iops_start_str = IOPS_WRITE_START_STR; desc->bw_start_str = BW_WRITE_START_STR; } else if (tokens[2] == "randwrite") { desc->type = FILE_TYPE_RAND_WRITE; desc->iops_start_str = IOPS_WRITE_START_STR; desc->bw_start_str = BW_WRITE_START_STR; } return 1; } int parse_iops(const char* p) { vector<string> tokens; split_token_string(p, ',', tokens); string iops = tokens[0]; if (iops[iops.length() - 1] == 'k') return (int)(atof(iops.c_str()) * 1000); return atoi(iops.c_str()); } int parse_bw(const char* p) { return atoi(p); } int parse_single_job(file_desc_t* desc, list<string>& lines) { const char* p; const char* iops_start_str; const char* bw_start_str; for (list<string>::iterator it = lines.begin(); it != lines.end(); it++) { if (NULL != (p = strstr(it->c_str(), desc->iops_start_str))) { desc->iops = parse_iops(p + strlen(desc->iops_start_str)); } else if (NULL != (p = strstr(it->c_str(), desc->bw_start_str))) { desc->bw = parse_bw(p + strlen(desc->bw_start_str)); } } return 1; } int parse_multi_jobs(file_desc_t* desc, list<string>& lines) { const char* p; int is_first_iops = 1; for (list<string>::iterator it = lines.begin(); it != lines.end(); it++) { if (NULL != (p = strstr(it->c_str(), desc->iops_start_str))) { if (!is_first_iops) continue; desc->iops = desc->thread_count * parse_iops(p + strlen(desc->iops_start_str)); is_first_iops = 0; } else if (NULL != (p = strstr(it->c_str(), desc->bw_start_str))) { desc->bw = parse_bw(p + strlen(desc->bw_start_str)); } } return 1; } int out_result(const char* path, file_desc_t* desc) { FILE* fp = fopen(path, "a+"); fprintf(fp, "%s\t%d\t%d\n", desc->name, desc->iops, desc->bw); fclose(fp); return 1; } int parse(char* filepath, list<string>& lines) { file_desc_t desc; memset(&desc, 0, sizeof(desc)); parse_file_name(&desc, filepath); if (desc.thread_count == 1) parse_single_job(&desc, lines); else parse_multi_jobs(&desc, lines); out_result("../result.csv", &desc); return 1; } int main(int argc, char** argv) { if (argc != 2) { DBG("argc is not 2.\n"); return 0; } char* filepath = argv[1]; list<string> lines; read_lines_from_file(filepath, lines); parse(filepath, lines); return 1; } |
test_case1/parse.sh
1 2 3 4 5 6 7 8 9 | #!/bin/bash g++ -g -o parse parse.cpp || exit 1 cd result for it in `ls *`; do echo $it ../parse $it done |
how to run:
1 2 3 4 | apt install fio cd test_case1 python3 ./test.py # generate fio output data in result dir. ./parse.sh # generate report data in result.csv |
ps. /dev/sda6 is just an example path, if this device path exists, all data in it will be erased.
refer to:
https://blog.csdn.net/luyegang1/article/details/74453879