diff options
author | Amit Arora <amit.arora@linaro.org> | 2010-10-27 12:02:53 +0530 |
---|---|---|
committer | Amit Arora <amit.arora@linaro.org> | 2010-10-27 12:07:03 +0530 |
commit | ed3e565b961db8dd95b098483d49b624268f3f97 (patch) | |
tree | e8423223db445de0ab7fe550201a242c170206a2 | |
parent | eb6cba934b52f6685394d04bd1937ab7309fc9e1 (diff) | |
download | powerdebug-ed3e565b961db8dd95b098483d49b624268f3f97.tar.gz |
Discover debugfs mntpoint and split header files
-rw-r--r-- | clocks.c | 54 | ||||
-rw-r--r-- | clocks.h | 38 | ||||
-rw-r--r-- | display.c | 1 | ||||
-rw-r--r-- | display.h | 28 | ||||
-rw-r--r-- | powerdebug.h | 29 |
5 files changed, 123 insertions, 27 deletions
@@ -15,6 +15,7 @@ *******************************************************************************/ #include "powerdebug.h" +#include "clocks.h" #include <errno.h> #include <sys/stat.h> @@ -27,7 +28,24 @@ static int gadder = 0; void init_clock_details(void) { - strcpy(clk_dir_path, "/debug/clock"); + char *path = debugfs_locate_mpoint(); + struct stat buf; + + + if (path) + strcpy(clk_dir_path, path); + else { + fprintf(stderr, "powerdebug: Unable to locate debugfs mount" + " point. Mount debugfs and try again..\n"); + exit(1); + } + sprintf(clk_dir_path, "%s/clock", clk_dir_path); + //strcpy(clk_dir_path, "/debug/clock"); // Hardcoded for testing.. + if (stat(clk_dir_path, &buf)) { + fprintf(stderr, "powerdebug: Unable to find clock tree" + " information at %s. Exiting..\n", clk_dir_path); + exit(1); + } strcpy(clk_name, ""); strcpy(highlighted_path, ""); } @@ -350,3 +368,37 @@ void print_clock_info(struct clock_info *clk, int level, int bmp) } } } + +char *debugfs_locate_mpoint(void) +{ + int ret; + FILE *filep; + char **path; + char fsname[64]; + struct statfs sfs; + + path = likely_mpoints; + while (*path) { + ret = statfs(*path, &sfs); + if (ret >= 0 && sfs.f_type == (long)DEBUGFS_MAGIC) + return *path; + path++; + } + + filep = fopen("/proc/mounts", "r"); + if (filep == NULL) { + fprintf(stderr, "powerdebug: Error opening /proc/mounts."); + exit(1); + } + + while (fscanf(filep, "%*s %s %s %*s %*d %*d\n", + debugfs_mntpoint, fsname) == 2) + if (!strcmp(fsname, "debugfs")) + break; + fclose(filep); + + if (strcmp(fsname, "debugfs")) + return NULL; + + return debugfs_mntpoint; +} diff --git a/clocks.h b/clocks.h new file mode 100644 index 0000000..91cf434 --- /dev/null +++ b/clocks.h @@ -0,0 +1,38 @@ +/******************************************************************************* + * Copyright (C) 2010, Linaro + * Copyright (C) 2010, IBM Corporation + * + * This file is part of PowerDebug. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Amit Arora <amit.arora@linaro.org> (IBM Corporation) + * - initial API and implementation + *******************************************************************************/ + +#include <sys/stat.h> +#include <sys/vfs.h> +#include <linux/magic.h> + +struct clock_info { + char name[NAME_MAX]; + int flags; + int rate; + int usecount; + int num_children; + int last_child; + struct clock_info *parent; + struct clock_info **children; +} *clocks_info; + +char debugfs_mntpoint[1024]; + +char *likely_mpoints[] = { + "/sys/kernel/debug", + "/debug", + NULL +}; @@ -15,6 +15,7 @@ *******************************************************************************/ #include "powerdebug.h" +#include "display.h" #define print(w, x, y, fmt, args...) do { mvwprintw(w, y, x, fmt, ##args); } while (0) #define NUM_FOOTER_ITEMS 5 diff --git a/display.h b/display.h new file mode 100644 index 0000000..c35bd44 --- /dev/null +++ b/display.h @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (C) 2010, Linaro + * Copyright (C) 2010, IBM Corporation + * + * This file is part of PowerDebug. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Amit Arora <amit.arora@linaro.org> (IBM Corporation) + * - initial API and implementation + *******************************************************************************/ + +#define VALUE_MAX 16 + +WINDOW windows[TOTAL_FEATURE_WINS]; + +#define PT_COLOR_DEFAULT 1 +#define PT_COLOR_HEADER_BAR 2 +#define PT_COLOR_ERROR 3 +#define PT_COLOR_RED 4 +#define PT_COLOR_YELLOW 5 +#define PT_COLOR_GREEN 6 +#define PT_COLOR_BRIGHT 7 +#define PT_COLOR_BLUE 8 diff --git a/powerdebug.h b/powerdebug.h index bb9f1c0..901cf77 100644 --- a/powerdebug.h +++ b/powerdebug.h @@ -27,12 +27,7 @@ #define VALUE_MAX 16 #define TOTAL_FEATURE_WINS 3 /* Regulator, Clock and Sensor (for now) */ - -WINDOW windows[TOTAL_FEATURE_WINS]; -extern char *win_names[TOTAL_FEATURE_WINS]; - enum {REGULATOR, CLOCK, SENSOR}; -extern int selectedwindow; struct regulator_info { char name[NAME_MAX]; @@ -50,16 +45,8 @@ struct regulator_info { int num_users; } *regulators_info; -struct clock_info { - char name[NAME_MAX]; - int flags; - int rate; - int usecount; - int num_children; - int last_child; - struct clock_info *parent; - struct clock_info **children; -} *clocks_info; +extern char *win_names[TOTAL_FEATURE_WINS]; +extern int selectedwindow; extern int numregulators; extern int dump; @@ -83,17 +70,7 @@ 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, int rate, int usecount, int highlight); - -#define PT_COLOR_DEFAULT 1 -#define PT_COLOR_HEADER_BAR 2 -#define PT_COLOR_ERROR 3 -#define PT_COLOR_RED 4 -#define PT_COLOR_YELLOW 5 -#define PT_COLOR_GREEN 6 -#define PT_COLOR_BRIGHT 7 -#define PT_COLOR_BLUE 8 - - +extern char *debugfs_locate_mpoint(void); extern void init_curses(void); extern void fini_curses(void); |