static void print_chip_power(const sensors_chip_name *name, const sensors_feature *feature, int label_size) { double val; const sensors_subfeature *sf; struct sensor_subfeature_data sensors[6]; struct sensor_subfeature_data alarms[3]; int sensor_count, alarm_count; char *label; const char *unit; int i; 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); sensor_count = alarm_count = 0; /* Power sensors come in 2 flavors: instantaneous and averaged. To keep things simple, we assume that each sensor only implements one flavor. */ sf = sensors_get_subfeature(name, feature, SENSORS_SUBFEATURE_POWER_INPUT); get_sensor_limit_data(name, feature, sf ? power_inst_sensors : power_avg_sensors, sensors, ARRAY_SIZE(sensors), &sensor_count, alarms, ARRAY_SIZE(alarms), &alarm_count); /* Add sensors common to both flavors. */ get_sensor_limit_data(name, feature, power_common_sensors, sensors, ARRAY_SIZE(sensors), &sensor_count, alarms, ARRAY_SIZE(alarms), &alarm_count); if (!sf) sf = sensors_get_subfeature(name, feature, SENSORS_SUBFEATURE_POWER_AVERAGE); if (sf && get_input_value(name, sf, &val) == 0) { scale_value(&val, &unit); printf("%6.2f %sW ", val, unit); } else printf(" N/A "); for (i = 0; i < sensor_count; i++) scale_value(&sensors[i].value, &sensors[i].unit); print_limits(sensors, sensor_count, alarms, alarm_count, label_size, "%s = %6.2f %sW"); printf("\n"); }
static void print_chip_curr(const sensors_chip_name *name, const sensors_feature *feature, int label_size) { const sensors_subfeature *sf; double val; char *label; struct sensor_subfeature_data sensors[NUM_CURR_SENSORS]; struct sensor_subfeature_data alarms[NUM_CURR_ALARMS]; int sensor_count, alarm_count; 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_CURR_INPUT); if (sf && get_input_value(name, sf, &val) == 0) printf("%+6.2f A ", val); else printf(" N/A "); sensor_count = alarm_count = 0; get_sensor_limit_data(name, feature, current_sensors, sensors, &sensor_count, alarms, &alarm_count); print_limits(sensors, sensor_count, alarms, alarm_count, label_size, "%s = %+6.2f A"); printf("\n"); }
/* * Get sensor limit information. * *num_limits and *num_alarms must be initialized by the caller. */ static void get_sensor_limit_data(const sensors_chip_name *name, const sensors_feature *feature, const struct sensor_subfeature_list *sfl, struct sensor_subfeature_data *limits, int max_limits, int *num_limits, struct sensor_subfeature_data *alarms, int max_alarms, int *num_alarms) { const sensors_subfeature *sf; for (; sfl->subfeature >= 0; sfl++) { sf = sensors_get_subfeature(name, feature, sfl->subfeature); if (sf) { if (sfl->alarm) { /* * Only queue alarm subfeatures if the alarm * is active, and don't store the alarm value * (it is implied to be active if queued). */ if (get_value(name, sf)) { if (*num_alarms >= max_alarms) { fprintf(stderr, "Not enough %s buffers (%d)\n", "alarm", max_alarms); } else { alarms[*num_alarms].name = sfl->name; (*num_alarms)++; } } } else { /* * Always queue limit subfeatures with their value. */ if (*num_limits >= max_limits) { fprintf(stderr, "Not enough %s buffers (%d)\n", "limit", max_limits); } else { limits[*num_limits].value = get_value(name, sf); limits[*num_limits].name = sfl->name; (*num_limits)++; } } if (sfl->exists) { get_sensor_limit_data(name, feature, sfl->exists, limits, max_limits, num_limits, alarms, max_alarms, num_alarms); } } } }
static void print_chip_power(const sensors_chip_name *name, const sensors_feature *feature, int label_size) { double val; const sensors_subfeature *sf; struct sensor_subfeature_data sensors[NUM_POWER_SENSORS]; struct sensor_subfeature_data alarms[NUM_POWER_ALARMS]; int sensor_count, alarm_count; char *label; const char *unit; int i; 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); sensor_count = alarm_count = 0; /* * Power sensors come in 2 flavors: instantaneous and averaged. * Most devices only support one flavor, so we try to display the * average power if the instantaneous power attribute does not exist. * If both instantaneous power and average power are supported, * average power is displayed as limit. */ sf = sensors_get_subfeature(name, feature, SENSORS_SUBFEATURE_POWER_INPUT); get_sensor_limit_data(name, feature, sf ? power_inst_sensors : power_avg_sensors, sensors, &sensor_count, alarms, &alarm_count); /* Add sensors common to both flavors. */ get_sensor_limit_data(name, feature, power_common_sensors, sensors, &sensor_count, alarms, &alarm_count); if (!sf) sf = sensors_get_subfeature(name, feature, SENSORS_SUBFEATURE_POWER_AVERAGE); if (sf && get_input_value(name, sf, &val) == 0) { scale_value(&val, &unit); printf("%6.2f %sW%*s", val, unit, 2 - (int)strlen(unit), ""); } else printf(" N/A "); for (i = 0; i < sensor_count; i++) { /* * Unit is W and needs to be scaled for all attributes except * interval, which does not need to be scaled and is reported in * seconds. */ if (strcmp(sensors[i].name, "interval")) { char *tmpstr; tmpstr = alloca(4); scale_value(&sensors[i].value, &unit); snprintf(tmpstr, 4, "%sW", unit); sensors[i].unit = tmpstr; } else { sensors[i].unit = "s"; } } print_limits(sensors, sensor_count, alarms, alarm_count, label_size, "%s = %6.2f %s"); printf("\n"); }
static void print_chip_temp(const sensors_chip_name *name, const sensors_feature *feature, int label_size) { struct sensor_subfeature_data sensors[NUM_TEMP_SENSORS]; struct sensor_subfeature_data alarms[NUM_TEMP_ALARMS]; int sensor_count, alarm_count; const sensors_subfeature *sf; double val; char *label; int i; 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_TEMP_FAULT); if (sf && get_value(name, sf)) { printf(" FAULT "); } else { sf = sensors_get_subfeature(name, feature, SENSORS_SUBFEATURE_TEMP_INPUT); if (sf && get_input_value(name, sf, &val) == 0) { get_input_value(name, sf, &val); if (fahrenheit) val = deg_ctof(val); printf("%+6.1f%s ", val, degstr); } else printf(" N/A "); } sensor_count = alarm_count = 0; get_sensor_limit_data(name, feature, temp_sensors, sensors, &sensor_count, alarms, &alarm_count); for (i = 0; i < sensor_count; i++) { if (fahrenheit) sensors[i].value = deg_ctof(sensors[i].value); sensors[i].unit = degstr; } print_limits(sensors, sensor_count, alarms, alarm_count, label_size, "%-4s = %+5.1f%s"); /* print out temperature sensor info */ sf = sensors_get_subfeature(name, feature, SENSORS_SUBFEATURE_TEMP_TYPE); if (sf) { int sens = (int)get_value(name, sf); /* older kernels / drivers sometimes report a beta value for thermistors */ if (sens > 1000) sens = 4; printf(" sensor = %s", sens == 0 ? "disabled" : sens == 1 ? "CPU diode" : sens == 2 ? "transistor" : sens == 3 ? "thermal diode" : sens == 4 ? "thermistor" : sens == 5 ? "AMD AMDSI" : sens == 6 ? "Intel PECI" : "unknown"); } printf("\n"); }