add support for collecting results into simple CSV file
authorTomas Vondra <tomas@2ndquadrant.com>
Thu, 13 Oct 2016 12:48:03 +0000 (14:48 +0200)
committerTomas Vondra <tomas@2ndquadrant.com>
Mon, 27 Feb 2017 00:32:51 +0000 (01:32 +0100)
Originally the results were collected into a JSON format, which is
not very convenient when running ad-hoc benchmarks.

client/benchmarks/runner.py

index b6ef293a40537d2aa41967a4c7d884a48abe1742..1a420fe5e5c97d2e3dd54cd989d700654ba5e486 100644 (file)
@@ -2,7 +2,7 @@ import json
 import os
 
 from utils.logging import log
-
+from multiprocessing import Process, Queue
 
 class BenchmarkRunner(object):
        'manages runs of all the benchmarks, including cluster restarts etc.'
@@ -81,10 +81,24 @@ class BenchmarkRunner(object):
                # start collector(s) of additional info
                self._collector.start()
 
+               # if requested output to CSV, create a queue and collector process
+               csv_queue = None
+               csv_collector = None
+               if config['benchmark']['csv']:
+                       csv_queue = Queue()
+                       csv_collector = Process(target=csv_collect_results, args=(config_name, csv_queue))
+                       csv_collector.start()
+
                # run the tests
-               r = bench.run_tests()
+               r = bench.run_tests(csv_queue)
+
+               # notify the result collector to end and wait for it to terminate
+               if csv_queue:
+                       csv_queue.put("STOP")
+                       csv_collector.join()
 
                # stop the cluster and collector
+               log("terminating collectors")
                self._collector.stop()
                self._cluster.stop()
 
@@ -111,3 +125,26 @@ class BenchmarkRunner(object):
 
                for config_name in self._configs:
                        self._run_config(config_name)
+
+
+def csv_collect_results(bench_name, queue):
+       'collect results into a CSV files (through a queue)'
+
+       with open("%s.csv" % (bench_name,), 'w') as results_file:
+
+               # collect data from the queue - once we get a plain string (instead of
+               # a list), it's a sign to terminate the collector
+               while True:
+
+                       v = queue.get()
+
+                       # if we got a string, it means 'terminate'
+                       if isinstance(v, str):
+                               log("terminating CSV result collector")
+                               return
+
+                       v = [str(x) for x in v]
+
+                       # otherwise we expect the value to be a list, and we just print it
+                       results_file.write(bench_name + "\t" + "\t".join(v) + "\n")
+                       results_file.flush()