Skip to content

Commit 7f77475

Browse files
pablomhclaude
andcommitted
feat(locust): Add sort_stats option to sort stats table alphabetically
Add sort_stats parameter to run_locust() and show_locust_stats() that sorts the stats table entries alphabetically by request name. Defaults to False to preserve existing insertion-order behavior. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent e4a2695 commit 7f77475

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

extras/opl/locust.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import tabulate
1313

1414

15-
def run_locust(args, status_data, test_set, new_stats=False, summary_only=False):
15+
def run_locust(args, status_data, test_set, new_stats=False, summary_only=False, sort_stats=False):
1616
# Local runner is True by default, bot overwrite it if we have selected
1717
# master or worker runner
1818
assert not (
@@ -81,7 +81,7 @@ def run_locust(args, status_data, test_set, new_stats=False, summary_only=False)
8181
status_data.set_now("results.end")
8282
logging.info("Local Locust run finished")
8383

84-
return show_locust_stats(env.stats, status_data, new_stats, summary_only)
84+
return show_locust_stats(env.stats, status_data, new_stats, summary_only, sort_stats)
8585

8686
elif args.locust_master_runner:
8787
env.create_master_runner(
@@ -122,7 +122,7 @@ def run_locust(args, status_data, test_set, new_stats=False, summary_only=False)
122122
status_data.set_now("results.end")
123123
logging.info("Master Locust run finished")
124124

125-
return show_locust_stats(env.stats, status_data, new_stats, summary_only)
125+
return show_locust_stats(env.stats, status_data, new_stats, summary_only, sort_stats)
126126

127127
elif args.locust_worker_runner:
128128
env.create_worker_runner(
@@ -146,7 +146,7 @@ def run_locust(args, status_data, test_set, new_stats=False, summary_only=False)
146146
raise Exception("No runner specified")
147147

148148

149-
def show_locust_stats(locust_stats, status_data, new_stats, summary_only):
149+
def show_locust_stats(locust_stats, status_data, new_stats, summary_only, sort_stats=False):
150150
"""
151151
Print Locust stats obejct and format nice table of it.
152152
Also add values to status data object.
@@ -172,7 +172,8 @@ def show_locust_stats(locust_stats, status_data, new_stats, summary_only):
172172
sum_total_response_time = 0.0
173173
sum_total_content_length = 0
174174
sum_total_rps = 0.0
175-
for name, value in locust_stats.entries.items():
175+
entries = sorted(locust_stats.entries.items()) if sort_stats else locust_stats.entries.items()
176+
for name, value in entries:
176177
sum_count += value.num_requests
177178
sum_failures += value.num_failures
178179
sum_total_response_time += value.median_response_time * value.num_requests

0 commit comments

Comments
 (0)