From b69fd48c272bac512ada9b77c5ff8218872379bf Mon Sep 17 00:00:00 2001 From: Christophe Geuzaine <cgeuzaine@ulg.ac.be> Date: Sun, 26 Feb 2006 00:40:30 +0000 Subject: [PATCH] add windows code to get cpu time + relocate this in Timer.cpp --- Box/Main.cpp | 29 +------------------ Common/AdaptiveViews.cpp | 1 + Common/Message.h | 1 - Common/Timer.cpp | 62 +++++++++++++++++++++++++++++----------- Common/Timer.h | 2 ++ Fltk/Message.cpp | 46 +++-------------------------- Mesh/3D_Mesh_Netgen.cpp | 3 +- Mesh/DiscreteSurface.cpp | 3 +- Mesh/Generator.cpp | 3 +- Mesh/SecondOrder.cpp | 3 +- 10 files changed, 61 insertions(+), 92 deletions(-) diff --git a/Box/Main.cpp b/Box/Main.cpp index 2d9d51a6bf..1b17005355 100644 --- a/Box/Main.cpp +++ b/Box/Main.cpp @@ -1,4 +1,4 @@ -// $Id: Main.cpp,v 1.55 2006-01-30 00:40:19 geuzaine Exp $ +// $Id: Main.cpp,v 1.56 2006-02-26 00:40:29 geuzaine Exp $ // // Copyright (C) 1997-2006 C. Geuzaine, J.-F. Remacle // @@ -20,14 +20,6 @@ // Please report all bugs and problems to <gmsh@geuz.org>. #include <signal.h> -#include <sys/time.h> -#include <sys/resource.h> - -#if defined(__APPLE__) -#define RUSAGE_SELF 0 -#define RUSAGE_CHILDREN -1 -#endif - #include "ParUtil.h" #include "PluginManager.h" #include "Gmsh.h" @@ -243,25 +235,6 @@ void Msg(int level, char *fmt, ...) exit(1); } -// CPU time computation - -void GetResources(long *s, long *us, long *mem) -{ - static struct rusage r; - - getrusage(RUSAGE_SELF, &r); - *s = (long)r.ru_utime.tv_sec; - *us = (long)r.ru_utime.tv_usec; - *mem = (long)r.ru_maxrss; -} - -double Cpu(void) -{ - long s, us, mem; - GetResources(&s, &us, &mem); - return (double)s + (double)us / 1.e6; -} - // interactive value dialog double GetValue(char *text, double defaultval) diff --git a/Common/AdaptiveViews.cpp b/Common/AdaptiveViews.cpp index 540f35a170..2c41435b12 100644 --- a/Common/AdaptiveViews.cpp +++ b/Common/AdaptiveViews.cpp @@ -24,6 +24,7 @@ #include <set> #include "AdaptiveViews.h" #include "Plugin.h" +#include "Timer.h" // A recursive effective implementation diff --git a/Common/Message.h b/Common/Message.h index d935a92983..ab4ab897d4 100644 --- a/Common/Message.h +++ b/Common/Message.h @@ -73,7 +73,6 @@ void Signal(int signum); void Msg(int level, char *fmt, ...); -double Cpu(void); void Exit(int); double GetValue(char *text, double defaultval); bool GetBinaryAnswer(const char *question, const char *yes, const char *no, diff --git a/Common/Timer.cpp b/Common/Timer.cpp index d8d60c59c5..d8fafadc1e 100644 --- a/Common/Timer.cpp +++ b/Common/Timer.cpp @@ -1,4 +1,4 @@ -// $Id: Timer.cpp,v 1.22 2006-02-25 21:57:51 geuzaine Exp $ +// $Id: Timer.cpp,v 1.23 2006-02-26 00:40:29 geuzaine Exp $ // // Copyright (C) 1997-2006 C. Geuzaine, J.-F. Remacle // @@ -21,40 +21,68 @@ #if !defined(WIN32) || defined(__CYGWIN__) -#include <time.h> // FIXME: for sgi and maybe others -#include <sys/time.h> #include <unistd.h> - -double GetTimeInSeconds() -{ - struct timeval tp; - gettimeofday(&tp, (struct timezone *)0); - double t = (double)tp.tv_sec + 1.e-6 * (double)tp.tv_usec; - return t; -} - -void SleepInSeconds(double s) -{ - usleep((long)(1.e6 * s)); -} +#include <time.h> // for sgi and maybe others +#include <sys/time.h> +#include <sys/resource.h> #else // pure windows -#include "Gmsh.h" #include <windows.h> +#endif + +#if defined(__APPLE__) +#define RUSAGE_SELF 0 +#define RUSAGE_CHILDREN -1 +#endif + double GetTimeInSeconds() { +#if !defined(WIN32) || defined(__CYGWIN__) + struct timeval tp; + gettimeofday(&tp, (struct timezone *)0); + double t = (double)tp.tv_sec + 1.e-6 * (double)tp.tv_usec; + return t; +#else FILETIME ft; GetSystemTimeAsFileTime(&ft); double t = 1.e-7 * 4294967296. * (double)ft.dwHighDateTime + 1.e-7 * (double)ft.dwLowDateTime; return t; +#endif } void SleepInSeconds(double s) { +#if !defined(WIN32) || defined(__CYGWIN__) + usleep((long)(1.e6 * s)); +#else Sleep((long)(1.e3 * s)); +#endif } +void GetResources(double *s, long *mem) +{ +#if !defined(WIN32) || defined(__CYGWIN__) + static struct rusage r; + getrusage(RUSAGE_SELF, &r); + *s = (double)r.ru_utime.tv_sec + 1.e-6 * (double)r.ru_utime.tv_usec; + *mem = (long)r.ru_maxrss; +#else + FILETIME creation, exit, kernel, user; + if(GetProcessTimes(GetCurrentProcess(), &creation, &exit, &kernel, &user)){ + *s = 1.e-7 * 4294967296. * (double)user.dwHighDateTime + + 1.e-7 * (double)user.dwLowDateTime; + } + *mem = 0; #endif +} + +double Cpu() +{ + long mem = 0; + double s = 0.; + GetResources(&s, &mem); + return s; +} diff --git a/Common/Timer.h b/Common/Timer.h index 51a227829e..55b06f87fd 100644 --- a/Common/Timer.h +++ b/Common/Timer.h @@ -22,5 +22,7 @@ double GetTimeInSeconds(); void SleepInSeconds(double s); +void GetResources(double *s, long *mem); +double Cpu(); #endif diff --git a/Fltk/Message.cpp b/Fltk/Message.cpp index 4391fbef52..30c5008f09 100644 --- a/Fltk/Message.cpp +++ b/Fltk/Message.cpp @@ -1,4 +1,4 @@ -// $Id: Message.cpp,v 1.70 2006-02-25 05:27:59 geuzaine Exp $ +// $Id: Message.cpp,v 1.71 2006-02-26 00:40:29 geuzaine Exp $ // // Copyright (C) 1997-2006 C. Geuzaine, J.-F. Remacle // @@ -19,19 +19,11 @@ // // Please report all bugs and problems to <gmsh@geuz.org>. +#include <signal.h> #if !defined(WIN32) || defined(__CYGWIN__) -#include <unistd.h> -#include <sys/time.h> -#include <sys/resource.h> -#endif - -#if defined(__APPLE__) -#define RUSAGE_SELF 0 -#define RUSAGE_CHILDREN -1 +#include <unistd.h> // for unlink #endif -#include <signal.h> - #include "Gmsh.h" #include "GmshUI.h" #include "GmshVersion.h" @@ -73,7 +65,7 @@ void Signal(int sig_num) void Debug() { - ; + printf("debug!\n"); } void Msg(int level, char *fmt, ...) @@ -267,36 +259,6 @@ void Exit(int level) exit(0); } -// CPU time computation, etc. - -void GetResources(long *s, long *us, long *mem) -{ -#if !defined(WIN32) || defined(__CYGWIN__) - static struct rusage r; - - getrusage(RUSAGE_SELF, &r); - *s = (long)r.ru_utime.tv_sec; - *us = (long)r.ru_utime.tv_usec; - *mem = (long)r.ru_maxrss; -#else - *s = 0; - *us = 0; - *mem = 0; -#endif -} - -void PrintResources(long s, long us, long mem) -{ - Msg(INFO, "cpu %ld.%ld s / mem %ld kb\n", s, us, mem); -} - -double Cpu(void) -{ - long s, us, mem; - GetResources(&s, &us, &mem); - return (double)s + (double)us / 1.e6; -} - double GetValue(char *text, double defaultval) { if(CTX.nopopup) diff --git a/Mesh/3D_Mesh_Netgen.cpp b/Mesh/3D_Mesh_Netgen.cpp index ab8f18cc9e..3cd69ef09d 100644 --- a/Mesh/3D_Mesh_Netgen.cpp +++ b/Mesh/3D_Mesh_Netgen.cpp @@ -1,4 +1,4 @@ -// $Id: 3D_Mesh_Netgen.cpp,v 1.20 2006-01-29 22:53:41 geuzaine Exp $ +// $Id: 3D_Mesh_Netgen.cpp,v 1.21 2006-02-26 00:40:29 geuzaine Exp $ // // Copyright (C) 1997-2006 C. Geuzaine, J.-F. Remacle // @@ -29,6 +29,7 @@ #include "Create.h" #include "Numeric.h" #include "Context.h" +#include "Timer.h" extern Context_T CTX; extern Mesh *THEM; diff --git a/Mesh/DiscreteSurface.cpp b/Mesh/DiscreteSurface.cpp index aa153a996b..3783ad82df 100644 --- a/Mesh/DiscreteSurface.cpp +++ b/Mesh/DiscreteSurface.cpp @@ -1,4 +1,4 @@ -// $Id: DiscreteSurface.cpp,v 1.35 2006-01-06 00:34:26 geuzaine Exp $ +// $Id: DiscreteSurface.cpp,v 1.36 2006-02-26 00:40:29 geuzaine Exp $ // // Copyright (C) 1997-2006 C. Geuzaine, J.-F. Remacle // @@ -29,6 +29,7 @@ #include "Context.h" #include "BDS.h" #include "PartitionMesh.h" +#include "Timer.h" extern Mesh *THEM; extern Context_T CTX; diff --git a/Mesh/Generator.cpp b/Mesh/Generator.cpp index 05260c2a88..de67222cea 100644 --- a/Mesh/Generator.cpp +++ b/Mesh/Generator.cpp @@ -1,4 +1,4 @@ -// $Id: Generator.cpp,v 1.79 2006-02-25 14:20:07 geuzaine Exp $ +// $Id: Generator.cpp,v 1.80 2006-02-26 00:40:30 geuzaine Exp $ // // Copyright (C) 1997-2006 C. Geuzaine, J.-F. Remacle // @@ -28,6 +28,7 @@ #include "OpenFile.h" #include "Views.h" #include "PartitionMesh.h" +#include "Timer.h" extern Mesh *THEM; extern Context_T CTX; diff --git a/Mesh/SecondOrder.cpp b/Mesh/SecondOrder.cpp index 128135a8a9..3e497c4e28 100644 --- a/Mesh/SecondOrder.cpp +++ b/Mesh/SecondOrder.cpp @@ -1,4 +1,4 @@ -// $Id: SecondOrder.cpp,v 1.35 2006-01-06 00:34:26 geuzaine Exp $ +// $Id: SecondOrder.cpp,v 1.36 2006-02-26 00:40:30 geuzaine Exp $ // // Copyright (C) 1997-2006 C. Geuzaine, J.-F. Remacle // @@ -25,6 +25,7 @@ #include "Utils.h" #include "Interpolation.h" #include "Numeric.h" +#include "Timer.h" extern Mesh *THEM; -- GitLab