From 4c93dffd4fe537dfee2a1d35d4f74bd721551a96 Mon Sep 17 00:00:00 2001 From: "Darrick J. Wong" Date: Thu, 17 Apr 2008 01:28:51 +0000 Subject: [PATCH] Subject: [PATCH 3/4 v2] sensors: Print energy and power meters Display power and energy meters in sensors. Signed-off-by: Darrick J. Wong git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@5184 7894878c-1315-0410-8ee3-d5d059ff63e0 --- CHANGES | 1 + prog/sensors/chips.c | 85 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+) diff --git a/CHANGES b/CHANGES index 8235d3be..23bfab9e 100644 --- a/CHANGES +++ b/CHANGES @@ -2,6 +2,7 @@ lm-sensors CHANGES file ----------------------- SVN-HEAD + sensors: Print energy and power sensors libsensors: Use __func__ instead of __FUNCTION__ Parse the configuration file in C locale Late compute statements override early ones diff --git a/prog/sensors/chips.c b/prog/sensors/chips.c index 024646ac..52ab5e04 100644 --- a/prog/sensors/chips.c +++ b/prog/sensors/chips.c @@ -401,6 +401,85 @@ static void print_chip_fan(const sensors_chip_name *name, printf("\n"); } +static void print_chip_power(const sensors_chip_name *name, + const sensors_feature *feature, + int label_size) +{ + int need_space = 0; + const sensors_subfeature *sf, *sfmin, *sfmax, *sfint; + char *label; + + if (!(label = sensors_get_label(name, feature))) { + fprintf(stderr, "ERROR: Can't get label of feature %s!\n", + feature->name); + return; + } + print_label(label, label_size); + free(label); + + sf = sensors_get_subfeature(name, feature, + SENSORS_SUBFEATURE_POWER_AVERAGE); + if (sf) + printf("%6.2f W", get_value(name, sf)); + else + printf(" N/A"); + + sfmin = sensors_get_subfeature(name, feature, + SENSORS_SUBFEATURE_POWER_AVERAGE_HIGHEST); + sfmax = sensors_get_subfeature(name, feature, + SENSORS_SUBFEATURE_POWER_AVERAGE_LOWEST); + sfint = sensors_get_subfeature(name, feature, + SENSORS_SUBFEATURE_POWER_AVERAGE_INTERVAL); + if (sfmin || sfmax || sfint) { + printf(" ("); + + if (sfmin) { + printf("min = %6.2f W", get_value(name, sfmin)); + need_space = 1; + } + + if (sfmax) { + printf("%smax = %6.2f W", (need_space ? ", " : ""), + get_value(name, sfmax)); + need_space = 1; + } + + if (sfint) { + printf("%sinterval = %6.2f s", (need_space ? ", " : ""), + get_value(name, sfint)); + need_space = 1; + } + printf(")"); + } + + printf("\n"); +} + +static void print_chip_energy(const sensors_chip_name *name, + const sensors_feature *feature, + int label_size) +{ + const sensors_subfeature *sf; + char *label; + + if (!(label = sensors_get_label(name, feature))) { + fprintf(stderr, "ERROR: Can't get label of feature %s!\n", + feature->name); + return; + } + print_label(label, label_size); + free(label); + + sf = sensors_get_subfeature(name, feature, + SENSORS_SUBFEATURE_ENERGY_INPUT); + if (sf) + printf("%6.2f J", get_value(name, sf)); + else + printf(" N/A"); + + printf("\n"); +} + static void print_chip_vid(const sensors_chip_name *name, const sensors_feature *feature, int label_size) @@ -468,6 +547,12 @@ void print_chip(const sensors_chip_name *name) case SENSORS_FEATURE_BEEP_ENABLE: print_chip_beep_enable(name, feature, label_size); break; + case SENSORS_FEATURE_POWER: + print_chip_power(name, feature, label_size); + break; + case SENSORS_FEATURE_ENERGY: + print_chip_energy(name, feature, label_size); + break; default: continue; }