summaryrefslogtreecommitdiffstats
path: root/src/H5timer.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/H5timer.c')
-rw-r--r--src/H5timer.c148
1 files changed, 66 insertions, 82 deletions
diff --git a/src/H5timer.c b/src/H5timer.c
index 61d6f0f..1df2d8d 100644
--- a/src/H5timer.c
+++ b/src/H5timer.c
@@ -25,12 +25,10 @@
/* Module Setup */
/****************/
-
/***********/
/* Headers */
/***********/
-#include "H5private.h" /* Generic Functions */
-
+#include "H5private.h" /* Generic Functions */
/****************/
/* Local Macros */
@@ -47,38 +45,30 @@
#define H5_SEC_PER_HOUR (double)(60.0F * 60.0F)
#define H5_SEC_PER_MIN (double)(60.0F)
-
/******************/
/* Local Typedefs */
/******************/
-
/********************/
/* Package Typedefs */
/********************/
-
/********************/
/* Local Prototypes */
/********************/
-
/*********************/
/* Package Variables */
/*********************/
-
/*****************************/
/* Library Private Variables */
/*****************************/
-
/*******************/
/* Local Variables */
/*******************/
-
-
/*-------------------------------------------------------------------------
* Function: H5_bandwidth
*
@@ -105,45 +95,50 @@
*-------------------------------------------------------------------------
*/
void
-H5_bandwidth(char *buf/*out*/, double nbytes, double nseconds)
+H5_bandwidth(char *buf /*out*/, double nbytes, double nseconds)
{
- double bw;
+ double bw;
- if(nseconds <= (double)0.0F)
+ if (nseconds <= (double)0.0F)
HDstrcpy(buf, " NaN");
else {
bw = nbytes / nseconds;
- if(H5_DBL_ABS_EQUAL(bw, (double)0.0F))
+ if (H5_DBL_ABS_EQUAL(bw, (double)0.0F))
HDstrcpy(buf, "0.000 B/s");
- else if(bw < (double)1.0F)
+ else if (bw < (double)1.0F)
HDsprintf(buf, "%10.4e", bw);
- else if(bw < (double)H5_KB) {
+ else if (bw < (double)H5_KB) {
HDsprintf(buf, "%05.4f", bw);
HDstrcpy(buf + 5, " B/s");
- } else if(bw < (double)H5_MB) {
+ }
+ else if (bw < (double)H5_MB) {
HDsprintf(buf, "%05.4f", bw / (double)H5_KB);
HDstrcpy(buf + 5, " kB/s");
- } else if(bw < (double)H5_GB) {
+ }
+ else if (bw < (double)H5_GB) {
HDsprintf(buf, "%05.4f", bw / (double)H5_MB);
HDstrcpy(buf + 5, " MB/s");
- } else if(bw < (double)H5_TB) {
+ }
+ else if (bw < (double)H5_TB) {
HDsprintf(buf, "%05.4f", bw / (double)H5_GB);
HDstrcpy(buf + 5, " GB/s");
- } else if(bw < (double)H5_PB) {
+ }
+ else if (bw < (double)H5_PB) {
HDsprintf(buf, "%05.4f", bw / (double)H5_TB);
HDstrcpy(buf + 5, " TB/s");
- } else if(bw < (double)H5_EB) {
+ }
+ else if (bw < (double)H5_EB) {
HDsprintf(buf, "%05.4f", bw / (double)H5_PB);
HDstrcpy(buf + 5, " PB/s");
- } else {
+ }
+ else {
HDsprintf(buf, "%10.4e", bw);
- if(HDstrlen(buf) > 10)
+ if (HDstrlen(buf) > 10)
HDsprintf(buf, "%10.3e", bw);
} /* end else-if */
- } /* end else */
+ } /* end else */
} /* end H5_bandwidth() */
-
/*-------------------------------------------------------------------------
* Function: H5_now
*
@@ -159,7 +154,7 @@ H5_bandwidth(char *buf/*out*/, double nbytes, double nseconds)
time_t
H5_now(void)
{
- time_t now; /* Current time */
+ time_t now; /* Current time */
#ifdef H5_HAVE_GETTIMEOFDAY
{
@@ -168,14 +163,13 @@ H5_now(void)
HDgettimeofday(&now_tv, NULL);
now = now_tv.tv_sec;
}
-#else /* H5_HAVE_GETTIMEOFDAY */
+#else /* H5_HAVE_GETTIMEOFDAY */
now = HDtime(NULL);
#endif /* H5_HAVE_GETTIMEOFDAY */
- return(now);
+ return (now);
} /* end H5_now() */
-
/*-------------------------------------------------------------------------
* Function: H5_now_usec
*
@@ -191,7 +185,7 @@ H5_now(void)
uint64_t
H5_now_usec(void)
{
- uint64_t now; /* Current time, in microseconds */
+ uint64_t now; /* Current time, in microseconds */
#if defined(H5_HAVE_CLOCK_GETTIME)
{
@@ -207,14 +201,13 @@ H5_now_usec(void)
HDgettimeofday(&now_tv, NULL);
now = (uint64_t)(now_tv.tv_sec * (1000 * 1000)) + (uint64_t)now_tv.tv_usec;
}
-#else /* H5_HAVE_GETTIMEOFDAY */
- now = (uint64_t)(HDtime(NULL) * (1000 * 1000));
+#else /* H5_HAVE_GETTIMEOFDAY */
+ now = (uint64_t)(HDtime(NULL) * (1000 * 1000));
#endif /* H5_HAVE_GETTIMEOFDAY */
- return(now);
+ return (now);
} /* end H5_now_usec() */
-
/*--------------------------------------------------------------------------
* Function: H5_get_time
*
@@ -255,8 +248,6 @@ H5_get_time(void)
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5_get_time() */
-
-
/*-------------------------------------------------------------------------
* Function: H5__timer_get_timevals
*
@@ -279,10 +270,10 @@ H5__timer_get_timevals(H5_timevals_t *times /*in,out*/)
/* Windows call handles both system/user and elapsed times */
#ifdef H5_HAVE_WIN32_API
- if(H5_get_win32_times(times) < 0) {
- times->elapsed = -1.0;
- times->system = -1.0;
- times->user = -1.0;
+ if (H5_get_win32_times(times) < 0) {
+ times->elapsed = -1.0;
+ times->system = -1.0;
+ times->user = -1.0;
return -1;
} /* end if */
@@ -292,14 +283,14 @@ H5__timer_get_timevals(H5_timevals_t *times /*in,out*/)
* System and user times *
*************************/
#if defined(H5_HAVE_GETRUSAGE)
-{
- struct rusage res;
+ {
+ struct rusage res;
- if(HDgetrusage(RUSAGE_SELF, &res) < 0)
- return -1;
- times->system = (double)res.ru_stime.tv_sec + ((double)res.ru_stime.tv_usec / (double)1.0E6F);
- times->user = (double)res.ru_utime.tv_sec + ((double)res.ru_utime.tv_usec / (double)1.0E6F);
-}
+ if (HDgetrusage(RUSAGE_SELF, &res) < 0)
+ return -1;
+ times->system = (double)res.ru_stime.tv_sec + ((double)res.ru_stime.tv_usec / (double)1.0E6F);
+ times->user = (double)res.ru_utime.tv_sec + ((double)res.ru_utime.tv_usec / (double)1.0E6F);
+ }
#else
/* No suitable way to get system/user times */
/* This is not an error condition, they just won't be available */
@@ -318,7 +309,6 @@ H5__timer_get_timevals(H5_timevals_t *times /*in,out*/)
return 0;
} /* end H5__timer_get_timevals() */
-
/*-------------------------------------------------------------------------
* Function: H5_timer_init
*
@@ -384,7 +374,6 @@ H5_timer_init(H5_timer_t *timer /*in,out*/)
return 0;
} /* end H5_timer_init() */
-
/*-------------------------------------------------------------------------
* Function: H5_timer_start
*
@@ -407,7 +396,7 @@ H5_timer_start(H5_timer_t *timer /*in,out*/)
/* Start the timer
* This sets the "initial" times to the system-defined start times.
*/
- if(H5__timer_get_timevals(&(timer->initial)) < 0)
+ if (H5__timer_get_timevals(&(timer->initial)) < 0)
return -1;
timer->is_running = TRUE;
@@ -415,7 +404,6 @@ H5_timer_start(H5_timer_t *timer /*in,out*/)
return 0;
} /* end H5_timer_start() */
-
/*-------------------------------------------------------------------------
* Function: H5_timer_stop
*
@@ -436,27 +424,26 @@ H5_timer_stop(H5_timer_t *timer /*in,out*/)
HDassert(timer);
/* Stop the timer */
- if(H5__timer_get_timevals(&(timer->final_interval)) < 0)
+ if (H5__timer_get_timevals(&(timer->final_interval)) < 0)
return -1;
/* The "final" times are stored as intervals (final - initial)
* for more useful reporting to the user.
*/
timer->final_interval.elapsed = timer->final_interval.elapsed - timer->initial.elapsed;
- timer->final_interval.system = timer->final_interval.system - timer->initial.system;
- timer->final_interval.user = timer->final_interval.user - timer->initial.user;
+ timer->final_interval.system = timer->final_interval.system - timer->initial.system;
+ timer->final_interval.user = timer->final_interval.user - timer->initial.user;
/* Add the intervals to the elapsed time */
timer->total.elapsed += timer->final_interval.elapsed;
- timer->total.system += timer->final_interval.system;
- timer->total.user += timer->final_interval.user;
+ timer->total.system += timer->final_interval.system;
+ timer->total.user += timer->final_interval.user;
timer->is_running = FALSE;
return 0;
} /* end H5_timer_stop() */
-
/*-------------------------------------------------------------------------
* Function: H5_timer_get_times
*
@@ -487,18 +474,18 @@ H5_timer_get_times(H5_timer_t timer, H5_timevals_t *times /*in,out*/)
/* Sanity check */
HDassert(times);
- if(timer.is_running) {
- H5_timevals_t now;
+ if (timer.is_running) {
+ H5_timevals_t now;
/* Get the current times and report the current intervals without
* stopping the timer.
*/
- if(H5__timer_get_timevals(&now) < 0)
+ if (H5__timer_get_timevals(&now) < 0)
return -1;
times->elapsed = now.elapsed - timer.initial.elapsed;
- times->system = now.system - timer.initial.system;
- times->user = now.user - timer.initial.user;
+ times->system = now.system - timer.initial.system;
+ times->user = now.user - timer.initial.user;
} /* end if */
else {
times->elapsed = timer.final_interval.elapsed;
@@ -509,7 +496,6 @@ H5_timer_get_times(H5_timer_t timer, H5_timevals_t *times /*in,out*/)
return 0;
} /* end H5_timer_get_times() */
-
/*-------------------------------------------------------------------------
* Function: H5_timer_get_total_times
*
@@ -543,18 +529,18 @@ H5_timer_get_total_times(H5_timer_t timer, H5_timevals_t *times /*in,out*/)
/* Sanity check */
HDassert(times);
- if(timer.is_running) {
- H5_timevals_t now;
+ if (timer.is_running) {
+ H5_timevals_t now;
/* Get the current times and report the current totals without
* stopping the timer.
*/
- if(H5__timer_get_timevals(&now) < 0)
+ if (H5__timer_get_timevals(&now) < 0)
return -1;
times->elapsed = timer.total.elapsed + (now.elapsed - timer.initial.elapsed);
- times->system = timer.total.system + (now.system - timer.initial.system);
- times->user = timer.total.user + (now.user - timer.initial.user);
+ times->system = timer.total.system + (now.system - timer.initial.system);
+ times->user = timer.total.user + (now.user - timer.initial.user);
} /* end if */
else {
times->elapsed = timer.total.elapsed;
@@ -565,7 +551,6 @@ H5_timer_get_total_times(H5_timer_t timer, H5_timevals_t *times /*in,out*/)
return 0;
} /* end H5_timer_get_total_times() */
-
/*-------------------------------------------------------------------------
* Function: H5_timer_get_time_string
*
@@ -594,7 +579,7 @@ H5_timer_get_total_times(H5_timer_t timer, H5_timevals_t *times /*in,out*/)
char *
H5_timer_get_time_string(double seconds)
{
- char *s; /* output string */
+ char *s; /* output string */
/* Used when the time is greater than 59 seconds */
double days;
@@ -603,7 +588,7 @@ H5_timer_get_time_string(double seconds)
double remainder_sec;
/* Extract larger time units from count of seconds */
- if(seconds > (double)60.0F) {
+ if (seconds > (double)60.0F) {
/* Set initial # of seconds */
remainder_sec = seconds;
@@ -623,7 +608,7 @@ H5_timer_get_time_string(double seconds)
} /* end if */
/* Allocate */
- if(NULL == (s = (char *)HDcalloc(H5TIMER_TIME_STRING_LEN, sizeof(char))))
+ if (NULL == (s = (char *)HDcalloc(H5TIMER_TIME_STRING_LEN, sizeof(char))))
return NULL;
/* Do we need a format string? Some people might like a certain
@@ -631,26 +616,26 @@ H5_timer_get_time_string(double seconds)
* time unit. Perhaps this could be passed as an integer.
* (name? round_up_size? ?)
*/
- if(seconds < (double)0.0F)
+ if (seconds < (double)0.0F)
HDsprintf(s, "N/A");
- else if(H5_DBL_ABS_EQUAL((double)0.0F, seconds))
+ else if (H5_DBL_ABS_EQUAL((double)0.0F, seconds))
HDsprintf(s, "0.0 s");
- else if(seconds < (double)1.0E-6F)
+ else if (seconds < (double)1.0E-6F)
/* t < 1 us, Print time in ns */
HDsprintf(s, "%.f ns", seconds * (double)1.0E9F);
- else if(seconds < (double)1.0E-3F)
+ else if (seconds < (double)1.0E-3F)
/* t < 1 ms, Print time in us */
HDsprintf(s, "%.1f us", seconds * (double)1.0E6F);
- else if(seconds < (double)1.0F)
+ else if (seconds < (double)1.0F)
/* t < 1 s, Print time in ms */
HDsprintf(s, "%.1f ms", seconds * (double)1.0E3F);
- else if(seconds < H5_SEC_PER_MIN)
+ else if (seconds < H5_SEC_PER_MIN)
/* t < 1 m, Print time in s */
HDsprintf(s, "%.2f s", seconds);
- else if(seconds < H5_SEC_PER_HOUR)
+ else if (seconds < H5_SEC_PER_HOUR)
/* t < 1 h, Print time in m and s */
HDsprintf(s, "%.f m %.f s", minutes, remainder_sec);
- else if(seconds < H5_SEC_PER_DAY)
+ else if (seconds < H5_SEC_PER_DAY)
/* t < 1 d, Print time in h, m and s */
HDsprintf(s, "%.f h %.f m %.f s", hours, minutes, remainder_sec);
else
@@ -659,4 +644,3 @@ H5_timer_get_time_string(double seconds)
return s;
} /* end H5_timer_get_time_string() */
-