diff mbox

[powerdebug,14/17] Optimize the code

Message ID 1308610705-23281-14-git-send-email-daniel.lezcano@linaro.org
State Accepted
Headers show

Commit Message

Daniel Lezcano June 20, 2011, 10:58 p.m. UTC
With this patch the content of the debugfs file is readen only when the
'refresh' button is hit and at the init of powerdebug.

Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
---
 clocks.c    |   13 +++++++------
 display.c   |   13 ++++++-------
 display.h   |    3 +--
 regulator.c |    2 +-
 sensor.c    |    2 +-
 5 files changed, 16 insertions(+), 17 deletions(-)
diff mbox

Patch

diff --git a/clocks.c b/clocks.c
index 6943b70..0bd0a0e 100644
--- a/clocks.c
+++ b/clocks.c
@@ -262,6 +262,10 @@  static int _clock_print_info_cb(struct tree *t, void *data)
 
 static int clock_print_info_cb(struct tree *t, void *data)
 {
+        /* we skip the root node of the tree */
+	if (!t->parent)
+		return 0;
+
         /* show the clock when *all* its parent is expanded */
 	if (tree_for_each_parent(t->parent, is_collapsed, NULL))
 		return 0;
@@ -315,9 +319,9 @@  static int clock_select(void)
  * found in the files. Then print the result to the text based interface
  * Return 0 on success, < 0 otherwise
  */
-static int clock_display(void)
+static int clock_display(bool refresh)
 {
-	if (read_clock_info(clock_tree))
+	if (refresh && read_clock_info(clock_tree))
 		return -1;
 
 	return clock_print_info(clock_tree);
@@ -334,13 +338,10 @@  static int clock_find(const char *name)
 
 	for (i = 0; i < nr; i++) {
 
-		ret = read_clock_info(ptree[i]);
-		if (ret)
-			break;
-
 		ret = _clock_print_info_cb(ptree[i], &line);
 		if (ret)
 			break;
+
 	}
 
 	display_refresh_pad(CLOCK);
diff --git a/display.c b/display.c
index 38596b0..23a4172 100644
--- a/display.c
+++ b/display.c
@@ -111,14 +111,14 @@  static int display_show_footer(int win, char *string)
 	return 0;
 }
 
-int display_refresh(int win)
+static int display_refresh(int win, bool read)
 {
 	/* we are trying to refresh a window which is not showed */
 	if (win != current_win)
 		return 0;
 
 	if (windata[win].ops && windata[win].ops->display)
-		return windata[win].ops->display();
+		return windata[win].ops->display(read);
 
 	return 0;
 }
@@ -391,13 +391,12 @@  static int display_keystroke(int fd, void *data)
 
 	case 'r':
 	case 'R':
-		/* refresh will be done after */
-		break;
+		return display_refresh(current_win, true);
 	default:
 		return 0;
 	}
 
-	display_refresh(current_win);
+	display_refresh(current_win, false);
 
 	return 0;
 }
@@ -416,7 +415,7 @@  static int display_switch_to_main(int fd)
 	if (display_show_footer(current_win, NULL))
 		return -1;
 
-	return display_refresh(current_win);
+	return display_refresh(current_win, false);
 }
 
 static int display_find_keystroke(int fd, void *data)
@@ -547,7 +546,7 @@  int display_init(int wdefault)
 	if (display_show_footer(wdefault, NULL))
 		return -1;
 
-	return display_refresh(wdefault);
+	return display_refresh(wdefault, true);
 }
 
 int display_column_name(const char *line)
diff --git a/display.h b/display.h
index 7fa5361..9e4e21a 100644
--- a/display.h
+++ b/display.h
@@ -16,7 +16,7 @@ 
 enum { CLOCK, REGULATOR, SENSOR };
 
 struct display_ops {
-	int (*display)(void);
+	int (*display)(bool refresh);
 	int (*select)(void);
 	int (*find)(const char *);
 	int (*selectf)(void);
@@ -31,5 +31,4 @@  extern void *display_get_row_data(int window);
 
 extern int display_init(int wdefault);
 extern int display_register(int win, struct display_ops *ops);
-extern int display_refresh(int win);
 extern int display_column_name(const char *line);
diff --git a/regulator.c b/regulator.c
index 97ab15b..849f906 100644
--- a/regulator.c
+++ b/regulator.c
@@ -156,7 +156,7 @@  static int regulator_print_header(void)
 
 }
 
-static int regulator_display(void)
+static int regulator_display(bool refresh)
 {
 	int ret, line = 0;
 
diff --git a/sensor.c b/sensor.c
index 2a8f4bb..d63510e 100644
--- a/sensor.c
+++ b/sensor.c
@@ -250,7 +250,7 @@  static int sensor_print_header(void)
 	return ret;
 }
 
-static int sensor_display(void)
+static int sensor_display(bool refresh)
 {
 	int ret, line = 0;