summaryrefslogtreecommitdiffstats
path: root/src/H5system.c
diff options
context:
space:
mode:
authorDana Robinson <derobins@hdfgroup.org>2020-08-15 00:16:11 (GMT)
committerDana Robinson <derobins@hdfgroup.org>2020-08-15 00:16:11 (GMT)
commit62c296f1eb69255c5140a675270b11b5b265a220 (patch)
tree704a648065d1b20586457843958606b1ff37bb0f /src/H5system.c
parent5a61eb24af840b45105f71da4ea4edc7062e24d9 (diff)
downloadhdf5-62c296f1eb69255c5140a675270b11b5b265a220.zip
hdf5-62c296f1eb69255c5140a675270b11b5b265a220.tar.gz
hdf5-62c296f1eb69255c5140a675270b11b5b265a220.tar.bz2
Brings monotonic timer changes from develop
Diffstat (limited to 'src/H5system.c')
-rw-r--r--src/H5system.c151
1 files changed, 104 insertions, 47 deletions
diff --git a/src/H5system.c b/src/H5system.c
index dfb8d21..e2747f4 100644
--- a/src/H5system.c
+++ b/src/H5system.c
@@ -13,11 +13,11 @@
/*-------------------------------------------------------------------------
*
- * Created: H5system.c
- * Aug 21 2006
- * Quincey Koziol <koziol@hdfgroup.org>
+ * Created: H5system.c
+ * Aug 21 2006
+ * Quincey Koziol
*
- * Purpose: System call wrapper implementations.
+ * Purpose: System call wrapper implementations.
*
*-------------------------------------------------------------------------
*/
@@ -30,10 +30,10 @@
/***********/
/* Headers */
/***********/
-#include "H5private.h" /* Generic Functions */
-#include "H5Eprivate.h" /* Error handling */
-#include "H5Fprivate.h" /* File access */
-#include "H5MMprivate.h" /* Memory management */
+#include "H5private.h" /* Generic Functions */
+#include "H5Eprivate.h" /* Error handling */
+#include "H5Fprivate.h" /* File access */
+#include "H5MMprivate.h" /* Memory management */
/****************/
@@ -377,7 +377,7 @@ HDfprintf(FILE *stream, const char *fmt, ...)
if(fwidth)
len += HDsnprintf(format_templ + len, (sizeof(format_templ) - (size_t)(len + 1)), "%d", fwidth);
HDstrncat(format_templ, "s", (sizeof(format_templ) - (size_t)(len + 1)));
- fprintf(stream, format_templ, "UNDEF");
+ n = fprintf(stream, format_templ, "UNDEF");
}
}
break;
@@ -407,11 +407,25 @@ HDfprintf(FILE *stream, const char *fmt, ...)
htri_t tri_var = HDva_arg(ap, htri_t);
if(tri_var > 0)
- fprintf(stream, "TRUE");
+ n = fprintf(stream, "TRUE");
else if(!tri_var)
- fprintf(stream, "FALSE");
+ n = fprintf(stream, "FALSE");
else
- fprintf(stream, "FAIL(%d)", (int)tri_var);
+ n = fprintf(stream, "FAIL(%d)", (int)tri_var);
+ }
+ break;
+
+ case 'T': /* Elapsed time, in seconds */
+ {
+ double seconds = HDva_arg(ap, double);
+ char *time_string = H5_timer_get_time_string(seconds);
+
+ if(time_string) {
+ n = fprintf(stream, format_templ, time_string);
+ HDfree(time_string);
+ } /* end if */
+ else
+ n = fprintf(stream, format_templ, "(error)");
}
break;
@@ -474,8 +488,6 @@ H5_GCC_DIAG_ON(format-nonliteral)
* Programmer: Robb Matzke
* Thursday, April 9, 1998
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
#ifndef HDstrtoll
@@ -833,11 +845,88 @@ Wsetenv(const char *name, const char *value, int overwrite)
#pragma comment(lib, "advapi32.lib")
#endif
+
+/*-------------------------------------------------------------------------
+ * Function: H5_get_win32_times
+ *
+ * Purpose: Gets the elapsed, system and user times on Windows platforms.
+ * All time values are in seconds.
+ *
+ * Return: Success: 0
+ * Failure: -1
+ *
+ * Programmer: Dana Robinson
+ * May 2011
+ *
+ *-------------------------------------------------------------------------
+ */
+#ifdef H5_HAVE_WIN32_API
+int
+H5_get_win32_times(H5_timevals_t *tvs /*in,out*/)
+{
+ static HANDLE process_handle;
+ ULARGE_INTEGER kernel_start;
+ ULARGE_INTEGER user_start;
+ FILETIME KernelTime;
+ FILETIME UserTime;
+ FILETIME CreationTime;
+ FILETIME ExitTime;
+ LARGE_INTEGER counts_start;
+ static LARGE_INTEGER counts_freq;
+ static hbool_t is_initialized = FALSE;
+ BOOL err;
+
+ HDassert(tvs);
+
+ if(!is_initialized) {
+ /* NOTE: This is just a pseudo handle and does not need to be closed. */
+ process_handle = GetCurrentProcess();
+ err = QueryPerformanceFrequency(&counts_freq);
+ if(0 == err)
+ return -1;
+ is_initialized = TRUE;
+ } /* end if */
+
+ /*************************
+ * System and user times *
+ *************************/
+
+ err = GetProcessTimes(process_handle, &CreationTime, &ExitTime, &KernelTime,
+ &UserTime);
+ if(0 == err)
+ return -1;
+
+ /* The 1.0E7 factor seems strange but it's due to the clock
+ * ticking in 100 ns increments.
+ */
+ kernel_start.HighPart = KernelTime.dwHighDateTime;
+ kernel_start.LowPart = KernelTime.dwLowDateTime;
+ tvs->system = (double)(kernel_start.QuadPart / 1.0E7F);
+
+ user_start.HighPart = UserTime.dwHighDateTime;
+ user_start.LowPart = UserTime.dwLowDateTime;
+ tvs->user = (double)(user_start.QuadPart / 1.0E7F);
+
+ /****************
+ * Elapsed time *
+ ****************/
+
+ err = QueryPerformanceCounter(&counts_start);
+ if(0 == err)
+ return -1;
+
+ tvs->elapsed = (double)(counts_start.QuadPart) / (double)counts_freq.QuadPart;
+
+ return 0;
+} /* end H5_get_win32_times() */
+#endif
+
#define WloginBuffer_count 256
static char Wlogin_buffer[WloginBuffer_count];
+
char*
-Wgetlogin()
+Wgetlogin(void)
{
#ifdef H5_HAVE_WINSOCK2_H
@@ -1342,38 +1431,6 @@ H5_nanosleep(uint64_t nanosec)
FUNC_LEAVE_NOAPI_VOID
} /* end H5_nanosleep() */
-
-/*--------------------------------------------------------------------------
- * Function: H5_get_time
- *
- * Purpose: Get the current time, as the time of seconds after the UNIX epoch
- *
- * Return: SUCCEED/FAIL
- *
- * Programmer: Quincey Koziol
- * October 05, 2016
- *--------------------------------------------------------------------------
- */
-double
-H5_get_time(void)
-{
-#ifdef H5_HAVE_GETTIMEOFDAY
- struct timeval curr_time;
-#endif /* H5_HAVE_GETTIMEOFDAY */
- double ret_value = (double)0.0f;
-
- FUNC_ENTER_NOAPI_NOINIT_NOERR
-
-#ifdef H5_HAVE_GETTIMEOFDAY
- HDgettimeofday(&curr_time, NULL);
-
- ret_value = (double)curr_time.tv_sec + ((double)curr_time.tv_usec / (double)1000000.0f);
-#endif /* H5_HAVE_GETTIMEOFDAY */
-
- FUNC_LEAVE_NOAPI(ret_value)
-} /* end H5_get_time() */
-
-
#ifdef H5_HAVE_WIN32_API
#define H5_WIN32_ENV_VAR_BUFFER_SIZE 32767