From e4e89fe27a37a1abf70387d07adfb3b1b9f115ef Mon Sep 17 00:00:00 2001 From: John Keiser Date: Fri, 13 Mar 2020 13:19:21 -0700 Subject: [PATCH] Fix parse benchmarker (#554) * Fix parse benchmarker * Make CI fail when parse doesn't work --- benchmark/benchmarker.h | 6 +++--- benchmark/perfdiff.cpp | 17 ++++++++++++++++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/benchmark/benchmarker.h b/benchmark/benchmarker.h index 1899358c..609d30b7 100644 --- a/benchmark/benchmarker.h +++ b/benchmark/benchmarker.h @@ -298,7 +298,7 @@ struct benchmarker { // Allocate document::parser collector.start(); document::parser parser; - error_code error = parser.set_capacity(json.size()); + bool alloc_ok = parser.allocate_capacity(json.size()); event_count allocate_count = collector.end(); allocate_stage << allocate_count; // Run it once to get hot buffers @@ -309,14 +309,14 @@ struct benchmarker { } } - if (error) { + if (!alloc_ok) { exit_error(string("Unable to allocate_stage ") + to_string(json.size()) + " bytes for the JSON result."); } verbose() << "[verbose] allocated memory for parsed JSON " << endl; // Stage 1 (find structurals) collector.start(); - error = active_implementation->stage1((const uint8_t *)json.data(), json.size(), parser, false); + error_code error = active_implementation->stage1((const uint8_t *)json.data(), json.size(), parser, false); event_count stage1_count = collector.end(); stage1 << stage1_count; if (error) { diff --git a/benchmark/perfdiff.cpp b/benchmark/perfdiff.cpp index 2842dfa3..63a010b8 100644 --- a/benchmark/perfdiff.cpp +++ b/benchmark/perfdiff.cpp @@ -7,16 +7,27 @@ #include #include #include +#include #ifdef _WIN32 #define popen _popen #define pclose _pclose #endif +int closepipe(FILE *pipe) { + int exit_code = pclose(pipe); + if (exit_code != EXIT_SUCCESS) { + std::cerr << "Error " << exit_code << " running benchmark command!" << std::endl; + exit(EXIT_FAILURE); + }; + return exit_code; +} + std::string exec(const char* cmd) { + std::cerr << cmd << std::endl; std::array buffer; std::string result; - std::unique_ptr pipe(popen(cmd, "r"), pclose); + std::unique_ptr pipe(popen(cmd, "r"), closepipe); if (!pipe) { throw std::runtime_error("popen() failed!"); } @@ -43,6 +54,10 @@ double readThroughput(std::string parseOutput) { result += std::stod(line.substr(pos)); numResults++; } + if (numResults == 0) { + std::cerr << "No results returned from benchmark command!" << std::endl; + exit(EXIT_FAILURE); + } return result / numResults; }