mirror of
https://github.com/ceph/ceph
synced 2024-12-29 15:03:33 +00:00
Merge PR #59566 into main
* refs/pull/59566/head: cephfs-top: fix exception on small sized windows cephfs-top: fix exception on large sized windows Reviewed-by: Venky Shankar <vshankar@redhat.com> Reviewed-by: Neeraj Pratap Singh <neesingh@redhat.com> Reviewed-by: Dhairya Parmar <dparmar@redhat.com>
This commit is contained in:
commit
e0b974a06a
@ -45,6 +45,7 @@ FS_TOP_SUPPORTED_VER = 2
|
||||
ITEMS_PAD_LEN = 3
|
||||
ITEMS_PAD = " " * ITEMS_PAD_LEN
|
||||
DEFAULT_REFRESH_INTERVAL = 1
|
||||
DEFAULT_PAD_WIDTH = 300 # for medium size windows
|
||||
|
||||
# metadata provided by mgr/stats
|
||||
FS_TOP_MAIN_WINDOW_COL_CLIENT_ID = "client_id"
|
||||
@ -290,7 +291,7 @@ class FSTop(FSTopBase):
|
||||
self.conffile = args.conffile
|
||||
self.refresh_interval_secs = args.delay
|
||||
self.PAD_HEIGHT = 10000 # height of the fstop_pad
|
||||
self.PAD_WIDTH = 300 # width of the fstop_pad
|
||||
self.PAD_WIDTH = DEFAULT_PAD_WIDTH # width of the fstop_pad
|
||||
self.exit_ev = threading.Event()
|
||||
|
||||
def handle_signal(self, signum, _):
|
||||
@ -358,6 +359,12 @@ class FSTop(FSTopBase):
|
||||
# If the terminal do not support the visibility
|
||||
# requested it will raise an exception
|
||||
pass
|
||||
|
||||
# Check the window size before creating the pad. For large windows,
|
||||
# PAD_WIDTH = window width.
|
||||
h, w = self.stdscr.getmaxyx()
|
||||
if (w > DEFAULT_PAD_WIDTH):
|
||||
self.PAD_WIDTH = w
|
||||
self.fstop_pad = curses.newpad(self.PAD_HEIGHT, self.PAD_WIDTH)
|
||||
self.run_all_display()
|
||||
|
||||
@ -934,6 +941,15 @@ class FSTop(FSTopBase):
|
||||
self.header.addstr(5, 0, help, curses.A_DIM)
|
||||
return True
|
||||
|
||||
def handle_header(self, stats_json, help, screen_title, color_id=0):
|
||||
try:
|
||||
return self.create_header(stats_json, help, screen_title, color_id)
|
||||
except curses.error:
|
||||
curses.endwin()
|
||||
sys.stderr.write("Error creating header. Please increase the window width to use "
|
||||
"cephfs-top.\n")
|
||||
exit()
|
||||
|
||||
def run_display(self):
|
||||
# clear the pads to have a smooth refresh
|
||||
self.header.erase()
|
||||
@ -983,7 +999,7 @@ class FSTop(FSTopBase):
|
||||
current_states["limit"] = None
|
||||
self.header.erase() # erase previous text
|
||||
self.fsstats.erase()
|
||||
self.create_header(stats_json, help, screen_title, 3)
|
||||
self.handle_header(stats_json, help, screen_title, 3)
|
||||
else:
|
||||
self.tablehead_y = 0
|
||||
help = "COMMANDS: " + help_commands
|
||||
@ -996,7 +1012,7 @@ class FSTop(FSTopBase):
|
||||
else:
|
||||
num_client = len(client_metadata)
|
||||
vscrollEnd += num_client
|
||||
if self.create_header(stats_json, help, screen_title, 3):
|
||||
if self.handle_header(stats_json, help, screen_title, 3):
|
||||
self.create_table_header()
|
||||
self.create_clients(stats_json, fs)
|
||||
|
||||
@ -1030,7 +1046,10 @@ class FSTop(FSTopBase):
|
||||
elif cmd == curses.KEY_END:
|
||||
hscrollOffset = self.PAD_WIDTH - self.viewportWidth - 1
|
||||
elif cmd == curses.KEY_RESIZE:
|
||||
# terminal resize event. Update the viewport dimensions
|
||||
# terminal resize event.
|
||||
# Update the pad dimensions
|
||||
self.PAD_WIDTH = DEFAULT_PAD_WIDTH
|
||||
# Update the viewport dimensions
|
||||
windowsize = self.stdscr.getmaxyx()
|
||||
self.viewportHeight, self.viewportWidth = windowsize[0] - 1, windowsize[1] - 1
|
||||
|
||||
@ -1112,7 +1131,7 @@ class FSTop(FSTopBase):
|
||||
current_states["limit"] = None
|
||||
self.header.erase() # erase previous text
|
||||
self.fsstats.erase()
|
||||
self.create_header(stats_json, help, screen_title, 2)
|
||||
self.handle_header(stats_json, help, screen_title, 2)
|
||||
else:
|
||||
self.tablehead_y = 0
|
||||
num_client = 0
|
||||
@ -1128,7 +1147,7 @@ class FSTop(FSTopBase):
|
||||
else:
|
||||
num_client = len(client_metadata)
|
||||
vscrollEnd += num_client
|
||||
if self.create_header(stats_json, help, screen_title, 2):
|
||||
if self.handle_header(stats_json, help, screen_title, 2):
|
||||
if not index: # do it only for the first fs
|
||||
self.create_table_header()
|
||||
self.create_clients(stats_json, fs)
|
||||
@ -1163,7 +1182,10 @@ class FSTop(FSTopBase):
|
||||
elif cmd == curses.KEY_END:
|
||||
hscrollOffset = self.PAD_WIDTH - self.viewportWidth - 1
|
||||
elif cmd == curses.KEY_RESIZE:
|
||||
# terminal resize event. Update the viewport dimensions
|
||||
# terminal resize event.
|
||||
# Update the pad dimensions
|
||||
self.PAD_WIDTH = DEFAULT_PAD_WIDTH
|
||||
# Update the viewport dimensions
|
||||
windowsize = self.stdscr.getmaxyx()
|
||||
self.viewportHeight, self.viewportWidth = windowsize[0] - 1, windowsize[1] - 1
|
||||
if cmd:
|
||||
|
Loading…
Reference in New Issue
Block a user