Set cwd when running pgbench
authorMark Wong <mark@2ndQuadrant.com>
Tue, 9 Jan 2018 17:15:08 +0000 (09:15 -0800)
committerMark Wong <mark@2ndQuadrant.com>
Tue, 30 Jan 2018 22:22:33 +0000 (14:22 -0800)
The output directory is used for the cwd when executing pgbench so that
the output files are saved in the results directory.

client/benchmarks/pgbench.py
client/perffarm-client.py

index bd6a0e68db33d8f4981aa27f4f9ebad5fb76c80f..d11d23c51259d9309897038d8985212796d49e4c 100644 (file)
@@ -16,19 +16,22 @@ class PgBench(object):
     #      read-write/read-only tests
     # TODO allow running 'prepared' mode
 
-    def __init__(self, bin_path, dbname, runs=3, duration=60, csv=False):
+    def __init__(self, bin_path, dbname, runs=3, duration=60, csv=False,
+                 results_dir=None):
         '''
         bin_path   - path to PostgreSQL binaries (dropdb, createdb, psql
                      commands)
         dbname     - name of the database to use
-        runs       - number of runs (for each client count)
         duration   - duration of each execution
+        runs       - number of runs (for each client count)
+        out_dir    - output directory
         '''
 
         self._bin = bin_path
         self._csv = csv
         self._dbname = dbname
         self._duration = duration
+        self._outdir = results_dir
         self._runs = runs
 
         self._env = os.environ
@@ -66,7 +69,7 @@ class PgBench(object):
 
         log("initializing pgbench '%s' with scale %s" % (self._dbname, scale))
         r = run_cmd(['pgbench', '-i', '-s', str(scale), self._dbname],
-                    env=self._env)
+                    env=self._env, cwd=self._outdir)
 
         # remember the init duration
         self._results[scale]['init'] = r[2]
@@ -171,7 +174,7 @@ class PgBench(object):
             "duration=%d" % (nclients, njobs, aggregate, read_only, duration))
 
         start = time.time()
-        r = run_cmd(args, env=self._env)
+        r = run_cmd(args, env=self._env, cwd=self._outdir)
         end = time.time()
 
         r = PgBench._parse_results(r[1])
index 49a73aa519b669a4e245254a26d6d8e15a327b55..b04138dca09755586095513e4a3490233a040c20 100755 (executable)
@@ -52,6 +52,7 @@ if __name__ == '__main__':
         # register one config for each benchmark (should be moved to a config
         # file)
 
+        PGBENCH_CONFIG['results_dir'] = OUTPUT_DIR
         runner.register_config('pgbench-basic',
                                'pgbench',
                                dbname=DATABASE_NAME,