From patchwork Mon Jun 20 22:58:22 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 2101 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 46E7D23E54 for ; Mon, 20 Jun 2011 22:59:00 +0000 (UTC) Received: from mail-vw0-f52.google.com (mail-vw0-f52.google.com [209.85.212.52]) by fiordland.canonical.com (Postfix) with ESMTP id 1808AA1805E for ; Mon, 20 Jun 2011 22:59:00 +0000 (UTC) Received: by mail-vw0-f52.google.com with SMTP id 16so4124077vws.11 for ; Mon, 20 Jun 2011 15:58:59 -0700 (PDT) Received: by 10.52.175.197 with SMTP id cc5mr4324645vdc.287.1308610739823; Mon, 20 Jun 2011 15:58:59 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.52.183.130 with SMTP id em2cs32816vdc; Mon, 20 Jun 2011 15:58:59 -0700 (PDT) Received: by 10.216.18.72 with SMTP id k50mr1474853wek.49.1308610737376; Mon, 20 Jun 2011 15:58:57 -0700 (PDT) Received: from smtp.smtpout.orange.fr (smtp03.smtpout.orange.fr [80.12.242.125]) by mx.google.com with ESMTP id b42si13985751wek.104.2011.06.20.15.58.56; Mon, 20 Jun 2011 15:58:57 -0700 (PDT) Received-SPF: neutral (google.com: 80.12.242.125 is neither permitted nor denied by best guess record for domain of daniel.lezcano@linaro.org) client-ip=80.12.242.125; Authentication-Results: mx.google.com; spf=neutral (google.com: 80.12.242.125 is neither permitted nor denied by best guess record for domain of daniel.lezcano@linaro.org) smtp.mail=daniel.lezcano@linaro.org Received: from monster.dhcp.lxc ([92.134.95.191]) by mwinf5d06 with ME id yNyp1g00347kPVY03NywDP; Tue, 21 Jun 2011 00:58:56 +0200 From: Daniel Lezcano To: linaro-dev@lists.linaro.org Subject: [powerdebug 14/17] Optimize the code Date: Tue, 21 Jun 2011 00:58:22 +0200 Message-Id: <1308610705-23281-14-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1308610705-23281-1-git-send-email-daniel.lezcano@linaro.org> References: <1308610705-23281-1-git-send-email-daniel.lezcano@linaro.org> 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 --- clocks.c | 13 +++++++------ display.c | 13 ++++++------- display.h | 3 +-- regulator.c | 2 +- sensor.c | 2 +- 5 files changed, 16 insertions(+), 17 deletions(-) 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;