Changeset 5185
- Timestamp:
- 04/17/08 03:30:37 (5 years ago)
- Location:
- lm-sensors/branches/lm-sensors-3.0.0
- Files:
-
- 2 modified
-
CHANGES (modified) (1 diff)
-
prog/sensors/chips.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lm-sensors/branches/lm-sensors-3.0.0/CHANGES
r5184 r5185 3 3 4 4 SVN-HEAD 5 sensors: Print energy and power sensors 5 sensors: Print energy and power sensors with automatically scaled units 6 6 libsensors: Use __func__ instead of __FUNCTION__ 7 7 Parse the configuration file in C locale -
lm-sensors/branches/lm-sensors-3.0.0/prog/sensors/chips.c
r5184 r5185 24 24 #include <stdlib.h> 25 25 #include <string.h> 26 #include <math.h> 26 27 27 28 #include "main.h" … … 402 403 } 403 404 405 struct scale_table { 406 double upper_bound; 407 const char *unit; 408 }; 409 410 static void scale_value(double *value, const char **prefixstr) 411 { 412 double abs_value = fabs(*value); 413 double divisor = 1e-9; 414 static struct scale_table prefix_scales[] = { 415 {1e-6, "n"}, 416 {1e-3, "u"}, 417 {1, "m"}, 418 {1e3, ""}, 419 {1e6, "k"}, 420 {1e9, "M"}, 421 {0, "G"}, /* no upper bound */ 422 }; 423 struct scale_table *scale = prefix_scales; 424 425 while (scale->upper_bound && abs_value > scale->upper_bound) { 426 divisor = scale->upper_bound; 427 scale++; 428 } 429 430 *value /= divisor; 431 *prefixstr = scale->unit; 432 } 433 404 434 static void print_chip_power(const sensors_chip_name *name, 405 435 const sensors_feature *feature, 406 436 int label_size) 407 437 { 438 double val; 408 439 int need_space = 0; 409 440 const sensors_subfeature *sf, *sfmin, *sfmax, *sfint; 410 441 char *label; 442 const char *unit; 411 443 412 444 if (!(label = sensors_get_label(name, feature))) { … … 420 452 sf = sensors_get_subfeature(name, feature, 421 453 SENSORS_SUBFEATURE_POWER_AVERAGE); 422 if (sf) 423 printf("%6.2f W", get_value(name, sf)); 424 else 454 if (sf) { 455 val = get_value(name, sf); 456 scale_value(&val, &unit); 457 printf("%6.2f %sW", val, unit); 458 } else 425 459 printf(" N/A"); 426 460 … … 435 469 436 470 if (sfmin) { 437 printf("min = %6.2f W", get_value(name, sfmin)); 471 val = get_value(name, sfmin); 472 scale_value(&val, &unit); 473 printf("min = %6.2f %sW", val, unit); 438 474 need_space = 1; 439 475 } 440 476 441 477 if (sfmax) { 442 printf("%smax = %6.2f W", (need_space ? ", " : ""), 443 get_value(name, sfmax)); 478 val = get_value(name, sfmax); 479 scale_value(&val, &unit); 480 printf("%smax = %6.2f %sW", (need_space ? ", " : ""), 481 val, unit); 444 482 need_space = 1; 445 483 } … … 460 498 int label_size) 461 499 { 500 double val; 462 501 const sensors_subfeature *sf; 463 502 char *label; 503 const char *unit; 464 504 465 505 if (!(label = sensors_get_label(name, feature))) { … … 473 513 sf = sensors_get_subfeature(name, feature, 474 514 SENSORS_SUBFEATURE_ENERGY_INPUT); 475 if (sf) 476 printf("%6.2f J", get_value(name, sf)); 477 else 515 if (sf) { 516 val = get_value(name, sf); 517 scale_value(&val, &unit); 518 printf("%6.2f %sJ", val, unit); 519 } else 478 520 printf(" N/A"); 479 521
