9 #include "hebench/modules/general/include/hebench_utilities.h"
13 using namespace std::literals;
18 std::vector<std::string_view> OverviewHeader::extractInfoFromCSVLine(std::string_view s_row,
const std::string_view &s_tag, std::size_t num_values)
20 std::vector<std::string_view> retval;
22 retval.reserve(num_values);
23 hebench::Utilities::trim(s_row);
24 auto pos = s_row.find(s_tag);
25 if (pos != std::string_view::npos)
27 s_row.remove_prefix(pos + s_tag.size());
28 while (!s_row.empty() && retval.size() < num_values)
30 hebench::Utilities::ltrim(s_row);
31 char ch_to_find =
',';
32 if (!s_row.empty() && s_row.front() ==
'"')
36 s_row.remove_prefix(1);
38 pos = s_row.find_first_of(ch_to_find);
39 if (pos == std::string_view::npos)
43 retval.emplace_back(s_row.substr(0, pos));
44 hebench::Utilities::trim(retval.back());
45 s_row.remove_prefix(pos);
50 s_row.remove_prefix(1);
51 if (ch_to_find ==
'"')
54 pos = s_row.find_first_of(
',');
55 if (pos == std::string_view::npos)
56 s_row = std::string_view();
58 s_row.remove_prefix(pos + 1);
67 std::string OverviewHeader::extractCiphertextBitset(std::vector<std::string_view> s_indices)
69 std::bitset<
sizeof(std::uint32_t) << 3> cipher_bits;
70 if (hebench::Utilities::ToLowerCase(s_indices.front()) ==
"none")
72 else if (hebench::Utilities::ToLowerCase(s_indices.front()) ==
"all")
76 for (std::size_t i = 0; i < s_indices.size(); ++i)
78 std::stringstream ss = std::stringstream(std::string(s_indices[i]));
82 throw std::runtime_error(
"Invalid value for encrypted parameters index. Expected an integer between 0 and " +
std::to_string(
sizeof(std::uint32_t) - 1) +
", inclussive, but read \"" + std::string(s_indices[i]) +
"\".");
83 cipher_bits.set(position);
87 std::string retval = cipher_bits.to_string();
88 hebench::Utilities::ltrim(retval,
"0");
94 void OverviewHeader::parseHeader(
const std::string &filename,
const std::string &s_header,
const std::string &s_end_state)
96 static const std::string s_trim = std::string(
",") + hebench::Utilities::BlankTrim;
98 std::stringstream ss(s_header);
100 while (std::getline(ss, s_line))
102 hebench::Utilities::trim(s_line, s_trim.c_str());
103 std::vector<std::string_view> values;
105 if (this->workload_name.empty())
107 values = extractInfoFromCSVLine(s_line,
"Workload,", 1);
108 if (values.size() > 0)
109 this->workload_name.assign(values.front().begin(), values.front().end());
111 this->end_state = s_end_state;
112 if (this->category.empty())
114 values = extractInfoFromCSVLine(s_line,
"Category,", 1);
115 if (values.size() > 0)
116 this->category.assign(values.front().begin(), values.front().end());
118 if (this->data_type.empty())
120 values = extractInfoFromCSVLine(s_line,
"Data type,", 1);
121 if (values.size() > 0)
122 this->data_type.assign(values.front().begin(), values.front().end());
124 if (this->cipher_text.empty())
126 values = extractInfoFromCSVLine(s_line,
"Encrypted op parameters (index),",
sizeof(std::uint32_t));
127 if (values.size() > 0)
128 this->cipher_text = extractCiphertextBitset(values);
130 if (this->scheme.empty())
132 values = extractInfoFromCSVLine(s_line,
"Scheme,", 1);
133 if (values.size() > 0)
134 this->scheme.assign(values.front().begin(), values.front().end());
136 if (this->security.empty())
138 values = extractInfoFromCSVLine(s_line,
"Security,", 1);
139 if (values.size() > 0)
140 this->security.assign(values.front().begin(), values.front().end());
143 values = extractInfoFromCSVLine(s_line,
"Extra,", 1);
144 if (values.size() > 0)
146 std::string s_tmp(values.front());
147 std::stringstream ss_value(s_tmp);
148 ss_value >> this->other;
150 throw std::runtime_error(
"Invalid value for \"Extra\" tag. Expected an integer, but read \"" + s_tmp +
"\".");
154 this->report_file = filename;
156 std::string_view s_view = this->report_file;
157 auto pos = s_view.find(
"wp_");
158 if (pos != std::string_view::npos)
160 s_view.remove_prefix(pos +
"wp_"sv.size());
161 pos = s_view.find_first_of(
"-/\\");
162 if (pos != std::string_view::npos)
163 s_view.remove_suffix(s_view.size() - pos);
165 auto tokens = hebench::Utilities::tokenize(s_view,
"_");
166 for (std::size_t i = 0; i < tokens.size(); ++i)
167 this->w_params.emplace_back(tokens[i].begin(), tokens[i].end());
171 void OverviewHeader::outputHeader(std::ostream &os,
bool new_line)
173 (this->workload_name.find_first_of(
',') == std::string::npos ?
174 os << this->workload_name :
175 os <<
"\"" << this->workload_name <<
"\"");
177 os <<
"\"" << this->end_state <<
"\""
179 os <<
"\"" << this->report_file <<
"\""
181 (this->category.find_first_of(
',') == std::string::npos ?
182 os << this->category :
183 os <<
"\"" << this->category <<
"\"");
185 (this->data_type.find_first_of(
',') == std::string::npos ?
186 os << this->data_type :
187 os <<
"\"" << this->data_type <<
"\"");
189 (this->cipher_text.find_first_of(
',') == std::string::npos ?
190 os << this->cipher_text :
191 os <<
"\"" << this->cipher_text <<
"\"");
193 (this->scheme.find_first_of(
',') == std::string::npos ?
195 os <<
"\"" << this->scheme <<
"\"");
197 (this->security.find_first_of(
',') == std::string::npos ?
198 os << this->security :
199 os <<
"\"" << this->security <<
"\"");
200 os <<
"," << this->other;
std::string to_string(const std::string_view &s)