diff options
-rw-r--r-- | clocks.c | 99 | ||||
-rw-r--r-- | display.c | 63 | ||||
-rw-r--r-- | powerdebug.c | 52 | ||||
-rw-r--r-- | powerdebug.h | 10 |
4 files changed, 168 insertions, 56 deletions
@@ -15,8 +15,21 @@ *******************************************************************************/ #include "powerdebug.h" -#include<error.h> -#include<errno.h> +#include <errno.h> + +static int clk_tree_level = 1; +static char clk_dir_path[PATH_MAX]; +static char highlighted_path[PATH_MAX]; +static char clk_name[NAME_MAX]; +static int gadder = 0; + + +void init_clock_details(void) +{ + strcpy(clk_dir_path, "/debug/clock"); + strcpy(clk_name, ""); + strcpy(highlighted_path, ""); +} int get_int_from(char *file) { @@ -35,29 +48,65 @@ int get_int_from(char *file) return atoi(result); } -int read_and_print_clock_info(int verbose, int hrow) +int read_and_print_clock_info(int verbose, int hrow, int selected) +{ + if (selected) { + // if (!(strcmp(clk_dir_path, "/debug/clock") && + // strcmp(highlighted_path, ".."))) { + strcpy(clk_dir_path, highlighted_path); + hrow = 0; + clk_tree_level += gadder; + if (clk_tree_level <=0) + clk_tree_level = 1; + } + + hrow = read_and_print_clock_one_level(verbose, hrow, selected); + + return hrow; +} + +void set_hl_dir_path_to_parent(void) +{ + char *ptr; + + strcpy(highlighted_path, clk_dir_path); + if (strcmp(clk_dir_path, "/clock/debug")) { + ptr = strrchr(highlighted_path, '/'); + if (ptr) + ptr[0]='\0'; + } +} + +int read_and_print_clock_one_level(int verbose, int hrow, int selected) { int line = 0, usecount = 0, flags = 0, rate = 0; +// int parent_dir_row = 1000; DIR *dir, *subdir; char filename[PATH_MAX], devpath[PATH_MAX], clockname[NAME_MAX]; struct dirent *item, *subitem; (void)verbose; - print_clock_header(1); + print_clock_header(clk_tree_level); - sprintf(filename, "%s", "/debug/clock"); + sprintf(filename, "%s", clk_dir_path); dir = opendir(filename); if (!dir) return 0; while ((item = readdir(dir))) { - if (item->d_name[0] == '.') /* skip the hidden files */ + /* skip hidden dirs except ".." */ + if (item->d_name[0] == '.' && strcmp(item->d_name, "..")) continue; - sprintf(devpath, "/debug/clock/%s", item->d_name); - strcpy(clockname, item->d_name); + if (selected && hrow == line && !strcmp(item->d_name, "..")) { + sprintf(devpath, "%s", clk_dir_path); + strcpy(clockname, ".."); + } else { + sprintf(devpath, "%s/%s", clk_dir_path, item->d_name); + strcpy(clockname, item->d_name); + } subdir = opendir(devpath); @@ -80,8 +129,38 @@ int read_and_print_clock_info(int verbose, int hrow) usecount = get_int_from(filename); } - print_clock_info_line(line, clockname, flags, rate, - usecount, (hrow == line) ? 1 : 0); + if (hrow == line) { + if (!strcmp(clockname, "..")) { + if (clk_tree_level != 1) { + set_hl_dir_path_to_parent(); + gadder = -1; + } + } else { + strcpy(highlighted_path, devpath); + gadder = 1; + } + } + +// sprintf(clockname, "%s:dp-%s:n-%s:hp-%s", +// clockname, clk_dir_path, clk_name, highlighted_path); + +/* if (strcmp(clockname, "..")) { + int row = line + 1; + + if (line > parent_dir_row) + row--; + print_clock_info_line(row, clockname, flags, rate, usecount, + (hrow == line) ? 1 : 0); + } else { + print_clock_info_line(0, clockname, flags, rate, usecount, + (hrow == line) ? 1 : 0); + parent_dir_row = line; + } +*/ + + print_clock_info_line(line, clockname, flags, rate, usecount, + (hrow == line) ? 1 : 0); + line++; closedir(subdir); } @@ -101,9 +101,15 @@ void create_windows(void) } -int create_regulator_win(int row, int maxrows) +/* + * maxrows is the MAXIMUM number of rows we need for this window + * pshare is the minimum number of rows we should have for this (in %age) + * maxrows prevails in case of an argument ! + */ +int create_regulator_win(int row, int maxrows, int *pshare) { int numrows; + int idealrows; // Based on pshare provided to us if (regulator_win) { delwin(regulator_win); @@ -111,10 +117,13 @@ int create_regulator_win(int row, int maxrows) } getmaxyx(stdscr, maxy, maxx); - if (maxrows < (maxy/2 - 2)) + + idealrows = ((maxy - 2) * (*pshare)) / 100; + if (maxrows < idealrows) { numrows = maxrows; - else - numrows = maxy/2 - 2; + *pshare = (numrows * 100) / maxy; + } else + numrows = idealrows; regulator_win = subwin(stdscr, numrows, maxx, row, 0); refresh(); @@ -122,9 +131,10 @@ int create_regulator_win(int row, int maxrows) return numrows + row; } -int create_clock_win(int row, int maxrows) +int create_clock_win(int row, int maxrows, int *pshare) { int numrows; + int idealrows; if (clock_win) { delwin(clock_win); @@ -132,10 +142,12 @@ int create_clock_win(int row, int maxrows) } getmaxyx(stdscr, maxy, maxx); - if (maxrows < (maxy/2 - 2)) + idealrows = ((maxy - 2) * (*pshare)) / 100; + + if (maxrows < idealrows) numrows = maxrows; else - numrows = maxy/2 - 2; + numrows = idealrows; clock_win = subwin(stdscr, numrows, maxx, row, 0); refresh(); @@ -143,9 +155,10 @@ int create_clock_win(int row, int maxrows) return numrows + row; } -int create_sensor_win(int row, int maxrows) +int create_sensor_win(int row, int maxrows, int *pshare) { int numrows; + int idealrows; if (sensor_win) { delwin(sensor_win); @@ -153,10 +166,12 @@ int create_sensor_win(int row, int maxrows) } getmaxyx(stdscr, maxy, maxx); - if (maxrows < 4) + idealrows = ((maxy - 2) * (*pshare)) / 100; + + if (maxrows < idealrows) numrows = maxrows; else - numrows = 4; + numrows = idealrows; sensor_win = subwin(stdscr, numrows, maxx, row, 0); refresh(); @@ -284,20 +299,22 @@ void print_sensor_header(void) void print_clock_info_line(int line, char *clockname, int flags, int rate, int usecount, int highlight) { - if (highlight) { - //wattrset(clock_win, COLOR_PAIR(PT_COLOR_RED)); - //wbkgd(clock_win, COLOR_PAIR(PT_COLOR_RED)); - wattron(clock_win, WA_BOLD); - } + if (highlight) + wattron(clock_win, WA_BOLD|WA_STANDOUT); + else + wattron(clock_win, WA_DIM); + print(clock_win, 0, line + 2, "%s", clockname); - print(clock_win, 24, line + 2, "%d", flags); - print(clock_win, 36, line + 2, "%d", rate); - print(clock_win, 48, line + 2, "%d", usecount); - if (highlight) { - //use_default_colors(); - //wattrset(clock_win, COLOR_PAIR(PT_COLOR_DEFAULT)); - //wbkgd(clock_win, COLOR_PAIR(PT_COLOR_DEFAULT)); - wattroff(clock_win, WA_BOLD); + if (strcmp(clockname, "..")) { + print(clock_win, 24, line + 2, "%d", flags); + print(clock_win, 36, line + 2, "%d", rate); + print(clock_win, 48, line + 2, "%d", usecount); } + + if (highlight) + wattroff(clock_win, WA_BOLD|WA_STANDOUT); + else + wattroff(clock_win, WA_DIM); + wrefresh(clock_win); } diff --git a/powerdebug.c b/powerdebug.c index 1417cb2..043c0ce 100644 --- a/powerdebug.c +++ b/powerdebug.c @@ -41,9 +41,8 @@ int init_regulator_ds(void) regulators_info = (struct regulator_info *)malloc(numregulators* sizeof(struct regulator_info)); if (!regulators_info) { - fprintf(stderr, "init_regulator_ds: Not enough memory to "); - fprintf(stderr, "read information for %d regulators!\n", - numregulators); + fprintf(stderr, "init_regulator_ds: Not enough memory to " + "read information for %d regulators!\n", numregulators); return(1); } @@ -231,7 +230,9 @@ int main(int argc, char **argv) { int c; int firsttime = 1; + int enter_hit = 0; int regulators = 0, sensors = 0, clocks = 0, verbose = 0; + int r_share = 0, s_share = 0, c_share = 0; //%age share of the win size /* * Options: @@ -314,19 +315,32 @@ int main(int argc, char **argv) int row = 1; if (!dump) { - if(firsttime) { + if(firsttime) init_curses(); - firsttime = 0; - } create_windows(); show_header(); + if (sensors) + s_share = 20; + if (regulators) { + if (!sensors && clocks) + r_share = 50; + else if (clocks) + r_share = 40; + else + r_share = 80; + } + c_share = 100 - (r_share + s_share); } if (regulators) { read_regulator_info(); if (!dump) { + int orig_r_share = r_share; + row = create_regulator_win(row, -numregulators+2); + numregulators + 2, + &r_share); + c_share += (orig_r_share - r_share); show_regulator_info(verbose); } else @@ -335,15 +349,20 @@ numregulators+2); if (clocks && !dump) { int hrow; - row = create_clock_win(row, 100);//giv big no.as of now + + if (firsttime) + init_clock_details(); + row = create_clock_win(row, 100, &c_share);//giv big no.as of now hrow = read_and_print_clock_info(verbose, - highlighted_row); + highlighted_row, + enter_hit); highlighted_row = hrow; + enter_hit = 0; } if (sensors) { if (!dump) { - row = create_sensor_win(row, 100);//big no. as of now + row = create_sensor_win(row, 100, &s_share);//big no. as of now print_sensor_header(); } else @@ -371,21 +390,16 @@ numregulators+2); highlighted_row++; keychar = toupper(keystroke); -#ifdef DEBUG_KEY - if (keystroke == 13) { - killall_windows(); - fini_curses(); - printf("powerdebug: key=%d : char=%c\n", keystroke, keychar); - printf("highlighted_row = %d\n", highlighted_row); - exit(0); - } -#endif + if (keystroke == 13) + enter_hit = 1; if (keychar == 'Q') exit(0); if (keychar == 'R') ticktime = 3; } + if (firsttime) + firsttime = 0; } exit(0); diff --git a/powerdebug.h b/powerdebug.h index 45b1872..356308c 100644 --- a/powerdebug.h +++ b/powerdebug.h @@ -56,9 +56,11 @@ extern int dump; extern void usage(char **argv); extern void version(void); extern void print_regulator_info(int verbose); -extern int read_and_print_clock_info(int verbose, int hrow); +extern int read_and_print_clock_info(int verbose, int hrow, int selected); +extern int read_and_print_clock_one_level(int verbose, int hrow, int selected); extern void get_sensor_info(char *path, char *name, char *sensor, int verbose); extern void print_string_val(char *name, char *val); +extern void init_clock_details(void); extern void print_clock_header(int level); extern void print_sensor_header(void); extern void print_clock_info_line(int line, char *clockname, int flags, @@ -80,7 +82,7 @@ extern void fini_curses(void); extern void killall_windows(void); extern void show_header(void); extern void create_windows(void); -extern int create_regulator_win(int row, int numrows); -extern int create_clock_win(int row, int numrows); -extern int create_sensor_win(int row, int numrows); +extern int create_regulator_win(int row, int numrows, int *pshare); +extern int create_clock_win(int row, int numrows, int *pshare); +extern int create_sensor_win(int row, int numrows, int *pshare); extern void show_regulator_info(int verbose); |