MCPcopy Create free account
hub / github.com/Compaile/ctrack / parse_function_timing

Function parse_function_timing

benchmark/ctrack_benchmark.cpp:196–267  ·  view source on GitHub ↗

Parse timing from CTRACK results string for a specific function

Source from the content-addressed store, hash-verified

194
195// Parse timing from CTRACK results string for a specific function
196double parse_function_timing(const std::string &results, const std::string &function_name)
197{
198 // Look for the Details section first
199 size_t details_pos = results.find("Details");
200 if (details_pos == std::string::npos)
201 {
202 return -1.0; // Details section not found
203 }
204
205 // Look for the function name after the Details section
206 size_t func_pos = results.find(function_name, details_pos);
207 if (func_pos == std::string::npos)
208 {
209 return -1.0; // Function not found in Details section
210 }
211
212 // Find the line containing this function in the Details section
213 size_t line_start = results.rfind('\n', func_pos);
214 if (line_start == std::string::npos)
215 line_start = details_pos;
216 else
217 line_start++; // Skip the newline
218
219 size_t line_end = results.find('\n', func_pos);
220 if (line_end == std::string::npos)
221 line_end = results.length();
222
223 std::string line = results.substr(line_start, line_end - line_start);
224
225 // Look for the "time acc" column value (4th column after filename, function, line)
226 // Split by | and find the 4th field
227 std::vector<std::string> fields;
228 std::istringstream iss(line);
229 std::string field;
230
231 while (std::getline(iss, field, '|'))
232 {
233 // Trim whitespace
234 field.erase(0, field.find_first_not_of(" \t"));
235 field.erase(field.find_last_not_of(" \t") + 1);
236 if (!field.empty())
237 {
238 fields.push_back(field);
239 }
240 }
241
242 // The time acc should be in the 4th field (0-indexed: filename=0, function=1, line=2, time_acc=3)
243 if (fields.size() > 3)
244 {
245 std::string time_acc = fields[3];
246
247 // Parse value and unit from time_acc (e.g., "2.09 ms")
248 std::istringstream time_iss(time_acc);
249 double value;
250 std::string unit;
251
252 if (time_iss >> value >> unit)
253 {

Callers 1

measure_accuracyFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected