|
| 1 | +# Copyright (C) 2019 Redis Labs Ltd. |
| 2 | +# |
| 3 | +# This file is part of mbdirector. |
| 4 | +# |
| 5 | +# mbdirector is free software: you can redistribute it and/or modify |
| 6 | +# it under the terms of the GNU General Public License as published by |
| 7 | +# the Free Software Foundation, version 2. |
| 8 | +# |
| 9 | +# mbdirector is distributed in the hope that it will be useful, |
| 10 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | +# GNU General Public License for more details. |
| 13 | +# |
| 14 | +# You should have received a copy of the GNU General Public License |
| 15 | +# along with memtier_benchmark. If not, see <http://www.gnu.org/licenses/>. |
| 16 | + |
1 | 17 | import os.path
|
2 | 18 | import json
|
3 | 19 |
|
4 | 20 | from flask import (Flask, render_template, send_file, abort, Response,
|
5 | 21 | send_from_directory)
|
6 | 22 | from werkzeug.serving import run_simple
|
7 | 23 |
|
| 24 | + |
8 | 25 | class Config(object):
|
9 | 26 | RESULTS_BASEDIR = 'results'
|
10 | 27 |
|
| 28 | + |
11 | 29 | app = Flask(__name__)
|
12 | 30 | app.config.from_object('mbdirector.serve.Config')
|
13 | 31 |
|
| 32 | + |
14 | 33 | class BenchmarkResults(object):
|
15 | 34 | def __init__(self, dirname):
|
16 | 35 | self.dirname = dirname
|
@@ -41,6 +60,7 @@ def files(self):
|
41 | 60 | if os.path.exists(os.path.join(self.dirname, f))]
|
42 | 61 | return result
|
43 | 62 |
|
| 63 | + |
44 | 64 | class RunResults(object):
|
45 | 65 | OK = 'ok'
|
46 | 66 | NOTFOUND = 'results-not-found'
|
@@ -130,36 +150,42 @@ def get_run_results():
|
130 | 150 |
|
131 | 151 | return [RunResults(d) for d in sorted(dirs)]
|
132 | 152 |
|
| 153 | + |
133 | 154 | @app.route('/')
|
134 | 155 | def index():
|
135 | 156 | return render_template('index.html', results=get_run_results())
|
136 | 157 |
|
| 158 | + |
137 | 159 | @app.route('/run/<run>')
|
138 | 160 | def get_run(run):
|
139 | 161 | return render_template('run.html', run=RunResults(run))
|
140 | 162 |
|
| 163 | + |
141 | 164 | @app.route('/run/<run>/spec')
|
142 | 165 | def get_run_spec(run):
|
143 | 166 | specfile = open(os.path.join(
|
144 | 167 | app.config['RESULTS_BASEDIR'], run, 'spec.json'), 'r')
|
145 | 168 | return send_file(specfile, mimetype='text/plain')
|
146 | 169 |
|
| 170 | + |
147 | 171 | @app.route('/run/<run>/<benchmark>/json')
|
148 | 172 | def get_benchmark_json(run, benchmark):
|
149 | 173 | run = RunResults(run)
|
150 |
| - if not benchmark in run.benchmarks: |
| 174 | + if benchmark not in run.benchmarks: |
151 | 175 | abort(404)
|
152 | 176 | return Response(run.benchmarks[benchmark].print_json(),
|
153 | 177 | mimetype='text/plan')
|
154 | 178 |
|
| 179 | + |
155 | 180 | @app.route('/run/<run>/<benchmark>/file/<filename>')
|
156 | 181 | def get_benchmark_file(run, benchmark, filename):
|
157 | 182 | run = RunResults(run)
|
158 |
| - if not benchmark in run.benchmarks: |
| 183 | + if benchmark not in run.benchmarks: |
159 | 184 | abort(404)
|
160 | 185 | return send_from_directory(
|
161 | 186 | os.path.abspath(run.benchmarks[benchmark].dirname),
|
162 | 187 | filename, mimetype='text/plan')
|
163 | 188 |
|
| 189 | + |
164 | 190 | def run_webserver(bind, port):
|
165 | 191 | run_simple(bind, port, app)
|
0 commit comments