1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-11-15 17:47:09 +00:00

nvidiabar, etc (#215)

* First experiment with $nvidiabar

Added nvidiabar, nvidiagraph and nvidiagauge. Using a dummy value of 50% for now until it is integrated with the nvidia value query functions.

* Implement get_nvidia_barval()

`get_nvidia_barval()` no longer returns a dummy "50%" but instead an actual value for supported arguments:

`gpuutil`, `memutil`, `membwutil`, `videoutil`,`pcieutil`, `fanlevel` and `gputemp`
This commit is contained in:
Matt Sturgeon 2016-05-03 13:03:45 +01:00 committed by Brenden Matthews
parent 06f87b9c26
commit d8c659e7de
3 changed files with 96 additions and 0 deletions

View File

@ -1804,6 +1804,27 @@ struct text_object *construct_text_object(char *s, const char *arg,
}
obj->callbacks.print = &print_nvidia_value;
obj->callbacks.free = &free_nvidia;
END OBJ_ARG(nvidiabar, 0, "nvidiabar needs an argument")
if (scan_nvidia_args(obj, arg, BAR)) {
CRIT_ERR(obj, free_at_crash, "nvidiabar: invalid argument"
" specified: '%s'\n", arg);
}
obj->callbacks.barval = &get_nvidia_barval;
obj->callbacks.free = &free_nvidia;
END OBJ_ARG(nvidiagraph, 0, "nvidiagraph needs an argument")
if (scan_nvidia_args(obj, arg, GRAPH)) {
CRIT_ERR(obj, free_at_crash, "nvidiagraph: invalid argument"
" specified: '%s'\n", arg);
}
obj->callbacks.graphval = &get_nvidia_barval;
obj->callbacks.free = &free_nvidia;
END OBJ_ARG(nvidiagauge, 0, "nvidiagauge needs an argument")
if (scan_nvidia_args(obj, arg, GAUGE)) {
CRIT_ERR(obj, free_at_crash, "nvidiagauge: invalid argument"
" specified: '%s'\n", arg);
}
obj->callbacks.gaugeval = &get_nvidia_barval;
obj->callbacks.free = &free_nvidia;
#endif /* BUILD_NVIDIA */
#ifdef BUILD_APCUPSD
END OBJ_ARG(apcupsd, &update_apcupsd, "apcupsd needs arguments: <host> <port>")

View File

@ -56,6 +56,15 @@
* TEMP GPU ${nvidia gputemp}°C (${nvidia gputempthreshold}°C max.), SYS ${nvidia ambienttemp}°C
* FAN ${nvidia fanspeed}% RPM (${nvidia fanlevel}%)
*
* --==| NVIDIA Bars |==--
* LOAD ${nvidiabar gpuutil}
* VRAM ${nvidiabar memutil}
* RAM ${nvidiabar membwutil}
* VIDEO ${nvidiabar videoutil}
* PCIe ${nvidiabar pcieutil}
* Fan ${nvidiabar fanlevel}
* TEMP ${nvidiabar gputemp}
*
*/
@ -331,6 +340,31 @@ namespace {
nvidia_display_setting nvidia_display;
}
// Extract arguments for nvidiabar, etc, and run set_nvidia_type
int scan_nvidia_args (struct text_object *obj, const char *args, unsigned int special_t) {
const char *arg = args;
switch (special_t) {
case BAR:
arg = scan_bar(obj, arg, 100);
break;
case GRAPH:
arg = scan_graph(obj, arg, 100);
break;
case GAUGE:
arg = scan_gauge(obj, arg, 100);
break;
default:
return 1;
}
// Return error if no argument
// (sometimes scan_graph gets excited and eats the whole string!
if (!arg) return 1;
return set_nvidia_type(obj, arg);
}
// Evaluate module parameters and prepare query
int set_nvidia_type(struct text_object *obj, const char *arg)
@ -704,6 +738,45 @@ void print_nvidia_value(struct text_object *obj, char *p, int p_max_size)
}
double get_nvidia_barval(struct text_object *obj) {
struct nvidia_s *nvs = static_cast<nvidia_s *>(obj->data.opaque);
int temp1, temp2;
double value;
// Assume failure
value = 0;
// Convert query_result to a percentage
if (nvs != NULL) {
switch (nvs->attribute) {
case ATTR_UTILS_STRING: // one of the percentage utils (gpuutil, membwutil, videoutil and pcieutil)
value = get_nvidia_string_value(nvs->target, ATTR_UTILS_STRING, nvs->token, nvs->search);
break;
case ATTR_MEM_UTIL: // memutil
temp1 = get_nvidia_value(nvs->target, ATTR_MEM_USED);
temp2 = get_nvidia_value(nvs->target, ATTR_MEM_TOTAL);
value = ((float)temp1 * 100 / (float)temp2) + 0.5;
break;
case ATTR_FAN_LEVEL: // fanlevel
case ATTR_FAN_SPEED: // TODO warn user to use fanlevel if they use fanspeed
value = get_nvidia_value(nvs->target, ATTR_FAN_LEVEL);
break;
case ATTR_GPU_TEMP: // gputemp (calculate out of gputempthreshold)
temp1 = get_nvidia_value(nvs->target, ATTR_GPU_TEMP);
temp2 = get_nvidia_value(nvs->target, ATTR_GPU_TEMP_THRESHOLD);
value = ((float)temp1 * 100 / (float)temp2) + 0.5;
break;
// TODO: calculate gpufreq, memfreq, etc
// can use (val-min)÷(max-min)×100. Perhaps a helper function or macro
// TODO: throw errors if unsupported args are used
}
}
// Return the percentage
return value;
}
// Cleanup
void free_nvidia(struct text_object *obj)

View File

@ -32,8 +32,10 @@
#ifndef NVIDIA_CONKY_H
#define NVIDIA_CONKY_H
int scan_nvidia_args (struct text_object *obj, const char *args, unsigned int special_t);
int set_nvidia_type(struct text_object *, const char *);
void print_nvidia_value(struct text_object *, char *, int);
double get_nvidia_barval(struct text_object *obj);
void free_nvidia(struct text_object *);
#endif