aboutsummaryrefslogtreecommitdiff
path: root/devices
diff options
context:
space:
mode:
authorarjan <arjan@arjan-desktop.localdomain>2010-09-18 04:47:34 -0700
committerarjan <arjan@arjan-desktop.localdomain>2010-09-18 04:47:34 -0700
commit9b8da64b2694f9c6e11ebe338d6b436e4eb8962b (patch)
tree56b186a02a87ae251f7c174fe7182d28954ad7d7 /devices
parente8eef1e946a4a361a1e017f724934d2e00eea801 (diff)
downloadpowertop-9b8da64b2694f9c6e11ebe338d6b436e4eb8962b.tar.gz
use indexes for the results as well.... major speedup
Diffstat (limited to 'devices')
-rw-r--r--devices/ahci.cpp21
-rw-r--r--devices/ahci.h2
-rw-r--r--devices/alsa.cpp3
-rw-r--r--devices/alsa.h1
-rw-r--r--devices/backlight.cpp14
-rw-r--r--devices/backlight.h2
-rw-r--r--devices/i915-gpu.cpp5
-rw-r--r--devices/rfkill.cpp6
-rw-r--r--devices/rfkill.h2
-rw-r--r--devices/thinkpad-fan.cpp5
-rw-r--r--devices/usb.cpp21
-rw-r--r--devices/usb.h3
12 files changed, 65 insertions, 20 deletions
diff --git a/devices/ahci.cpp b/devices/ahci.cpp
index 5716235..dc65795 100644
--- a/devices/ahci.cpp
+++ b/devices/ahci.cpp
@@ -169,19 +169,30 @@ double ahci::power_usage(struct result_bundle *result, struct parameter_bundle *
active_index = get_param_index("ahci-link-power-active");
if (!partial_index)
- active_index = get_param_index("ahci-link-power-partial");
+ partial_index = get_param_index("ahci-link-power-partial");
+
power = 0;
factor = get_parameter_value(active_index, bundle);
- sprintf(buffer, "%s-active", name);
- utilization = get_result_value(buffer, result);
+ if (!active_rindex) {
+ sprintf(buffer, "%s-active", name);
+ active_rindex = get_result_index(buffer);
+ }
+
+
+ utilization = get_result_value(active_rindex, result);
power += utilization * factor / 100.0;
- sprintf(buffer, "%s-partial", name);
+
+ if (!partial_rindex) {
+ sprintf(buffer, "%s-partial", name);
+ partial_rindex = get_result_index(buffer);
+ }
+
factor = get_parameter_value(partial_index, bundle);
- utilization = get_result_value(buffer, result);
+ utilization = get_result_value(partial_rindex, result);
power += utilization * factor / 100.0;
diff --git a/devices/ahci.h b/devices/ahci.h
index 839b56e..27d0a29 100644
--- a/devices/ahci.h
+++ b/devices/ahci.h
@@ -11,6 +11,8 @@ class ahci: public device {
uint64_t start_slumber, end_slumber;
char sysfs_path[4096];
char name[4096];
+ int partial_rindex;
+ int active_rindex;
public:
ahci(char *_name, char *path);
diff --git a/devices/alsa.cpp b/devices/alsa.cpp
index 175a6e5..378e13c 100644
--- a/devices/alsa.cpp
+++ b/devices/alsa.cpp
@@ -25,6 +25,7 @@ alsa::alsa(char *_name, char *path)
strncpy(sysfs_path, path, sizeof(sysfs_path));
sprintf(devname, "alsa:%s", _name);
strncpy(name, devname, sizeof(name));
+ rindex = get_result_index(name);
}
void alsa::start_measurement(void)
@@ -141,7 +142,7 @@ double alsa::power_usage(struct result_bundle *result, struct parameter_bundle *
index = get_param_index("alsa-codec-power");
factor = get_parameter_value(index, bundle);
- utilization = get_result_value(name, result);
+ utilization = get_result_value(rindex, result);
power += utilization * factor / 100.0;
diff --git a/devices/alsa.h b/devices/alsa.h
index e3f2f37..5a6e28c 100644
--- a/devices/alsa.h
+++ b/devices/alsa.h
@@ -10,6 +10,7 @@ class alsa: public device {
uint64_t start_inactive, end_inactive;
char sysfs_path[4096];
char name[4096];
+ int rindex;
public:
alsa(char *_name, char *path);
diff --git a/devices/backlight.cpp b/devices/backlight.cpp
index c547e18..270b774 100644
--- a/devices/backlight.cpp
+++ b/devices/backlight.cpp
@@ -24,6 +24,8 @@ backlight::backlight(char *_name, char *path)
strncpy(sysfs_path, path, sizeof(sysfs_path));
sprintf(devname, "backlight:%s", _name);
strncpy(name, devname, sizeof(name));
+ r_index = get_result_index(name);
+ r_index_power = 0;
}
void backlight::start_measurement(void)
@@ -165,17 +167,21 @@ double backlight::power_usage(struct result_bundle *result, struct parameter_bun
if (!bl_index)
bl_index = get_param_index("backlight");
if (!blp_index)
- bl_index = get_param_index("backlight-power");
+ blp_index = get_param_index("backlight-power");
power = 0;
factor = get_parameter_value(bl_index, bundle);
- utilization = get_result_value(name, result);
+ utilization = get_result_value(r_index, result);
power += utilization * factor / 100.0;
factor = get_parameter_value(blp_index, bundle);
- sprintf(powername, "%s-power", name);
- utilization = get_result_value(powername, result);
+
+ if (!r_index_power) {
+ sprintf(powername, "%s-power", name);
+ r_index_power = get_result_index(powername);
+ }
+ utilization = get_result_value(r_index_power, result);
power += utilization * factor / 100.0;
diff --git a/devices/backlight.h b/devices/backlight.h
index a178dbb..a44bed3 100644
--- a/devices/backlight.h
+++ b/devices/backlight.h
@@ -9,6 +9,8 @@ class backlight: public device {
int start_level, end_level;
char sysfs_path[4096];
char name[4096];
+ int r_index;
+ int r_index_power;
public:
backlight(char *_name, char *path);
diff --git a/devices/i915-gpu.cpp b/devices/i915-gpu.cpp
index f1c5ed0..0681cb9 100644
--- a/devices/i915-gpu.cpp
+++ b/devices/i915-gpu.cpp
@@ -58,13 +58,16 @@ double i915gpu::power_usage(struct result_bundle *result, struct parameter_bundl
double factor;
double utilization;
static int index = 0;
+ static int rindex = 0;
if (!index)
index = get_param_index("gpu-operations");
+ if (!rindex)
+ rindex = get_result_index("gpu-operations");
power = 0;
factor = get_parameter_value(index, bundle);
- utilization = get_result_value("gpu-operations", result);
+ utilization = get_result_value(rindex, result);
power += utilization * factor / 100.0;
return power;
diff --git a/devices/rfkill.cpp b/devices/rfkill.cpp
index e585e91..9ecc331 100644
--- a/devices/rfkill.cpp
+++ b/devices/rfkill.cpp
@@ -26,6 +26,8 @@ rfkill::rfkill(char *_name, char *path)
sprintf(devname, "radio:%s", _name);
strncpy(name, devname, sizeof(name));
register_parameter(devname);
+ index = get_param_index(devname);
+ rindex = get_result_index(name);
}
void rfkill::start_measurement(void)
@@ -137,8 +139,8 @@ double rfkill::power_usage(struct result_bundle *result, struct parameter_bundle
double utilization;
power = 0;
- factor = get_parameter_value(name, bundle);
- utilization = get_result_value(name, result);
+ factor = get_parameter_value(index, bundle);
+ utilization = get_result_value(rindex, result);
power += utilization * factor / 100.0;
diff --git a/devices/rfkill.h b/devices/rfkill.h
index b85bf59..05acae2 100644
--- a/devices/rfkill.h
+++ b/devices/rfkill.h
@@ -9,6 +9,8 @@ class rfkill: public device {
int start_hard, end_hard;
char sysfs_path[4096];
char name[4096];
+ int index;
+ int rindex;
public:
rfkill(char *_name, char *path);
diff --git a/devices/thinkpad-fan.cpp b/devices/thinkpad-fan.cpp
index c60dbab..2ced2a9 100644
--- a/devices/thinkpad-fan.cpp
+++ b/devices/thinkpad-fan.cpp
@@ -67,14 +67,17 @@ double thinkpad_fan::power_usage(struct result_bundle *result, struct parameter_
double utilization;
static int fan_index = 0, fansqr_index = 0;
+ static int r_index = 0;
if (!fan_index)
fan_index = get_param_index("thinkpad-fan");
if (!fansqr_index)
fansqr_index = get_param_index("thinkpad-fan-sqr");
+ if (!r_index)
+ r_index = get_result_index("thinkpad-fan");
power = 0;
- utilization = get_result_value("thinkpad-fan", result);
+ utilization = get_result_value(r_index, result);
utilization = utilization - 50;
if (utilization < 0)
diff --git a/devices/usb.cpp b/devices/usb.cpp
index f187a98..cbaee74 100644
--- a/devices/usb.cpp
+++ b/devices/usb.cpp
@@ -21,6 +21,15 @@ usbdevice::usbdevice(const char *_name, const char *path, const char *devid)
active_after = 0;
connected_before = 0;
connected_after = 0;
+ index = 0;
+ r_index = get_result_index(name);
+ rootport = 0;
+ /* root ports should count as 0 .. their activity is derived */
+ if (strcmp(devname, "usb-device-1d6b-0001") == 0)
+ rootport = 1;
+ if (strcmp(devname, "usb-device-1d6b-0002") == 0)
+ rootport = 1;
+
}
@@ -93,15 +102,15 @@ double usbdevice::power_usage(struct result_bundle *result, struct parameter_bun
double factor;
double utilization;
- /* root ports should count as 0 .. their activity is derived */
- if (strcmp(devname, "usb-device-1d6b-0001") == 0)
- return 0.0;
- if (strcmp(devname, "usb-device-1d6b-0002") == 0)
+ if (rootport)
return 0.0;
+ if (index == 0)
+ index = get_param_index(devname);
+
power = 0;
- factor = get_parameter_value(devname, bundle);
- utilization = get_result_value(name, result);
+ factor = get_parameter_value(index, bundle);
+ utilization = get_result_value(r_index, result);
power += utilization * factor / 100.0;
diff --git a/devices/usb.h b/devices/usb.h
index 65d4b74..1f4b542 100644
--- a/devices/usb.h
+++ b/devices/usb.h
@@ -10,6 +10,9 @@ class usbdevice: public device {
char sysfs_path[4096];
char name[4096];
char devname[4096];
+ int index;
+ int r_index;
+ int rootport;
public:
usbdevice(const char *_name, const char *path, const char *devid);