diff options
-rw-r--r-- | cpu/cpudevice.h | 3 | ||||
-rw-r--r-- | devices/device.cpp | 20 | ||||
-rw-r--r-- | devices/thinkpad-fan.cpp | 20 | ||||
-rw-r--r-- | devices/thinkpad-fan.h | 5 | ||||
-rw-r--r-- | display.cpp | 13 | ||||
-rw-r--r-- | main.cpp | 7 | ||||
-rw-r--r-- | process/do_process.cpp | 2 |
7 files changed, 48 insertions, 22 deletions
diff --git a/cpu/cpudevice.h b/cpu/cpudevice.h index 5fe2bc8..04b4e6e 100644 --- a/cpu/cpudevice.h +++ b/cpu/cpudevice.h @@ -24,7 +24,8 @@ public: cpudevice(const char *classname = "cpu", const char *device_name = "cpu0", class abstract_cpu *_cpu = NULL); virtual const char * class_name(void) { return _class;}; - virtual const char * device_name(void) {return _cpuname;}; + virtual const char * device_name(void) {return "CPU use";}; + virtual const char * util_units(void) { return NULL; }; virtual double power_usage(struct result_bundle *result, struct parameter_bundle *bundle); virtual bool show_in_list(void) {return false;}; diff --git a/devices/device.cpp b/devices/device.cpp index 4d7989c..13eb28e 100644 --- a/devices/device.cpp +++ b/devices/device.cpp @@ -85,26 +85,34 @@ void report_devices(void) sort(all_devices.begin(), all_devices.end(), power_device_sort); - wprintw(win, "Device statistics\n"); + wprintw(win, "Power est. Usage Device\n"); for (i = 0; i < all_devices.size(); i++) { double P; - sprintf(util, "%5.1f%s", all_devices[i]->utilization(), all_devices[i]->util_units()); + + util[0] = 0; + + if (all_devices[i]->util_units()) { + if (all_devices[i]->utilization() < 1000) + sprintf(util, "%5.1f%s", all_devices[i]->utilization(), all_devices[i]->util_units()); + else + sprintf(util, "%5i%s", (int)all_devices[i]->utilization(), all_devices[i]->util_units()); + } while (strlen(util) < 9) strcat(util, " "); P = all_devices[i]->power_usage(&all_results, &all_parameters); if (P > 1.5) - sprintf(power, "%7.2fW ", P); + sprintf(power, "%7.2fW ", P); else - sprintf(power, "%7.2fmW", P*1000); + sprintf(power, "%6.1f mW ", P*1000); if (!all_devices[i]->power_valid()) - strcpy(power, " "); + strcpy(power, " "); wprintw(win, "%s %s %s\n", - util, power, + util, all_devices[i]->human_name() ); } diff --git a/devices/thinkpad-fan.cpp b/devices/thinkpad-fan.cpp index 2ced2a9..a3acb1a 100644 --- a/devices/thinkpad-fan.cpp +++ b/devices/thinkpad-fan.cpp @@ -21,6 +21,9 @@ thinkpad_fan::thinkpad_fan() { start_rate = 0; end_rate = 0; + fan_index = get_param_index("thinkpad-fan"); + fansqr_index = get_param_index("thinkpad-fan-sqr"); + r_index = get_result_index("thinkpad-fan"); } void thinkpad_fan::start_measurement(void) @@ -39,7 +42,7 @@ void thinkpad_fan::end_measurement(void) double thinkpad_fan::utilization(void) { - return (start_rate+end_rate) / 100.0; + return (start_rate+end_rate) / 2; } void create_thinkpad_fan(void) @@ -66,29 +69,20 @@ double thinkpad_fan::power_usage(struct result_bundle *result, struct parameter_ double factor; 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(r_index, result); - utilization = utilization - 50; + utilization = utilization - 2400; if (utilization < 0) utilization = 0; factor = get_parameter_value(fansqr_index, bundle); - power += factor * pow(utilization / 100.0, 2); + power += factor * pow(utilization / 3000.0, 2); factor = get_parameter_value(fan_index, bundle); - power -= utilization * factor / 100.0; + power -= utilization / 5000.0 * factor; if (power <= 0.0) power = 0.0; diff --git a/devices/thinkpad-fan.h b/devices/thinkpad-fan.h index 985ff68..07d75c7 100644 --- a/devices/thinkpad-fan.h +++ b/devices/thinkpad-fan.h @@ -3,9 +3,12 @@ #include "device.h" +#include "../parameters/parameters.h" class thinkpad_fan: public device { double start_rate, end_rate; + int fan_index, fansqr_index; + int r_index; public: thinkpad_fan(); @@ -20,6 +23,8 @@ public: virtual const char * device_name(void) { return "Fan-1";}; virtual const char * human_name(void) { return "Laptop fan";}; virtual double power_usage(struct result_bundle *result, struct parameter_bundle *bundle); + virtual const char * util_units(void) { return "rpm"; }; + virtual int power_valid(void) { return utilization_power_valid(r_index);}; }; extern void create_thinkpad_fan(void); diff --git a/display.cpp b/display.cpp index 576f2ea..ef9918e 100644 --- a/display.cpp +++ b/display.cpp @@ -9,6 +9,8 @@ using namespace std; +static int display = 0; + vector<string> tab_names; map<string, WINDOW *> tab_windows; @@ -37,6 +39,7 @@ void init_display(void) // create_tab("Checklist"); // create_tab("Actions"); + display = 1; } WINDOW *tab_bar = NULL; @@ -47,6 +50,10 @@ void show_tab(unsigned int tab) { WINDOW *win; unsigned int i; + + if (!display) + return; + if (tab_bar) { delwin(tab_bar); tab_bar = NULL; @@ -81,6 +88,8 @@ void show_tab(unsigned int tab) void show_next_tab(void) { + if (!display) + return; current_tab ++; if (current_tab >= (int)tab_names.size()) current_tab = 0; @@ -89,6 +98,8 @@ void show_next_tab(void) void show_prev_tab(void) { + if (!display) + return; current_tab --; if (current_tab < 0) current_tab = tab_names.size() - 1; @@ -97,5 +108,7 @@ void show_prev_tab(void) void show_cur_tab(void) { + if (!display) + return; show_tab(current_tab); } @@ -128,10 +128,14 @@ int main(int argc, char **argv) - learn_parameters(100); + learn_parameters(500); save_parameters("saved_parameters.powertop"); + if (debug_learning) { + dump_parameter_bundle(); + exit(0); + } /* first one is short to not let the user wait too long */ init_display(); @@ -157,6 +161,7 @@ int main(int argc, char **argv) save_parameters("saved_parameters.powertop"); learn_parameters(500); save_parameters("saved_parameters.powertop"); + dump_parameter_bundle(); return 0; diff --git a/process/do_process.cpp b/process/do_process.cpp index 1aa0afc..73d7ec7 100644 --- a/process/do_process.cpp +++ b/process/do_process.cpp @@ -455,7 +455,7 @@ void process_update_display(void) win = tab_windows["Overview"]; if (!win) - exit(0); + return; wclear(win); |