Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1832 Displaying locustfile and tasks ratio information on index.html #1868

Merged
merged 2 commits into from
Sep 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ docs/_build/**
docs/cli-help-output.txt
docs/config-options.rst
mock.*.egg
web_test_*.csv
.eggs/
dist/**
.idea/**
*.iml
Expand Down
2 changes: 2 additions & 0 deletions locust/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def __init__(
user_classes=None,
shape_class=None,
tags=None,
locustfile=None,
exclude_tags=None,
events=None,
host=None,
Expand All @@ -93,6 +94,7 @@ def __init__(
else:
self.events = Events()

self.locustfile = locustfile
self.user_classes = user_classes or []
self.shape_class = shape_class
self.tags = tags
Expand Down
12 changes: 11 additions & 1 deletion locust/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import datetime
from itertools import chain
from .stats import sort_stats
from .user.inspectuser import get_task_ratio_dict
from html import escape
from json import dumps


def render_template(file, **kwargs):
Expand Down Expand Up @@ -42,7 +45,7 @@ def get_html_report(environment, show_download_link=True):
history = stats.history

static_js = []
js_files = ["jquery-1.11.3.min.js", "echarts.common.min.js", "vintage.js", "chart.js"]
js_files = ["jquery-1.11.3.min.js", "echarts.common.min.js", "vintage.js", "chart.js", "tasks.js"]
for js_file in js_files:
path = os.path.join(os.path.dirname(__file__), "static", js_file)
static_js.append("// " + js_file)
Expand All @@ -59,6 +62,11 @@ def get_html_report(environment, show_download_link=True):
static_css.append(f.read())
static_css.extend(["", ""])

task_data = {
"per_class": get_task_ratio_dict(environment.user_classes),
"total": get_task_ratio_dict(environment.user_classes, total=True),
}

res = render_template(
"report.html",
int=int,
Expand All @@ -73,6 +81,8 @@ def get_html_report(environment, show_download_link=True):
static_js="\n".join(static_js),
static_css="\n".join(static_css),
show_download_link=show_download_link,
locustfile=environment.locustfile,
tasks=escape(dumps(task_data)),
)

return res
10 changes: 6 additions & 4 deletions locust/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from .shape import LoadTestShape
from .input_events import input_listener
from .html import get_html_report

from json import dumps

version = locust.__version__

Expand Down Expand Up @@ -99,11 +99,12 @@ def load_locustfile(path):
return imported.__doc__, user_classes, shape_class


def create_environment(user_classes, options, events=None, shape_class=None):
def create_environment(user_classes, options, events=None, shape_class=None, locustfile=None):
"""
Create an Environment instance from options
"""
return Environment(
locustfile=locustfile,
user_classes=user_classes,
shape_class=shape_class,
tags=options.tags,
Expand Down Expand Up @@ -204,7 +205,9 @@ def main():
)

# create locust Environment
environment = create_environment(user_classes, options, events=locust.events, shape_class=shape_class)
environment = create_environment(
user_classes, options, events=locust.events, shape_class=shape_class, locustfile=os.path.basename(locustfile)
)

if shape_class and (options.num_users or options.spawn_rate):
logger.warning(
Expand All @@ -220,7 +223,6 @@ def main():
print_task_ratio(user_classes, total=True)
sys.exit(0)
if options.show_task_ratio_json:
from json import dumps

task_data = {
"per_class": get_task_ratio_dict(user_classes),
Expand Down
Loading