00001 //=========================================================================== 00002 //= cronometro.h Diciembre de 1998 = 00003 //=-------------------------------------------------------------------------= 00004 //= Definiciones de utileria para medicion de tiempos (real y CPU) = 00005 //=-------------------------------------------------------------------------= 00006 //= ADVERTENCIA: ESTE SOFTWARE NO ESTA CONCEBIDO NI DISENNADO PARA EL USO = 00007 //= EN EQUIPO DE CONTROL EN LINEA EN ENTORNOS PELIGROSOS QUE REQUIERAN UN = 00008 //= DESEMPENNO LIBRE DE FALLAS, COMO LA OPERACION DE PLANTAS NUCLEARES, = 00009 //= SISTEMAS DE NAVEGACION O COMUNICACION EN AVIONES, TRAFICO AEREO, = 00010 //= EQUIPO MEDICO DEL CUAL DEPENDAN VIDAS HUMANAS O SISTEMAS DE ARMAMENTO, = 00011 //= EN LOS CUALES UNA FALLA EN EL SOFTWARE PUEDA IMPLICAR DIRECTAMENTE LA = 00012 //= MUERTE, DANNOS PERSONALES O DANNOS FISICOS Y/O AMBIENTALES GRAVES = 00013 //= ("ACTIVIDADES DE ALGO RIESGO"). = 00014 //=-------------------------------------------------------------------------= 00015 //= Autor original: Oscar J. Chavarro G. A.K.A. JEDILINK. Copyright (c), = 00016 //= 1997 - 2003, oscarchavarro@hotmail.com = 00017 //= AQUYNZA es software libre, y se rige bajo los terminos de la licencia = 00018 //= LGPL de GNU (http://www.gnu.org). Para mayor informacion respecto a la = 00019 //= licencia de uso, consulte el archivo ./doc/LICENCIA en la distribucion. = 00020 //=========================================================================== 00021 00022 #ifndef __CRONOMETRO__ 00023 #define __CRONOMETRO__ 00024 00025 #include "jed_defs.h" 00026 00027 #ifdef UNIX_ENABLED 00028 #if PLATAFORMA == SGI 00029 #define _BSD_COMPAT 00030 #define _BSD_TYPES 00031 #endif 00032 #include <sys/time.h> 00033 #include <unistd.h> 00034 #include <sys/resource.h> 00035 #endif 00036 #ifndef UNIX_ENABLED 00037 //#warning "OJO: Esto no esta probado en esta plataforma!" 00038 #endif 00039 00040 class CRONOMETRO 00041 { 00042 private: 00043 //long real_sec; // Tiempo real total en segundos y microsegundos 00044 //long real_usec; 00045 long real_dsec; // Tiempo real transcurrido desde el ultimo arranque 00046 long real_dusec; // hasta el ultimo stop en segundos u microsegundos. 00047 00048 //long cpu_sec; // Tiempo cpu total en segundos y microsegundos 00049 //long cpu_usec; 00050 long cpu_dsec; // Tiempo cpu transcurrido desde el ultimo arranque 00051 long cpu_dusec; // hasta el ultimo stop en segundos u microsegundos. 00052 00053 00054 void 00055 calcular_delta_real(long sec_antes, long usec_antes, 00056 long sec_despues, long usec_despues); 00057 void 00058 calcular_delta_cpu(long sec_antes, long usec_antes, 00059 long sec_despues, long usec_despues); 00060 00061 #ifdef UNIX_ENABLED 00062 struct timeval antes_real; 00063 struct timeval despues_real; 00064 struct rusage antes_recursos; 00065 struct rusage despues_recursos; 00066 #endif 00067 00068 #if PLATAFORMA == i386_WIN32_VC 00069 DWORD antes_real; 00070 DWORD despues_real; 00071 #endif 00072 00073 public: 00074 CRONOMETRO(); 00075 void restart(void); 00076 void update(void); 00077 double segundos_reales(void); 00078 double segundos_cpu(void); 00079 }; 00080 00081 #endif // __CRONOMETRO__ 00082 00083 //=========================================================================== 00084 //= EOF = 00085 //=========================================================================== 00086