diff --git a/Box/Main.cpp b/Box/Main.cpp index 2d9d51a6bf1ee93c8b0983c15205646f60d1cde5..1b170053558c39eac9fbdd8f7e28839917ce3569 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 540f35a170d78ab403ba8f6c8794b37b55058832..2c41435b12bc04df20a5863adc8535d563310bf0 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 d935a929836df283b1e996df356b4ce839e481b1..ab4ab897d4970b34e56d5118de940bef8de36ba2 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 d8d60c59c5ab9060e43507f6ff5adac78ae667fb..d8fafadc1ef81406bed7532d94e7367d374b6512 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 51a227829edb5a593738aade8913fc73af10e996..55b06f87fd24fa22e2330ba99b886732f1fb3b5d 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 4391fbef5243363b13caef8455ab929cf2459bf1..30c5008f09d1255f633661ca724f6166f0cece3f 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 ab8f18cc9ee8178c21fd6465b3070940e2582660..3cd69ef09dd3441c7eb0ba0f1e272d6d71e628d0 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 aa153a996b486342d3995be08ae97e905e6e0880..3783ad82df409e14daab793c8531e951f0ff2d5c 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 05260c2a88d155eba60fc334e8eb33ab1ea5c1bd..de67222cea5b971cced68f05794d55edbcb1177a 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 128135a8a915942fccc9dcd6d5b4f8b1328a26d4..3e497c4e28f487e40287da3d0cdd4b89bb33f682 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;