Fix printing in perf preference panel
[lttngtop.git] / src / cursesdisplay.c
index 8417fdafe293a684ff0d85f6dc8ab7e94280d548..acf5753008490925b019c3241838e8c63e2d9d3d 100644 (file)
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
- * MA 02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #include <stdio.h>
@@ -27,6 +26,7 @@
 
 #include "cursesdisplay.h"
 #include "lttngtoptypes.h"
+#include "iostreamtop.h"
 #include "common.h"
 
 #define DEFAULT_DELAY 15
@@ -165,7 +165,7 @@ void print_headers(int line, char *desc, int value, int first, int second)
        wattron(header, A_BOLD);
        mvwprintw(header, line, 4, "%s", desc);
        wattroff(header, A_BOLD);
-       mvwprintw(header, line, 16, "N/A", value);
+       mvwprintw(header, line, 16, "%d", value);
        wmove(header, line, 24);
        print_digits(header, first, second);
        wmove(header, line, 40);
@@ -210,7 +210,8 @@ void print_log(char *str)
                        wmove(status, ++current_line, 1);
                        current_char = 1;
                } else {
-                       mvwprintw(status, current_line, current_char++, "%c", log_lines[i]);
+                       mvwprintw(status, current_line, current_char++, "%c",
+                                       log_lines[i]);
                }
        }
        wrefresh(status);
@@ -236,7 +237,7 @@ void update_footer()
        wmove(footer, 1, 1);
        print_key(footer, "F2", "CPUtop  ", current_view == cpu);
        print_key(footer, "F3", "PerfTop  ", current_view == perf);
-       print_key(footer, "F6", "IOTop  ", current_view == iostream);
+       print_key(footer, "F4", "IOTop  ", current_view == iostream);
        print_key(footer, "Enter", "Details  ", current_view == process_details);
        print_key(footer, "q", "Quit | ", 0);
        print_key(footer, "P", "Perf Pref  ", 0);
@@ -253,11 +254,9 @@ void basic_header()
        set_window_title(header, "Statistics for interval [gathering data...[");
        wattron(header, A_BOLD);
        mvwprintw(header, 1, 4, "CPUs");
-       mvwprintw(header, 2, 4, "Processes");
-       mvwprintw(header, 3, 4, "Threads");
-       mvwprintw(header, 4, 4, "Files");
-       mvwprintw(header, 5, 4, "Network");
-       mvwprintw(header, 6, 4, "IO");
+       mvwprintw(header, 2, 4, "Threads");
+       mvwprintw(header, 3, 4, "Files");
+       mvwprintw(header, 4, 4, "Network");
        wattroff(header, A_BOLD);
        wrefresh(header);
 }
@@ -280,15 +279,13 @@ void update_header()
        wattroff(header, A_BOLD);
        wprintw(header, "\t%d\t(max/cpu : %0.2f%)", data->cpu_table->len,
                        100.0/data->cpu_table->len);
-       print_headers(2, "Processes", data->nbproc, data->nbnewproc,
-                       -1*(data->nbdeadproc));
-       print_headers(3, "Threads", data->nbthreads, data->nbnewthreads,
+       print_headers(2, "Threads", data->nbthreads, data->nbnewthreads,
                        -1*(data->nbdeadthreads));
-       print_headers(4, "Files", data->nbfiles, data->nbnewfiles,
+       print_headers(3, "Files", data->nbfiles, data->nbnewfiles,
                        -1*(data->nbclosedfiles));
-       mvwprintw(header, 4, 43, "N/A kbytes/sec");
-       print_headers(5, "Network", 114, 0, 0);
-       mvwprintw(header, 5, 43, "N/A Mbytes/sec");
+       mvwprintw(header, 3, 43, "N/A kbytes/sec");
+       print_headers(4, "Network", 0, 0, 0);
+       mvwprintw(header, 4, 43, "N/A Mbytes/sec");
        wrefresh(header);
 }
 
@@ -420,6 +417,8 @@ void update_process_details()
        unsigned long elapsed;
        double maxcputime;
        struct processtop *tmp = find_process_tid(data, selected_tid, selected_comm);
+       struct files *file_tmp;
+       int i, j = 0;
 
        set_window_title(center, "Process details");
 
@@ -442,11 +441,35 @@ void update_process_details()
        wprintw(center, "%d", tmp->ppid);
        print_key_title("CPU", 5);
        wprintw(center, "%1.2f %%", tmp->totalcpunsec/maxcputime);
+
+       print_key_title("READ B/s", 6);
+       wprintw(center, "%d", tmp->fileread);
+
+       print_key_title("WRITE B/s", 7);
+       wprintw(center, "%d", tmp->filewrite);
+
+       wattron(center, A_BOLD);
+       mvwprintw(center, 8, 1, "FD");
+       mvwprintw(center, 8, 12, "READ");
+       mvwprintw(center, 8, 22, "WRITE");
+       mvwprintw(center, 8, 32, "FILENAME");
+       wattroff(center, A_BOLD);
+
+       for (i = 0; i < tmp->process_files_table->len; i++) {
+               file_tmp = get_file(tmp, i);
+               if (file_tmp != NULL) {
+                       mvwprintw(center, 9 + j, 1, "%d", i);
+                       mvwprintw(center, 9 + j, 12, "%d", file_tmp->read);
+                       mvwprintw(center, 9 + j, 22, "%d", file_tmp->write);
+                       mvwprintw(center, 9 + j, 32, "%s", file_tmp->name);
+                       j++;
+               }
+       }
 }
 
 void update_perf()
 {
-       int i, j;
+       int i;
        int nblinedisplayed = 0;
        int current_line = 0;
        struct processtop *tmp;
@@ -468,9 +491,9 @@ void update_perf()
        g_hash_table_iter_init(&iter, data->perf_list);
        while (g_hash_table_iter_next (&iter, &key, (gpointer) &perfn1)) {
                if (perfn1->visible) {
-                       /* + 6 to strip the "_perf_" prefix */
+                       /* + 5 to strip the "perf_" prefix */
                        mvwprintw(center, 1, perf_row, "%s",
-                                       (char *) key + 6);
+                                       (char *) key + 5);
                        perf_row += 20;
                }
                if (perfn1->sort) {
@@ -506,7 +529,8 @@ void update_perf()
                                        value = perfn2->count;
                                else
                                        value = 0;
-                               mvwprintw(center, current_line + header_offset, perf_row, "%d", value);
+                               mvwprintw(center, current_line + header_offset,
+                                               perf_row, "%d", value);
                                perf_row += 20;
                        }
                }
@@ -517,53 +541,13 @@ void update_perf()
        }
 }
 
-void update_fileio()
-{
-       int i;
-       int offset;
-
-       set_window_title(center, "IO Top");
-       wattron(center, A_BOLD);
-       mvwprintw(center, 1, 10, "READ");
-       mvwprintw(center, 2, 1, "bytes");
-       mvwprintw(center, 2, 15, "bytes/sec");
-
-       mvwprintw(center, 1, 39, "WRITE");
-       mvwprintw(center, 2, 33, "bytes");
-       mvwprintw(center, 2, 45, "bytes/sec");
-
-       if (toggle_threads > 0) {
-               mvwprintw(center, 1, 60, "TGID");
-               mvwprintw(center, 1, 70, "PID");
-               offset = 8;
-       } else {
-               mvwprintw(center, 1, 60, "PID(TGID)");
-               offset = 0;
-       }
-       mvwprintw(center, 1, 72 + offset, "NAME");
-       wattroff(center, A_BOLD);
-
-       for (i = 3; i < LINES - 3 - 8 - 1; i++) {
-               mvwprintw(center, i, 1, "%d", i*1000);
-               mvwprintw(center, i, 15, "%dk", i);
-               mvwprintw(center, i, 28, "|    %d", i*2000);
-               mvwprintw(center, i, 45, "%dk", i*2);
-               if (toggle_threads > 0) {
-                       mvwprintw(center, i, 57, "|  %d", i);
-                       mvwprintw(center, i, 70, "%d", i);
-               } else {
-                       mvwprintw(center, i, 57, "|  %d", i);
-               }
-               mvwprintw(center, i, 72 + offset, "process_%d", i);
-       }
-}
-
 gint sort_by_ret_desc(gconstpointer p1, gconstpointer p2)
 {
        struct processtop *n1 = *(struct processtop **)p1;
        struct processtop *n2 = *(struct processtop **)p2;
-       unsigned long totaln1 = n1->iostream->ret_total;
-       unsigned long totaln2 = n2->iostream->ret_total;
+
+       unsigned long totaln1 = n1->totalfileread + n1->totalfilewrite;
+       unsigned long totaln2 = n2->totalfileread + n2->totalfilewrite;
 
        if (totaln1 < totaln2)
                return 1;
@@ -579,6 +563,7 @@ void update_iostream()
        struct processtop *tmp;
        int nblinedisplayed = 0;
        int current_line = 0;
+       int total = 0;
 
        set_window_title(center, "IO Top");
        wattron(center, A_BOLD);
@@ -606,24 +591,28 @@ void update_iostream()
                        wattron(center, COLOR_PAIR(5));
                        mvwhline(center, current_line + header_offset, 1, ' ', COLS-3);
                }
+
                /* READ (bytes/sec) */
                mvwprintw(center, current_line + header_offset, 1, "%lu",
-                               tmp->iostream->ret_read);
+                       tmp->fileread);
 
                /* WRITE (bytes/sec) */
                mvwprintw(center, current_line + header_offset, 20, "%lu",
-                               tmp->iostream->ret_write);
+                       tmp->filewrite);
 
                /* TOTAL STREAM */
-               if(tmp->iostream->ret_total >= 1000000)
+               total = tmp->totalfileread + tmp->totalfilewrite;
+
+               if (total >= 1000000)
                        mvwprintw(center, current_line + header_offset, 40, "%lu MB",
-                                       tmp->iostream->ret_total/1000000);
-               else if(tmp->iostream->ret_total >=1000)
+                                       total/1000000);
+               else if (total >= 1000)
                        mvwprintw(center, current_line + header_offset, 40, "%lu KB",
-                                       tmp->iostream->ret_total/1000);
+                                       total/1000);
                else
                        mvwprintw(center, current_line + header_offset, 40, "%lu B",
-                                       tmp->iostream->ret_total);
+                                       total);
+
                /* TGID */
                mvwprintw(center, current_line + header_offset, 60, "%d", tmp->pid);
                /* PID */
@@ -655,9 +644,6 @@ void update_current_view()
        case process_details:
                update_process_details();
                break;
-       case fileio:
-               update_fileio();
-               break;
        case iostream:
                update_iostream();
                break;
@@ -701,7 +687,8 @@ void update_perf_panel(int line_selected, int toggle_view, int toggle_sort)
        box(perf_panel_window, 0 , 0);
        set_window_title(perf_panel_window, "Perf Preferences ");
        wattron(perf_panel_window, A_BOLD);
-       mvwprintw(perf_panel_window, g_hash_table_size(data->perf_list) + 1, 1, " 's' to sort");
+       mvwprintw(perf_panel_window, g_hash_table_size(data->perf_list) + 1, 1,
+                       " 's' to sort");
        wattroff(perf_panel_window, A_BOLD);
 
        if (toggle_sort == 1) {
@@ -735,7 +722,7 @@ void update_perf_panel(int line_selected, int toggle_view, int toggle_sort)
                        wattron(perf_panel_window, A_BOLD);
                mvwprintw(perf_panel_window, i + 1, 1, "[%c] %s",
                                perf->visible == 1 ? 'x' : ' ',
-                               (char *) perflist->data + 6);
+                               (char *) perflist->data + 5);
                wattroff(perf_panel_window, A_BOLD);
                wattroff(perf_panel_window, COLOR_PAIR(5));
                i++;
@@ -919,16 +906,6 @@ void *handle_keyboard(void *p)
                        update_current_view();
                        break;
                case KEY_F(4):
-                       current_view = fileio;
-                       toggle_tree = -1;
-                       update_current_view();
-                       break;
-               case KEY_F(5):
-                       current_view = netio;
-                       toggle_tree = -1;
-                       update_current_view();
-                       break;
-               case KEY_F(6):
                        current_view = iostream;
                        toggle_tree = -1;
                        update_current_view();
@@ -952,12 +929,8 @@ void *handle_keyboard(void *p)
                        toggle_perf_panel();
                        break;
                default:
-                       /*
-                        * commented because it makes the list refresh in different order
-                        * if we sort and there are equal values
-                        if (data)
-                        update_current_view();
-                        */
+                       if (data)
+                               update_current_view();
                        break;
                }
                update_footer();
@@ -970,8 +943,8 @@ void init_ncurses()
        sem_init(&update_display_sem, 0, 1);
        init_screen();
 
-       header = create_window(7, COLS - 1, 0, 0);
-       center = create_window(LINES - 7 - 7, COLS - 1, 7, 0);
+       header = create_window(6, COLS - 1, 0, 0);
+       center = create_window(LINES - 7 - 7, COLS - 1, 6, 0);
        status = create_window(MAX_LOG_LINES + 2, COLS - 1, LINES - 7, 0);
        footer = create_window(1, COLS - 1, LINES - 1, 0);
 
This page took 0.038452 seconds and 4 git commands to generate.