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

Added totals for print_stats (command line output) #354

Closed
Closed
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
41 changes: 39 additions & 2 deletions locust/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ def from_dict(cls, data):
def avg(values):
return sum(values, 0.0) / max(len(values), 1)


def median_from_dict(total, count):
"""
total is the number of requests made
Expand All @@ -407,6 +408,17 @@ def median_from_dict(total, count):
pos -= count[k]


def median(input_list):
try:
input_list.sort()
if len(input_list) % 2 == 1:
return input_list[len(input_list)/2]
else:
return (input_list[len(input_list)/2]+input_list[len(input_list)/2-1])/2.0
except (IndexError, TypeError):
return 0


global_stats = RequestStats()
"""
A global instance for holding the statistics. Should be removed eventually.
Expand Down Expand Up @@ -454,20 +466,45 @@ def print_stats(stats):
total_rps = 0
total_reqs = 0
total_failures = 0
total_min = None
running_avg = 0
running_median = []
total_max = 0
total_stat_methods = len(stats)

for key in sorted(stats.iterkeys()):
r = stats[key]
total_rps += r.current_rps
total_reqs += r.num_requests
total_failures += r.num_failures
running_avg += r.avg_response_time
running_median.append(r.median_response_time)

if total_min is None:
total_min = r.min_response_time

if total_max < r.max_response_time:
total_max = r.max_response_time

if total_min > r.min_response_time:
total_min = r.min_response_time

console_logger.info(r)
console_logger.info("-" * (80 + STATS_NAME_WIDTH))

try:
total_average = float(running_avg / total_stat_methods)
total_median = int(median(running_median))
fail_percent = (total_failures/float(total_reqs))*100
except ZeroDivisionError:
total_average = 0
total_median = 0
fail_percent = 0

console_logger.info((" %-" + str(STATS_NAME_WIDTH) + "s %7d %12s %42.2f") % ('Total', total_reqs, "%d(%.2f%%)" % (total_failures, fail_percent), total_rps))
if total_min is None:
total_min = 0

console_logger.info("-" * (80 + STATS_NAME_WIDTH))
console_logger.info((" %-" + str(STATS_NAME_WIDTH) + "s %7d %12s %7d %7d %7d %10d %7.2f") % ('Total', total_reqs, "%d(%.2f%%)" % (total_failures, fail_percent), total_average, total_min, total_max, total_median, total_rps))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, in the case of exiting before executing, total_min will be None and this line will fail with a TypeError.

console_logger.info("")

def print_percentile_stats(stats):
Expand Down