From: Daniel Lezcano dlezcano@fr.ibm.com
Signed-off-by: Daniel Lezcano dlezcano@fr.ibm.com --- clocks.c | 142 +++++++++++++++++++++++++++++----------------------------- clocks.h | 1 - powerdebug.c | 8 ++-- powerdebug.h | 7 +-- 4 files changed, 78 insertions(+), 80 deletions(-)
diff --git a/clocks.c b/clocks.c index 17d4f6a..4fe8093 100644 --- a/clocks.c +++ b/clocks.c @@ -21,7 +21,7 @@ static char clk_dir_path[PATH_MAX]; static char clk_name[NAME_MAX]; static int bold[MAX_LINES];
-int init_clock_details(void) +int init_clock_details(bool dump) { char *path = debugfs_locate_mpoint(); struct stat buf; @@ -81,7 +81,73 @@ int get_int_from(char *file) return atoi(result); }
-void find_parents_for_clock(char *clkname, int complete) +static void dump_parent(struct clock_info *clk, int line, bool dump) +{ + char *unit = "Hz"; + double drate; + static char spaces[64]; + char str[256]; + static int maxline; + + if (maxline < line) + maxline = line; + + if (clk && clk->parent) + dump_parent(clk->parent, ++line, dump); + + drate = (double)clk->rate; + if (drate > 1000 && drate < 1000000) { + unit = "KHz"; + drate /= 1000; + } + if (drate > 1000000) { + unit = "MHz"; + drate /= 1000000; + } + if (clk == clocks_info) { + line++; + strcpy(spaces, ""); + sprintf(str, "%s%s (flags:%d,usecount:%d,rate:%5.2f %s)\n", + spaces, clk->name, clk->flags, clk->usecount, drate, + unit); + } else { + if (!(clk->parent == clocks_info)) + strcat(spaces, " "); + sprintf(str, "%s`- %s (flags:%d,usecount:%d,rate:%5.2f %s)\n", + spaces, clk->name, clk->flags, clk->usecount, drate, + unit); + } + if (dump) + //printf("line=%d:m%d:l%d %s", maxline - line + 2, maxline, line, str); + printf("%s", str); + else + print_one_clock(maxline - line + 2, str, 1, 0); +} + +static void dump_all_parents(char *clkarg, bool dump) +{ + struct clock_info *clk; + char spaces[1024]; + + strcpy(spaces, ""); + + clk = find_clock(clocks_info, clkarg); + + if (!clk) + printf("Clock NOT found!\n"); + else { + /* while(clk && clk != clocks_info) { */ + /* printf("%s\n", clk->name); */ + /* strcat(spaces, " "); */ + /* clk = clk->parent; */ + /* printf("%s <-- ", spaces); */ + /* } */ + /* printf(" /\n"); */ + dump_parent(clk, 1, dump); + } +} + +void find_parents_for_clock(char *clkname, int complete, bool dump) { char name[256];
@@ -96,7 +162,7 @@ void find_parents_for_clock(char *clkname, int complete) } sprintf(name, "Parents for "%s" Clock : \n", clkname); print_one_clock(0, name, 1, 1); - dump_all_parents(clkname); + dump_all_parents(clkname, dump); }
int read_and_print_clock_info(int verbose, int hrow, int selected) @@ -262,11 +328,11 @@ void destroy_clocks_info_recur(struct clock_info *clock) } }
-void read_and_dump_clock_info_one(char *clk) +void read_and_dump_clock_info_one(char *clk, bool dump) { printf("\nParents for "%s" Clock :\n\n", clk); read_clock_info(clk_dir_path); - dump_all_parents(clk); + dump_all_parents(clk, dump); printf("\n\n"); }
@@ -396,72 +462,6 @@ void insert_children(struct clock_info **parent, struct clock_info *clk) (*parent)->num_children++; }
-void dump_parent(struct clock_info *clk, int line) -{ - char *unit = "Hz"; - double drate; - static char spaces[64]; - char str[256]; - static int maxline; - - if (maxline < line) - maxline = line; - - if (clk && clk->parent) - dump_parent(clk->parent, ++line); - - drate = (double)clk->rate; - if (drate > 1000 && drate < 1000000) { - unit = "KHz"; - drate /= 1000; - } - if (drate > 1000000) { - unit = "MHz"; - drate /= 1000000; - } - if (clk == clocks_info) { - line++; - strcpy(spaces, ""); - sprintf(str, "%s%s (flags:%d,usecount:%d,rate:%5.2f %s)\n", - spaces, clk->name, clk->flags, clk->usecount, drate, - unit); - } else { - if (!(clk->parent == clocks_info)) - strcat(spaces, " "); - sprintf(str, "%s`- %s (flags:%d,usecount:%d,rate:%5.2f %s)\n", - spaces, clk->name, clk->flags, clk->usecount, drate, - unit); - } - if (dump) - //printf("line=%d:m%d:l%d %s", maxline - line + 2, maxline, line, str); - printf("%s", str); - else - print_one_clock(maxline - line + 2, str, 1, 0); -} - -void dump_all_parents(char *clkarg) -{ - struct clock_info *clk; - char spaces[1024]; - - strcpy(spaces, ""); - - clk = find_clock(clocks_info, clkarg); - - if (!clk) - printf("Clock NOT found!\n"); - else { -// while(clk && clk != clocks_info) { -// printf("%s\n", clk->name); -// strcat(spaces, " "); -// clk = clk->parent; -// printf("%s <-- ", spaces); -// } -// printf(" /\n"); - dump_parent(clk, 1); - } -} - struct clock_info *find_clock(struct clock_info *clk, char *clkarg) { int i; diff --git a/clocks.h b/clocks.h index 0fce60d..b8a100b 100644 --- a/clocks.h +++ b/clocks.h @@ -52,5 +52,4 @@ void add_clock_details_recur(struct clock_info *clk, int hrow, int selected); void destroy_clocks_info(void); void destroy_clocks_info_recur(struct clock_info *clock); void collapse_all_subclocks(struct clock_info *clock); -void dump_all_parents(char *clkarg); struct clock_info *find_clock(struct clock_info *clk, char *clkarg); diff --git a/powerdebug.c b/powerdebug.c index 37225a6..2f3a77d 100644 --- a/powerdebug.c +++ b/powerdebug.c @@ -18,7 +18,7 @@ #include <stdbool.h> #include "powerdebug.h"
-bool dump = false; +static bool dump = false; int highlighted_row; int selectedwindow = -1;
@@ -277,7 +277,7 @@ int mainloop(struct powerdebug_options *options) if (options->clocks || selectedwindow == CLOCK) { int ret = 0; if (firsttime[CLOCK]) { - ret = init_clock_details(); + ret = init_clock_details(dump); if (!ret) firsttime[CLOCK] = 0; strcpy(clkname_str, ""); @@ -301,11 +301,11 @@ int mainloop(struct powerdebug_options *options) enter_hit = false; } else find_parents_for_clock(clkname_str, - enter_hit); + enter_hit, dump); } if (!ret && dump) { if (options->findparent) - read_and_dump_clock_info_one(options->clkarg); + read_and_dump_clock_info_one(options->clkarg, dump); else read_and_dump_clock_info(options->verbose); } diff --git a/powerdebug.h b/powerdebug.h index a8e7de2..f6358e0 100644 --- a/powerdebug.h +++ b/powerdebug.h @@ -34,7 +34,6 @@ extern struct regulator_info *regulators_info; extern int selectedwindow;
extern int numregulators; -extern bool dump;
extern int init_regulator_ds(void); extern void print_regulator_info(int verbose); @@ -42,17 +41,17 @@ extern void read_regulator_info(void); extern void print_regulator_info(int verbose);
extern void read_and_dump_clock_info(int verbose); -extern void read_and_dump_clock_info_one(char *clk); +extern void read_and_dump_clock_info_one(char *clk, bool dump); extern void read_clock_info(char *clkpath); extern struct clock_info *read_clock_info_recur(char *clkpath, int level, struct clock_info *parent); extern void dump_clock_info(struct clock_info *clk, int level, int bmp); extern void insert_children(struct clock_info **parent, struct clock_info *clk); -extern void find_parents_for_clock(char *clkname, int complete); +extern void find_parents_for_clock(char *clkname, int complete, bool dump); extern int read_and_print_clock_info(int verbose, int hrow, int selected); extern void print_clock_info(int verbose, int hrow, int selected); extern void print_string_val(char *name, char *val); -extern int init_clock_details(void); +extern int init_clock_details(bool dump); extern void print_clock_header(void); extern void print_one_clock(int line, char *str, int bold, int highlight); extern char *debugfs_locate_mpoint(void);