Skip to content

Commit d66975c

Browse files
committed
Merge branch 'fix_curses_overlaps'
2 parents 04662fd + 0b48368 commit d66975c

File tree

2 files changed

+98
-92
lines changed

2 files changed

+98
-92
lines changed

src/interface.c

Lines changed: 97 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -485,8 +485,82 @@ static inline void werase_and_wnoutrefresh(WINDOW *w) {
485485
wnoutrefresh(w);
486486
}
487487

488-
static void draw_devices(struct list_head *devices,
489-
struct nvtop_interface *interface) {
488+
static bool cleaned_enc_window(struct device_window *dev, double encode_decode_hiding_timer, nvtop_time tnow) {
489+
if (encode_decode_hiding_timer > 0. && nvtop_difftime(dev->last_encode_seen, tnow) > encode_decode_hiding_timer) {
490+
if (dev->enc_was_visible) {
491+
dev->enc_was_visible = false;
492+
if (dev->dec_was_visible) {
493+
werase_and_wnoutrefresh(dev->gpu_util_enc_dec);
494+
werase_and_wnoutrefresh(dev->mem_util_enc_dec);
495+
} else {
496+
werase_and_wnoutrefresh(dev->gpu_util_no_enc_or_dec);
497+
werase_and_wnoutrefresh(dev->mem_util_no_enc_or_dec);
498+
}
499+
}
500+
return true;
501+
} else {
502+
return false;
503+
}
504+
}
505+
506+
static bool cleaned_dec_window(struct device_window *dev, double encode_decode_hiding_timer, nvtop_time tnow) {
507+
if (encode_decode_hiding_timer > 0. && nvtop_difftime(dev->last_decode_seen, tnow) > encode_decode_hiding_timer) {
508+
if (dev->dec_was_visible) {
509+
dev->dec_was_visible = false;
510+
if (dev->enc_was_visible) {
511+
werase_and_wnoutrefresh(dev->gpu_util_enc_dec);
512+
werase_and_wnoutrefresh(dev->mem_util_enc_dec);
513+
} else {
514+
werase_and_wnoutrefresh(dev->gpu_util_no_enc_or_dec);
515+
werase_and_wnoutrefresh(dev->mem_util_no_enc_or_dec);
516+
}
517+
}
518+
return true;
519+
} else {
520+
return false;
521+
}
522+
}
523+
524+
static void encode_decode_show_select(struct device_window *dev, bool encode_valid, bool decode_valid,
525+
unsigned encode_rate, unsigned decode_rate, double encode_decode_hiding_timer,
526+
bool *display_encode, bool *display_decode) {
527+
nvtop_time tnow;
528+
nvtop_get_current_time(&tnow);
529+
if (encode_valid && encode_rate > 0) {
530+
*display_encode = true;
531+
dev->last_encode_seen = tnow;
532+
if (!dev->enc_was_visible) {
533+
dev->enc_was_visible = true;
534+
if (!dev->dec_was_visible) {
535+
werase_and_wnoutrefresh(dev->gpu_util_no_enc_and_dec);
536+
werase_and_wnoutrefresh(dev->mem_util_no_enc_and_dec);
537+
} else {
538+
werase_and_wnoutrefresh(dev->gpu_util_no_enc_or_dec);
539+
werase_and_wnoutrefresh(dev->mem_util_no_enc_or_dec);
540+
}
541+
}
542+
} else {
543+
*display_encode = !cleaned_enc_window(dev, encode_decode_hiding_timer, tnow);
544+
}
545+
if (decode_valid && decode_rate > 0) {
546+
*display_decode = true;
547+
dev->last_decode_seen = tnow;
548+
if (!dev->dec_was_visible) {
549+
dev->dec_was_visible = true;
550+
if (!dev->enc_was_visible) {
551+
werase_and_wnoutrefresh(dev->gpu_util_no_enc_and_dec);
552+
werase_and_wnoutrefresh(dev->mem_util_no_enc_and_dec);
553+
} else {
554+
werase_and_wnoutrefresh(dev->gpu_util_no_enc_or_dec);
555+
werase_and_wnoutrefresh(dev->mem_util_no_enc_or_dec);
556+
}
557+
}
558+
} else {
559+
*display_decode = !cleaned_dec_window(dev, encode_decode_hiding_timer, tnow);
560+
}
561+
}
562+
563+
static void draw_devices(struct list_head *devices, struct nvtop_interface *interface) {
490564
struct gpu_info *device;
491565
unsigned dev_id = 0;
492566

@@ -503,111 +577,43 @@ static void draw_devices(struct list_head *devices,
503577
wprintw(dev->name_win, "[N/A]");
504578
wnoutrefresh(dev->name_win);
505579
}
580+
bool display_encode = false;
581+
bool display_decode = false;
582+
encode_decode_show_select(dev, IS_VALID(gpuinfo_encoder_rate_valid, device->dynamic_info.valid),
583+
IS_VALID(gpuinfo_decoder_rate_valid, device->dynamic_info.valid),
584+
device->dynamic_info.encoder_rate, device->dynamic_info.decoder_rate,
585+
interface->options.encode_decode_hiding_timer, &display_encode, &display_decode);
506586

507-
char buff[1024];
508-
nvtop_time tnow;
509-
nvtop_get_current_time(&tnow);
510-
bool is_encode_displayed = true;
511-
if (IS_VALID(gpuinfo_encoder_rate_valid, device->dynamic_info.valid)) {
512-
if (device->dynamic_info.encoder_rate > 0) {
513-
is_encode_displayed = true;
514-
dev->last_encode_seen = tnow;
515-
if (!dev->enc_was_visible) {
516-
dev->enc_was_visible = true;
517-
if (!dev->dec_was_visible) {
518-
werase_and_wnoutrefresh(dev->gpu_util_no_enc_and_dec);
519-
werase_and_wnoutrefresh(dev->mem_util_no_enc_and_dec);
520-
} else {
521-
werase_and_wnoutrefresh(dev->gpu_util_no_enc_or_dec);
522-
werase_and_wnoutrefresh(dev->mem_util_no_enc_or_dec);
523-
}
524-
}
525-
} else {
526-
if (interface->options.encode_decode_hiding_timer > 0. &&
527-
nvtop_difftime(dev->last_encode_seen, tnow) >
528-
interface->options.encode_decode_hiding_timer) {
529-
is_encode_displayed = false;
530-
if (dev->enc_was_visible) {
531-
dev->enc_was_visible = false;
532-
if (dev->dec_was_visible) {
533-
werase_and_wnoutrefresh(dev->gpu_util_enc_dec);
534-
werase_and_wnoutrefresh(dev->mem_util_enc_dec);
535-
} else {
536-
werase_and_wnoutrefresh(dev->gpu_util_no_enc_or_dec);
537-
werase_and_wnoutrefresh(dev->mem_util_no_enc_or_dec);
538-
}
539-
}
540-
}
541-
}
542-
} else {
543-
is_encode_displayed = false;
544-
}
545-
bool is_decode_displayed = true;
546-
if (IS_VALID(gpuinfo_decoder_rate_valid, device->dynamic_info.valid)) {
547-
if (device->dynamic_info.decoder_rate > 0) {
548-
is_decode_displayed = true;
549-
dev->last_decode_seen = tnow;
550-
if (!dev->dec_was_visible) {
551-
dev->dec_was_visible = true;
552-
if (!dev->enc_was_visible) {
553-
werase_and_wnoutrefresh(dev->gpu_util_no_enc_and_dec);
554-
werase_and_wnoutrefresh(dev->mem_util_no_enc_and_dec);
555-
} else {
556-
werase_and_wnoutrefresh(dev->gpu_util_no_enc_or_dec);
557-
werase_and_wnoutrefresh(dev->mem_util_no_enc_or_dec);
558-
}
559-
}
560-
} else {
561-
if (interface->options.encode_decode_hiding_timer > 0. &&
562-
nvtop_difftime(dev->last_decode_seen, tnow) >
563-
interface->options.encode_decode_hiding_timer) {
564-
is_decode_displayed = false;
565-
if (dev->dec_was_visible) {
566-
dev->dec_was_visible = false;
567-
if (dev->enc_was_visible) {
568-
werase_and_wnoutrefresh(dev->gpu_util_enc_dec);
569-
werase_and_wnoutrefresh(dev->mem_util_enc_dec);
570-
} else {
571-
werase_and_wnoutrefresh(dev->gpu_util_no_enc_or_dec);
572-
werase_and_wnoutrefresh(dev->mem_util_no_enc_or_dec);
573-
}
574-
}
575-
}
576-
}
577-
} else {
578-
is_decode_displayed = false;
579-
}
580587
WINDOW *gpu_util_win;
581588
WINDOW *mem_util_win;
582589
WINDOW *encode_win = dev->encode_util;
583590
WINDOW *decode_win = dev->decode_util;
584-
if (is_encode_displayed && is_decode_displayed) {
591+
if (display_encode && display_decode) {
585592
gpu_util_win = dev->gpu_util_enc_dec;
586593
mem_util_win = dev->mem_util_enc_dec;
587594
} else {
588-
if (is_encode_displayed || is_decode_displayed) {
589-
if (is_encode_displayed)
590-
encode_win = dev->decode_util;
595+
if (display_encode || display_decode) {
596+
// If encode only, place at decode location
597+
encode_win = dev->decode_util;
591598
gpu_util_win = dev->gpu_util_no_enc_or_dec;
592599
mem_util_win = dev->mem_util_no_enc_or_dec;
593600
} else {
594601
gpu_util_win = dev->gpu_util_no_enc_and_dec;
595602
mem_util_win = dev->mem_util_no_enc_and_dec;
596603
}
597604
}
598-
if (is_encode_displayed) {
599-
if (IS_VALID(gpuinfo_encoder_rate_valid, device->dynamic_info.valid)) {
600-
snprintf(buff, 1024, "%u%%", device->dynamic_info.encoder_rate);
601-
draw_percentage_meter(encode_win, "ENC",
602-
device->dynamic_info.encoder_rate, buff);
603-
}
605+
char buff[1024];
606+
if (display_encode) {
607+
unsigned rate =
608+
IS_VALID(gpuinfo_encoder_rate_valid, device->dynamic_info.valid) ? device->dynamic_info.encoder_rate : 0;
609+
snprintf(buff, 1024, "%u%%", rate);
610+
draw_percentage_meter(encode_win, "ENC", rate, buff);
604611
}
605-
if (is_decode_displayed) {
606-
if (IS_VALID(gpuinfo_decoder_rate_valid, device->dynamic_info.valid)) {
607-
snprintf(buff, 1024, "%u%%", device->dynamic_info.decoder_rate);
608-
draw_percentage_meter(decode_win, "DEC",
609-
device->dynamic_info.decoder_rate, buff);
610-
}
612+
if (display_decode) {
613+
unsigned rate =
614+
IS_VALID(gpuinfo_decoder_rate_valid, device->dynamic_info.valid) ? device->dynamic_info.decoder_rate : 0;
615+
snprintf(buff, 1024, "%u%%", rate);
616+
draw_percentage_meter(decode_win, "DEC", rate, buff);
611617
}
612618
if (IS_VALID(gpuinfo_gpu_util_rate_valid, device->dynamic_info.valid)) {
613619
snprintf(buff, 1024, "%u%%", device->dynamic_info.gpu_util_rate);

src/nvtop.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,8 @@ int main(int argc, char **argv) {
324324
double time_slept = interface_update_interval(interface);
325325
while (!signal_exit) {
326326
if (signal_resize_win) {
327-
update_window_size_to_terminal_size(interface);
328327
signal_resize_win = 0;
328+
update_window_size_to_terminal_size(interface);
329329
}
330330
if (time_slept >= interface_update_interval(interface)) {
331331
gpuinfo_refresh_dynamic_info(&devices);

0 commit comments

Comments
 (0)