Add tool for generating line graphs of test run times

This commit adds a simple utility for generating graphs of an
individual tests run time over the entire set of test_runs. I imagine
this command will grow over time to generate other graphs, but for
right now it only does the one type.

Change-Id: I9ba442e83aeeac1ab9aad4b3e24ad09fd1e0f805
This commit is contained in:
Matthew Treinish 2014-12-17 21:29:33 -05:00
parent b8671a116c
commit 3036d15bf7
4 changed files with 76 additions and 0 deletions

View File

@ -5,3 +5,4 @@ pbr>=0.6,<1.0
python-subunit>=0.0.18
six>=1.5.2
SQLAlchemy>=0.7.8
pandas

View File

@ -28,6 +28,7 @@ console_scripts =
subunit2sql = subunit2sql.shell:main
sql2subunit = subunit2sql.write_subunit:main
subunit2sql-db-manage = subunit2sql.migrations.cli:main
subunit2sql-graph = subunit2sql.analysis.run_time:main
oslo.config.opts =
subunit2sql.shell = subunit2sql.shell:list_opts
subunit2sql.write_subunit = subunit2sql.write_subunit:list_opts

View File

View File

@ -0,0 +1,74 @@
#!/bin/env python2
# Copyright 2014 Hewlett-Packard Development Company, L.P.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import copy
import sys
from oslo.config import cfg
import pandas as pd
from subunit2sql.db import api
from subunit2sql import shell
CONF = cfg.CONF
SHELL_OPTS = [
cfg.StrOpt('test_id', positional=True, required=True,
help='Test id to extract time series for'),
cfg.StrOpt('title', short='t', help='Optional title to use for the graph '
'output. If one is not specified, the '
'full test_id will be used'),
cfg.StrOpt('output', short='o', required=True,
help='Output path to write image file to. The file extension '
'will determine the file format.')
]
def cli_opts():
for opt in SHELL_OPTS:
CONF.register_cli_opt(opt)
def list_opts():
opt_list = copy.deepcopy(SHELL_OPTS)
return [('DEFAULT', opt_list)]
def generate_series(test_id):
session = api.get_session()
run_times = api.get_test_run_time_series(test_id, session)
if not CONF.title:
test = api.get_test_by_id(test_id, session)
session.close()
ts = pd.Series(run_times)
if not CONF.title:
plot = ts.plot().set_title(test.test_id)
else:
plot = ts.plot().set_title(CONF.title)
plot = pd.rolling_mean(ts, 50).plot()
fig = plot.get_figure()
plot.set_ylabel('Time (sec.)')
fig.savefig(CONF.output)
return ts
def main():
cli_opts()
shell.parse_args(sys.argv)
generate_series(CONF.test_id)
print('Graph saved at: %s' % CONF.output)
if __name__ == "__main__":
sys.exit(main())