aboutsummaryrefslogtreecommitdiffstats
path: root/erts/emulator/nifs/common/socket_dbg.c
diff options
context:
space:
mode:
authorMicael Karlberg <[email protected]>2019-05-22 12:28:09 +0200
committerMicael Karlberg <[email protected]>2019-05-22 12:28:09 +0200
commit8551ec93d2864d8122472d8531a5268ee500d38d (patch)
treeaa25a489d3f913d5c38332bbaa5940b4ea761a79 /erts/emulator/nifs/common/socket_dbg.c
parent02752f185b18c7f1c3f57dd80cf7c12f925dfe6a (diff)
downloadotp-8551ec93d2864d8122472d8531a5268ee500d38d.tar.gz
otp-8551ec93d2864d8122472d8531a5268ee500d38d.tar.bz2
otp-8551ec93d2864d8122472d8531a5268ee500d38d.zip
[esock] Replace usage of clock_gettime(CLOCK_REALTIME, ...)
The usage of the function clock_gettime(CLOCK_REALTIME, ...) has been replaced with enif_monotonic_time(ERL_NIF_USEC) and enif_time_offset(ERL_NIF_USEC). For now its if-def'ed so that we still *can* use clock_gettime, but for the momemnt its not used even if its available. OTP-15566, OTP-15686
Diffstat (limited to 'erts/emulator/nifs/common/socket_dbg.c')
-rw-r--r--erts/emulator/nifs/common/socket_dbg.c57
1 files changed, 3 insertions, 54 deletions
diff --git a/erts/emulator/nifs/common/socket_dbg.c b/erts/emulator/nifs/common/socket_dbg.c
index 96f75a328f..7dfc4b77bc 100644
--- a/erts/emulator/nifs/common/socket_dbg.c
+++ b/erts/emulator/nifs/common/socket_dbg.c
@@ -30,6 +30,7 @@
#include <time.h>
#include <erl_nif.h>
+#include "socket_util.h"
#include "socket_dbg.h"
#define TSELF() enif_thread_self()
@@ -38,12 +39,6 @@
static FILE* dbgout = NULL;
-#if defined(CLOCK_REALTIME)
-static int realtime(struct timespec* tsP);
-static int timespec2str(char *buf, unsigned int len, struct timespec *ts);
-#endif
-
-
extern
void esock_dbg_init(char* filename)
{
@@ -73,10 +68,7 @@ void esock_dbg_printf( const char* prefix, const char* format, ... )
{
va_list args;
char f[512 + sizeof(format)]; // This has to suffice...
-#if defined(CLOCK_REALTIME)
char stamp[30];
- struct timespec ts;
-#endif
int res;
/*
@@ -85,64 +77,21 @@ void esock_dbg_printf( const char* prefix, const char* format, ... )
* But then I must change the API....something for later.
*/
-#if defined(CLOCK_REALTIME)
- if (!realtime(&ts) &&
- (timespec2str(stamp, sizeof(stamp), &ts) == 0)) {
+ if (esock_timestamp(stamp, sizeof(stamp))) {
res = enif_snprintf(f, sizeof(f), "%s [%s] [%s] %s",
prefix, stamp, TSNAME(), format);
} else {
res = enif_snprintf(f, sizeof(f), "%s [%s] %s",
prefix, TSNAME(), format);
}
-#else
- res = enif_snprintf(f, sizeof(f), "%s [%s] %s",
- prefix, TSNAME(), format);
-#endif
if (res > 0) {
va_start (args, format);
enif_vfprintf (dbgout, f, args);
va_end (args);
- fflush(stdout);
+ fflush(dbgout);
}
return;
}
-
-#if defined(CLOCK_REALTIME)
-static
-int realtime(struct timespec* tsP)
-{
- return clock_gettime(CLOCK_REALTIME, tsP);
-}
-
-
-
-
-/*
- * Convert a timespec struct into a readable/printable string
- */
-static
-int timespec2str(char *buf, unsigned int len, struct timespec *ts)
-{
- int ret, buflen;
- struct tm t;
-
- tzset();
- if (localtime_r(&(ts->tv_sec), &t) == NULL)
- return 1;
-
- ret = strftime(buf, len, "%F %T", &t);
- if (ret == 0)
- return 2;
- len -= ret - 1;
- buflen = strlen(buf);
-
- ret = snprintf(&buf[buflen], len, ".%06ld", ts->tv_nsec/1000);
- if (ret >= len)
- return 3;
-
- return 0;
-}
-#endif