aboutsummaryrefslogtreecommitdiffstats
path: root/yardstick/benchmark
diff options
context:
space:
mode:
authorrajesh_4k <4k.rajesh@gmail.com>2017-02-27 18:09:00 +0530
committerJing Lu <lvjing5@huawei.com>2017-03-30 09:46:32 +0000
commit06c0f074a136414d1e9704aa4e30c62e50f2d5ce (patch)
treeca1db646cb02b0b7c9b29ac8cd1c282f94e29fc3 /yardstick/benchmark
parentaa499064bf305e41a56a2f86d17c1cc29a1d7b0c (diff)
Yardstick: User interface for Yardstick.
Currently Yardstick doesnt have any UI which gives detail analysis of the test-results. This commit generates a HTML page after the execution of a command "yardstick report generate <task-ID> <TC-name>" which intern can be executed after the execution of test-case. Used: Highcharts.js for the graphs. JIRA: YARDSTICK-280 Change-Id: Ic98cc348719f3922bff178f52e7944a4a931763a Signed-off-by: Rajesh K <4k.rajesh@gmail.com> (cherry picked from commit 25b21add71fcf7c2c795bd950b5117d69fac68fb)
Diffstat (limited to 'yardstick/benchmark')
-rw-r--r--yardstick/benchmark/core/__init__.py2
-rw-r--r--yardstick/benchmark/core/report.py126
-rw-r--r--yardstick/benchmark/core/task.py4
3 files changed, 132 insertions, 0 deletions
diff --git a/yardstick/benchmark/core/__init__.py b/yardstick/benchmark/core/__init__.py
index 79ebc732f..70036ea1e 100644
--- a/yardstick/benchmark/core/__init__.py
+++ b/yardstick/benchmark/core/__init__.py
@@ -20,6 +20,8 @@ class Param(object):
self.parse_only = kwargs.get('parse-only')
self.output_file = kwargs.get('output-file', '/tmp/yardstick.out')
self.suite = kwargs.get('suite')
+ self.task_id = kwargs.get('task_id')
+ self.yaml_name = kwargs.get('yaml_name')
# list
self.input_file = kwargs.get('input_file')
diff --git a/yardstick/benchmark/core/report.py b/yardstick/benchmark/core/report.py
new file mode 100644
index 000000000..997a125e7
--- /dev/null
+++ b/yardstick/benchmark/core/report.py
@@ -0,0 +1,126 @@
+#############################################################################
+# Copyright (c) 2017 Rajesh Kudaka
+#
+# Author: Rajesh Kudaka 4k.rajesh@gmail.com
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+""" Handler for yardstick command 'report' """
+
+from __future__ import print_function
+
+from __future__ import absolute_import
+
+import ast
+import re
+import uuid
+
+from api.utils import influx
+
+from django.conf import settings
+from django.template import Context
+from django.template import Template
+
+from oslo_utils import encodeutils
+from oslo_utils import uuidutils
+from yardstick.common import constants as consts
+from yardstick.common.html_template import template
+from yardstick.common.utils import cliargs
+
+settings.configure()
+
+
+class Report(object):
+ """Report commands.
+
+ Set of commands to manage benchmark tasks.
+ """
+
+ def __init__(self):
+ self.Timestamp = []
+ self.yaml_name = ""
+ self.task_id = ""
+
+ def _validate(self, yaml_name, task_id):
+ if re.match("^[a-z0-9_-]+$", yaml_name):
+ self.yaml_name = yaml_name
+ else:
+ raise ValueError("invalid yaml_name", yaml_name)
+
+ if uuidutils.is_uuid_like(task_id):
+ task_id = '{' + task_id + '}'
+ task_uuid = (uuid.UUID(task_id))
+ self.task_id = task_uuid
+ else:
+ raise ValueError("invalid task_id", task_id)
+
+ def _get_fieldkeys(self):
+ fieldkeys_cmd = "show field keys from \"%s\""
+ fieldkeys_query = fieldkeys_cmd % (self.yaml_name)
+ query_exec = influx.query(fieldkeys_query)
+ if query_exec:
+ return query_exec
+ else:
+ raise KeyError("Task ID or Test case not found..")
+
+ def _get_tasks(self):
+ task_cmd = "select * from \"%s\" where task_id= '%s'"
+ task_query = task_cmd % (self.yaml_name, self.task_id)
+ query_exec = influx.query(task_query)
+ if query_exec:
+ return query_exec
+ else:
+ raise KeyError("Task ID or Test case not found..")
+
+ @cliargs("task_id", type=str, help=" task id", nargs=1)
+ @cliargs("yaml_name", type=str, help=" Yaml file Name", nargs=1)
+ def generate(self, args):
+ """Start report generation."""
+ self._validate(args.yaml_name[0], args.task_id[0])
+
+ self.db_fieldkeys = self._get_fieldkeys()
+
+ self.db_task = self._get_tasks()
+
+ field_keys = []
+ temp_series = []
+ table_vals = {}
+
+ field_keys = [encodeutils.to_utf8(field['fieldKey'])
+ for field in self.db_fieldkeys]
+
+ for key in field_keys:
+ self.Timestamp = []
+ series = {}
+ values = []
+ for task in self.db_task:
+ task_time = encodeutils.to_utf8(task['time'])
+ if not isinstance(task_time, str):
+ task_time = str(task_time, 'utf8')
+ key = str(key, 'utf8')
+ task_time = task_time[11:]
+ head, sep, tail = task_time.partition('.')
+ task_time = head + "." + tail[:6]
+ self.Timestamp.append(task_time)
+ if isinstance(task[key], float) is True:
+ values.append(task[key])
+ else:
+ values.append(ast.literal_eval(task[key]))
+ table_vals['Timestamp'] = self.Timestamp
+ table_vals[key] = values
+ series['name'] = key
+ series['data'] = values
+ temp_series.append(series)
+
+ Template_html = Template(template)
+ Context_html = Context({"series": temp_series,
+ "Timestamp": self.Timestamp,
+ "task_id": self.task_id,
+ "table": table_vals})
+ with open(consts.DEFAULT_HTML_FILE, "w") as file_open:
+ file_open.write(Template_html.render(Context_html))
+
+ print("Report generated. View /tmp/yardstick.htm")
diff --git a/yardstick/benchmark/core/task.py b/yardstick/benchmark/core/task.py
index 47315b587..40122764c 100644
--- a/yardstick/benchmark/core/task.py
+++ b/yardstick/benchmark/core/task.py
@@ -107,6 +107,10 @@ class Task(object): # pragma: no cover
LOG.info("total finished in %d secs",
total_end_time - total_start_time)
+ scenario = scenarios[0]
+ print("To generate report execute => yardstick report generate ",
+ scenario['task_id'], scenario['tc'])
+
print("Done, exiting")
def _run(self, scenarios, run_in_parallel, output_file):