setup_postgres.py 1.1 KB

123456789101112131415161718192021222324252627
  1. import subprocess
  2. import os
  3. import setup_util
  4. def start(args, logfile, errfile, cwd='wt'):
  5. setup_util.replace_text("wt/benchmark.cpp", "INSERT_DB_HOST_HERE", args.database_host);
  6. subprocess.check_call('g++ -O3 -DNDEBUG -DBENCHMARK_USE_POSTGRES -std=c++0x -L/usr/local/lib -I/usr/local/include -o benchmark_postgres.wt benchmark.cpp -lwt -lwthttp -lwtdbo -lwtdbopostgres -lboost_thread', shell=True, cwd=cwd, stderr=errfile, stdout=logfile)
  7. os.environ['LD_LIBRARY_PATH'] = '/usr/local/lib:' + os.environ.get('LD_LIBRARY_PATH', '.')
  8. subprocess.Popen(['./benchmark_postgres.wt',
  9. '-c', 'wt_config.xml',
  10. '-t', str(args.max_threads * 4),
  11. '--docroot', '.',
  12. '--http-address', '0.0.0.0',
  13. '--http-port', '8080',
  14. '--accesslog=-',
  15. '--no-compression'],
  16. cwd=cwd, stderr=errfile, stdout=logfile)
  17. return 0
  18. def stop(logfile, errfile):
  19. p = subprocess.Popen(['ps', 'aux'], stdout=subprocess.PIPE)
  20. out, err = p.communicate()
  21. for line in out.splitlines():
  22. if 'benchmark_postgres.wt' in line:
  23. pid = int(line.split(None, 2)[1])
  24. os.kill(pid, 15)
  25. return 0