Commit 27015b4c authored by Yuqi Zhang's avatar Yuqi Zhang
Browse files

better time log

parent 542312cd
......@@ -14,7 +14,7 @@
#define CRDT_OVERHEAD
//#define CRDT_OPCOUNT
//#define CRDT_ELE_STATUS
//#define CRDT_TIME
#define CRDT_TIME
#endif
......@@ -22,6 +22,8 @@
#include <sys/time.h>
#include "vector_clock.h"
static inline long currentTime()
{
struct timeval tv;
......@@ -29,14 +31,37 @@ static inline long currentTime()
return tv.tv_sec * 1000000 + tv.tv_usec;
}
static FILE *__CRDT_log = NULL;
#define CHECK_FILE \
do \
{ \
char fname[32]; \
sprintf(fname, "server%d_crdt.log", CURRENT_PID); \
if (__CRDT_log == NULL) __CRDT_log = fopen(fname, "a"); \
} while (0)
static void CRDT_log(const char *fmt, ...)
{
va_list ap;
char msg[LOG_MAX_LEN];
va_start(ap, fmt);
vsnprintf(msg, sizeof(msg), fmt, ap);
va_end(ap);
CHECK_FILE;
fprintf(__CRDT_log, "%ld, user_log: %s\n", currentTime(), msg);
fflush(__CRDT_log);
}
#endif
#ifdef CRDT_TIME
#define TIME_ISTR_BEGIN long __begin__ = currentTime();
#define TIME_ISTR_END \
serverLog(LL_NOTICE, "%s, %d: %ld", c->argv[0]->ptr, c->argc, currentTime() - __begin__);
#define TIME_ISTR_END CRDT_log("%s, %d: %ld", c->argv[0]->ptr, c->argc, currentTime() - __begin__);
#else
......@@ -47,18 +72,6 @@ static inline long currentTime()
#ifdef CRDT_LOG
#include "vector_clock.h"
static FILE *__CRDT_log = NULL;
#define CHECK_FILE \
do \
{ \
char fname[32]; \
sprintf(fname, "server%d_crdt.log", CURRENT_PID); \
if (__CRDT_log == NULL) __CRDT_log = fopen(fname, "a"); \
} while (0)
#define LOG_ISTR_PRE \
do \
{ \
......@@ -85,20 +98,6 @@ static FILE *__CRDT_log = NULL;
fflush(__CRDT_log); \
} while (0)
static void CRDT_log(const char *fmt, ...)
{
va_list ap;
char msg[LOG_MAX_LEN];
va_start(ap, fmt);
vsnprintf(msg, sizeof(msg), fmt, ap);
va_end(ap);
CHECK_FILE;
fprintf(__CRDT_log, "%ld, user_log: %s\n", currentTime(), msg);
fflush(__CRDT_log);
}
#else
#define LOG_ISTR_PRE
#define LOG_ISTR_EFF
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment