Remove the # in the example so we can just copy/paste it to a shell
[lttngtop.git] / src / cursesdisplay.c
index 0f7948581b800f5c8d062230421f1443c32132f2..eb0caa08deb8ba6d563f603690a84d76f330d7b2 100644 (file)
@@ -27,6 +27,7 @@
 
 #include "cursesdisplay.h"
 #include "lttngtoptypes.h"
+#include "iostreamtop.h"
 #include "common.h"
 
 #define DEFAULT_DELAY 15
@@ -210,7 +211,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);
@@ -420,6 +422,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,20 +446,38 @@ 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);
+
+       for (i = 0; i < tmp->process_files_table->len; i++) {
+               file_tmp = get_file(tmp, i);
+               if (file_tmp != NULL) {
+                       print_key_title("file", 8+j);
+                       wprintw(center, "%s fd = %d", file_tmp->name, i);
+                       wprintw(center, " read = %d", file_tmp->read);
+                       wprintw(center, " write = %d", file_tmp->write);
+                       j++;
+               }
+       }
 }
 
 void update_perf()
 {
-       int i, j;
+       int i;
        int nblinedisplayed = 0;
        int current_line = 0;
        struct processtop *tmp;
        int header_offset = 2;
        int perf_row = 40;
        struct perfcounter *perfn1, *perfn2;
-       GList *perflist;
        char *perf_key = NULL;
        int value;
+       GHashTableIter iter;
+       gpointer key;
 
        set_window_title(center, "Perf Top");
        wattron(center, A_BOLD);
@@ -464,26 +486,25 @@ void update_perf()
        mvwprintw(center, 1, 22, "NAME");
 
        perf_row = 40;
-       perflist = g_list_first(g_hash_table_get_keys(data->perf_list));
-       while (perflist) {
-               perfn1 = g_hash_table_lookup(data->perf_list, perflist->data);
-               /* + 6 to strip the "_perf_" prefix */
+       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 */
                        mvwprintw(center, 1, perf_row, "%s",
-                                       (char *) perflist->data + 6);
+                                       (char *) key + 6);
                        perf_row += 20;
                }
                if (perfn1->sort) {
-                       perf_key = (char *) perflist->data;
+                       perf_key = (char *) key;
                }
-               perflist = g_list_next(perflist);
        }
+
        wattroff(center, A_BOLD);
 
        g_ptr_array_sort_with_data(data->process_table, sort_perf, perf_key);
+
        for (i = 0; i < data->process_table->len && 
                        nblinedisplayed < max_center_lines; i++) {
-               GList *perf_keys;
                tmp = g_ptr_array_index(data->process_table, i);
 
                if (current_line == selected_line) {
@@ -496,32 +517,20 @@ void update_perf()
                mvwprintw(center, current_line + header_offset, 11, "%d", tmp->tid);
                mvwprintw(center, current_line + header_offset, 22, "%s", tmp->comm);
 
-               /* FIXME : sometimes there is a segfault here, I have no idea why :-( */
-               perf_keys = g_hash_table_get_keys(data->perf_list);
-               if (perf_keys)
-                       perflist = g_list_first(perf_keys);
-               else
-                       perflist = NULL;
+               g_hash_table_iter_init(&iter, data->perf_list);
 
                perf_row = 40;
-               j = 0;
-               while (perflist) {
-                       j++;
-                       perfn1 = g_hash_table_lookup(data->perf_list, perflist->data);
-                       if (!perfn1) {
-                               perflist = g_list_next(perflist);
-                               continue;
-                       }
+               while (g_hash_table_iter_next (&iter, &key, (gpointer) &perfn1)) {
                        if (perfn1->visible) {
-                               perfn2 = g_hash_table_lookup(tmp->perf, perflist->data);
+                               perfn2 = g_hash_table_lookup(tmp->perf, (char *) key);
                                if (perfn2)
                                        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;
                        }
-                       perflist = g_list_next(perflist);
                }
 
                wattroff(center, COLOR_PAIR(5));
@@ -575,8 +584,9 @@ 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;
@@ -592,6 +602,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);
@@ -619,24 +630,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 */
@@ -714,7 +729,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) {
@@ -965,12 +981,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();
This page took 0.035688 seconds and 4 git commands to generate.