Do not parse all nvidia-smi output, use --query-gpu option.

This commit is contained in:
Kolan Sh 2016-10-11 15:25:52 +03:00
parent 4bd3c716fa
commit 4b559e8b20
1 changed files with 15 additions and 53 deletions

View File

@ -3084,7 +3084,7 @@ static gboolean
sensors_nvidia_smi_read(gboolean setup)
{
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 *output = NULL;
gchar *errout = NULL;
@ -3109,49 +3109,12 @@ sensors_nvidia_smi_read(gboolean setup)
if (result && output)
{
str = output;
/* Look for GPU N: or GPU X:Y:Z sections, but avoid GPU : lines
| Recent nvidia-smi output looks like (eg 270.41.06):
|
| 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%
| ...
/* nvidia-smi --format=csv --query-gpu=temperature.gpu:
* temperature.gpu
* 52
*/
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 Current Temp");
if (!str)
{
str = stmp;
continue;
}
str += 27;
if (sscanf(str, " : %f", &temp) != 1)
continue;
}
if (setup)
{
smi = g_new0(NvidiaSmi, 1);
@ -3165,7 +3128,6 @@ sensors_nvidia_smi_read(gboolean setup)
smi->temp = temp;
}
}
}
if (output)
g_free(output);
if (errout)