aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--Makefile6
-rw-r--r--README11
-rw-r--r--clocks.c94
-rw-r--r--debian/changelog7
-rw-r--r--display.c139
-rw-r--r--output.c2
-rw-r--r--powerdebug.812
-rw-r--r--powerdebug.c52
-rw-r--r--powerdebug.h15
10 files changed, 323 insertions, 20 deletions
diff --git a/ChangeLog b/ChangeLog
index c06a351..3b4c1d4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,2 +1,5 @@
-1.0 -- Sep, 6th 2010
+0.2 -- Sep, 8th 2010
+ * Add support for clock tree
+
+0.1 -- Sep, 6th 2010
* Initial Release
diff --git a/Makefile b/Makefile
index ac4d871..8e25946 100644
--- a/Makefile
+++ b/Makefile
@@ -5,7 +5,9 @@ WARNFLAGS=-Wall -Wshadow -W -Wformat -Wimplicit-function-declaration -Wimplicit-
CFLAGS?=-O1 -g ${WARNFLAGS}
CC?=gcc
-OBJS = powerdebug.o output.o sensor.o display.o
+OBJS = powerdebug.o output.o sensor.o clocks.o display.o
+
+default: powerdebug
powerdebug.8.gz: powerdebug.8
gzip -c $< > $@
@@ -21,5 +23,7 @@ install: powerdebug powerdebug.8.gz
All: install
+all: powerdebug powerdebug.8.gz
+
clean:
rm -f powerdebug *.o powerdebug.8.gz
diff --git a/README b/README
index 0d7bbad..a87194c 100644
--- a/README
+++ b/README
@@ -1,8 +1,11 @@
powerdebug
----------
-This is a new tool which displays regulator and sensor information.
-Current version only displays regulator information properly. Support
-will be added for sensors, clock domains and voltage domains, later.
+This is a new tool which displays regulator, sensor and clock tree
+information.
- -- Amit Arora <amit.arora@linaro.org> Fri, 03 Sep 2010
+Current version only displays regulator information properly. And shows
+first level of clock tree from debugfs (linux-pm branch kernel
+required). Support will be added for sensors and voltage domains, later.
+
+ -- Amit Arora <amit.arora@linaro.org> Fri, 08 Sep 2010
diff --git a/clocks.c b/clocks.c
new file mode 100644
index 0000000..9a49d9e
--- /dev/null
+++ b/clocks.c
@@ -0,0 +1,94 @@
+/*******************************************************************************
+ * 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"
+#include<error.h>
+#include<errno.h>
+
+int get_int_from(char *file)
+{
+ FILE *filep;
+ char result[NAME_MAX];
+ int ret;
+
+ filep = fopen(file, "r");
+
+ if (!filep)
+ return -1; //TBD : What should we return on failure, here ?
+
+ ret = fscanf(filep, "%s", result);
+ fclose(filep);
+
+ return atoi(result);
+}
+
+int read_and_print_clock_info(int verbose, int hrow)
+{
+ int line = 0, usecount = 0, flags = 0, rate = 0;
+ DIR *dir, *subdir;
+ char filename[PATH_MAX], devpath[PATH_MAX], clockname[NAME_MAX];
+ struct dirent *item, *subitem;
+
+ (void)verbose;
+
+ print_clock_header(1);
+
+ sprintf(filename, "%s", "/debug/clock");
+
+ dir = opendir(filename);
+ if (!dir)
+ return 0;
+
+ while ((item = readdir(dir))) {
+ if (item->d_name[0] == '.') /* skip the hidden files */
+ continue;
+
+ sprintf(devpath, "/debug/clock/%s", item->d_name);
+ strcpy(clockname, item->d_name);
+
+ subdir = opendir(devpath);
+
+ if (!subdir)
+ continue;
+
+ while ((subitem = readdir(subdir))) {
+ if (subitem->d_name[0] == '.') /* skip hidden files */
+ continue;
+
+ sprintf(filename, "%s/%s", devpath, subitem->d_name);
+
+ if (!strcmp(subitem->d_name, "flags"))
+ flags = get_int_from(filename);
+
+ if (!strcmp(subitem->d_name, "rate"))
+ rate = get_int_from(filename);
+
+ if (!strcmp(subitem->d_name, "usecount"))
+ usecount = get_int_from(filename);
+ }
+
+ print_clock_info_line(line, clockname, flags, rate,
+ usecount, (hrow == line) ? 1 : 0);
+ line++;
+ closedir(subdir);
+ }
+
+ closedir(dir);
+
+ if (hrow >= (line - 1))
+ hrow = -1;
+ return hrow;
+}
diff --git a/debian/changelog b/debian/changelog
index de7d831..e5ae8e8 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,10 @@
+powerdebug (0.2) maverick; urgency=low
+
+ * Add support for clock tree information
+ * Add options for ticktime
+
+ -- Amit Arora <amit.arora@linaro.org> Fri, 08 Sep 2010 16:41:48 +0530
+
powerdebug (0.1) maverick; urgency=low
* Initial Release.
diff --git a/display.c b/display.c
index 326b223..ff2295a 100644
--- a/display.c
+++ b/display.c
@@ -14,7 +14,6 @@
* - initial API and implementation
*******************************************************************************/
-
#include "powerdebug.h"
#define print(w, x, y, fmt, args...) do { mvwprintw(w, y, x, fmt, ##args); } while (0)
@@ -22,6 +21,8 @@
static WINDOW *header_win;
static WINDOW *regulator_win;
+static WINDOW *clock_win;
+static WINDOW *sensor_win;
static WINDOW *footer_win;
int maxx, maxy;
@@ -42,6 +43,14 @@ void killall_windows(void)
delwin(regulator_win);
regulator_win = NULL;
}
+ if (clock_win) {
+ delwin(clock_win);
+ clock_win = NULL;
+ }
+ if (sensor_win) {
+ delwin(sensor_win);
+ sensor_win = NULL;
+ }
if (footer_win) {
delwin(footer_win);
footer_win = NULL;
@@ -60,13 +69,13 @@ void init_curses(void)
use_default_colors();
init_pair(PT_COLOR_DEFAULT, COLOR_WHITE, COLOR_BLACK);
- init_pair(PT_COLOR_HEADER_BAR, COLOR_BLACK, COLOR_WHITE);
init_pair(PT_COLOR_ERROR, COLOR_BLACK, COLOR_RED);
- init_pair(PT_COLOR_RED, COLOR_WHITE, COLOR_RED);
+ init_pair(PT_COLOR_HEADER_BAR, COLOR_BLACK, COLOR_WHITE);
init_pair(PT_COLOR_YELLOW, COLOR_WHITE, COLOR_YELLOW);
init_pair(PT_COLOR_GREEN, COLOR_WHITE, COLOR_GREEN);
- init_pair(PT_COLOR_BLUE, COLOR_WHITE, COLOR_BLUE);
init_pair(PT_COLOR_BRIGHT, COLOR_WHITE, COLOR_BLACK);
+ init_pair(PT_COLOR_BLUE, COLOR_WHITE, COLOR_BLUE);
+ init_pair(PT_COLOR_RED, COLOR_WHITE, COLOR_RED);
atexit(fini_curses);
}
@@ -79,7 +88,8 @@ void create_windows(void)
killall_windows();
header_win = subwin(stdscr, 1, maxx, 0, 0);
- regulator_win = subwin(stdscr, maxy-3, maxx, 1, 0);
+// regulator_win = subwin(stdscr, maxy/2 - 2, maxx, 1, 0);
+// clock_win = subwin(stdscr, maxy/2 - 2, maxx, maxy/2, 0);
footer_win = subwin(stdscr, 1, maxx, maxy-1, 0);
@@ -91,6 +101,68 @@ void create_windows(void)
}
+int create_regulator_win(int row, int maxrows)
+{
+ int numrows;
+
+ if (regulator_win) {
+ delwin(regulator_win);
+ regulator_win = NULL;
+ }
+
+ getmaxyx(stdscr, maxy, maxx);
+ if (maxrows < (maxy/2 - 2))
+ numrows = maxrows;
+ else
+ numrows = maxy/2 - 2;
+ regulator_win = subwin(stdscr, numrows, maxx, row, 0);
+
+ refresh();
+
+ return numrows + row;
+}
+
+int create_clock_win(int row, int maxrows)
+{
+ int numrows;
+
+ if (clock_win) {
+ delwin(clock_win);
+ clock_win = NULL;
+ }
+
+ getmaxyx(stdscr, maxy, maxx);
+ if (maxrows < (maxy/2 - 2))
+ numrows = maxrows;
+ else
+ numrows = maxy/2 - 2;
+ clock_win = subwin(stdscr, numrows, maxx, row, 0);
+
+ refresh();
+
+ return numrows + row;
+}
+
+int create_sensor_win(int row, int maxrows)
+{
+ int numrows;
+
+ if (sensor_win) {
+ delwin(sensor_win);
+ sensor_win = NULL;
+ }
+
+ getmaxyx(stdscr, maxy, maxx);
+ if (maxrows < 4)
+ numrows = maxrows;
+ else
+ numrows = 4;
+ sensor_win = subwin(stdscr, numrows, maxx, row, 0);
+
+ refresh();
+
+ return numrows + row;
+}
void show_header(void)
{
@@ -172,3 +244,60 @@ void show_regulator_info(int verbose)
wrefresh(regulator_win);
}
+
+void print_clock_header(int level)
+{
+ char lev[NAME_MAX];
+
+ sprintf(lev, "(Level %d)\n", level);
+ werase(clock_win);
+ wattron(clock_win, A_BOLD);
+ wattron(clock_win, A_STANDOUT);
+ print(clock_win, 0, 0, "Clock Information");
+ wattroff(clock_win, A_STANDOUT);
+ print(clock_win, 0, 1, "Name");
+ print(clock_win, 24, 1, "Flags");
+ print(clock_win, 36, 1, "Rate");
+ print(clock_win, 48, 1, "Usecount");
+ print(clock_win, 60, 1, lev);
+ wattroff(clock_win, A_BOLD);
+ wrefresh(clock_win);
+}
+
+void print_sensor_header(void)
+{
+ werase(sensor_win);
+ wattron(sensor_win, A_BOLD);
+ wattron(sensor_win, A_STANDOUT);
+ print(sensor_win, 0, 0, "Sensor Information");
+ wattroff(sensor_win, A_STANDOUT);
+ print(sensor_win, 0, 1, "Name");
+ print(sensor_win, 36, 1, "Temperature");
+ wattroff(sensor_win, A_BOLD);
+ wattron(sensor_win, A_BLINK);
+ print(sensor_win, 0, 2, "Currently Sensor information available"
+ " only in Dump mode!");
+ wattroff(sensor_win, A_BLINK);
+ wrefresh(sensor_win);
+}
+
+void print_clock_info_line(int line, char *clockname, int flags, int rate,
+ int usecount, int highlight)
+{
+ if (highlight) {
+ //wattrset(clock_win, COLOR_PAIR(PT_COLOR_RED));
+ //wbkgd(clock_win, COLOR_PAIR(PT_COLOR_RED));
+ wattron(clock_win, WA_BOLD);
+ }
+ print(clock_win, 0, line + 2, "%s", clockname);
+ print(clock_win, 24, line + 2, "%d", flags);
+ print(clock_win, 36, line + 2, "%d", rate);
+ print(clock_win, 48, line + 2, "%d", usecount);
+ if (highlight) {
+ //use_default_colors();
+ //wattrset(clock_win, COLOR_PAIR(PT_COLOR_DEFAULT));
+ //wbkgd(clock_win, COLOR_PAIR(PT_COLOR_DEFAULT));
+ wattroff(clock_win, WA_BOLD);
+ }
+ wrefresh(clock_win);
+}
diff --git a/output.c b/output.c
index 7fd3039..419ae63 100644
--- a/output.c
+++ b/output.c
@@ -21,6 +21,8 @@ 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(" -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");
diff --git a/powerdebug.8 b/powerdebug.8
index 20fa327..5a2a9e4 100644
--- a/powerdebug.8
+++ b/powerdebug.8
@@ -19,13 +19,13 @@
powerdebug \- A tool to display regulator and sensor information
.SH SYNOPSIS
.B powerdebug
-.RB [[-r|-s] [-v] [-d]]
+.RB [[-r|-s|-c] [-v] [-d] [-t <ticktime>]]
.RB [-V]
.RB [-h]
.br
.SH DESCRIPTION
-This tool can be used to display regulator and sensor related
-information.
+This tool can be used to display regulator, sensor and clock tree
+related information.
.PP
.\" TeX users may be more comfortable with the \fB<whatever>\fP and
.\" \fI<whatever>\fP escape sequences to invode bold face and italics,
@@ -44,6 +44,12 @@ For a complete description, see the Info files.
\fB\-s\fR, \fB\-\-sensor
print sensor information.
.TP
+\fB\-c\fR, \fB\-\-clock
+ print clock tree related information.
+.TP
+\fB\-t\fR, \fB\-\-time
+ set the ticktime to specified value.
+.TP
\fB\-v\fR, \fB\-\-verbose
show detailed information.
.TP
diff --git a/powerdebug.c b/powerdebug.c
index a7b37c2..1417cb2 100644
--- a/powerdebug.c
+++ b/powerdebug.c
@@ -19,7 +19,8 @@
int numregulators;
int dump;
-int ticktime=3; /* in seconds */
+int highlighted_row;
+double ticktime = 10.0; /* in seconds */
int init_regulator_ds(void)
{
@@ -230,12 +231,14 @@ int main(int argc, char **argv)
{
int c;
int firsttime = 1;
- int regulators = 0, sensors = 0, verbose = 0;
+ int regulators = 0, sensors = 0, clocks = 0, verbose = 0;
/*
* Options:
* -r, --regulator : regulator
* -s, --sensor : sensors
+ * -c, --clock : clocks
+ * -t, --time : ticktime
* -d, --dump : dump
* -v, --verbose : verbose
* -V, --version : version
@@ -248,6 +251,8 @@ int main(int argc, char **argv)
static struct option long_options[] = {
{"regulator", 0, 0, 'r'},
{"sensor", 0, 0, 's'},
+ {"clock", 0, 0, 'c'},
+ {"time", 0, 0, 't'},
{"dump", 0, 0, 'd'},
{"verbose", 0, 0, 'v'},
{"version", 0, 0, 'V'},
@@ -255,7 +260,7 @@ int main(int argc, char **argv)
{0, 0, 0, 0}
};
- c = getopt_long(argc, argv, "rsdvVh", long_options, &optindex);
+ c = getopt_long(argc, argv, "rsct:dvVh", long_options, &optindex);
if (c == -1)
break;
@@ -266,6 +271,12 @@ int main(int argc, char **argv)
case 's':
sensors = 1;
break;
+ case 'c':
+ clocks = 1;
+ break;
+ case 't':
+ ticktime = strtod(optarg, NULL);
+ break;
case 'd':
dump = 1;
break;
@@ -290,7 +301,7 @@ int main(int argc, char **argv)
/* Need atleast one option specified */
- if (!regulators && !sensors) {
+ if (!regulators && !sensors && !clocks) {
usage(argv);
}
@@ -300,6 +311,7 @@ int main(int argc, char **argv)
int key = 0;
struct timeval tval;
fd_set readfds;
+ int row = 1;
if (!dump) {
if(firsttime) {
@@ -312,15 +324,30 @@ int main(int argc, char **argv)
if (regulators) {
read_regulator_info();
- if (!dump)
+ if (!dump) {
+ row = create_regulator_win(row,
+numregulators+2);
show_regulator_info(verbose);
+ }
else
print_regulator_info(verbose);
}
+ if (clocks && !dump) {
+ int hrow;
+ row = create_clock_win(row, 100);//giv big no.as of now
+ hrow = read_and_print_clock_info(verbose,
+ highlighted_row);
+ highlighted_row = hrow;
+ }
if (sensors) {
- read_and_print_sensor_info(verbose);
+ if (!dump) {
+ row = create_sensor_win(row, 100);//big no. as of now
+ print_sensor_header();
+ }
+ else
+ read_and_print_sensor_info(verbose);
}
if (dump)
@@ -340,7 +367,20 @@ int main(int argc, char **argv)
if (keystroke == EOF)
exit(0);
+ if (keystroke == 9)
+ highlighted_row++;
+
keychar = toupper(keystroke);
+#ifdef DEBUG_KEY
+ if (keystroke == 13) {
+ killall_windows();
+ fini_curses();
+ printf("powerdebug: key=%d : char=%c\n", keystroke, keychar);
+ printf("highlighted_row = %d\n", highlighted_row);
+ exit(0);
+ }
+#endif
+
if (keychar == 'Q')
exit(0);
if (keychar == 'R')
diff --git a/powerdebug.h b/powerdebug.h
index 21abcdf..45b1872 100644
--- a/powerdebug.h
+++ b/powerdebug.h
@@ -43,14 +43,26 @@ struct regulator_info {
int num_users;
} *regulators_info;
+struct clock_info {
+ char name[NAME_MAX];
+ int flags;
+ int rate;
+ int usecount;
+} *clocks_info;
+
extern int numregulators;
extern int dump;
extern void usage(char **argv);
extern void version(void);
extern void print_regulator_info(int verbose);
+extern int read_and_print_clock_info(int verbose, int hrow);
extern void get_sensor_info(char *path, char *name, char *sensor, int verbose);
extern void print_string_val(char *name, char *val);
+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
@@ -68,4 +80,7 @@ extern void fini_curses(void);
extern void killall_windows(void);
extern void show_header(void);
extern void create_windows(void);
+extern int create_regulator_win(int row, int numrows);
+extern int create_clock_win(int row, int numrows);
+extern int create_sensor_win(int row, int numrows);
extern void show_regulator_info(int verbose);