aboutsummaryrefslogtreecommitdiff
path: root/sensor.c
diff options
context:
space:
mode:
authorAmit Arora <amit.arora@linaro.org>2010-08-03 10:15:20 +0530
committerAmit Arora <amit.arora@linaro.org>2010-08-03 10:15:20 +0530
commite9e16b0ae8add42168c68e9d8bbd27d97fa944bd (patch)
tree9d9734e227bf83e15e770975ecacbc71ae49868c /sensor.c
New powerdebug tool
This is a new tool to show some of the information which powertop doesn't - like, information for sensor, regulator etc.
Diffstat (limited to 'sensor.c')
-rw-r--r--sensor.c91
1 files changed, 91 insertions, 0 deletions
diff --git a/sensor.c b/sensor.c
new file mode 100644
index 0000000..333eb7f
--- /dev/null
+++ b/sensor.c
@@ -0,0 +1,91 @@
+#include "powerdebug.h"
+#include "sensor.h"
+
+char *get_num(char *fname, char *sensor)
+{
+ char tmpstr[NAME_MAX];
+ char *str;
+
+ strcpy(tmpstr, (fname+strlen(sensor)));
+
+ str = strrchr(tmpstr, '_');
+ str[0] = '\0';
+
+ str = strdup(tmpstr);
+ return str;
+}
+
+
+void get_sensor_info(char *path, char *fname, char *sensor, int verbose)
+{
+ FILE *filep;
+ char filename[PATH_MAX];
+ char **items = NULL, **suffix = NULL;
+ char *item, result[NAME_MAX], *num;
+ int ret, count = 0;
+
+ (void)verbose; // get rid of warning
+
+ sprintf(filename, "%s/%s", path, fname);
+
+ if(!strcmp(sensor, "in")) {
+ items = (char **)items_in;
+ suffix = (char **)suffix_in;
+ }
+
+ if(!strcmp(sensor, "temp")) {
+ items = (char **)items_temp;
+ suffix = (char **)suffix_temp;
+ }
+
+ if(!strcmp(sensor, "fan")) {
+ items = (char **)items_fan;
+ suffix = (char **)suffix_fan;
+ }
+ if(!strcmp(sensor, "pwm")) {
+ items = (char **)items_pwm;
+ suffix = (char **)suffix_pwm;
+ }
+
+
+ if (!items || !suffix)
+ return;
+
+ item = strrchr(fname, '_');
+ if(!item)
+ return;
+
+ if(item)
+ item++;
+
+ if(item > (fname + strlen(fname)))
+ return;
+
+ num = get_num(fname, sensor);
+// strncpy(num, fname, item - fname -1);
+
+ filep = fopen(filename, "r");
+
+ if(!filep)
+ goto exit;
+
+ ret = fscanf(filep, "%s", result);
+
+ fclose(filep);
+ if(ret != 1)
+ goto exit;
+
+ while(strcmp(items[count], "")) {
+ if(!strcmp(items[count], item))
+ printf("\'temp\' %s sensor %s\t\t%d%s\n",
+ num, items[count], atoi(result)/1000,
+ suffix[count]);
+ count++;
+ }
+
+exit:
+ free(num);
+ return;
+}
+
+