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

Move dividers (pipe characters) in stats command line output. Also shrink percentiles output and remove 99.999 percentile by default Fixes #1514 #1525

Merged
merged 4 commits into from
Aug 18, 2020
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
22 changes: 11 additions & 11 deletions locust/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
console_logger = logging.getLogger("locust.stats_logger")

STATS_NAME_WIDTH = 60
STATS_TYPE_WIDTH = 20
STATS_TYPE_WIDTH = 8

"""Default interval for how frequently the CSV file is written if this option
is configured."""
Expand Down Expand Up @@ -42,7 +42,6 @@
0.99,
0.999,
0.9999,
0.99999,
1.0
]

Expand Down Expand Up @@ -512,7 +511,7 @@ def to_string(self, current=True):
else:
rps = self.total_rps
fail_per_sec = self.total_fail_per_sec
return (" %-" + str(STATS_NAME_WIDTH) + "s %7d %12s %7d %7d %7d | %7d %7.2f %7.2f") % (
return (" %-" + str(STATS_NAME_WIDTH) + "s %7d %12s | %7d %7d %7d %7d | %7.2f %7.2f") % (
(self.method and self.method + " " or "") + self.name,
self.num_requests,
"%d(%.2f%%)" % (self.num_failures, self.fail_ratio * 100),
Expand Down Expand Up @@ -579,10 +578,11 @@ def percentile(self):
if not self.num_requests:
raise ValueError("Can't calculate percentile on url with no successful requests")

tpl = f" %-{str(STATS_TYPE_WIDTH)}s %-{str(STATS_NAME_WIDTH)}s %8d {' '.join(['%7d'] * len(PERCENTILES_TO_REPORT))}"
tpl = f" %-{str(STATS_TYPE_WIDTH)}s %-{str(STATS_NAME_WIDTH)}s %8d {' '.join(['%6d'] * len(PERCENTILES_TO_REPORT))}"

return tpl % ((self.method, self.name, self.num_requests)
+ tuple([self.get_response_time_percentile(p) for p in PERCENTILES_TO_REPORT]))
return tpl % ((self.method, self.name)
+ tuple([self.get_response_time_percentile(p) for p in PERCENTILES_TO_REPORT])
+ (self.num_requests,))

def _cache_response_times(self, t):
self.response_times_cache[t] = CachedResponseTimes(
Expand Down Expand Up @@ -697,7 +697,7 @@ def on_worker_report(client_id, data):


def print_stats(stats, current=True):
console_logger.info((" %-" + str(STATS_NAME_WIDTH) + "s %7s %12s %7s %7s %7s | %7s %7s %7s") % ('Name', '# reqs', '# fails', 'Avg', 'Min', 'Max', 'Median', 'req/s', 'failures/s'))
console_logger.info((" %-" + str(STATS_NAME_WIDTH) + "s %7s %12s | %7s %7s %7s %7s | %7s %7s") % ('Name', '# reqs', '# fails', 'Avg', 'Min', 'Max', 'Median', 'req/s', 'failures/s'))
console_logger.info("-" * (80 + STATS_NAME_WIDTH))
for key in sorted(stats.entries.keys()):
r = stats.entries[key]
Expand All @@ -708,11 +708,11 @@ def print_stats(stats, current=True):


def print_percentile_stats(stats):
console_logger.info("Percentage of the requests completed within given times")
headers = ('Type', 'Name', '# reqs') + tuple(get_readable_percentiles(PERCENTILES_TO_REPORT))
console_logger.info("Response time percentiles (approximated)")
headers = ('Type', 'Name') + tuple(get_readable_percentiles(PERCENTILES_TO_REPORT)) + ('# reqs',)
console_logger.info((f" %-{str(STATS_TYPE_WIDTH)}s %-{str(STATS_NAME_WIDTH)}s %8s "
f"{' '.join(['%7s'] * len(PERCENTILES_TO_REPORT))}") % headers)
separator = f'{"-" * STATS_TYPE_WIDTH}|{"-" * STATS_NAME_WIDTH}|{"-" * 9}|{("-" * 7 + "|") * len(PERCENTILES_TO_REPORT)}'
f"{' '.join(['%6s'] * len(PERCENTILES_TO_REPORT))}") % headers)
separator = f'{"-" * STATS_TYPE_WIDTH}|{"-" * STATS_NAME_WIDTH}|{"-" * 9}|{("-" * 6 + "|") * len(PERCENTILES_TO_REPORT)}'
console_logger.info(separator)
for key in sorted(stats.entries.keys()):
r = stats.entries[key]
Expand Down
7 changes: 4 additions & 3 deletions locust/test/test_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,21 +226,22 @@ def test_percentile_rounded_down(self):
s1 = StatsEntry(self.stats, "rounding down!", "GET")
s1.log(122, 0) # (rounded 120) min
actual_percentile = s1.percentile().split()
self.assertEqual(actual_percentile, ['GET', 'rounding', 'down!', '1'] + ['120'] * len(PERCENTILES_TO_REPORT))

self.assertEqual(actual_percentile, ['GET', 'rounding', 'down!'] + ['120'] * len(PERCENTILES_TO_REPORT) + ['1'])

def test_percentile_rounded_up(self):
s2 = StatsEntry(self.stats, "rounding up!", "GET")
s2.log(127, 0) # (rounded 130) min
actual_percentile = s2.percentile().split()
self.assertEqual(actual_percentile, ['GET', 'rounding', 'up!', '1'] + ['130'] * len(PERCENTILES_TO_REPORT))
self.assertEqual(actual_percentile, ['GET', 'rounding', 'up!'] + ['130'] * len(PERCENTILES_TO_REPORT) + ['1'])

def test_custom_percentile_list(self):
s = StatsEntry(self.stats, "custom_percentiles", "GET")
custom_percentile_list = [0.50, 0.90, 0.95, 0.99]
locust.stats.PERCENTILES_TO_REPORT = custom_percentile_list
s.log(150, 0)
actual_percentile = s.percentile().split()
self.assertEqual(actual_percentile, ['GET', 'custom_percentiles', '1'] + ['150'] * len(custom_percentile_list))
self.assertEqual(actual_percentile, ['GET', 'custom_percentiles'] + ['150'] * len(custom_percentile_list) + ['1'])

def test_error_grouping(self):
# reset stats
Expand Down