Limpiar aún más código de CpuMon
Signed-off-by: somebody_master <somebody_master@somebodyserver.mooo.com>
This commit is contained in:
parent
6a5b24cb20
commit
324702e4ca
@ -28,7 +28,7 @@ enum EstadosCPU {
|
||||
|
||||
typedef struct DatosCPU {
|
||||
std::string cpu;
|
||||
size_t times[NUM_ESTADOS_CPU];
|
||||
size_t tiempos[NUM_ESTADOS_CPU];
|
||||
} DatosCPU;
|
||||
|
||||
class CpuMon {
|
||||
@ -49,7 +49,7 @@ public:
|
||||
void leerEstadoCPU(std::vector<DatosCPU> &entradas);
|
||||
void obtenerUsoCPU(const std::vector<DatosCPU> &entradas1,
|
||||
const std::vector<DatosCPU> &entradas2);
|
||||
std::string obtenerBarra(float *porcentaje, uint8_t *cpu);
|
||||
std::string obtenerBarra(float *porcentaje, std::string cpu);
|
||||
void setNum_sectores(uint8_t num_sectores);
|
||||
};
|
||||
#endif // CPU_MON_HPP_
|
||||
|
@ -68,39 +68,39 @@ void CpuMon::leerEstadoCPU(std::vector<DatosCPU> &entradas) {
|
||||
const std::string STR_TOT("tot");
|
||||
|
||||
while (std::getline(fileStat, linea)) {
|
||||
// cpu stats line found
|
||||
// línea de datos de cpu encontrada
|
||||
if (!linea.compare(0, LEN_STR_CPU, STR_CPU)) {
|
||||
std::istringstream ss(linea);
|
||||
|
||||
// store entry
|
||||
// almacenar entrada
|
||||
entradas.emplace_back(DatosCPU());
|
||||
DatosCPU &entry = entradas.back();
|
||||
DatosCPU &entrada = entradas.back();
|
||||
|
||||
// read cpu label
|
||||
ss >> entry.cpu;
|
||||
|
||||
// remove "cpu" from the label when it's a processor number
|
||||
if (entry.cpu.size() > LEN_STR_CPU)
|
||||
entry.cpu.erase(0, LEN_STR_CPU);
|
||||
// replace "cpu" with "tot" when it's total values
|
||||
else
|
||||
entry.cpu = STR_TOT;
|
||||
|
||||
// read times
|
||||
for (int i = 0; i < NUM_ESTADOS_CPU; ++i)
|
||||
ss >> entry.times[i];
|
||||
// leer etiqueta de cpu
|
||||
ss >> entrada.cpu;
|
||||
// eliminar "cpu" de la etiqueta cuando es el número de un procesador
|
||||
if (entrada.cpu.size() > LEN_STR_CPU) {
|
||||
entrada.cpu.erase(0, LEN_STR_CPU);
|
||||
// reemplazar "cpu" con "tot" cuando son los valores totales
|
||||
} else {
|
||||
entrada.cpu = STR_TOT;
|
||||
}
|
||||
// leer tiempos
|
||||
for (int i = 0; i < NUM_ESTADOS_CPU; ++i) {
|
||||
ss >> entrada.tiempos[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
size_t CpuMon::getTiempoInactivo(const DatosCPU &e) {
|
||||
return e.times[S_IDLE] + e.times[S_IOWAIT];
|
||||
return e.tiempos[S_IDLE] + e.tiempos[S_IOWAIT];
|
||||
}
|
||||
|
||||
size_t CpuMon::getTiempoActivo(const DatosCPU &e) {
|
||||
return e.times[S_USER] + e.times[S_NICE] + e.times[S_SYSTEM] +
|
||||
e.times[S_IRQ] + e.times[S_SOFTIRQ] + e.times[S_STEAL] +
|
||||
e.times[S_GUEST] + e.times[S_GUEST_NICE];
|
||||
return e.tiempos[S_USER] + e.tiempos[S_NICE] + e.tiempos[S_SYSTEM] +
|
||||
e.tiempos[S_IRQ] + e.tiempos[S_SOFTIRQ] + e.tiempos[S_STEAL] +
|
||||
e.tiempos[S_GUEST] + e.tiempos[S_GUEST_NICE];
|
||||
}
|
||||
|
||||
void CpuMon::obtenerUsoCPU(const std::vector<DatosCPU> &entradas1,
|
||||
@ -122,19 +122,19 @@ void CpuMon::obtenerUsoCPU(const std::vector<DatosCPU> &entradas1,
|
||||
const float TIEMPO_TOTAL = TIEMPO_ACTIVO + TIEMPO_INACTIVO;
|
||||
|
||||
float usoCPU = 1.f * TIEMPO_ACTIVO / TIEMPO_TOTAL;
|
||||
salida[i - 1] = CpuMon::obtenerBarra(&usoCPU, &i);
|
||||
salida[i - 1] = CpuMon::obtenerBarra(&usoCPU, e1.cpu);
|
||||
}
|
||||
|
||||
ui::mostrarVentana(ventanaMonitorCPU, &salida, &columnas, &num_sectores);
|
||||
}
|
||||
|
||||
std::string CpuMon::obtenerBarra(float *porcentaje, uint8_t *cpu) {
|
||||
std::string CpuMon::obtenerBarra(float *porcentaje, std::string cpu) {
|
||||
std::string barra = " CPU ";
|
||||
|
||||
if (CpuMon::num_hilos > 9 && *cpu < 10) {
|
||||
barra.append("0").append(std::to_string(*cpu).append(" ["));
|
||||
if (CpuMon::num_hilos > 9 && cpu.length() < 2) {
|
||||
barra.append("0").append(cpu).append(" [");
|
||||
} else {
|
||||
barra.append(std::to_string(*cpu).append(" ["));
|
||||
barra.append(cpu).append(" [");
|
||||
}
|
||||
std::string cierre = "] ";
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user