/*****************************************************************************1! *2! * Elmer, A Finite Element Software for Multiphysical Problems3! *4! * Copyright 1st April 1995 - , CSC - IT Center for Science Ltd., Finland5! *6! * This library is free software; you can redistribute it and/or7! * modify it under the terms of the GNU Lesser General Public8! * License as published by the Free Software Foundation; either9! * version 2.1 of the License, or (at your option) any later version.10! *11! * This library is distributed in the hope that it will be useful,12! * but WITHOUT ANY WARRANTY; without even the implied warranty of13! * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU14! * Lesser General Public License for more details.15! *16! * You should have received a copy of the GNU Lesser General Public17! * License along with this library (in file ../LGPL-2.1); if not, write18! * to the Free Software Foundation, Inc., 51 Franklin Street,19! * Fifth Floor, Boston, MA 02110-1301 USA20! *21! *****************************************************************************22!23! ******************************************************************************24! *25! * Provide system time / memory usage.26! *27! ******************************************************************************28! *29! * Authors: Juha Ruokolainen30! * Email: [email protected]31! * Web: http://www.csc.fi/elmer32! * Address: CSC - IT Center for Science Ltd.33! * Keilaranta 1434! * 02101 Espoo, Finland35! *36! * Original Date: 02 Jun 199737! *38! *****************************************************************************/3940#include "../config.h"4142#if defined(MINGW32) || defined(WIN32)4344#include <sys/types.h>45#include <time.h>4647double STDCALLBULL FC_FUNC(realtime,REALTIME) ( )48{49return clock() / (double)CLOCKS_PER_SEC;50}5152double STDCALLBULL FC_FUNC(cputime,CPUTIME) ( )53{54return clock() / (double)CLOCKS_PER_SEC;55}5657double STDCALLBULL FC_FUNC(cpumemory,CPUMEMORY) ( )58{59return 0.0;60}6162#else6364#include <sys/types.h>65#include <sys/times.h>66#include <sys/param.h>6768#include <sys/time.h>69#include <sys/resource.h>7071static struct rusage usage;7273static struct timeval tp;74static struct timezone tzp;7576#ifdef USE_ISO_C_BINDINGS77double cputime ()78{79getrusage( RUSAGE_SELF, &usage );80return (double) usage.ru_utime.tv_sec + usage.ru_utime.tv_usec*1.0e-6;81}8283double realtime()84{85gettimeofday( &tp,&tzp );86return (double) tp.tv_sec + tp.tv_usec*1.0e-6;87}8889double cpumemory()90{91getrusage( RUSAGE_SELF, &usage );92return (double) 1.0 * usage.ru_maxrss;93}94#else95double FC_FUNC(cputime,CPUTIME) ()96{97getrusage( RUSAGE_SELF, &usage );98return (double) usage.ru_utime.tv_sec + usage.ru_utime.tv_usec*1.0e-6;99}100101double FC_FUNC(realtime,REALTIME) ()102{103gettimeofday( &tp,&tzp );104return (double) tp.tv_sec + tp.tv_usec*1.0e-6;105}106107double FC_FUNC(cpumemory,CPUMEMORY) ()108{109getrusage( RUSAGE_SELF, &usage );110return (double) 1.0 * usage.ru_maxrss;111}112#endif /* USE_ISO_C_BINDINGS*/113114#endif // WIN32115116117