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
d391e4fc
Commit
d391e4fc
authored
Oct 01, 2020
by
David Redondo
🏎
Browse files
Revert mixin approach.
parent
6c3cf0f2
Changes
6
Hide whitespace changes
Inline
Side-by-side
plugins/global/cpu/cpu.cpp
View file @
d391e4fc
...
...
@@ -19,6 +19,8 @@
#include
"cpu.h"
#include
<KLocalizedString>
CpuObject
::
CpuObject
(
const
QString
&
id
,
const
QString
&
name
,
SensorContainer
*
parent
)
:
SensorObject
(
id
,
name
,
parent
)
,
m_frequency
{
nullptr
}
...
...
plugins/global/cpu/cpu.h
View file @
d391e4fc
...
...
@@ -20,14 +20,14 @@
#ifndef CPU_H
#define CPU_H
#include
<KLocalizedString>
#include
<SensorObject.h>
class
CpuObject
:
public
SensorObject
{
public:
CpuObject
(
const
QString
&
id
,
const
QString
&
name
,
SensorContainer
*
parent
);
// const int physicalId; // NOTE The combination of these two ids is not necessarily unique with hyperthreading
// const int coreId;
protected:
SensorProperty
*
m_usage
;
SensorProperty
*
m_system
;
...
...
@@ -37,25 +37,4 @@ protected:
SensorProperty
*
m_temperature
;
};
template
<
typename
T
>
class
AllCpusObject
:
public
T
{
public:
AllCpusObject
(
unsigned
int
cpus
,
unsigned
int
cores
,
SensorContainer
*
parent
);
static_assert
(
std
::
is_base_of
<
CpuObject
,
T
>::
value
,
"Base of AllCpuObject must be a CpuObject"
);
};
template
<
typename
T
>
AllCpusObject
<
T
>::
AllCpusObject
(
unsigned
int
cpus
,
unsigned
int
cores
,
SensorContainer
*
parent
)
:
T
(
QStringLiteral
(
"all"
),
i18nc
(
"@title"
,
"All"
),
parent
)
{
delete
T
::
m_frequency
;
delete
T
::
m_temperature
;
auto
cpuCount
=
new
SensorProperty
(
QStringLiteral
(
"cpuCount"
),
i18nc
(
"@title"
,
"Number of CPUs"
),
cpus
,
this
);
cpuCount
->
setShortName
(
i18nc
(
"@title, Short fort 'Number of CPUs'"
,
"CPUs"
));
cpuCount
->
setDescription
(
i18nc
(
"@info"
,
"Number of physical CPUs installed in the system"
));
auto
coreCount
=
new
SensorProperty
(
QStringLiteral
(
"coreCount"
),
i18nc
(
"@title"
,
"Number of Cores"
),
cores
,
this
);
coreCount
->
setShortName
(
i18nc
(
"@title, Short fort 'Number of Cores'"
,
"Cores"
));
coreCount
->
setDescription
(
i18nc
(
"@info"
,
"Number of CPU cores across all physical CPUS"
));
}
#endif
plugins/global/cpu/freebsdcpu.cpp
View file @
d391e4fc
...
...
@@ -43,6 +43,7 @@ FreeBsdCpuObject::FreeBsdCpuObject(const QString &id, const QString &name, Senso
}
const
QByteArray
tjmax
=
QByteArrayLiteral
(
"dev.cpu."
)
+
id
.
right
(
1
).
toLocal8Bit
()
+
QByteArrayLiteral
(
".coretemp.tjmax"
);
int
maxTemperature
;
size_t
maxTemperatureSize
=
sizeof
(
maxTemperature
);
// This is only availabel on Intel (using the coretemp driver)
if
(
readSysctl
(
tjmax
.
constData
(),
&
maxTemperature
))
{
m_temperature
->
setMax
(
maxTemperature
);
...
...
@@ -68,7 +69,7 @@ void FreeBsdCpuObject::update(long system, long user, long idle)
m_userTicks
=
user
;
m_totalTicks
=
totalTicks
;
if
(
!
m_frequency
)
{
if
(
id
()
==
QStringLiteral
(
"all"
)
)
{
return
;
}
...
...
@@ -96,13 +97,22 @@ FreeBsdCpuPluginPrivate::FreeBsdCpuPluginPrivate(CpuPlugin* q)
for
(
int
i
=
0
;
i
<
numCpu
;
++
i
)
{
new
FreeBsdCpuObject
(
QStringLiteral
(
"cpu%1"
).
arg
(
i
),
i18nc
(
"@title"
,
"CPU %1"
,
i
+
1
),
m_container
);
}
m_allCpusObject
=
new
AllCpusObject
<
FreeBsdCpuObject
>
(
numCpu
,
numCpu
,
m_container
);
// Add total usage sensors
auto
total
=
new
FreeBsdCpuObject
(
QStringLiteral
(
"all"
),
i18nc
(
"@title"
,
"All"
),
m_container
);
auto
cpuCount
=
new
SensorProperty
(
QStringLiteral
(
"cpuCount"
),
i18nc
(
"@title"
,
"Number of CPUs"
),
numCpu
,
total
);
cpuCount
->
setShortName
(
i18nc
(
"@title, Short fort 'Number of CPUs'"
,
"CPUs"
));
cpuCount
->
setDescription
(
i18nc
(
"@info"
,
"Number of physical CPUs installed in the system"
));
auto
coreCount
=
new
SensorProperty
(
QStringLiteral
(
"coreCount"
),
i18nc
(
"@title"
,
"Number of Cores"
),
numCpu
,
total
);
coreCount
->
setShortName
(
i18nc
(
"@title, Short fort 'Number of Cores'"
,
"Cores"
));
coreCount
->
setDescription
(
i18nc
(
"@info"
,
"Number of CPU cores across all physical CPUS"
));
}
void
FreeBsdCpuPluginPrivate
::
update
()
{
auto
updateCpu
=
[]
(
FreeBsdCpuObject
*
cpu
,
long
*
cp_time
){
cpu
->
update
(
cp_time
[
CP_SYS
]
+
cp_time
[
CP_INTR
],
cp_time
[
CP_USER
]
+
cp_time
[
CP_NICE
],
cp_time
[
CP_IDLE
]);
cpu
->
update
(
cp_time
[
CP_SYS
+
CP_INTR
],
cp_time
[
CP_USER
]
+
cp_time
[
CP_NICE
],
cp_time
[
CP_IDLE
]);
};
unsigned
int
numCores
=
m_container
->
objects
().
count
()
-
1
;
std
::
vector
<
long
>
cp_times
(
numCores
*
CPUSTATES
);
...
...
@@ -116,6 +126,6 @@ void FreeBsdCpuPluginPrivate::update()
// update total values
long
cp_time
[
CPUSTATES
];
if
(
readSysctl
(
"kern.cp_time"
,
&
cp_time
))
{
updateCpu
(
m_all
Cpu
s
Object
,
cp_time
);
updateCpu
(
static_cast
<
FreeBsd
CpuObject
*>
(
m_container
->
object
(
QStringLiteral
(
"all"
)))
,
cp_time
);
}
}
plugins/global/cpu/freebsdcpu.h
View file @
d391e4fc
...
...
@@ -18,8 +18,6 @@ class FreeBsdCpuPluginPrivate : public CpuPluginPrivate {
public:
FreeBsdCpuPluginPrivate
(
CpuPlugin
*
q
);
void
update
()
override
;
private:
AllCpusObject
<
FreeBsdCpuObject
>
*
m_allCpusObject
;
};
#endif
plugins/global/cpu/linuxcpu.cpp
View file @
d391e4fc
...
...
@@ -143,8 +143,15 @@ LinuxCpuPluginPrivate::LinuxCpuPluginPrivate(CpuPlugin *q)
m_cpusBySystemIds
.
insert
({
physicalId
,
coreId
},
cpu
);
}
const
int
cores
=
m_container
->
objects
().
size
();
// Add total usage sensors
auto
total
=
new
LinuxCpuObject
(
QStringLiteral
(
"all"
),
i18nc
(
"@title"
,
"All"
),
m_container
,
0
);
auto
cpuCount
=
new
SensorProperty
(
QStringLiteral
(
"cpuCount"
),
i18nc
(
"@title"
,
"Number of CPUs"
),
numCores
.
size
(),
total
);
cpuCount
->
setShortName
(
i18nc
(
"@title, Short fort 'Number of CPUs'"
,
"CPUs"
));
cpuCount
->
setDescription
(
i18nc
(
"@info"
,
"Number of physical CPUs installed in the system"
));
m_allCpusObject
=
new
AllCpusObject
<
LinuxCpuObject
>
(
numCores
.
size
(),
cores
,
m_container
);
auto
coreCount
=
new
SensorProperty
(
QStringLiteral
(
"coreCount"
),
i18nc
(
"@title"
,
"Number of Cores"
),
cores
,
total
);
coreCount
->
setShortName
(
i18nc
(
"@title, Short fort 'Number of Cores'"
,
"Cores"
));
coreCount
->
setDescription
(
i18nc
(
"@info"
,
"Number of CPU cores across all physical CPUS"
));
addSensors
();
}
...
...
@@ -160,7 +167,7 @@ void LinuxCpuPluginPrivate::update()
LinuxCpuObject
*
cpu
;
// Total values
if
(
line
.
startsWith
(
"cpu "
))
{
cpu
=
m_all
Cpu
s
Object
;
cpu
=
static_cast
<
Linux
CpuObject
*>
(
m_container
->
object
(
QStringLiteral
(
"all"
)))
;
}
else
if
(
line
.
startsWith
(
"cpu"
))
{
cpu
=
static_cast
<
LinuxCpuObject
*>
(
m_container
->
object
(
line
.
left
(
line
.
indexOf
(
' '
))));
}
else
{
...
...
@@ -236,7 +243,6 @@ void LinuxCpuPluginPrivate::addSensorsIntel(const sensors_chip_name * const chip
void
LinuxCpuPluginPrivate
::
addSensorsAmd
(
const
sensors_chip_name
*
const
chipName
)
{
#ifdef HAVE_SENSORS
// All Processors should have the Tctl pseudo temperature as temp1. Newer ones have the real die
// temperature Tdie as temp2. Some of those have temperatures for each core complex die (CCD) as
// temp3-6 or temp3-10 depending on the number of CCDS.
...
...
@@ -276,6 +282,5 @@ void LinuxCpuPluginPrivate::addSensorsAmd(const sensors_chip_name * const chipNa
}
else
if
(
tctl
)
{
setSingleSensor
(
tctl
);
}
#endif
}
plugins/global/cpu/linuxcpu.h
View file @
d391e4fc
...
...
@@ -31,7 +31,7 @@ struct sensors_feature;
class
LinuxCpuObject
:
public
CpuObject
{
public:
LinuxCpuObject
(
const
QString
&
id
,
const
QString
&
name
,
SensorContainer
*
parent
,
double
frequency
=
0
);
LinuxCpuObject
(
const
QString
&
id
,
const
QString
&
name
,
SensorContainer
*
parent
,
double
frequency
);
void
update
(
unsigned
long
long
system
,
unsigned
long
long
user
,
unsigned
long
long
wait
,
unsigned
long
long
idle
);
void
setTemperatureSensor
(
const
sensors_chip_name
*
const
chipName
,
const
sensors_feature
*
const
feature
);
...
...
@@ -53,7 +53,6 @@ private:
void
addSensorsIntel
(
const
sensors_chip_name
*
const
chipName
);
void
addSensorsAmd
(
const
sensors_chip_name
*
const
chipName
);
QMultiHash
<
QPair
<
unsigned
int
,
unsigned
int
>
,
LinuxCpuObject
*
const
>
m_cpusBySystemIds
;
AllCpusObject
<
LinuxCpuObject
>
*
m_allCpusObject
;
};
#endif
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