]> git.ipfire.org Git - thirdparty/vectorscan.git/commitdiff
hsbench: add CSV dump support
authorWang Xiang W <xiang.w.wang@intel.com>
Thu, 30 Apr 2020 11:37:55 +0000 (07:37 -0400)
committerKonstantinos Margaritis <markos@users.noreply.github.com>
Mon, 25 Jan 2021 12:13:13 +0000 (14:13 +0200)
tools/hsbench/engine.h
tools/hsbench/engine_chimera.cpp
tools/hsbench/engine_chimera.h
tools/hsbench/engine_hyperscan.cpp
tools/hsbench/engine_hyperscan.h
tools/hsbench/engine_pcre.cpp
tools/hsbench/engine_pcre.h
tools/hsbench/main.cpp

index e41f9948c25f8fb3b3124e36b8428cd5cd88b83a..aea1c816256665db10a24888153d373f6dd078fd 100644 (file)
@@ -88,6 +88,8 @@ public:
 
     virtual void printStats() const = 0;
 
+    virtual void printCsvStats() const = 0;
+
     virtual void sqlStats(SqlDB &db) const = 0;
 };
 
index 8a15c5bee2480442a1d14d0c2496e1c06cbbbadc..24a99d61f507b72e7580b17df649eb3be6532a2d 100644 (file)
@@ -187,6 +187,16 @@ void EngineChimera::printStats() const {
 #endif
 }
 
+void EngineChimera::printCsvStats() const {
+    printf(",\"%s\"", compile_stats.signatures.c_str());
+    printf(",\"%zu\"", compile_stats.expressionCount);
+    printf(",\"0x%x\"", compile_stats.crc32);
+    printf(",\"%zu\"", compile_stats.compiledSize);
+    printf(",\"%zu\"", compile_stats.scratchSize);
+    printf(",\"%0.3Lf\"", compile_stats.compileSecs);
+    printf(",\"%u\"", compile_stats.peakMemorySize);
+}
+
 void EngineChimera::sqlStats(SqlDB &sqldb) const {
     ostringstream crc;
     crc << "0x" << hex << compile_stats.crc32;
index 8e2cd0f6ca3ea38492d5d6b4069d1a6b298cc51f..187dec8cbd47cfa3c5902d6026f3fa4443223949 100644 (file)
@@ -89,6 +89,8 @@ public:
 
     void printStats() const;
 
+    void printCsvStats() const;
+
     void sqlStats(SqlDB &db) const;
 
 private:
index 79c58f77dc4b7baeccf0c894a041bfb0f948bf8e..c94b42af73334b3d2cc48d047fb7adfc35bf9600 100644 (file)
@@ -276,6 +276,17 @@ void EngineHyperscan::printStats() const {
 #endif
 }
 
+void EngineHyperscan::printCsvStats() const {
+    printf(",\"%s\"", compile_stats.signatures.c_str());
+    printf(",\"%zu\"", compile_stats.expressionCount);
+    printf(",\"0x%x\"", compile_stats.crc32);
+    printf(",\"%zu\"", compile_stats.compiledSize);
+    printf(",\"%zu\"", compile_stats.streamSize);
+    printf(",\"%zu\"", compile_stats.scratchSize);
+    printf(",\"%0.3Lf\"", compile_stats.compileSecs);
+    printf(",\"%u\"", compile_stats.peakMemorySize);
+}
+
 void EngineHyperscan::sqlStats(SqlDB &sqldb) const {
     ostringstream crc;
     crc << "0x" << hex << compile_stats.crc32;
index a8105d753a675c4b2d92f79ac4d28aad42f8282d..253ec9aaaecefd851688ca9c65829ebfe04033d5 100644 (file)
@@ -98,6 +98,8 @@ public:
 
     void printStats() const;
 
+    void printCsvStats() const;
+
     void sqlStats(SqlDB &db) const;
 
 private:
index 85616e987aa8b52a662bcaf132955f7d03f75c83..23ab9d176c033a666a7653d09b4bbf1d9feaa645 100644 (file)
@@ -227,6 +227,15 @@ void EnginePCRE::printStats() const {
 #endif
 }
 
+void EnginePCRE::printCsvStats() const {
+    printf(",\"%s\"", compile_stats.signatures.c_str());
+    printf(",\"%zu\"", compile_stats.expressionCount);
+    printf(",\"%zu\"", compile_stats.compiledSize);
+    printf(",\"%zu\"", compile_stats.scratchSize);
+    printf(",\"%0.3Lf\"", compile_stats.compileSecs);
+    printf(",\"%u\"", compile_stats.peakMemorySize);
+}
+
 void EnginePCRE::sqlStats(SqlDB &sqldb) const {
     ostringstream crc;
 
index 2e7dad9c54465c13f37b0fb09af2a9deca706a80..d121581f44692c98115d97e0db0be12665c001e2 100644 (file)
@@ -97,6 +97,8 @@ public:
 
     void printStats() const;
 
+    void printCsvStats() const;
+
     void sqlStats(SqlDB &db) const;
 
 private:
index 4e65c8e0bc6a02bc63426318246d44802b664e09..3349ecc81a54d5a263f5064f931b51cea6d31861 100644 (file)
@@ -98,6 +98,7 @@ bool display_per_scan = false;
 ScanMode scan_mode = ScanMode::STREAMING;
 bool useHybrid = false;
 bool usePcre = false;
+bool dumpCsvOut = false;
 unsigned repeats = 20;
 string exprPath("");
 string corpusFile("");
@@ -211,6 +212,7 @@ void usage(const char *error) {
     printf("                  Benchmark with threads on specified CPUs or CPU"
            " range.\n");
 #endif
+    printf("  -C              Dump CSV output for tput matrix.\n");
     printf("  -i DIR          Don't compile, load from files in DIR"
            " instead.\n");
     printf("  -w DIR          After compiling, save to files in DIR.\n");
@@ -275,6 +277,9 @@ void processArgs(int argc, char *argv[], vector<BenchmarkSigs> &sigSets,
         case 'c':
             corpusFile.assign(optarg);
             break;
+        case 'C':
+            dumpCsvOut = true;
+            break;
         case 'd': {
             unsigned dist;
             if (!fromString(optarg, dist)) {
@@ -849,6 +854,39 @@ void displayResults(const vector<unique_ptr<ThreadContext>> &threads,
     }
 }
 
+/** Dump benchmark results to csv. */
+static
+void displayCsvResults(const vector<unique_ptr<ThreadContext>> &threads,
+                       const vector<DataBlock> &corpus_blocks) {
+    u64a bytesPerRun = byte_size(corpus_blocks);
+    u64a matchesPerRun = threads[0]->results[0].matches;
+
+    // Sanity check: all of our results should have the same match count.
+    for (const auto &t : threads) {
+        if (!all_of(begin(t->results), end(t->results),
+                    [&matchesPerRun](const ResultEntry &e) {
+                        return e.matches == matchesPerRun;
+                    })) {
+            printf("\nWARNING: PER-SCAN MATCH COUNTS ARE INCONSISTENT!\n\n");
+            break;
+        }
+    }
+
+    u64a totalBytes = bytesPerRun * repeats * threads.size();
+    u64a totalBlocks = corpus_blocks.size() * repeats * threads.size();
+    printf(",\"%0.3f\"", totalSecs);
+    printf(",\"%0.2Lf\"", calc_mbps(totalSecs, totalBytes));
+
+    double matchRate = ((double)matchesPerRun * 1024) / bytesPerRun;
+    printf(",\"%llu\"", matchesPerRun);
+    printf(",\"%0.3f\"", matchRate);
+
+    double blockRate = (double)totalBlocks / (double)totalSecs;
+    printf(",\"%0.2f\"", blockRate);
+    printf("\n");
+}
+
+
 /** Dump per-scan throughput data to sql. */
 static
 void sqlPerScanResults(const vector<unique_ptr<ThreadContext>> &threads,
@@ -982,7 +1020,9 @@ void runBenchmark(const Engine &db,
         t->join();
     }
 
-    if (sqloutFile.empty()) {
+    if (dumpCsvOut) {
+        displayCsvResults(threads, corpus_blocks);
+    } else if (sqloutFile.empty()) {
         // Display global results.
         displayResults(threads, corpus_blocks);
     } else {
@@ -1059,7 +1099,9 @@ int HS_CDECL main(int argc, char *argv[]) {
                 exit(1);
             }
 
-            if (sqloutFile.empty()) {
+            if (dumpCsvOut) {
+                engine->printCsvStats();
+            } else if (sqloutFile.empty()) {
                 // Display global results.
                 engine->printStats();
                 printf("\n");