2 * Copyright (C) 2011 Julien Desfossez
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License Version 2 as
6 * published by the Free Software Foundation;
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #include <semaphore.h>
27 #include "cursesdisplay.h"
28 #include "lttngtoptypes.h"
29 #include "iostreamtop.h"
32 #define DEFAULT_DELAY 15
33 #define MAX_LINE_LENGTH 50
34 #define MAX_LOG_LINES 4
36 /* to prevent concurrent updates of the different windows */
37 sem_t update_display_sem
;
40 WINDOW
*footer
, *header
, *center
, *status
;
41 WINDOW
*perf_panel_window
= NULL
;
42 PANEL
*perf_panel
, *main_panel
;
44 int perf_panel_visible
= 0;
45 int perf_line_selected
= 0;
47 int last_display_index
, currently_displayed_index
;
49 struct processtop
*selected_process
= NULL
;
52 int selected_line
= 0; /* select bar position */
53 int selected_in_list
= 0; /* selection relative to the whole list */
54 int list_offset
= 0; /* first index in the list to display (scroll) */
56 char log_lines
[MAX_LINE_LENGTH
* MAX_LOG_LINES
+ MAX_LOG_LINES
];
58 int max_elements
= 80;
60 int toggle_threads
= -1;
61 int toggle_pause
= -1;
64 GPtrArray
*selected_processes
;
66 pthread_t keyboard_thread
;
75 static void handle_sigterm(int signal
)
84 halfdelay(DEFAULT_DELAY
);
86 intrflush(stdscr
, false);
92 init_pair(1, COLOR_RED
, COLOR_BLACK
); /* - */
93 init_pair(2, COLOR_GREEN
, COLOR_BLACK
); /* + */
94 init_pair(3, COLOR_BLACK
, COLOR_WHITE
); /* keys */
95 init_pair(4, COLOR_WHITE
, COLOR_GREEN
); /* keys activated */
96 init_pair(5, COLOR_WHITE
, COLOR_BLUE
); /* select line */
97 init_pair(6, COLOR_WHITE
, COLOR_GREEN
); /* selected process */
99 termtype
= getenv("TERM");
100 if (!strcmp(termtype
, "xterm") || !strcmp(termtype
, "xterm-color") ||
101 !strcmp(termtype
, "vt220")) {
102 define_key("\033[H", KEY_HOME
);
103 define_key("\033[F", KEY_END
);
104 define_key("\033OP", KEY_F(1));
105 define_key("\033OQ", KEY_F(2));
106 define_key("\033OR", KEY_F(3));
107 define_key("\033OS", KEY_F(4));
108 define_key("\0330U", KEY_F(6));
109 define_key("\033[11~", KEY_F(1));
110 define_key("\033[12~", KEY_F(2));
111 define_key("\033[13~", KEY_F(3));
112 define_key("\033[14~", KEY_F(4));
113 define_key("\033[16~", KEY_F(6));
114 define_key("\033[17;2~", KEY_F(18));
116 signal(SIGTERM
, handle_sigterm
);
117 mousemask(BUTTON1_CLICKED
, NULL
);
121 WINDOW
*create_window(int height
, int width
, int startx
, int starty
)
124 win
= newwin(height
, width
, startx
, starty
);
130 WINDOW
*create_window_no_border(int height
, int width
, int startx
, int starty
)
133 win
= newwin(height
, width
, startx
, starty
);
138 void print_digit(WINDOW
*win
, int digit
)
141 wattron(win
, COLOR_PAIR(1));
142 wprintw(win
, "%d", digit
);
143 wattroff(win
, COLOR_PAIR(1));
144 } else if (digit
> 0) {
145 wattron(win
, COLOR_PAIR(2));
146 wprintw(win
, "+%d", digit
);
147 wattroff(win
, COLOR_PAIR(2));
153 void print_digits(WINDOW
*win
, int first
, int second
)
156 print_digit(win
, first
);
158 print_digit(win
, second
);
162 void print_headers(int line
, char *desc
, int value
, int first
, int second
)
164 wattron(header
, A_BOLD
);
165 mvwprintw(header
, line
, 4, "%s", desc
);
166 wattroff(header
, A_BOLD
);
167 mvwprintw(header
, line
, 16, "%d", value
);
168 wmove(header
, line
, 24);
169 print_digits(header
, first
, second
);
170 wmove(header
, line
, 40);
173 void set_window_title(WINDOW
*win
, char *title
)
175 wattron(win
, A_BOLD
);
176 mvwprintw(win
, 0, 1, title
);
177 wattroff(win
, A_BOLD
);
180 void print_log(char *str
)
183 int current_line
= 1;
184 int current_char
= 1;
186 /* rotate the line buffer */
187 if (nb_log_lines
>= MAX_LOG_LINES
) {
188 tmp
= strndup(log_lines
, MAX_LINE_LENGTH
* MAX_LOG_LINES
+ MAX_LOG_LINES
);
189 tmp2
= strchr(tmp
, '\n');
190 memset(log_lines
, '\0', strlen(log_lines
));
191 strncat(log_lines
, tmp2
+ 1, strlen(tmp2
) - 1);
192 log_lines
[strlen(log_lines
)] = '\n';
193 log_lines
[strlen(log_lines
)] = '\0';
198 strncat(log_lines
, str
, MAX_LINE_LENGTH
- 1);
200 if (nb_log_lines
< MAX_LOG_LINES
)
201 log_lines
[strlen(log_lines
)] = '\n';
202 log_lines
[strlen(log_lines
)] = '\0';
206 set_window_title(status
, "Status");
207 for (i
= 0; i
< strlen(log_lines
); i
++) {
208 if (log_lines
[i
] == '\n') {
209 wmove(status
, ++current_line
, 1);
212 mvwprintw(status
, current_line
, current_char
++, "%c",
219 int process_selected(struct processtop
*process
)
222 struct processtop
*stored_process
;
224 for (i
= 0; i
< selected_processes
->len
; i
++) {
225 stored_process
= g_ptr_array_index(selected_processes
, i
);
226 if (stored_process
->tid
== process
->tid
)
232 void update_selected_processes()
234 if (process_selected(selected_process
)) {
235 g_ptr_array_remove(selected_processes
, selected_process
);
236 print_log("Process removed");
238 g_ptr_array_add(selected_processes
, selected_process
);
239 print_log("Process added");
243 void print_key(WINDOW
*win
, char *key
, char *desc
, int toggle
)
250 wattron(win
, COLOR_PAIR(pair
));
251 wprintw(footer
, "%s", key
);
252 wattroff(win
, COLOR_PAIR(pair
));
253 wprintw(footer
, ":%s", desc
);
258 sem_wait(&update_display_sem
);
261 print_key(footer
, "F2", "CPUtop ", current_view
== cpu
);
262 print_key(footer
, "F3", "PerfTop ", current_view
== perf
);
263 print_key(footer
, "F4", "IOTop ", current_view
== iostream
);
264 print_key(footer
, "Enter", "Details ", current_view
== process_details
);
265 print_key(footer
, "Space", "Highlight ", 0);
266 print_key(footer
, "q", "Quit | ", 0);
267 print_key(footer
, "P", "Perf Pref ", 0);
268 print_key(footer
, "p", "Pause ", toggle_pause
);
271 sem_post(&update_display_sem
);
278 set_window_title(header
, "Statistics for interval [gathering data...[");
279 wattron(header
, A_BOLD
);
280 mvwprintw(header
, 1, 4, "CPUs");
281 mvwprintw(header
, 2, 4, "Threads");
282 mvwprintw(header
, 3, 4, "FDs");
283 wattroff(header
, A_BOLD
);
287 struct tm
format_timestamp(uint64_t timestamp
)
290 uint64_t ts_sec
= 0, ts_nsec
;
294 ts_sec
+= ts_nsec
/ NSEC_PER_SEC
;
295 ts_nsec
= ts_nsec
% NSEC_PER_SEC
;
297 time_s
= (time_t) ts_sec
;
299 localtime_r(&time_s
, &tm
);
304 static void scale_unit(uint64_t bytes
, char *ret
)
306 if (bytes
>= 1000000000)
307 sprintf(ret
, "%" PRIu64
"G", bytes
/1000000000);
308 if (bytes
>= 1000000)
309 sprintf(ret
, "%" PRIu64
"M", bytes
/1000000);
310 else if (bytes
>= 1000)
311 sprintf(ret
, "%" PRIu64
"K", bytes
/1000);
313 sprintf(ret
, "%" PRIu64
, bytes
);
318 struct processtop
*tmp
;
321 for (i
= 0; i
< data
->process_table
->len
; i
++) {
322 tmp
= g_ptr_array_index(data
->process_table
, i
);
323 total
+= tmp
->fileread
;
324 total
+= tmp
->filewrite
;
332 struct tm start
, end
;
333 uint64_t ts_nsec_start
, ts_nsec_end
;
336 ts_nsec_start
= data
->start
% NSEC_PER_SEC
;
337 start
= format_timestamp(data
->start
);
339 ts_nsec_end
= data
->end
% NSEC_PER_SEC
;
340 end
= format_timestamp(data
->end
);
344 set_window_title(header
, "Statistics for interval ");
345 wattron(header
, A_BOLD
);
347 wprintw(header
, "[%02d:%02d:%02d.%09" PRIu64
", %02d:%02d:%02d.%09" PRIu64
"[",
348 start
.tm_hour
, start
.tm_min
, start
.tm_sec
, ts_nsec_start
,
349 end
.tm_hour
, end
.tm_min
, end
.tm_sec
, ts_nsec_end
);
350 mvwprintw(header
, 1, 4, "CPUs");
351 wattroff(header
, A_BOLD
);
352 wprintw(header
, "\t%d\t(max/cpu : %0.2f%)", data
->cpu_table
->len
,
353 100.0/data
->cpu_table
->len
);
354 print_headers(2, "Threads", data
->nbthreads
, data
->nbnewthreads
,
355 -1*(data
->nbdeadthreads
));
356 print_headers(3, "FDs", data
->nbfiles
, data
->nbnewfiles
,
357 -1*(data
->nbclosedfiles
));
358 scale_unit(total_io(), io
);
359 mvwprintw(header
, 3, 43, "%sB/sec", io
);
363 gint
sort_by_cpu_desc(gconstpointer p1
, gconstpointer p2
)
365 struct processtop
*n1
= *(struct processtop
**)p1
;
366 struct processtop
*n2
= *(struct processtop
**)p2
;
367 unsigned long totaln1
= n1
->totalcpunsec
;
368 unsigned long totaln2
= n2
->totalcpunsec
;
370 if (totaln1
< totaln2
)
372 if (totaln1
== totaln2
)
377 gint
sort_by_cpu_group_by_threads_desc(gconstpointer p1
, gconstpointer p2
)
379 struct processtop
*n1
= *(struct processtop
**)p1
;
380 struct processtop
*n2
= *(struct processtop
**)p2
;
381 unsigned long totaln1
= n1
->threadstotalcpunsec
;
382 unsigned long totaln2
= n2
->threadstotalcpunsec
;
384 if (totaln1
< totaln2
)
386 if (totaln1
== totaln2
)
391 void update_cputop_display()
394 int header_offset
= 2;
395 struct processtop
*tmp
;
396 unsigned long elapsed
;
398 int nblinedisplayed
= 0;
399 int current_line
= 0;
401 elapsed
= data
->end
- data
->start
;
402 maxcputime
= elapsed
* data
->cpu_table
->len
/ 100.0;
404 g_ptr_array_sort(data
->process_table
, sort_by_cpu_desc
);
406 set_window_title(center
, "CPU Top");
407 wattron(center
, A_BOLD
);
408 mvwprintw(center
, 1, 1, "CPU(%)");
409 mvwprintw(center
, 1, 12, "TGID");
410 mvwprintw(center
, 1, 22, "PID");
411 mvwprintw(center
, 1, 32, "NAME");
412 wattroff(center
, A_BOLD
);
414 max_center_lines
= LINES
- 5 - 7 - 1 - header_offset
;
416 /* iterate the process (thread) list */
417 for (i
= list_offset
; i
< data
->process_table
->len
&&
418 nblinedisplayed
< max_center_lines
; i
++) {
419 tmp
= g_ptr_array_index(data
->process_table
, i
);
421 /* FIXME : random segfault here */
422 if (process_selected(tmp
)) {
423 wattron(center
, COLOR_PAIR(6));
424 mvwhline(center
, current_line
+ header_offset
, 1, ' ', COLS
-3);
426 if (current_line
== selected_line
) {
427 selected_process
= tmp
;
428 wattron(center
, COLOR_PAIR(5));
429 mvwhline(center
, current_line
+ header_offset
, 1, ' ', COLS
-3);
432 mvwprintw(center
, current_line
+ header_offset
, 1, "%1.2f",
433 tmp
->totalcpunsec
/ maxcputime
);
435 mvwprintw(center
, current_line
+ header_offset
, 12, "%d", tmp
->pid
);
437 mvwprintw(center
, current_line
+ header_offset
, 22, "%d", tmp
->tid
);
439 mvwprintw(center
, current_line
+ header_offset
, 32, "%s", tmp
->comm
);
440 wattroff(center
, COLOR_PAIR(6));
441 wattroff(center
, COLOR_PAIR(5));
447 gint
sort_perf(gconstpointer p1
, gconstpointer p2
, gpointer key
)
449 struct processtop
*n1
= *(struct processtop
**) p1
;
450 struct processtop
*n2
= *(struct processtop
**) p2
;
452 struct perfcounter
*tmp1
, *tmp2
;
453 unsigned long totaln2
= 0;
454 unsigned long totaln1
= 0;
459 tmp1
= g_hash_table_lookup(n1
->perf
, key
);
463 totaln1
= tmp1
->count
;
465 tmp2
= g_hash_table_lookup(n2
->perf
, key
);
469 totaln2
= tmp2
->count
;
471 if (totaln1
< totaln2
)
473 if (totaln1
== totaln2
) {
476 if (totaln1
< totaln2
)
483 void print_key_title(char *key
, int line
)
485 wattron(center
, A_BOLD
);
486 mvwprintw(center
, line
, 1, "%s\t", key
);
487 wattroff(center
, A_BOLD
);
490 void update_process_details()
492 unsigned long elapsed
;
494 struct processtop
*tmp
;
495 struct files
*file_tmp
;
498 char filename_buf
[COLS
];
500 set_window_title(center
, "Process details");
503 tmp
= find_process_tid(data
,
504 selected_process
->tid
,
505 selected_process
->comm
);
506 elapsed
= data
->end
- data
->start
;
507 maxcputime
= elapsed
* data
->cpu_table
->len
/ 100.0;
509 print_key_title("Name", 1);
510 wprintw(center
, "%s", selected_process
->comm
);
511 print_key_title("TID", 2);
512 wprintw(center
, "%d", selected_process
->tid
);
514 print_key_title("Does not exit at this time", 3);
518 print_key_title("PID", 3);
519 wprintw(center
, "%d", tmp
->pid
);
520 print_key_title("PPID", 4);
521 wprintw(center
, "%d", tmp
->ppid
);
522 print_key_title("CPU", 5);
523 wprintw(center
, "%1.2f %%", tmp
->totalcpunsec
/maxcputime
);
525 print_key_title("READ B/s", 6);
526 scale_unit(tmp
->fileread
, unit
);
527 wprintw(center
, "%s", unit
);
529 print_key_title("WRITE B/s", 7);
530 scale_unit(tmp
->filewrite
, unit
);
531 wprintw(center
, "%s", unit
);
533 wattron(center
, A_BOLD
);
534 mvwprintw(center
, 8, 1, "FD");
535 mvwprintw(center
, 8, 10, "READ");
536 mvwprintw(center
, 8, 17, "WRITE");
537 mvwprintw(center
, 8, 24, "FILENAME");
538 wattroff(center
, A_BOLD
);
540 for (i
= selected_line
; i
< tmp
->process_files_table
->len
&&
541 i
< (selected_line
+ max_center_lines
- 7); i
++) {
542 file_tmp
= get_file(tmp
, i
);
543 if (file_tmp
!= NULL
) {
544 mvwprintw(center
, 9 + j
, 1, "%d", i
);
545 scale_unit(file_tmp
->read
, unit
);
546 mvwprintw(center
, 9 + j
, 10, "%s", unit
);
547 scale_unit(file_tmp
->write
, unit
);
548 mvwprintw(center
, 9 + j
, 17, "%s", unit
);
549 snprintf(filename_buf
, COLS
- 25, "%s", file_tmp
->name
);
550 mvwprintw(center
, 9 + j
, 24, "%s", filename_buf
);
559 int nblinedisplayed
= 0;
560 int current_line
= 0;
561 struct processtop
*tmp
;
562 int header_offset
= 2;
564 struct perfcounter
*perfn1
, *perfn2
;
565 char *perf_key
= NULL
;
570 set_window_title(center
, "Perf Top");
571 wattron(center
, A_BOLD
);
572 mvwprintw(center
, 1, 1, "PID");
573 mvwprintw(center
, 1, 11, "TID");
574 mvwprintw(center
, 1, 22, "NAME");
577 g_hash_table_iter_init(&iter
, data
->perf_list
);
578 while (g_hash_table_iter_next (&iter
, &key
, (gpointer
) &perfn1
)) {
579 if (perfn1
->visible
) {
580 /* + 5 to strip the "perf_" prefix */
581 mvwprintw(center
, 1, perf_row
, "%s",
586 perf_key
= (char *) key
;
590 wattroff(center
, A_BOLD
);
592 g_ptr_array_sort_with_data(data
->process_table
, sort_perf
, perf_key
);
594 for (i
= 0; i
< data
->process_table
->len
&&
595 nblinedisplayed
< max_center_lines
; i
++) {
596 tmp
= g_ptr_array_index(data
->process_table
, i
);
598 if (process_selected(tmp
)) {
599 wattron(center
, COLOR_PAIR(6));
600 mvwhline(center
, current_line
+ header_offset
, 1, ' ', COLS
-3);
602 if (current_line
== selected_line
) {
603 selected_process
= tmp
;
604 wattron(center
, COLOR_PAIR(5));
605 mvwhline(center
, current_line
+ header_offset
, 1, ' ', COLS
-3);
608 mvwprintw(center
, current_line
+ header_offset
, 1, "%d", tmp
->pid
);
609 mvwprintw(center
, current_line
+ header_offset
, 11, "%d", tmp
->tid
);
610 mvwprintw(center
, current_line
+ header_offset
, 22, "%s", tmp
->comm
);
612 g_hash_table_iter_init(&iter
, data
->perf_list
);
615 while (g_hash_table_iter_next (&iter
, &key
, (gpointer
) &perfn1
)) {
616 if (perfn1
->visible
) {
617 perfn2
= g_hash_table_lookup(tmp
->perf
, (char *) key
);
619 value
= perfn2
->count
;
622 mvwprintw(center
, current_line
+ header_offset
,
623 perf_row
, "%d", value
);
628 wattroff(center
, COLOR_PAIR(6));
629 wattroff(center
, COLOR_PAIR(5));
635 gint
sort_by_ret_desc(gconstpointer p1
, gconstpointer p2
)
637 struct processtop
*n1
= *(struct processtop
**)p1
;
638 struct processtop
*n2
= *(struct processtop
**)p2
;
640 unsigned long totaln1
= n1
->totalfileread
+ n1
->totalfilewrite
;
641 unsigned long totaln2
= n2
->totalfileread
+ n2
->totalfilewrite
;
643 if (totaln1
< totaln2
)
645 if (totaln1
== totaln2
)
650 void update_iostream()
653 int header_offset
= 2;
654 struct processtop
*tmp
;
655 int nblinedisplayed
= 0;
656 int current_line
= 0;
660 set_window_title(center
, "IO Top");
661 wattron(center
, A_BOLD
);
662 mvwprintw(center
, 1, 1, "PID");
663 mvwprintw(center
, 1, 11, "TID");
664 mvwprintw(center
, 1, 22, "NAME");
665 mvwprintw(center
, 1, 40, "R (B/sec)");
666 mvwprintw(center
, 1, 52, "W (B/sec)");
667 mvwprintw(center
, 1, 64, "Total");
668 wattroff(center
, A_BOLD
);
670 g_ptr_array_sort(data
->process_table
, sort_by_ret_desc
);
672 for (i
= list_offset
; i
< data
->process_table
->len
&&
673 nblinedisplayed
< max_center_lines
; i
++) {
674 tmp
= g_ptr_array_index(data
->process_table
, i
);
676 if (process_selected(tmp
)) {
677 wattron(center
, COLOR_PAIR(6));
678 mvwhline(center
, current_line
+ header_offset
, 1, ' ', COLS
-3);
680 if (current_line
== selected_line
) {
681 selected_process
= tmp
;
682 wattron(center
, COLOR_PAIR(5));
683 mvwhline(center
, current_line
+ header_offset
, 1, ' ', COLS
-3);
686 mvwprintw(center
, current_line
+ header_offset
, 1, "%d", tmp
->pid
);
688 mvwprintw(center
, current_line
+ header_offset
, 11, "%d", tmp
->tid
);
690 mvwprintw(center
, current_line
+ header_offset
, 22, "%s", tmp
->comm
);
692 /* READ (bytes/sec) */
693 scale_unit(tmp
->fileread
, unit
);
694 mvwprintw(center
, current_line
+ header_offset
, 40, "%s", unit
);
696 /* WRITE (bytes/sec) */
697 scale_unit(tmp
->filewrite
, unit
);
698 mvwprintw(center
, current_line
+ header_offset
, 52, "%s", unit
);
701 total
= tmp
->totalfileread
+ tmp
->totalfilewrite
;
703 scale_unit(total
, unit
);
704 mvwprintw(center
, current_line
+ header_offset
, 64, "%s", unit
);
706 wattroff(center
, COLOR_PAIR(6));
707 wattroff(center
, COLOR_PAIR(5));
713 void update_current_view()
715 sem_wait(&update_display_sem
);
722 switch (current_view
) {
724 update_cputop_display();
729 case process_details
:
730 update_process_details();
736 update_cputop_display();
743 sem_post(&update_display_sem
);
746 void setup_perf_panel()
751 if (perf_panel_window
) {
752 del_panel(perf_panel
);
753 delwin(perf_panel_window
);
755 size
= g_hash_table_size(data
->perf_list
);
756 perf_panel_window
= create_window(size
+ 2, 30, 10, 10);
757 perf_panel
= new_panel(perf_panel_window
);
758 perf_panel_visible
= 0;
759 hide_panel(perf_panel
);
762 void update_perf_panel(int line_selected
, int toggle_view
, int toggle_sort
)
765 struct perfcounter
*perf
;
771 werase(perf_panel_window
);
772 box(perf_panel_window
, 0 , 0);
773 set_window_title(perf_panel_window
, "Perf Preferences ");
774 wattron(perf_panel_window
, A_BOLD
);
775 mvwprintw(perf_panel_window
, g_hash_table_size(data
->perf_list
) + 1, 1,
777 wattroff(perf_panel_window
, A_BOLD
);
779 if (toggle_sort
== 1) {
781 perflist
= g_list_first(g_hash_table_get_keys(data
->perf_list
));
783 perf
= g_hash_table_lookup(data
->perf_list
, perflist
->data
);
784 if (i
!= line_selected
)
789 perflist
= g_list_next(perflist
);
791 update_current_view();
795 perflist
= g_list_first(g_hash_table_get_keys(data
->perf_list
));
797 perf
= g_hash_table_lookup(data
->perf_list
, perflist
->data
);
798 if (i
== line_selected
&& toggle_view
== 1) {
799 perf
->visible
= perf
->visible
== 1 ? 0:1;
800 update_current_view();
802 if (i
== line_selected
) {
803 wattron(perf_panel_window
, COLOR_PAIR(5));
804 mvwhline(perf_panel_window
, i
+ 1, 1, ' ', 30 - 2);
807 wattron(perf_panel_window
, A_BOLD
);
808 mvwprintw(perf_panel_window
, i
+ 1, 1, "[%c] %s",
809 perf
->visible
== 1 ? 'x' : ' ',
810 (char *) perflist
->data
+ 5);
811 wattroff(perf_panel_window
, A_BOLD
);
812 wattroff(perf_panel_window
, COLOR_PAIR(5));
814 perflist
= g_list_next(perflist
);
820 void toggle_perf_panel(void)
822 if (perf_panel_visible
) {
823 hide_panel(perf_panel
);
824 perf_panel_visible
= 0;
827 update_perf_panel(perf_line_selected
, 0, 0);
828 show_panel(perf_panel
);
829 perf_panel_visible
= 1;
835 void display(unsigned int index
)
837 last_display_index
= index
;
838 currently_displayed_index
= index
;
839 data
= g_ptr_array_index(copies
, index
);
842 max_elements
= data
->process_table
->len
;
843 update_current_view();
853 sem_wait(&pause_sem
);
856 void resume_display()
860 sem_post(&pause_sem
);
863 void *handle_keyboard(void *p
)
866 while((ch
= getch())) {
868 /* Move the cursor and scroll */
870 if (perf_panel_visible
) {
871 if (perf_line_selected
< g_hash_table_size(data
->perf_list
) - 1)
872 perf_line_selected
++;
873 update_perf_panel(perf_line_selected
, 0, 0);
875 if (selected_line
< (max_center_lines
- 1) &&
876 selected_line
< max_elements
- 1) {
879 } else if (selected_in_list
< (max_elements
- 1)
880 && (list_offset
< (max_elements
- max_center_lines
))) {
884 update_current_view();
890 if (perf_panel_visible
) {
891 if (perf_line_selected
> 0)
892 perf_line_selected
--;
893 update_perf_panel(perf_line_selected
, 0, 0);
895 if (selected_line
> 0) {
898 } else if (selected_in_list
> 0 && list_offset
> 0) {
902 update_current_view();
908 /* Navigate the history with arrows */
910 if (currently_displayed_index
> 0) {
911 currently_displayed_index
--;
912 print_log("Going back in time");
914 print_log("Cannot rewind, last data is already displayed");
916 data
= g_ptr_array_index(copies
, currently_displayed_index
);
917 max_elements
= data
->process_table
->len
;
919 /* we force to pause the display when moving in time */
920 if (toggle_pause
< 0)
923 update_current_view();
927 if (currently_displayed_index
< last_display_index
) {
928 currently_displayed_index
++;
929 print_log("Going forward in time");
930 data
= g_ptr_array_index(copies
, currently_displayed_index
);
931 max_elements
= data
->process_table
->len
;
932 update_current_view();
935 print_log("Manually moving forward");
937 /* we force to resume the refresh when moving forward */
938 if (toggle_pause
> 0)
944 if (perf_panel_visible
) {
945 update_perf_panel(perf_line_selected
, 1, 0);
947 update_selected_processes();
948 update_current_view();
952 if (perf_panel_visible
)
953 update_perf_panel(perf_line_selected
, 0, 1);
956 case 13: /* FIXME : KEY_ENTER ?? */
957 if (current_view
!= process_details
) {
958 previous_view
= current_view
;
959 current_view
= process_details
;
961 current_view
= previous_view
;
962 previous_view
= process_details
;
964 update_current_view();
970 update_current_view();
975 update_current_view();
980 update_current_view();
983 current_view
= iostream
;
985 update_current_view();
992 toggle_threads
*= -1;
993 update_current_view();
996 if (toggle_pause
< 0) {
1003 toggle_perf_panel();
1007 update_current_view();
1017 selected_processes
= g_ptr_array_new();
1018 sem_init(&update_display_sem
, 0, 1);
1021 header
= create_window(5, COLS
- 1, 0, 0);
1022 center
= create_window(LINES
- 5 - 7, COLS
- 1, 5, 0);
1023 status
= create_window(MAX_LOG_LINES
+ 2, COLS
- 1, LINES
- 7, 0);
1024 footer
= create_window(1, COLS
- 1, LINES
- 1, 0);
1026 print_log("Starting display");
1028 main_panel
= new_panel(center
);
1036 pthread_create(&keyboard_thread
, NULL
, handle_keyboard
, (void *)NULL
);