Compare commits

..

2 Commits

1 changed files with 15 additions and 53 deletions

View File

@ -3084,7 +3084,7 @@ static gboolean
sensors_nvidia_smi_read(gboolean setup) sensors_nvidia_smi_read(gboolean setup)
{ {
gint n = 0; gint n = 0;
gchar *args[] = { "nvidia-smi", "-q", "-a", NULL }; gchar *args[] = { "nvidia-smi", "--format=csv", "--query-gpu=temperature.gpu", NULL };
gchar *str, *stmp, id[64]; gchar *str, *stmp, id[64];
gchar *output = NULL; gchar *output = NULL;
gchar *errout = NULL; gchar *errout = NULL;
@ -3109,49 +3109,12 @@ sensors_nvidia_smi_read(gboolean setup)
if (result && output) if (result && output)
{ {
str = output; str = output;
/* Look for GPU N: or GPU X:Y:Z sections, but avoid GPU : lines /* nvidia-smi --format=csv --query-gpu=temperature.gpu:
| Recent nvidia-smi output looks like (eg 270.41.06): * temperature.gpu
| * 52
| GPU 0:3:0
| Product Name : GeForce GTX 460
| ...
| Temperature
| Gpu : 32 C
|
| Older nvidia-smi output was like (eg 260.19.29):
|
| GPU 0:
| Product Name : GeForce GTX 285
| ...
| Temperature : 65 C
| Fan Speed : 100%
| Utilization
| GPU : 84%
| ...
*/ */
while ((str = g_strstr_len(str, -1, "GPU ")) != NULL) if (sscanf(str, "temperature.gpu\n%f", &temp) == 1)
{ {
str += 3;
if ( sscanf(str, " %63s", id) != 1
|| !strcmp(id, ":")
)
continue;
if ((str = g_strstr_len(str, -1, "Temperature")) != NULL)
{
str += 11;
if (sscanf(str, " : %f", &temp) != 1)
{
stmp = str;
str = g_strstr_len(str, -1, "Gpu");
if (!str)
{
str = stmp;
continue;
}
str += 3;
if (sscanf(str, " : %f", &temp) != 1)
continue;
}
if (setup) if (setup)
{ {
smi = g_new0(NvidiaSmi, 1); smi = g_new0(NvidiaSmi, 1);
@ -3165,7 +3128,6 @@ sensors_nvidia_smi_read(gboolean setup)
smi->temp = temp; smi->temp = temp;
} }
} }
}
if (output) if (output)
g_free(output); g_free(output);
if (errout) if (errout)