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
0221cfc6
Commit
0221cfc6
authored
Oct 07, 2020
by
David Redondo
🏎
Browse files
Add makeSensors() and initalize() like gpu plugin to enable custom sensorproperty subclasses
Use it for Temperature and for eventaul sysctl sensor.
parent
3359c6fb
Changes
5
Hide whitespace changes
Inline
Side-by-side
plugins/global/cpu/cpu.cpp
View file @
0221cfc6
...
...
@@ -24,64 +24,106 @@
BaseCpuObject
::
BaseCpuObject
(
const
QString
&
id
,
const
QString
&
name
,
SensorContainer
*
parent
)
:
SensorObject
(
id
,
name
,
parent
)
{
m_usage
=
new
SensorProperty
(
QStringLiteral
(
"usage"
),
i18nc
(
"@title"
,
"Total Usage"
),
this
);
m_usage
->
setPrefix
(
name
);
makeSensors
();
initialize
();
}
void
BaseCpuObject
::
makeSensors
()
{
m_usage
=
new
SensorProperty
(
QStringLiteral
(
"usage"
),
this
);
m_system
=
new
SensorProperty
(
QStringLiteral
(
"system"
),
this
);
m_user
=
new
SensorProperty
(
QStringLiteral
(
"user"
),
this
);
m_wait
=
new
SensorProperty
(
QStringLiteral
(
"wait"
),
this
);
auto
n
=
new
SensorProperty
(
QStringLiteral
(
"name"
),
i18nc
(
"@title"
,
"Name"
),
name
(),
this
);
n
->
setVariantType
(
QVariant
::
String
);
}
void
BaseCpuObject
::
initialize
()
{
m_usage
->
setPrefix
(
name
());
m_usage
->
setName
(
i18nc
(
"@title"
,
"Total Usage"
));
m_usage
->
setShortName
(
i18nc
(
"@title, Short for 'Total Usage'"
,
"Usage"
));
m_usage
->
setUnit
(
KSysGuard
::
UnitPercent
);
m_usage
->
setVariantType
(
QVariant
::
Double
);
m_usage
->
setMax
(
100
);
m_system
=
new
SensorProperty
(
QStringLiteral
(
"system"
),
i18nc
(
"@title"
,
"System Usage"
),
this
);
m_system
->
set
Prefix
(
name
);
m_system
->
setPrefix
(
name
()
);
m_system
->
set
Name
(
i18nc
(
"@title"
,
"System Usage"
)
);
m_system
->
setShortName
(
i18nc
(
"@title, Short for 'System Usage'"
,
"System"
));
m_system
->
setUnit
(
KSysGuard
::
UnitPercent
);
m_system
->
setVariantType
(
QVariant
::
Double
);
m_system
->
setMax
(
100
);
m_user
=
new
SensorProperty
(
QStringLiteral
(
"user"
),
i18nc
(
"@title"
,
"User Usage"
),
this
);
m_user
->
set
Prefix
(
name
);
m_user
->
setPrefix
(
name
()
);
m_user
->
set
Name
(
i18nc
(
"@title"
,
"User Usage"
)
);
m_user
->
setShortName
(
i18nc
(
"@title, Short for 'User Usage'"
,
"User"
));
m_user
->
setUnit
(
KSysGuard
::
UnitPercent
);
m_user
->
setVariantType
(
QVariant
::
Double
);
m_user
->
setMax
(
100
);
m_wait
=
new
SensorProperty
(
QStringLiteral
(
"wait"
),
i18nc
(
"@title"
,
"Wait Usage"
),
this
);
m_wait
->
set
Prefix
(
name
);
m_wait
->
setPrefix
(
name
()
);
m_wait
->
set
Name
(
i18nc
(
"@title"
,
"Wait Usage"
)
);
m_wait
->
setShortName
(
i18nc
(
"@title, Short for 'Wait Load'"
,
"Wait"
));
m_wait
->
setUnit
(
KSysGuard
::
UnitPercent
);
m_wait
->
setVariantType
(
QVariant
::
Double
);
m_wait
->
setMax
(
100
);
auto
n
=
new
SensorProperty
(
QStringLiteral
(
"name"
),
i18nc
(
"@title"
,
"Name"
),
name
,
this
);
n
->
setVariantType
(
QVariant
::
String
);
}
CpuObject
::
CpuObject
(
const
QString
&
id
,
const
QString
&
name
,
SensorContainer
*
parent
)
:
BaseCpuObject
(
id
,
name
,
parent
)
{
}
void
CpuObject
::
makeSensors
()
{
BaseCpuObject
::
makeSensors
();
m_frequency
=
new
SensorProperty
(
QStringLiteral
(
"frequency"
),
this
);
m_temperature
=
new
SensorProperty
(
QStringLiteral
(
"temperature"
),
this
);
}
m_frequency
=
new
SensorProperty
(
QStringLiteral
(
"frequency"
),
i18nc
(
"@title"
,
"Current Frequency"
),
this
);
m_frequency
->
setPrefix
(
name
);
void
CpuObject
::
initialize
()
{
BaseCpuObject
::
initialize
();
m_frequency
->
setPrefix
(
name
());
m_frequency
->
setName
(
i18nc
(
"@title"
,
"Current Frequency"
));
m_frequency
->
setShortName
(
i18nc
(
"@title, Short for 'Current Frequency'"
,
"Frequency"
));
m_frequency
->
setDescription
(
i18nc
(
"@info"
,
"Current frequency of the CPU"
));
m_frequency
->
setVariantType
(
QVariant
::
Double
);
m_frequency
->
setUnit
(
KSysGuard
::
Unit
::
UnitMegaHertz
);
m_temperature
=
new
SensorProperty
(
QStringLiteral
(
"temperature"
),
i18nc
(
"@title"
,
"Current Temperature"
),
this
);
m_temperature
->
setPrefix
(
name
);
m_temperature
->
setPrefix
(
name
()
);
m_temperature
->
setPrefix
(
i18nc
(
"@title"
,
"Current Temperature"
)
);
m_temperature
->
setShortName
(
i18nc
(
"@title, Short for Current Temperatur"
,
"Temperature"
));
m_temperature
->
setVariantType
(
QVariant
::
Double
);
m_temperature
->
setUnit
(
KSysGuard
::
Unit
::
UnitCelsius
);
}
AllCpusObject
::
AllCpusObject
(
unsigned
int
cpuCount
,
unsigned
int
coreCount
,
SensorContainer
*
parent
)
:
BaseCpuObject
(
QStringLiteral
(
"all"
),
i18nc
(
"@title"
,
"All"
),
parent
)
{
auto
cpus
=
new
SensorProperty
(
QStringLiteral
(
"cpuCount"
),
i18nc
(
"@title"
,
"Number of CPUs"
),
cpuCount
,
this
);
cpus
->
setShortName
(
i18nc
(
"@title, Short fort 'Number of CPUs'"
,
"CPUs"
));
cpus
->
setDescription
(
i18nc
(
"@info"
,
"Number of physical CPUs installed in the system"
));
m_cpuCount
->
setValue
(
cpuCount
);
m_coreCount
->
setValue
(
cpuCount
);
}
void
AllCpusObject
::
makeSensors
()
{
m_cpuCount
=
new
SensorProperty
(
QStringLiteral
(
"cpuCount"
),
this
);
m_coreCount
=
new
SensorProperty
(
QStringLiteral
(
"coreCount"
),
this
);
}
void
AllCpusObject
::
initialize
()
{
m_cpuCount
->
setName
(
i18nc
(
"@title"
,
"Number of CPUs"
));
m_cpuCount
->
setShortName
(
i18nc
(
"@title, Short fort 'Number of CPUs'"
,
"CPUs"
));
m_cpuCount
->
setDescription
(
i18nc
(
"@info"
,
"Number of physical CPUs installed in the system"
));
auto
cores
=
new
SensorProperty
(
QStringLiteral
(
"coreCount"
),
i18nc
(
"@title"
,
"Number of Cores"
)
,
coreCount
,
this
);
core
s
->
setShortName
(
i18nc
(
"@title, Short fort 'Number of Cores'"
,
"Cores"
));
core
s
->
setDescription
(
i18nc
(
"@info"
,
"Number of CPU cores across all physical CPUS"
));
m_coreCount
->
setName
(
i18nc
(
"@title"
,
"Number of Cores"
));
m_
core
Count
->
setShortName
(
i18nc
(
"@title, Short fort 'Number of Cores'"
,
"Cores"
));
m_
core
Count
->
setDescription
(
i18nc
(
"@info"
,
"Number of CPU cores across all physical CPUS"
));
}
plugins/global/cpu/cpu.h
View file @
0221cfc6
...
...
@@ -23,8 +23,13 @@
#include
<SensorObject.h>
class
BaseCpuObject
:
public
SensorObject
{
public:
protected:
BaseCpuObject
(
const
QString
&
id
,
const
QString
&
name
,
SensorContainer
*
parent
);
virtual
void
initialize
();
virtual
void
makeSensors
();
SensorProperty
*
m_usage
;
SensorProperty
*
m_system
;
SensorProperty
*
m_user
;
...
...
@@ -36,6 +41,9 @@ public:
CpuObject
(
const
QString
&
id
,
const
QString
&
name
,
SensorContainer
*
parent
);
protected:
void
initialize
()
override
;
void
makeSensors
()
override
;
SensorProperty
*
m_frequency
;
SensorProperty
*
m_temperature
;
};
...
...
@@ -45,6 +53,9 @@ public:
AllCpusObject
(
unsigned
int
cpuCount
,
unsigned
int
coreCount
,
SensorContainer
*
parent
);
protected:
void
initialize
()
override
;
void
makeSensors
()
override
;
SensorProperty
*
m_cpuCount
;
SensorProperty
*
m_coreCount
;
};
...
...
plugins/global/cpu/linuxcpu.cpp
View file @
0221cfc6
...
...
@@ -17,24 +17,14 @@ static double readCpuFreq(const QString &cpuId, const QString &attribute, bool &
return
0
;
}
LinuxCpuObject
::
LinuxCpuObject
(
const
QString
&
id
,
const
QString
&
name
,
Sensor
Container
*
parent
,
double
frequency
)
:
CpuObject
(
id
,
name
,
parent
)
TemperatureSensor
::
TemperatureSensor
(
const
QString
&
id
,
Sensor
Object
*
parent
)
:
SensorProperty
(
id
,
parent
)
,
m_sensorChipName
{
nullptr
}
,
m_temperatureSubfeature
{
-
1
}
{
m_frequency
->
setValue
(
frequency
);
bool
ok
;
const
double
max
=
readCpuFreq
(
id
,
"cpuinfo_max_freq"
,
ok
);
if
(
ok
)
{
m_frequency
->
setMax
(
max
);
}
const
double
min
=
readCpuFreq
(
id
,
"cpuinfo_min_freq"
,
ok
);
if
(
ok
)
{
m_frequency
->
setMin
(
min
);
}
}
void
LinuxCpuObject
::
set
TemperatureSensor
(
const
sensors_chip_name
*
const
chipName
,
const
sensors_feature
*
const
feature
)
void
TemperatureSensor
::
setFeature
(
const
sensors_chip_name
*
const
chipName
,
const
sensors_feature
*
const
feature
)
{
#ifdef HAVE_SENSORS
m_sensorChipName
=
chipName
;
...
...
@@ -42,19 +32,55 @@ void LinuxCpuObject::setTemperatureSensor(const sensors_chip_name * const chipNa
if
(
temperature
)
{
m_temperatureSubfeature
=
temperature
->
number
;
}
// Typically temp_emergency > temp_crit > temp_max, but not every processor has them
// Typically temp_emergency > temp_crit > temp_max, but not every processor has them
// see https://www.kernel.org/doc/html/latest/hwmon/sysfs-interface.html
double
value
;
for
(
auto
subfeatureType
:
{
SENSORS_SUBFEATURE_TEMP_EMERGENCY
,
SENSORS_SUBFEATURE_TEMP_CRIT
,
SENSORS_SUBFEATURE_TEMP_MAX
})
{
const
sensors_subfeature
*
const
subfeature
=
sensors_get_subfeature
(
chipName
,
feature
,
subfeatureType
);
if
(
subfeature
&&
sensors_get_value
(
chipName
,
subfeature
->
number
,
&
value
)
==
0
)
{
m_temperature
->
setMax
(
value
);
setMax
(
value
);
break
;
}
}
#endif
}
void
TemperatureSensor
::
update
()
{
#ifdef HAVE_SENSORS
if
(
m_sensorChipName
&&
m_temperatureSubfeature
!=
-
1
)
{
double
value
;
if
(
sensors_get_value
(
m_sensorChipName
,
m_temperatureSubfeature
,
&
value
)
==
0
)
{
setValue
(
value
);
}
}
#endif
}
LinuxCpuObject
::
LinuxCpuObject
(
const
QString
&
id
,
const
QString
&
name
,
SensorContainer
*
parent
,
double
frequency
)
:
CpuObject
(
id
,
name
,
parent
)
{
m_frequency
->
setValue
(
frequency
);
bool
ok
;
const
double
max
=
readCpuFreq
(
id
,
"cpuinfo_max_freq"
,
ok
);
if
(
ok
)
{
m_frequency
->
setMax
(
max
);
}
const
double
min
=
readCpuFreq
(
id
,
"cpuinfo_min_freq"
,
ok
);
if
(
ok
)
{
m_frequency
->
setMin
(
min
);
}
}
void
LinuxCpuObject
::
makeSensors
()
{
BaseCpuObject
::
makeSensors
();
m_frequency
=
new
SensorProperty
(
QStringLiteral
(
"frequency"
),
this
);
m_temperatureSensor
=
new
TemperatureSensor
(
QStringLiteral
(
"temperature"
),
this
);
m_temperature
=
m_temperatureSensor
;
}
void
LinuxCpuObject
::
update
(
unsigned
long
long
system
,
unsigned
long
long
user
,
unsigned
long
long
wait
,
unsigned
long
long
idle
)
{
if
(
!
isSubscribed
())
{
...
...
@@ -83,14 +109,7 @@ void LinuxCpuObject::update(unsigned long long system, unsigned long long user,
// frequency value changed even if the cpu apparently doesn't use CPUFreq?
// Third update temperature
#ifdef HAVE_SENSORS
if
(
m_sensorChipName
&&
m_temperatureSubfeature
!=
-
1
)
{
double
value
;
if
(
sensors_get_value
(
m_sensorChipName
,
m_temperatureSubfeature
,
&
value
)
==
0
)
{
m_temperature
->
setValue
(
value
);
}
}
#endif
m_temperatureSensor
->
update
();
}
void
LinuxAllCpusObject
::
update
(
unsigned
long
long
system
,
unsigned
long
long
user
,
unsigned
long
long
wait
,
unsigned
long
long
idle
)
{
...
...
@@ -102,4 +121,9 @@ void LinuxAllCpusObject::update(unsigned long long system, unsigned long long us
m_usage
->
setValue
(
m_usageComputer
.
totalUsage
);
}
TemperatureSensor
*
LinuxCpuObject
::
temperatureSensor
()
{
return
m_temperatureSensor
;
}
plugins/global/cpu/linuxcpu.h
View file @
0221cfc6
...
...
@@ -7,17 +7,28 @@ struct sensors_feature;
#include
"cpu.h"
#include
"usagecomputer.h"
class
TemperatureSensor
:
public
SensorProperty
{
public:
TemperatureSensor
(
const
QString
&
id
,
SensorObject
*
parent
);
void
setFeature
(
const
sensors_chip_name
*
const
chipName
,
const
sensors_feature
*
const
feature
);
void
update
();
private:
const
sensors_chip_name
*
m_sensorChipName
;
int
m_temperatureSubfeature
;
};
class
LinuxCpuObject
:
public
CpuObject
{
public:
LinuxCpuObject
(
const
QString
&
id
,
const
QString
&
name
,
SensorContainer
*
parent
,
double
frequency
=
0
);
void
update
(
unsigned
long
long
system
,
unsigned
long
long
user
,
unsigned
long
long
wait
,
unsigned
long
long
idle
);
void
set
TemperatureSensor
(
const
sensors_chip_name
*
const
chipName
,
const
sensors_feature
*
const
feature
);
TemperatureSensor
*
temperatureSensor
(
);
private:
void
makeSensors
()
override
;
UsageComputer
m_usageComputer
;
const
sensors_chip_name
*
m_sensorChipName
;
int
m_temperatureSubfeature
;
TemperatureSensor
*
m_temperatureSensor
;
};
class
LinuxAllCpusObject
:
public
AllCpusObject
{
...
...
plugins/global/cpu/linuxcpuplugin.cpp
View file @
0221cfc6
...
...
@@ -156,7 +156,7 @@ void LinuxCpuPluginPrivate::addSensorsIntel(const sensors_chip_name * const chip
// Naturally they share the same temperature sensor and have the same coreId.
auto
cpu_range
=
m_cpusBySystemIds
.
equal_range
({
physicalId
,
feature
.
key
()});
for
(
auto
cpu_it
=
cpu_range
.
first
;
cpu_it
!=
cpu_range
.
second
;
++
cpu_it
)
{
(
*
cpu_it
)
->
setT
emperatureSensor
(
chipName
,
feature
.
value
());
(
*
cpu_it
)
->
t
emperatureSensor
(
)
->
setFeature
(
chipName
,
feature
.
value
());
}
}
}
...
...
@@ -196,7 +196,7 @@ void LinuxCpuPluginPrivate::addSensorsAmd(const sensors_chip_name * const chipNa
auto
setSingleSensor
=
[
this
,
chipName
]
(
const
sensors_feature
*
const
feature
)
{
for
(
auto
&
cpu
:
m_cpusBySystemIds
)
{
cpu
->
setT
emperatureSensor
(
chipName
,
feature
);
cpu
->
t
emperatureSensor
(
)
->
setFeature
(
chipName
,
feature
);
}
};
if
(
tdie
)
{
...
...
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