1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
|
/**
* Copyright 1981-2016 ECMWF.
*
* This software is licensed under the terms of the Apache Licence
* Version 2.0 which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities
* granted to it by virtue of its status as an intergovernmental organisation
* nor does it submit to any jurisdiction.
*/
/* ****************************************************************
** Name: *func.c*
** ----
** Products Generation c functions used by Fortran.
**
** D. Jokic, ECMWF, Oct-2009.
**
** Modifications: -
**
** Initial AIX version Oct-2009.
** ****************************************************************/
#include <stdio.h>
#include <stdarg.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <signal.h>
#include <fcntl.h>
#include <sys/resource.h>
# define cstr2fort(a) a
# define _fcd char *
# define _fcdtocp(a) a
# define _fcdlen(a) strlen(a)
# define ITIMER itimer_
# define FTIMER ftimer_
# define RUSAGE rusage_
/* ================================================================
* Name: *ITIMER*
* ----
* - double ftimer_(double *time)
* Real*8 FTIMER,time in F90
* double timer = 0.0; timer=FTIMER(&timer); ... timer=FTIMER(&timer);
** ===============================================================*/
double FTIMER(double *time)
{
double diff;
struct timeval now;
gettimeofday( &now, NULL );
diff = (double)now.tv_sec + ((double)now.tv_usec / 1000000.);
/* printf("%g %g\n",*time,diff); */
if (*time != 0.0) diff -= *time;
/*
{
time_t tv_sec; * seconds *
suseconds_t tv_usec; * microseconds *
tv_usec = (*time%1)*1000000.;
tv_sec = (time_t) ((long)(*time/1))
tv_sec -= now.tv_sec;
tv_usec -= now.tv_usec;
if (tv_usec < 0)
{
tv_sec--;
tv_usec += 1000000;
}
diff = (double)tv_sec + ((double)tv_usec / 1000000.);
}
*/
return diff;
}
int ITIMER(int *seconds)
{
time_t timval1;
time(&timval1);
if (*seconds == 0) return (int)timval1;
return (int)(timval1 - (time_t)*seconds);
}
int RUSAGE()
{
struct rusage usage;
int who = RUSAGE_SELF;
int istat;
if (getrusage(who, &usage) != 0) return 1;
printf("RUSAGE user time used %d\n",usage.ru_utime.tv_sec);
printf("RUSAGE system time used %d\n",usage.ru_stime.tv_sec);
printf("RUSAGE maximum resident set size %d\n",usage.ru_maxrss);
printf("RUSAGE integral shared memory size %d\n",usage.ru_ixrss);
printf("RUSAGE integral unshared data size %d\n",usage.ru_idrss);
printf("RUSAGE integral unshared stack size %d\n",usage.ru_isrss);
printf("RUSAGE page reclaims %d\n",usage.ru_minflt);
printf("RUSAGE page faults %d\n",usage.ru_majflt);
printf("RUSAGE swaps %d\n",usage.ru_nswap);
printf("RUSAGE block input operations %d\n",usage.ru_inblock);
printf("RUSAGE block output operations %d\n",usage.ru_oublock);
printf("RUSAGE messages sent %d\n",usage.ru_msgsnd);
printf("RUSAGE messages received %d\n",usage.ru_msgrcv);
printf("RUSAGE signals received %d\n",usage.ru_nsignals);
printf("RUSAGE voluntary context switches %d\n",usage.ru_nvcsw);
printf("RUSAGE involuntary context switches %d\n",usage.ru_nivcsw);
return 0;
}
|