/* We do not fail on add_counter here, as some counters may not exist on all * hosts. The rest will work, and the missing/failed counters will die nicely * elsewhere */ static int add_all_monitors() { int i; char tmp[512]; add_counter(PDH_USER, &(current_han[SG_WIN32_PROC_USER])); add_counter(PDH_PRIV, &(current_han[SG_WIN32_PROC_PRIV])); add_counter(PDH_IDLE, &(current_han[SG_WIN32_PROC_IDLE])); add_counter(PDH_INTER, &(current_han[SG_WIN32_PROC_INT])); add_counter(PDH_MEM_CACHE, &(current_han[SG_WIN32_MEM_CACHE])); add_counter(PDH_UPTIME, &(current_han[SG_WIN32_UPTIME])); add_counter(PDH_PAGEIN, &(current_han[SG_WIN32_PAGEIN])); add_counter(PDH_PAGEOUT, &(current_han[SG_WIN32_PAGEOUT])); diskio_names = get_instance_list("PhysicalDisk", &diskio_no); if (diskio_names != NULL) { diskio_rhan = (HCOUNTER *)malloc(sizeof(HCOUNTER) * diskio_no); if (diskio_rhan == NULL) { PdhCloseQuery(h_query); return -1; } diskio_whan = (HCOUNTER *)malloc(sizeof(HCOUNTER) * diskio_no); if (diskio_whan == NULL) { PdhCloseQuery(h_query); free (diskio_rhan); return -1; } for (i = 0; i < diskio_no; i++) { snprintf(tmp, sizeof(tmp), PDH_DISKIOREAD, diskio_names[i]); add_counter(tmp, &diskio_rhan[i]); snprintf(tmp, sizeof(tmp), PDH_DISKIOWRITE, diskio_names[i]); add_counter(tmp, &diskio_whan[i]); } } return 0; }
int main_menu(void) { MENU *my_menu = NULL; ITEM **my_items = NULL; struct tool_instance *list = NULL; const char *ret_msg = NULL; // Init at refresh for first loop. int c = 'R'; do { switch (c) { // Navigate in the menu case KEY_DOWN: case KEY_RIGHT: menu_driver(my_menu, REQ_DOWN_ITEM); break ; case KEY_UP: case KEY_LEFT: menu_driver(my_menu, REQ_UP_ITEM); break ; // Select a migration to monitor case ' ': case 13: // Enter key { if (item_count(my_menu) > 0) { ITEM *curitem = current_item(my_menu); if (view_instance(item_description(curitem)) != EXIT_SUCCESS) { ret_msg = "An error occured while trying to display the tool's data."; } } } // No break here to allow refreshing the list // when coming out of the instance display. // Refresh the list. case 'r': case 'R': if (list) clear_instance_list(list); list = get_instance_list(); if (list == NULL) mvprintw(0, 0, "cloudmig-view: No cloudmig tool is running at the moment.\n"); if (my_menu) clear_menu(my_menu, my_items); my_items = NULL; my_menu = NULL; if (fill_menu(list, &my_items, &my_menu)) return EXIT_FAILURE; post_menu(my_menu); break; // Leave the monitor case 'q': case 'Q': break ; // Ignore the others default: break ; } mvprintw(LINES - 4, 0, "Use <SPACE> or <ENTER> to select the process to monitor."); mvprintw(LINES - 3, 0, " <q> or <Q> to quit this program."); mvprintw(LINES - 2, 0, " <r> or <R> to see refresh the list manually."); if (ret_msg) { mvprintw(LINES -6, 0, "%.*s", COLS, ret_msg); ret_msg = NULL; } refresh(); } while ((c = getch()) != 'q'); return EXIT_FAILURE; }