diff options
author | Amit Arora <amit.arora@linaro.org> | 2010-12-02 12:23:14 +0530 |
---|---|---|
committer | Amit Arora <amit.arora@linaro.org> | 2010-12-02 12:23:14 +0530 |
commit | 175527852cbe004893bc6f0cb59f4e9702db85ba (patch) | |
tree | 681e5a8cf41aa4848c65d78eaaaafb8e290ac71e | |
parent | 83ae6cbe2dc075e16bba51b0f8d641bad97b8fd3 (diff) | |
download | powerdebugV2-175527852cbe004893bc6f0cb59f4e9702db85ba.tar.gz |
Move around code to more logical destination
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | display.c | 1 | ||||
-rw-r--r-- | output.c | 101 | ||||
-rw-r--r-- | powerdebug.c | 193 | ||||
-rw-r--r-- | powerdebug.h | 28 | ||||
-rw-r--r-- | regulator.c | 197 | ||||
-rw-r--r-- | regulator.h | 55 | ||||
-rw-r--r-- | sensor.c | 65 |
8 files changed, 345 insertions, 297 deletions
@@ -5,7 +5,7 @@ WARNFLAGS=-Wall -Wshadow -W -Wformat -Wimplicit-function-declaration -Wimplicit- CFLAGS?=-O1 -g ${WARNFLAGS} CC?=gcc -OBJS = powerdebug.o output.o sensor.o clocks.o display.o +OBJS = powerdebug.o sensor.o clocks.o regulator.o display.o default: powerdebug @@ -15,6 +15,7 @@ *******************************************************************************/ #include "powerdebug.h" +#include "regulator.h" #include "display.h" #define print(w, x, y, fmt, args...) do { mvwprintw(w, y, x, fmt, ##args); } while (0) diff --git a/output.c b/output.c deleted file mode 100644 index 9d0d76c..0000000 --- a/output.c +++ /dev/null @@ -1,101 +0,0 @@ -/******************************************************************************* - * 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 "powerdebug.h" - -void usage(char **argv) -{ - printf("Usage: %s [OPTIONS]\n", argv[0]); - printf(" -r, --regulator Show regulator information\n"); - printf(" -s, --sensor Show sensor information\n"); - printf(" -c, --clock Show clock information\n"); - printf(" -p, --findparents Show all parents for a particular clock\n"); - printf(" -t, --time Set ticktime in seconds (eg. 10.0)\n"); - printf(" -d, --dump Dump information once (no refresh)\n"); - printf(" -v, --verbose Verbose mode (use with -r and/or -s)\n"); - printf(" -V, --version Show Version\n"); - printf(" -h, --help Help\n"); - - exit(0); -} - -void version() -{ - printf("powerdebug version %s\n", VERSION); - exit(0); -} - -void print_string_val(char *name, char *val) -{ - printf("\t%s=%s", name, val); - if(!strchr(val, '\n')) - printf("\n"); -} - -void print_regulator_info(int verbose) -{ - int i; - - for (i=0; i<numregulators; i++) { - printf("Regulator %d:\n", i+1); - print_string_val("name", regulators_info[i].name); - if (strcmp(regulators_info[i].status, "")) - print_string_val("status", regulators_info[i].status); - if (strcmp(regulators_info[i].state, "")) - print_string_val("state", regulators_info[i].state); - - if (!verbose) - continue; - - if (strcmp(regulators_info[i].type, "")) - print_string_val("type", regulators_info[i].type); - if (strcmp(regulators_info[i].opmode, "")) - print_string_val("opmode", regulators_info[i].opmode); - - if (regulators_info[i].microvolts) - printf("\tmicrovolts=%d\n", - regulators_info[i].microvolts); - if (regulators_info[i].min_microvolts) - printf("\tmin_microvolts=%d\n", - regulators_info[i].min_microvolts); - if (regulators_info[i].max_microvolts) - printf("\tmax_microvolts=%d\n", - regulators_info[i].max_microvolts); - - if (regulators_info[i].microamps) - printf("\tmicroamps=%d\n", - regulators_info[i].microamps); - if (regulators_info[i].min_microamps) - printf("\tmin_microamps=%d\n", - regulators_info[i].min_microamps); - if (regulators_info[i].max_microamps) - printf("\tmax_microamps=%d\n", - regulators_info[i].max_microamps); - if (regulators_info[i].requested_microamps) - printf("\trequested_microamps=%d\n", - regulators_info[i].requested_microamps); - - if (regulators_info[i].num_users) - printf("\tnum_users=%d\n", - regulators_info[i].num_users); - printf("\n"); - } - - if (!numregulators && verbose) { - printf("Could not find regulator information!"); - printf(" Looks like /sys/class/regulator is empty.\n\n"); - } -} diff --git a/powerdebug.c b/powerdebug.c index c94c14b..5ebb01e 100644 --- a/powerdebug.c +++ b/powerdebug.c @@ -28,190 +28,28 @@ char *win_names[TOTAL_FEATURE_WINS] = { "Clocks", "Sensors" }; -int init_regulator_ds(void) +void usage(char **argv) { - DIR *regdir; - struct dirent *item; + printf("Usage: %s [OPTIONS]\n", argv[0]); + printf(" -r, --regulator Show regulator information\n"); + printf(" -s, --sensor Show sensor information\n"); + printf(" -c, --clock Show clock information\n"); + printf(" -p, --findparents Show all parents for a particular clock\n"); + printf(" -t, --time Set ticktime in seconds (eg. 10.0)\n"); + printf(" -d, --dump Dump information once (no refresh)\n"); + printf(" -v, --verbose Verbose mode (use with -r and/or -s)\n"); + printf(" -V, --version Show Version\n"); + printf(" -h, --help Help\n"); - regdir = opendir("/sys/class/regulator"); - if (!regdir) - return(1); - while((item = readdir(regdir))) { - if (strncmp(item->d_name, "regulator", 9)) - continue; - - numregulators++; - } - closedir(regdir); - - regulators_info = (struct regulator_info *)malloc(numregulators* - sizeof(struct regulator_info)); - if (!regulators_info) { - fprintf(stderr, "init_regulator_ds: Not enough memory to " - "read information for %d regulators!\n", numregulators); - return(1); - } - - return(0); -} - -int read_and_print_sensor_info(int verbose) -{ - DIR *dir, *subdir; - int len, found = 0; - char filename[PATH_MAX], devpath[PATH_MAX]; - char device[PATH_MAX]; - struct dirent *item, *subitem; - - sprintf(filename, "%s", "/sys/class/hwmon"); - dir = opendir(filename); - if (!dir) - return errno; - - while ((item = readdir(dir))) { - if (item->d_name[0] == '.') /* skip the hidden files */ - continue; - - found = 1; - - sprintf(filename, "/sys/class/hwmon/%s", item->d_name); - sprintf(devpath, "%s/device", filename); - - len = readlink(devpath, device, PATH_MAX - 1); - - if (len < 0) - strcpy(devpath, filename); - else - device[len] = '\0'; - - subdir = opendir(devpath); - - printf("\nSensor Information for %s :\n", item->d_name); - fflush(stdin); - - while ((subitem = readdir(subdir))) { - if (subitem->d_name[0] == '.') /* skip hidden files */ - continue; - - if(!strncmp(subitem->d_name, "in", 2)) - get_sensor_info(devpath, subitem->d_name, "in", - verbose); - else if (!strncmp(subitem->d_name, "temp", 4)) - get_sensor_info(devpath, subitem->d_name, - "temp", verbose); - else if (!strncmp(subitem->d_name, "fan", 4)) - get_sensor_info(devpath, subitem->d_name, - "fan", verbose); - else if (!strncmp(subitem->d_name, "pwm", 4)) - get_sensor_info(devpath, subitem->d_name, - "pwm", verbose); - - } - - closedir(subdir); - } - closedir(dir); - - if(!found && verbose) { - printf("Could not find sensor information!"); - printf(" Looks like /sys/class/hwmon is empty.\n"); - } - - return 0; -} - -void read_info_from_dirent(struct dirent *ritem, char *str, int idx) -{ - if (!strcmp(ritem->d_name, "name")) - strcpy(regulators_info[idx].name, str); - if (!strcmp(ritem->d_name, "state")) - strcpy(regulators_info[idx].state, str); - if (!strcmp(ritem->d_name, "status")) - strcpy(regulators_info[idx].status, str); - - if (!strcmp(ritem->d_name, "type")) - strcpy(regulators_info[idx].type, str); - if (!strcmp(ritem->d_name, "opmode")) - strcpy(regulators_info[idx].opmode, str); - - if (!strcmp(ritem->d_name, "microvolts")) - regulators_info[idx].microvolts = atoi(str); - if (!strcmp(ritem->d_name, "min_microvolts")) - regulators_info[idx].min_microvolts = atoi(str); - if (!strcmp(ritem->d_name, "max_microvolts")) - regulators_info[idx].max_microvolts = atoi(str); - - if (!strcmp(ritem->d_name, "microamps")) - regulators_info[idx].microamps = atoi(str); - if (!strcmp(ritem->d_name, "min_microamps")) - regulators_info[idx].min_microamps = atoi(str); - if (!strcmp(ritem->d_name, "max_microamps")) - regulators_info[idx].max_microamps = atoi(str); - if (!strcmp(ritem->d_name, "requested_microamps")) - regulators_info[idx].requested_microamps = atoi(str); - - if (!strcmp(ritem->d_name, "num_users")) - regulators_info[idx].num_users = atoi(str); + exit(0); } -int read_regulator_info(void) +void version() { - FILE *file = NULL; - DIR *regdir, *dir; - int len, count = 0, ret = 0; - char line[1024], filename[1024], *fptr; - struct dirent *item, *ritem; - - regdir = opendir("/sys/class/regulator"); - if (!regdir) - return(1); - while((item = readdir(regdir))) { - if (strlen(item->d_name) < 3) - continue; - - if (strncmp(item->d_name, "regulator", 9)) - continue; - - len = sprintf(filename, "/sys/class/regulator/%s", - item->d_name); - - dir = opendir(filename); - if (!dir) - continue; - count++; - - if (count > numregulators) { - ret = 1; - goto exit; - } - - strcpy(regulators_info[count-1].name, item->d_name); - while((ritem = readdir(dir))) { - if (strlen(ritem->d_name) < 3) - continue; - - sprintf(filename + len, "/%s", ritem->d_name); - file = fopen(filename, "r"); - if (!file) - continue; - memset(line, 0, 1024); - fptr = fgets(line, 1024, file); - fclose(file); - if (!fptr) - continue; - read_info_from_dirent(ritem, fptr, count - 1); - } -exit: - closedir(dir); - if (ret) - break; - } - closedir(regdir); - - return ret; + printf("powerdebug version %s\n", VERSION); + exit(0); } - int main(int argc, char **argv) { int c, i; @@ -461,3 +299,4 @@ int main(int argc, char **argv) } exit(0); } + diff --git a/powerdebug.h b/powerdebug.h index 4799118..e2f7d65 100644 --- a/powerdebug.h +++ b/powerdebug.h @@ -25,25 +25,10 @@ #define VERSION "1.0" -#define VALUE_MAX 16 #define TOTAL_FEATURE_WINS 3 /* Regulator, Clock and Sensor (for now) */ enum {REGULATOR, CLOCK, SENSOR}; -struct regulator_info { - char name[NAME_MAX]; - char state[VALUE_MAX]; - char status[VALUE_MAX]; - char type[VALUE_MAX]; - char opmode[VALUE_MAX]; - int microvolts; - int min_microvolts; - int max_microvolts; - int microamps; - int min_microamps; - int max_microamps; - int requested_microamps; - int num_users; -} *regulators_info; +extern struct regulator_info *regulators_info; extern char *win_names[TOTAL_FEATURE_WINS]; extern int selectedwindow; @@ -54,7 +39,12 @@ extern double ticktime; extern void usage(char **argv); extern void version(void); + +extern void print_regulator_info(int verbose); +extern void init_regulator_ds(void); +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_clock_info(char *clkpath); @@ -65,14 +55,16 @@ extern void insert_children(struct clock_info **parent, struct clock_info *clk); extern void find_parents_for_clock(char *clkname, int complete); 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 get_sensor_info(char *path, char *name, char *sensor, int verbose); extern void print_string_val(char *name, char *val); extern int init_clock_details(void); extern void print_clock_header(void); -extern void print_sensor_header(void); extern void print_one_clock(int line, char *str, int bold, int highlight); extern char *debugfs_locate_mpoint(void); +extern void get_sensor_info(char *path, char *name, char *sensor, int verbose); +extern int read_and_print_sensor_info(int verbose); +extern void print_sensor_header(void); + extern void init_curses(void); extern void fini_curses(void); extern void killall_windows(int all); diff --git a/regulator.c b/regulator.c new file mode 100644 index 0000000..56b0b06 --- /dev/null +++ b/regulator.c @@ -0,0 +1,197 @@ +/******************************************************************************* + * 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 "regulator.h" + +int init_regulator_ds(void) +{ + DIR *regdir; + struct dirent *item; + + regdir = opendir("/sys/class/regulator"); + if (!regdir) + return(1); + while((item = readdir(regdir))) { + if (strncmp(item->d_name, "regulator", 9)) + continue; + + numregulators++; + } + closedir(regdir); + + regulators_info = (struct regulator_info *)malloc(numregulators* + sizeof(struct regulator_info)); + if (!regulators_info) { + fprintf(stderr, "init_regulator_ds: Not enough memory to " + "read information for %d regulators!\n", numregulators); + return(1); + } + + return(0); +} + +void print_string_val(char *name, char *val) +{ + printf("\t%s=%s", name, val); + if(!strchr(val, '\n')) + printf("\n"); +} + +void print_regulator_info(int verbose) +{ + int i; + + for (i=0; i<numregulators; i++) { + printf("Regulator %d:\n", i+1); + print_string_val("name", regulators_info[i].name); + if (strcmp(regulators_info[i].status, "")) + print_string_val("status", regulators_info[i].status); + if (strcmp(regulators_info[i].state, "")) + print_string_val("state", regulators_info[i].state); + + if (!verbose) + continue; + + if (strcmp(regulators_info[i].type, "")) + print_string_val("type", regulators_info[i].type); + if (strcmp(regulators_info[i].opmode, "")) + print_string_val("opmode", regulators_info[i].opmode); + + if (regulators_info[i].microvolts) + printf("\tmicrovolts=%d\n", + regulators_info[i].microvolts); + if (regulators_info[i].min_microvolts) + printf("\tmin_microvolts=%d\n", + regulators_info[i].min_microvolts); + if (regulators_info[i].max_microvolts) + printf("\tmax_microvolts=%d\n", + regulators_info[i].max_microvolts); + + if (regulators_info[i].microamps) + printf("\tmicroamps=%d\n", + regulators_info[i].microamps); + if (regulators_info[i].min_microamps) + printf("\tmin_microamps=%d\n", + regulators_info[i].min_microamps); + if (regulators_info[i].max_microamps) + printf("\tmax_microamps=%d\n", + regulators_info[i].max_microamps); + if (regulators_info[i].requested_microamps) + printf("\trequested_microamps=%d\n", + regulators_info[i].requested_microamps); + + if (regulators_info[i].num_users) + printf("\tnum_users=%d\n", + regulators_info[i].num_users); + printf("\n"); + } + + if (!numregulators && verbose) { + printf("Could not find regulator information!"); + printf(" Looks like /sys/class/regulator is empty.\n\n"); + } +} + +void read_info_from_dirent(struct dirent *ritem, char *str, int idx) +{ + if (!strcmp(ritem->d_name, "name")) + strcpy(regulators_info[idx].name, str); + if (!strcmp(ritem->d_name, "state")) + strcpy(regulators_info[idx].state, str); + if (!strcmp(ritem->d_name, "status")) + strcpy(regulators_info[idx].status, str); + + if (!strcmp(ritem->d_name, "type")) + strcpy(regulators_info[idx].type, str); + if (!strcmp(ritem->d_name, "opmode")) + strcpy(regulators_info[idx].opmode, str); + + if (!strcmp(ritem->d_name, "microvolts")) + regulators_info[idx].microvolts = atoi(str); + if (!strcmp(ritem->d_name, "min_microvolts")) + regulators_info[idx].min_microvolts = atoi(str); + if (!strcmp(ritem->d_name, "max_microvolts")) + regulators_info[idx].max_microvolts = atoi(str); + + if (!strcmp(ritem->d_name, "microamps")) + regulators_info[idx].microamps = atoi(str); + if (!strcmp(ritem->d_name, "min_microamps")) + regulators_info[idx].min_microamps = atoi(str); + if (!strcmp(ritem->d_name, "max_microamps")) + regulators_info[idx].max_microamps = atoi(str); + if (!strcmp(ritem->d_name, "requested_microamps")) + regulators_info[idx].requested_microamps = atoi(str); + + if (!strcmp(ritem->d_name, "num_users")) + regulators_info[idx].num_users = atoi(str); +} + +int read_regulator_info(void) +{ + FILE *file = NULL; + DIR *regdir, *dir; + int len, count = 0, ret = 0; + char line[1024], filename[1024], *fptr; + struct dirent *item, *ritem; + + regdir = opendir("/sys/class/regulator"); + if (!regdir) + return(1); + while((item = readdir(regdir))) { + if (strlen(item->d_name) < 3) + continue; + + if (strncmp(item->d_name, "regulator", 9)) + continue; + + len = sprintf(filename, "/sys/class/regulator/%s", + item->d_name); + + dir = opendir(filename); + if (!dir) + continue; + count++; + + if (count > numregulators) { + ret = 1; + goto exit; + } + + strcpy(regulators_info[count-1].name, item->d_name); + while((ritem = readdir(dir))) { + if (strlen(ritem->d_name) < 3) + continue; + + sprintf(filename + len, "/%s", ritem->d_name); + file = fopen(filename, "r"); + if (!file) + continue; + memset(line, 0, 1024); + fptr = fgets(line, 1024, file); + fclose(file); + if (!fptr) + continue; + read_info_from_dirent(ritem, fptr, count - 1); + } +exit: + closedir(dir); + if (ret) + break; + } + closedir(regdir); + + return ret; +} diff --git a/regulator.h b/regulator.h new file mode 100644 index 0000000..8e32b6d --- /dev/null +++ b/regulator.h @@ -0,0 +1,55 @@ +/******************************************************************************* + * 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 <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <string.h> +#include <dirent.h> +#include <getopt.h> + +#define VALUE_MAX 16 + +struct regulator_info { + char name[NAME_MAX]; + char state[VALUE_MAX]; + char status[VALUE_MAX]; + char type[VALUE_MAX]; + char opmode[VALUE_MAX]; + int microvolts; + int min_microvolts; + int max_microvolts; + int microamps; + int min_microamps; + int max_microamps; + int requested_microamps; + int num_users; +} *regulators_info; + +extern int numregulators; +extern int dump; + +/*extern void usage(char **argv); +extern void print_regulator_info(int verbose); + +extern void init_curses(void); +extern void fini_curses(void); +extern void killall_windows(int all); +extern void show_header(void); +extern void create_windows(void); +extern void create_selectedwindow(void); +extern void show_regulator_info(int verbose); +*/ @@ -99,3 +99,68 @@ exit: free(num); return; } + +int read_and_print_sensor_info(int verbose) +{ + DIR *dir, *subdir; + int len, found = 0; + char filename[PATH_MAX], devpath[PATH_MAX]; + char device[PATH_MAX]; + struct dirent *item, *subitem; + + sprintf(filename, "%s", "/sys/class/hwmon"); + dir = opendir(filename); + if (!dir) + return errno; + + while ((item = readdir(dir))) { + if (item->d_name[0] == '.') /* skip the hidden files */ + continue; + + found = 1; + + sprintf(filename, "/sys/class/hwmon/%s", item->d_name); + sprintf(devpath, "%s/device", filename); + + len = readlink(devpath, device, PATH_MAX - 1); + + if (len < 0) + strcpy(devpath, filename); + else + device[len] = '\0'; + + subdir = opendir(devpath); + + printf("\nSensor Information for %s :\n", item->d_name); + fflush(stdin); + + while ((subitem = readdir(subdir))) { + if (subitem->d_name[0] == '.') /* skip hidden files */ + continue; + + if(!strncmp(subitem->d_name, "in", 2)) + get_sensor_info(devpath, subitem->d_name, "in", + verbose); + else if (!strncmp(subitem->d_name, "temp", 4)) + get_sensor_info(devpath, subitem->d_name, + "temp", verbose); + else if (!strncmp(subitem->d_name, "fan", 4)) + get_sensor_info(devpath, subitem->d_name, + "fan", verbose); + else if (!strncmp(subitem->d_name, "pwm", 4)) + get_sensor_info(devpath, subitem->d_name, + "pwm", verbose); + + } + + closedir(subdir); + } + closedir(dir); + + if(!found && verbose) { + printf("Could not find sensor information!"); + printf(" Looks like /sys/class/hwmon is empty.\n"); + } + + return 0; +} |