Fix temperatures
This commit is contained in:
+44
-21
@@ -10,6 +10,8 @@
|
|||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
namespace metrics
|
namespace metrics
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -117,41 +119,62 @@ namespace metrics
|
|||||||
if (name != "coretemp" && name != "k10temp")
|
if (name != "coretemp" && name != "k10temp")
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// читаем все temp*_input
|
|
||||||
for (const auto &f : std::filesystem::directory_iterator(hwmon))
|
for (const auto &f : std::filesystem::directory_iterator(hwmon))
|
||||||
{
|
{
|
||||||
std::string fname = f.path().filename();
|
std::string fname = f.path().filename().string();
|
||||||
CpuTemperature temperature;
|
if (fname.find("temp") != 0)
|
||||||
if (fname.find("temp") == 0 && fname.find("_input") != std::string::npos)
|
continue;
|
||||||
|
|
||||||
|
// определяем, какой тип файла
|
||||||
|
std::string suffix;
|
||||||
|
if (fname.find("_input") != std::string::npos)
|
||||||
|
suffix = "_input";
|
||||||
|
else if (fname.find("_max") != std::string::npos)
|
||||||
|
suffix = "_max";
|
||||||
|
else
|
||||||
|
continue;
|
||||||
|
|
||||||
|
int millideg = 0;
|
||||||
|
std::ifstream tempFile(f.path());
|
||||||
|
tempFile >> millideg;
|
||||||
|
float value = millideg / 1000.0f;
|
||||||
|
|
||||||
|
// находим индекс ядра в temps по tempN
|
||||||
|
std::string numStr = fname.substr(4, fname.find('_') - 4);
|
||||||
|
int n = std::stoi(numStr);
|
||||||
|
|
||||||
|
// если _input — создаём новый объект
|
||||||
|
if (suffix == "_input")
|
||||||
{
|
{
|
||||||
int millideg = 0;
|
if (n >= static_cast<int>(physical.size()))
|
||||||
std::ifstream tempFile(f.path());
|
physical.resize(n + 1);
|
||||||
tempFile >> millideg;
|
physical[n].current = value;
|
||||||
temperature.current = millideg / 1000.0f; // °C
|
|
||||||
}
|
}
|
||||||
if (fname.find("temp") == 0 && fname.find("_max") != std::string::npos)
|
else
|
||||||
{
|
{
|
||||||
int millideg = 0;
|
// _max/_crit: если temps[n] ещё нет, создаём объект
|
||||||
std::ifstream tempFile(f.path());
|
if (n >= static_cast<int>(physical.size()))
|
||||||
tempFile >> millideg;
|
physical.resize(n + 1);
|
||||||
temperature.max = millideg / 1000.0f; // °C
|
if (suffix == "_max")
|
||||||
|
physical[n].max = value;
|
||||||
}
|
}
|
||||||
if (fname.find("temp") == 0 && fname.find("_crit") != std::string::npos)
|
|
||||||
{
|
|
||||||
int millideg = 0;
|
|
||||||
std::ifstream tempFile(f.path());
|
|
||||||
tempFile >> millideg;
|
|
||||||
temperature.critical = millideg / 1000.0f; // °C
|
|
||||||
}
|
|
||||||
physical.push_back(temperature);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Убираем пропуски: оставшиеся нули → копируем предыдущий или последующий?
|
||||||
|
// Можно фильтровать нулевые ядра, если нужно
|
||||||
|
physical.erase(std::remove_if(physical.begin(), physical.end(),
|
||||||
|
[](const CpuTemperature &t)
|
||||||
|
{ return t.current == 0 && t.max == 0; }),
|
||||||
|
physical.end());
|
||||||
|
|
||||||
for (size_t i = 0; i < logicalToPhysical.size(); ++i)
|
for (size_t i = 0; i < logicalToPhysical.size(); ++i)
|
||||||
{
|
{
|
||||||
int phys = logicalToPhysical[i];
|
int phys = logicalToPhysical[i];
|
||||||
if (phys >= static_cast<int>(physical.size()))
|
if (phys >= static_cast<int>(physical.size()))
|
||||||
phys = physical.size() - 1; // safety
|
phys = physical.size() - 1; // safety
|
||||||
logical[i] = physical[phys];
|
logical[i] = physical[phys];
|
||||||
|
|
||||||
|
std::cout << i << " " << logical[i].current << "/" << logical[i].max << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,5 @@ namespace metrics
|
|||||||
{
|
{
|
||||||
float current;
|
float current;
|
||||||
float max;
|
float max;
|
||||||
float critical;
|
|
||||||
};
|
};
|
||||||
} // namespace metrics
|
} // namespace metrics
|
||||||
@@ -43,7 +43,6 @@ namespace metrics
|
|||||||
{
|
{
|
||||||
buf.writeFloat(f.current);
|
buf.writeFloat(f.current);
|
||||||
buf.writeFloat(f.max);
|
buf.writeFloat(f.max);
|
||||||
buf.writeFloat(f.critical);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Memory
|
// Memory
|
||||||
@@ -90,7 +89,7 @@ namespace metrics
|
|||||||
h.cpu.coreTemps.clear();
|
h.cpu.coreTemps.clear();
|
||||||
h.cpu.coreTemps.reserve(numCpu);
|
h.cpu.coreTemps.reserve(numCpu);
|
||||||
for (uint8_t i = 0; i < numCpu; ++i)
|
for (uint8_t i = 0; i < numCpu; ++i)
|
||||||
h.cpu.coreTemps.push_back({buf.readFloat(), buf.readFloat(), buf.readFloat()});
|
h.cpu.coreTemps.push_back({buf.readFloat(), buf.readFloat()});
|
||||||
|
|
||||||
// Memory
|
// Memory
|
||||||
h.memory.memory.used = buf.readUint64();
|
h.memory.memory.used = buf.readUint64();
|
||||||
|
|||||||
Reference in New Issue
Block a user