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