-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -407,6 +408,14 @@ def median_from_dict(total, count): | |
pos -= count[k] | ||
|
||
|
||
def median(input_list): | ||
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 | ||
|
||
|
||
global_stats = RequestStats() | ||
""" | ||
A global instance for holding the statistics. Should be removed eventually. | ||
|
@@ -454,20 +463,41 @@ 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) | ||
|
||
total_average = float(running_avg / total_stat_methods) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If locust is exited before executing any requests, this line will throw a ZeroDivisionError. |
||
total_median = int(median(running_median)) | ||
console_logger.info("-" * (80 + STATS_NAME_WIDTH)) | ||
|
||
try: | ||
fail_percent = (total_failures/float(total_reqs))*100 | ||
except ZeroDivisionError: | ||
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)) | ||
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)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the length of input_list is 0, this will fail with an IndexError.