Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Plasma
KSysGuard
Commits
e1fe8f46
Commit
e1fe8f46
authored
Oct 07, 2020
by
Arjen Hiemstra
Browse files
Avoid having to reparse SMI query result when there are multiple GPUs
Also use std::vector for the container so we can use emplace()
parent
29d3c450
Changes
3
Hide whitespace changes
Inline
Side-by-side
plugins/global/gpu/LinuxNvidiaGpu.cpp
View file @
e1fe8f46
...
...
@@ -41,7 +41,7 @@ void LinuxNvidiaGpu::initialize()
}
auto
queryResult
=
s_smiProcess
->
query
();
if
(
m_index
>=
queryResult
.
length
(
))
{
if
(
m_index
>=
int
(
queryResult
.
size
()
))
{
qWarning
()
<<
"Could not retrieve information for NVidia GPU"
<<
m_index
;
}
else
{
auto
data
=
queryResult
.
at
(
m_index
);
...
...
plugins/global/gpu/NvidiaSmiProcess.cpp
View file @
e1fe8f46
...
...
@@ -19,12 +19,14 @@ bool NvidiaSmiProcess::isSupported() const
return
!
m_smiPath
.
isEmpty
();
}
QV
ector
<
NvidiaSmiProcess
::
GpuQueryResult
>
NvidiaSmiProcess
::
query
()
std
::
v
ector
<
NvidiaSmiProcess
::
GpuQueryResult
>
NvidiaSmiProcess
::
query
()
{
QVector
<
NvidiaSmiProcess
::
GpuQueryResult
>
result
;
if
(
!
isSupported
())
{
return
result
;
return
m_queryResult
;
}
if
(
!
m_queryResult
.
empty
())
{
return
m_queryResult
;
}
// Read and parse the result of "nvidia-smi query"
...
...
@@ -38,7 +40,7 @@ QVector<NvidiaSmiProcess::GpuQueryResult> NvidiaSmiProcess::query()
queryProcess
.
start
();
int
gpuCounter
=
0
;
GpuQueryResult
*
data
=
&
result
[
0
]
;
auto
data
=
m_queryResult
.
end
()
;
bool
readMemory
=
false
;
bool
readMaxClocks
=
false
;
...
...
@@ -50,13 +52,17 @@ QVector<NvidiaSmiProcess::GpuQueryResult> NvidiaSmiProcess::query()
auto
line
=
queryProcess
.
readLine
();
if
(
line
.
startsWith
(
"GPU "
))
{
// Start of GPU properties block.
result
.
append
(
GpuQueryResult
{});
data
=
&
result
[
gpuCounter
]
;
// Start of GPU properties block.
Ensure we have a new data object
// to write to.
data
=
m_queryResult
.
emplace
(
m_queryResult
.
end
())
;
gpuCounter
++
;
}
if
((
readMemory
||
readMaxClocks
)
&&
!
line
.
startsWith
(
" "
))
{
// Memory/clock information does not have a unique prefix but should
// be indented more than their "headers". So if the indentation is
// less, we are no longer in an info block and should treat it as
// such.
readMemory
=
false
;
readMaxClocks
=
false
;
}
...
...
@@ -90,7 +96,7 @@ QVector<NvidiaSmiProcess::GpuQueryResult> NvidiaSmiProcess::query()
}
}
return
r
esult
;
return
m_queryR
esult
;
}
void
NvidiaSmiProcess
::
ref
()
...
...
plugins/global/gpu/NvidiaSmiProcess.h
View file @
e1fe8f46
...
...
@@ -37,7 +37,7 @@ public:
bool
isSupported
()
const
;
QV
ector
<
GpuQueryResult
>
query
();
std
::
v
ector
<
GpuQueryResult
>
query
();
void
ref
();
void
unref
();
...
...
@@ -48,6 +48,7 @@ private:
void
readStatisticsData
();
QString
m_smiPath
;
std
::
vector
<
GpuQueryResult
>
m_queryResult
;
std
::
unique_ptr
<
QProcess
>
m_process
=
nullptr
;
int
m_references
=
0
;
};
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment