Skip to content

Commit 99b19e0

Browse files
committed
UX improvements
1 parent 5ef23e3 commit 99b19e0

4 files changed

Lines changed: 29 additions & 21 deletions

File tree

Lib/profiling/sampling/live_collector/collector.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -894,18 +894,26 @@ def _handle_input(self):
894894
self._trend_tracker.toggle()
895895

896896
elif ch == curses.KEY_LEFT or ch == curses.KEY_UP:
897-
# Navigate to previous thread in PER_THREAD mode
898-
if self.view_mode == "PER_THREAD" and len(self.thread_ids) > 0:
899-
self.current_thread_index = (
900-
self.current_thread_index - 1
901-
) % len(self.thread_ids)
897+
# Navigate to previous thread in PER_THREAD mode, or switch from ALL to PER_THREAD
898+
if len(self.thread_ids) > 0:
899+
if self.view_mode == "ALL":
900+
self.view_mode = "PER_THREAD"
901+
self.current_thread_index = 0
902+
else:
903+
self.current_thread_index = (
904+
self.current_thread_index - 1
905+
) % len(self.thread_ids)
902906

903907
elif ch == curses.KEY_RIGHT or ch == curses.KEY_DOWN:
904-
# Navigate to next thread in PER_THREAD mode
905-
if self.view_mode == "PER_THREAD" and len(self.thread_ids) > 0:
906-
self.current_thread_index = (
907-
self.current_thread_index + 1
908-
) % len(self.thread_ids)
908+
# Navigate to next thread in PER_THREAD mode, or switch from ALL to PER_THREAD
909+
if len(self.thread_ids) > 0:
910+
if self.view_mode == "ALL":
911+
self.view_mode = "PER_THREAD"
912+
self.current_thread_index = 0
913+
else:
914+
self.current_thread_index = (
915+
self.current_thread_index + 1
916+
) % len(self.thread_ids)
909917

910918
def init_curses(self, stdscr):
911919
"""Initialize curses display and suppress stdout/stderr."""

Lib/profiling/sampling/sample.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,7 @@ def main():
965965
action="store_const",
966966
const=SORT_MODE_NSAMPLES,
967967
dest="sort",
968-
help="Sort by number of direct samples (nsamples column)",
968+
help="Sort by number of direct samples (nsamples column, default)",
969969
)
970970
sort_group.add_argument(
971971
"--sort-tottime",
@@ -979,7 +979,7 @@ def main():
979979
action="store_const",
980980
const=SORT_MODE_CUMTIME,
981981
dest="sort",
982-
help="Sort by cumulative time (cumtime column, default)",
982+
help="Sort by cumulative time (cumtime column)",
983983
)
984984
sort_group.add_argument(
985985
"--sort-sample-pct",
@@ -1039,7 +1039,7 @@ def main():
10391039
elif args.format == "live":
10401040
_validate_live_format_args(args, parser)
10411041

1042-
sort_value = args.sort if args.sort is not None else SORT_MODE_CUMTIME
1042+
sort_value = args.sort if args.sort is not None else SORT_MODE_NSAMPLES
10431043

10441044
if args.module is not None and not args.module:
10451045
parser.error("argument -m/--module: expected one argument")

Lib/test/test_profiling/test_sampling_profiler/test_cli.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def test_cli_module_argument_parsing(self):
7979
self._verify_coordinator_command(mock_popen, ("-m", "mymodule"))
8080
mock_sample.assert_called_once_with(
8181
12345,
82-
sort=2, # default sort (sort_value from args.sort)
82+
sort=0, # default sort (sort_value from args.sort)
8383
sample_interval_usec=100,
8484
duration_sec=10,
8585
filename=None,
@@ -118,7 +118,7 @@ def test_cli_module_with_arguments(self):
118118
)
119119
mock_sample.assert_called_once_with(
120120
12345,
121-
sort=2,
121+
sort=0,
122122
sample_interval_usec=100,
123123
duration_sec=10,
124124
filename=None,
@@ -148,7 +148,7 @@ def test_cli_script_argument_parsing(self):
148148
self._verify_coordinator_command(mock_popen, ("myscript.py",))
149149
mock_sample.assert_called_once_with(
150150
12345,
151-
sort=2,
151+
sort=0,
152152
sample_interval_usec=100,
153153
duration_sec=10,
154154
filename=None,
@@ -323,7 +323,7 @@ def test_cli_script_with_profiler_options(self):
323323
# Verify profiler options were passed correctly
324324
mock_sample.assert_called_once_with(
325325
12345,
326-
sort=2, # default sort
326+
sort=0, # default sort
327327
sample_interval_usec=2000,
328328
duration_sec=60,
329329
filename="output.txt",
@@ -628,7 +628,7 @@ def test_argument_parsing_basic(self):
628628
filename=None,
629629
all_threads=False,
630630
limit=15,
631-
sort=2,
631+
sort=0,
632632
show_summary=True,
633633
output_format="pstats",
634634
realtime_stats=False,

Lib/test/test_profiling/test_sampling_profiler/test_live_collector_interaction.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -779,13 +779,13 @@ def test_arrow_up_navigates_like_left(self):
779779
self.collector._handle_input()
780780
self.assertEqual(self.collector.current_thread_index, 2) # Wrapped
781781

782-
def test_arrow_keys_do_nothing_in_all_mode(self):
783-
"""Test that arrow keys have no effect in ALL mode."""
782+
def test_arrow_keys_switch_to_per_thread_mode(self):
783+
"""Test that arrow keys switch from ALL mode to PER_THREAD mode."""
784784
self.assertEqual(self.collector.view_mode, "ALL")
785785

786786
self.mock_display.simulate_input(curses.KEY_RIGHT)
787787
self.collector._handle_input()
788-
self.assertEqual(self.collector.view_mode, "ALL")
788+
self.assertEqual(self.collector.view_mode, "PER_THREAD")
789789
self.assertEqual(self.collector.current_thread_index, 0)
790790

791791
def test_stats_list_in_all_mode(self):

0 commit comments

Comments
 (0)