提交 e04ef027 编写于 作者: wafwerar's avatar wafwerar

[TD-13768]<fix>: redefine time api.

上级 0595d9f1
...@@ -65,8 +65,6 @@ extern "C" { ...@@ -65,8 +65,6 @@ extern "C" {
#define in_addr_t unsigned long #define in_addr_t unsigned long
#define socklen_t int #define socklen_t int
struct tm *localtime_r(const time_t *timep, struct tm *result);
char * strptime(const char *buf, const char *fmt, struct tm *tm);
char * strsep(char **stringp, const char *delim); char * strsep(char **stringp, const char *delim);
char * getpass(const char *prefix); char * getpass(const char *prefix);
char * strndup(const char *s, size_t n); char * strndup(const char *s, size_t n);
......
...@@ -20,6 +20,15 @@ ...@@ -20,6 +20,15 @@
extern "C" { extern "C" {
#endif #endif
// If the error is in a third-party library, place this header file under the third-party library header file.
#ifndef ALLOW_FORBID_FUNC
#define strptime STRPTIME_FUNC_TAOS_FORBID
#define gettimeofday GETTIMEOFDAY_FUNC_TAOS_FORBID
#define localtime_s LOCALTIMES_FUNC_TAOS_FORBID
#define localtime_r LOCALTIMER_FUNC_TAOS_FORBID
#define time TIME_FUNC_TAOS_FORBID
#endif
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#ifdef _TD_GO_DLL_ #ifdef _TD_GO_DLL_
#define MILLISECOND_PER_SECOND (1000LL) #define MILLISECOND_PER_SECOND (1000LL)
...@@ -61,6 +70,9 @@ static FORCE_INLINE int64_t taosGetTimestampNs() { ...@@ -61,6 +70,9 @@ static FORCE_INLINE int64_t taosGetTimestampNs() {
return (int64_t)systemTime.tv_sec * 1000000000L + (int64_t)systemTime.tv_nsec; return (int64_t)systemTime.tv_sec * 1000000000L + (int64_t)systemTime.tv_nsec;
} }
char *taosStrpTime(const char *buf, const char *fmt, struct tm *tm);
struct tm *taosLocalTime(const time_t *timep, struct tm *result);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -61,7 +61,7 @@ int64_t taosGetIntervalStartTimestamp(int64_t startTime, int64_t slidingTime, in ...@@ -61,7 +61,7 @@ int64_t taosGetIntervalStartTimestamp(int64_t startTime, int64_t slidingTime, in
} }
struct tm tm; struct tm tm;
time_t t = (time_t)start; time_t t = (time_t)start;
localtime_r(&t, &tm); taosLocalTime(&t, &tm);
tm.tm_sec = 0; tm.tm_sec = 0;
tm.tm_min = 0; tm.tm_min = 0;
tm.tm_hour = 0; tm.tm_hour = 0;
......
...@@ -69,7 +69,7 @@ static int64_t m_deltaUtc = 0; ...@@ -69,7 +69,7 @@ static int64_t m_deltaUtc = 0;
void deltaToUtcInitOnce() { void deltaToUtcInitOnce() {
struct tm tm = {0}; struct tm tm = {0};
(void)strptime("1970-01-01 00:00:00", (const char*)("%Y-%m-%d %H:%M:%S"), &tm); (void)taosStrpTime("1970-01-01 00:00:00", (const char*)("%Y-%m-%d %H:%M:%S"), &tm);
m_deltaUtc = (int64_t)mktime(&tm); m_deltaUtc = (int64_t)mktime(&tm);
// printf("====delta:%lld\n\n", seconds); // printf("====delta:%lld\n\n", seconds);
} }
...@@ -236,9 +236,9 @@ int32_t parseTimeWithTz(const char* timestr, int64_t* time, int32_t timePrec, ch ...@@ -236,9 +236,9 @@ int32_t parseTimeWithTz(const char* timestr, int64_t* time, int32_t timePrec, ch
char* str; char* str;
if (delim == 'T') { if (delim == 'T') {
str = strptime(timestr, "%Y-%m-%dT%H:%M:%S", &tm); str = taosStrpTime(timestr, "%Y-%m-%dT%H:%M:%S", &tm);
} else if (delim == 0) { } else if (delim == 0) {
str = strptime(timestr, "%Y-%m-%d %H:%M:%S", &tm); str = taosStrpTime(timestr, "%Y-%m-%d %H:%M:%S", &tm);
} else { } else {
str = NULL; str = NULL;
} }
...@@ -303,7 +303,7 @@ int32_t parseLocaltime(char* timestr, int64_t* time, int32_t timePrec) { ...@@ -303,7 +303,7 @@ int32_t parseLocaltime(char* timestr, int64_t* time, int32_t timePrec) {
*time = 0; *time = 0;
struct tm tm = {0}; struct tm tm = {0};
char* str = strptime(timestr, "%Y-%m-%d %H:%M:%S", &tm); char* str = taosStrpTime(timestr, "%Y-%m-%d %H:%M:%S", &tm);
if (str == NULL) { if (str == NULL) {
return -1; return -1;
} }
...@@ -338,7 +338,7 @@ int32_t parseLocaltimeDst(char* timestr, int64_t* time, int32_t timePrec) { ...@@ -338,7 +338,7 @@ int32_t parseLocaltimeDst(char* timestr, int64_t* time, int32_t timePrec) {
struct tm tm = {0}; struct tm tm = {0};
tm.tm_isdst = -1; tm.tm_isdst = -1;
char* str = strptime(timestr, "%Y-%m-%d %H:%M:%S", &tm); char* str = taosStrpTime(timestr, "%Y-%m-%d %H:%M:%S", &tm);
if (str == NULL) { if (str == NULL) {
return -1; return -1;
} }
...@@ -466,7 +466,7 @@ int64_t taosTimeAdd(int64_t t, int64_t duration, char unit, int32_t precision) { ...@@ -466,7 +466,7 @@ int64_t taosTimeAdd(int64_t t, int64_t duration, char unit, int32_t precision) {
struct tm tm; struct tm tm;
time_t tt = (time_t)(t / TSDB_TICK_PER_SECOND(precision)); time_t tt = (time_t)(t / TSDB_TICK_PER_SECOND(precision));
localtime_r(&tt, &tm); taosLocalTime(&tt, &tm);
int32_t mon = tm.tm_year * 12 + tm.tm_mon + (int32_t)duration; int32_t mon = tm.tm_year * 12 + tm.tm_mon + (int32_t)duration;
tm.tm_year = mon / 12; tm.tm_year = mon / 12;
tm.tm_mon = mon % 12; tm.tm_mon = mon % 12;
...@@ -489,11 +489,11 @@ int32_t taosTimeCountInterval(int64_t skey, int64_t ekey, int64_t interval, char ...@@ -489,11 +489,11 @@ int32_t taosTimeCountInterval(int64_t skey, int64_t ekey, int64_t interval, char
struct tm tm; struct tm tm;
time_t t = (time_t)skey; time_t t = (time_t)skey;
localtime_r(&t, &tm); taosLocalTime(&t, &tm);
int32_t smon = tm.tm_year * 12 + tm.tm_mon; int32_t smon = tm.tm_year * 12 + tm.tm_mon;
t = (time_t)ekey; t = (time_t)ekey;
localtime_r(&t, &tm); taosLocalTime(&t, &tm);
int32_t emon = tm.tm_year * 12 + tm.tm_mon; int32_t emon = tm.tm_year * 12 + tm.tm_mon;
if (unit == 'y') { if (unit == 'y') {
...@@ -514,7 +514,7 @@ int64_t taosTimeTruncate(int64_t t, const SInterval* pInterval, int32_t precisio ...@@ -514,7 +514,7 @@ int64_t taosTimeTruncate(int64_t t, const SInterval* pInterval, int32_t precisio
start /= (int64_t)(TSDB_TICK_PER_SECOND(precision)); start /= (int64_t)(TSDB_TICK_PER_SECOND(precision));
struct tm tm; struct tm tm;
time_t tt = (time_t)start; time_t tt = (time_t)start;
localtime_r(&tt, &tm); taosLocalTime(&tt, &tm);
tm.tm_sec = 0; tm.tm_sec = 0;
tm.tm_min = 0; tm.tm_min = 0;
tm.tm_hour = 0; tm.tm_hour = 0;
...@@ -597,13 +597,13 @@ const char* fmtts(int64_t ts) { ...@@ -597,13 +597,13 @@ const char* fmtts(int64_t ts) {
if (ts > -62135625943 && ts < 32503651200) { if (ts > -62135625943 && ts < 32503651200) {
time_t t = (time_t)ts; time_t t = (time_t)ts;
localtime_r(&t, &tm); taosLocalTime(&t, &tm);
pos += strftime(buf + pos, sizeof(buf), "s=%Y-%m-%d %H:%M:%S", &tm); pos += strftime(buf + pos, sizeof(buf), "s=%Y-%m-%d %H:%M:%S", &tm);
} }
if (ts > -62135625943000 && ts < 32503651200000) { if (ts > -62135625943000 && ts < 32503651200000) {
time_t t = (time_t)(ts / 1000); time_t t = (time_t)(ts / 1000);
localtime_r(&t, &tm); taosLocalTime(&t, &tm);
if (pos > 0) { if (pos > 0) {
buf[pos++] = ' '; buf[pos++] = ' ';
buf[pos++] = '|'; buf[pos++] = '|';
...@@ -615,7 +615,7 @@ const char* fmtts(int64_t ts) { ...@@ -615,7 +615,7 @@ const char* fmtts(int64_t ts) {
{ {
time_t t = (time_t)(ts / 1000000); time_t t = (time_t)(ts / 1000000);
localtime_r(&t, &tm); taosLocalTime(&t, &tm);
if (pos > 0) { if (pos > 0) {
buf[pos++] = ' '; buf[pos++] = ' ';
buf[pos++] = '|'; buf[pos++] = '|';
......
...@@ -163,7 +163,7 @@ static void getNextTimeWindow(SInterval* pInterval, int32_t precision, int32_t o ...@@ -163,7 +163,7 @@ static void getNextTimeWindow(SInterval* pInterval, int32_t precision, int32_t o
struct tm tm; struct tm tm;
time_t t = (time_t)key; time_t t = (time_t)key;
localtime_r(&t, &tm); taosLocalTime(&t, &tm);
int mon = (int)(tm.tm_year * 12 + tm.tm_mon + interval * factor); int mon = (int)(tm.tm_year * 12 + tm.tm_mon + interval * factor);
tm.tm_year = mon / 12; tm.tm_year = mon / 12;
......
...@@ -1019,7 +1019,7 @@ TEST(testCase, external_sort_Test) { ...@@ -1019,7 +1019,7 @@ TEST(testCase, external_sort_Test) {
return; return;
#endif #endif
taosSeedRand(time(NULL)); taosSeedRand(taosGetTimestampSec());
SArray* pOrderVal = taosArrayInit(4, sizeof(SOrder)); SArray* pOrderVal = taosArrayInit(4, sizeof(SOrder));
SOrder o = {0}; SOrder o = {0};
...@@ -1080,7 +1080,7 @@ TEST(testCase, external_sort_Test) { ...@@ -1080,7 +1080,7 @@ TEST(testCase, external_sort_Test) {
} }
TEST(testCase, sorted_merge_Test) { TEST(testCase, sorted_merge_Test) {
taosSeedRand(time(NULL)); taosSeedRand(taosGetTimestampSec());
SArray* pOrderVal = taosArrayInit(4, sizeof(SOrder)); SArray* pOrderVal = taosArrayInit(4, sizeof(SOrder));
SOrder o = {0}; SOrder o = {0};
...@@ -1152,7 +1152,7 @@ TEST(testCase, sorted_merge_Test) { ...@@ -1152,7 +1152,7 @@ TEST(testCase, sorted_merge_Test) {
} }
TEST(testCase, time_interval_Operator_Test) { TEST(testCase, time_interval_Operator_Test) {
taosSeedRand(time(NULL)); taosSeedRand(taosGetTimestampSec());
SArray* pOrderVal = taosArrayInit(4, sizeof(SOrder)); SArray* pOrderVal = taosArrayInit(4, sizeof(SOrder));
SOrder o = {0}; SOrder o = {0};
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
#pragma GCC diagnostic ignored "-Wsign-compare" #pragma GCC diagnostic ignored "-Wsign-compare"
TEST(testCase, linear_hash_Tests) { TEST(testCase, linear_hash_Tests) {
taosSeedRand(time(NULL)); taosSeedRand(taosGetTimestampSec());
_hash_fn_t fn = taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT); _hash_fn_t fn = taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT);
#if 0 #if 0
......
...@@ -963,7 +963,7 @@ TEST(seqTest, randCase) { ...@@ -963,7 +963,7 @@ TEST(seqTest, randCase) {
stubSetRpcSendResponse(); stubSetRpcSendResponse();
stubSetCreateExecTask(); stubSetCreateExecTask();
taosSeedRand(time(NULL)); taosSeedRand(taosGetTimestampSec());
code = qWorkerInit(NODE_TYPE_VNODE, 1, NULL, &mgmt, mockPointer, qwtPutReqToQueue); code = qWorkerInit(NODE_TYPE_VNODE, 1, NULL, &mgmt, mockPointer, qwtPutReqToQueue);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
...@@ -1025,7 +1025,7 @@ TEST(seqTest, multithreadRand) { ...@@ -1025,7 +1025,7 @@ TEST(seqTest, multithreadRand) {
stubSetStringToPlan(); stubSetStringToPlan();
stubSetRpcSendResponse(); stubSetRpcSendResponse();
taosSeedRand(time(NULL)); taosSeedRand(taosGetTimestampSec());
code = qWorkerInit(NODE_TYPE_VNODE, 1, NULL, &mgmt, mockPointer, qwtPutReqToQueue); code = qWorkerInit(NODE_TYPE_VNODE, 1, NULL, &mgmt, mockPointer, qwtPutReqToQueue);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
...@@ -1076,7 +1076,7 @@ TEST(rcTest, shortExecshortDelay) { ...@@ -1076,7 +1076,7 @@ TEST(rcTest, shortExecshortDelay) {
stubSetPutDataBlock(); stubSetPutDataBlock();
stubSetGetDataBlock(); stubSetGetDataBlock();
taosSeedRand(time(NULL)); taosSeedRand(taosGetTimestampSec());
qwtTestStop = false; qwtTestStop = false;
qwtTestQuitThreadNum = 0; qwtTestQuitThreadNum = 0;
...@@ -1157,7 +1157,7 @@ TEST(rcTest, longExecshortDelay) { ...@@ -1157,7 +1157,7 @@ TEST(rcTest, longExecshortDelay) {
stubSetPutDataBlock(); stubSetPutDataBlock();
stubSetGetDataBlock(); stubSetGetDataBlock();
taosSeedRand(time(NULL)); taosSeedRand(taosGetTimestampSec());
qwtTestStop = false; qwtTestStop = false;
qwtTestQuitThreadNum = 0; qwtTestQuitThreadNum = 0;
...@@ -1240,7 +1240,7 @@ TEST(rcTest, shortExeclongDelay) { ...@@ -1240,7 +1240,7 @@ TEST(rcTest, shortExeclongDelay) {
stubSetPutDataBlock(); stubSetPutDataBlock();
stubSetGetDataBlock(); stubSetGetDataBlock();
taosSeedRand(time(NULL)); taosSeedRand(taosGetTimestampSec());
qwtTestStop = false; qwtTestStop = false;
qwtTestQuitThreadNum = 0; qwtTestQuitThreadNum = 0;
...@@ -1324,7 +1324,7 @@ TEST(rcTest, dropTest) { ...@@ -1324,7 +1324,7 @@ TEST(rcTest, dropTest) {
stubSetPutDataBlock(); stubSetPutDataBlock();
stubSetGetDataBlock(); stubSetGetDataBlock();
taosSeedRand(time(NULL)); taosSeedRand(taosGetTimestampSec());
code = qWorkerInit(NODE_TYPE_VNODE, 1, NULL, &mgmt, mockPointer, qwtPutReqToQueue); code = qWorkerInit(NODE_TYPE_VNODE, 1, NULL, &mgmt, mockPointer, qwtPutReqToQueue);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
...@@ -1358,7 +1358,7 @@ TEST(rcTest, dropTest) { ...@@ -1358,7 +1358,7 @@ TEST(rcTest, dropTest) {
int main(int argc, char** argv) { int main(int argc, char** argv) {
taosSeedRand(time(NULL)); taosSeedRand(taosGetTimestampSec());
testing::InitGoogleTest(&argc, argv); testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS(); return RUN_ALL_TESTS();
} }
......
...@@ -1286,7 +1286,7 @@ TEST(scalarModelogicTest, diff_columns_or_and_or) { ...@@ -1286,7 +1286,7 @@ TEST(scalarModelogicTest, diff_columns_or_and_or) {
int main(int argc, char** argv) { int main(int argc, char** argv) {
taosSeedRand(time(NULL)); taosSeedRand(taosGetTimestampSec());
testing::InitGoogleTest(&argc, argv); testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS(); return RUN_ALL_TESTS();
} }
......
...@@ -1435,7 +1435,7 @@ TEST(columnTest, greater_and_lower) { ...@@ -1435,7 +1435,7 @@ TEST(columnTest, greater_and_lower) {
int main(int argc, char** argv) { int main(int argc, char** argv) {
taosSeedRand(time(NULL)); taosSeedRand(taosGetTimestampSec());
testing::InitGoogleTest(&argc, argv); testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS(); return RUN_ALL_TESTS();
} }
......
...@@ -724,7 +724,7 @@ TEST(queryTest, flowCtrlCase) { ...@@ -724,7 +724,7 @@ TEST(queryTest, flowCtrlCase) {
schtInitLogFile(); schtInitLogFile();
taosSeedRand(time(NULL)); taosSeedRand(taosGetTimestampSec());
SArray *qnodeList = taosArrayInit(1, sizeof(SEp)); SArray *qnodeList = taosArrayInit(1, sizeof(SEp));
...@@ -873,7 +873,7 @@ TEST(multiThread, forceFree) { ...@@ -873,7 +873,7 @@ TEST(multiThread, forceFree) {
} }
int main(int argc, char** argv) { int main(int argc, char** argv) {
taosSeedRand(time(NULL)); taosSeedRand(taosGetTimestampSec());
testing::InitGoogleTest(&argc, argv); testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS(); return RUN_ALL_TESTS();
} }
......
...@@ -28,7 +28,7 @@ static void doSyncEnvStopTimer(SSyncEnv *pSyncEnv, tmr_h *pTimer); ...@@ -28,7 +28,7 @@ static void doSyncEnvStopTimer(SSyncEnv *pSyncEnv, tmr_h *pTimer);
int32_t syncEnvStart() { int32_t syncEnvStart() {
int32_t ret; int32_t ret;
taosSeedRand(time(NULL)); taosSeedRand(taosGetTimestampSec());
gSyncEnv = (SSyncEnv *)malloc(sizeof(SSyncEnv)); gSyncEnv = (SSyncEnv *)malloc(sizeof(SSyncEnv));
assert(gSyncEnv != NULL); assert(gSyncEnv != NULL);
ret = doSyncEnvStart(gSyncEnv); ret = doSyncEnvStart(gSyncEnv);
......
...@@ -44,7 +44,7 @@ int32_t syncIOStart(char *host, uint16_t port) { ...@@ -44,7 +44,7 @@ int32_t syncIOStart(char *host, uint16_t port) {
gSyncIO = syncIOCreate(host, port); gSyncIO = syncIOCreate(host, port);
assert(gSyncIO != NULL); assert(gSyncIO != NULL);
taosSeedRand(time(NULL)); taosSeedRand(taosGetTimestampSec());
int32_t ret = syncIOStartInternal(gSyncIO); int32_t ret = syncIOStartInternal(gSyncIO);
assert(ret == 0); assert(ret == 0);
......
...@@ -203,7 +203,7 @@ int main(int argc, char *argv[]) { ...@@ -203,7 +203,7 @@ int main(int argc, char *argv[]) {
tInfo("client is initialized"); tInfo("client is initialized");
tInfo("threads:%d msgSize:%d requests:%d", appThreads, msgSize, numOfReqs); tInfo("threads:%d msgSize:%d requests:%d", appThreads, msgSize, numOfReqs);
gettimeofday(&systemTime, NULL); taosGetTimeOfDay(&systemTime);
startTime = systemTime.tv_sec * 1000000 + systemTime.tv_usec; startTime = systemTime.tv_sec * 1000000 + systemTime.tv_usec;
SInfo *pInfo = (SInfo *)calloc(1, sizeof(SInfo) * appThreads); SInfo *pInfo = (SInfo *)calloc(1, sizeof(SInfo) * appThreads);
...@@ -226,7 +226,7 @@ int main(int argc, char *argv[]) { ...@@ -226,7 +226,7 @@ int main(int argc, char *argv[]) {
taosUsleep(1); taosUsleep(1);
} while (tcount < appThreads); } while (tcount < appThreads);
gettimeofday(&systemTime, NULL); taosGetTimeOfDay(&systemTime);
endTime = systemTime.tv_sec * 1000000 + systemTime.tv_usec; endTime = systemTime.tv_sec * 1000000 + systemTime.tv_usec;
float usedTime = (endTime - startTime) / 1000.0f; // mseconds float usedTime = (endTime - startTime) / 1000.0f; // mseconds
......
...@@ -181,7 +181,7 @@ int main(int argc, char *argv[]) { ...@@ -181,7 +181,7 @@ int main(int argc, char *argv[]) {
tInfo("client is initialized"); tInfo("client is initialized");
tInfo("threads:%d msgSize:%d requests:%d", appThreads, msgSize, numOfReqs); tInfo("threads:%d msgSize:%d requests:%d", appThreads, msgSize, numOfReqs);
gettimeofday(&systemTime, NULL); taosGetTimeOfDay(&systemTime);
startTime = systemTime.tv_sec * 1000000 + systemTime.tv_usec; startTime = systemTime.tv_sec * 1000000 + systemTime.tv_usec;
SInfo *pInfo = (SInfo *)calloc(1, sizeof(SInfo) * appThreads); SInfo *pInfo = (SInfo *)calloc(1, sizeof(SInfo) * appThreads);
...@@ -204,7 +204,7 @@ int main(int argc, char *argv[]) { ...@@ -204,7 +204,7 @@ int main(int argc, char *argv[]) {
taosUsleep(1); taosUsleep(1);
} while (tcount < appThreads); } while (tcount < appThreads);
gettimeofday(&systemTime, NULL); taosGetTimeOfDay(&systemTime);
endTime = systemTime.tv_sec * 1000000 + systemTime.tv_usec; endTime = systemTime.tv_sec * 1000000 + systemTime.tv_usec;
float usedTime = (endTime - startTime) / 1000.0f; // mseconds float usedTime = (endTime - startTime) / 1000.0f; // mseconds
......
...@@ -158,7 +158,7 @@ int main(int argc, char *argv[]) { ...@@ -158,7 +158,7 @@ int main(int argc, char *argv[]) {
tInfo("client is initialized"); tInfo("client is initialized");
gettimeofday(&systemTime, NULL); taosGetTimeOfDay(&systemTime);
startTime = systemTime.tv_sec*1000000 + systemTime.tv_usec; startTime = systemTime.tv_sec*1000000 + systemTime.tv_usec;
SInfo *pInfo = (SInfo *)calloc(1, sizeof(SInfo)*appThreads); SInfo *pInfo = (SInfo *)calloc(1, sizeof(SInfo)*appThreads);
...@@ -181,7 +181,7 @@ int main(int argc, char *argv[]) { ...@@ -181,7 +181,7 @@ int main(int argc, char *argv[]) {
taosUsleep(1); taosUsleep(1);
} while ( tcount < appThreads); } while ( tcount < appThreads);
gettimeofday(&systemTime, NULL); taosGetTimeOfDay(&systemTime);
endTime = systemTime.tv_sec*1000000 + systemTime.tv_usec; endTime = systemTime.tv_sec*1000000 + systemTime.tv_usec;
float usedTime = (endTime - startTime)/1000.0; // mseconds float usedTime = (endTime - startTime)/1000.0; // mseconds
......
...@@ -181,7 +181,7 @@ int main(int argc, char *argv[]) { ...@@ -181,7 +181,7 @@ int main(int argc, char *argv[]) {
tInfo("client is initialized"); tInfo("client is initialized");
tInfo("threads:%d msgSize:%d requests:%d", appThreads, msgSize, numOfReqs); tInfo("threads:%d msgSize:%d requests:%d", appThreads, msgSize, numOfReqs);
gettimeofday(&systemTime, NULL); taosGetTimeOfDay(&systemTime);
startTime = systemTime.tv_sec * 1000000 + systemTime.tv_usec; startTime = systemTime.tv_sec * 1000000 + systemTime.tv_usec;
SInfo *pInfo = (SInfo *)calloc(1, sizeof(SInfo) * appThreads); SInfo *pInfo = (SInfo *)calloc(1, sizeof(SInfo) * appThreads);
...@@ -204,7 +204,7 @@ int main(int argc, char *argv[]) { ...@@ -204,7 +204,7 @@ int main(int argc, char *argv[]) {
taosUsleep(1); taosUsleep(1);
} while (tcount < appThreads); } while (tcount < appThreads);
gettimeofday(&systemTime, NULL); taosGetTimeOfDay(&systemTime);
endTime = systemTime.tv_sec * 1000000 + systemTime.tv_usec; endTime = systemTime.tv_sec * 1000000 + systemTime.tv_usec;
float usedTime = (endTime - startTime) / 1000.0f; // mseconds float usedTime = (endTime - startTime) / 1000.0f; // mseconds
......
...@@ -33,11 +33,11 @@ uint32_t taosSafeRand(void) { ...@@ -33,11 +33,11 @@ uint32_t taosSafeRand(void) {
pFile = taosOpenFile("/dev/urandom", TD_FILE_READ); pFile = taosOpenFile("/dev/urandom", TD_FILE_READ);
if (pFile == NULL) { if (pFile == NULL) {
seed = (int)time(0); seed = (int)taosGetTimestampSec();
} else { } else {
int len = taosReadFile(pFile, &seed, sizeof(seed)); int len = taosReadFile(pFile, &seed, sizeof(seed));
if (len < 0) { if (len < 0) {
seed = (int)time(0); seed = (int)taosGetTimestampSec();
} }
taosCloseFile(&pFile); taosCloseFile(&pFile);
} }
......
...@@ -38,366 +38,368 @@ ...@@ -38,366 +38,368 @@
// //
//#include "lukemftp.h" //#include "lukemftp.h"
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) // #if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#include <time.h> // #include <time.h>
#include <stdlib.h> // #include <stdlib.h>
#include <string.h> // #include <string.h>
#include <winsock2.h> // #include <winsock2.h>
//#define TM_YEAR_BASE 1970 //origin // //#define TM_YEAR_BASE 1970 //origin
#define TM_YEAR_BASE 1900 //slguan // #define TM_YEAR_BASE 1900 //slguan
/* // /*
* We do not implement alternate representations. However, we always // * We do not implement alternate representations. However, we always
* check whether a given modifier is allowed for a certain conversion. // * check whether a given modifier is allowed for a certain conversion.
*/ // */
#define ALT_E 0x01 // #define ALT_E 0x01
#define ALT_O 0x02 // #define ALT_O 0x02
#define LEGAL_ALT(x) { if (alt_format & ~(x)) return (0); } // #define LEGAL_ALT(x) { if (alt_format & ~(x)) return (0); }
static int conv_num(const char **, int *, int, int); // static int conv_num(const char **buf, int *dest, int llim, int ulim)
// {
static const char *day[7] = { // int result = 0;
"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday",
"Friday", "Saturday" // /* The limit also determines the number of valid digits. */
}; // int rulim = ulim;
static const char *abday[7] = {
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" // if (**buf < '0' || **buf > '9')
}; // return (0);
static const char *mon[12] = {
"January", "February", "March", "April", "May", "June", "July", // do {
"August", "September", "October", "November", "December" // result *= 10;
}; // result += *(*buf)++ - '0';
static const char *abmon[12] = { // rulim /= 10;
"Jan", "Feb", "Mar", "Apr", "May", "Jun", // } while ((result * 10 <= ulim) && rulim && **buf >= '0' && **buf <= '9');
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
}; // if (result < llim || result > ulim)
static const char *am_pm[2] = { // return (0);
"AM", "PM"
}; // *dest = result;
// return (1);
// }
char *
strptime(const char *buf, const char *fmt, struct tm *tm) // static const char *day[7] = {
{ // "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday",
char c; // "Friday", "Saturday"
const char *bp; // };
size_t len = 0; // static const char *abday[7] = {
int alt_format, i, split_year = 0; // "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
// };
bp = buf; // static const char *mon[12] = {
// "January", "February", "March", "April", "May", "June", "July",
while ((c = *fmt) != '\0') { // "August", "September", "October", "November", "December"
/* Clear `alternate' modifier prior to new conversion. */ // };
alt_format = 0; // static const char *abmon[12] = {
// "Jan", "Feb", "Mar", "Apr", "May", "Jun",
/* Eat up white-space. */ // "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
if (isspace(c)) { // };
while (isspace(*bp)) // static const char *am_pm[2] = {
bp++; // "AM", "PM"
// };
fmt++;
continue; // #endif
}
// char *taosStrpTime(const char *buf, const char *fmt, struct tm *tm) {
if ((c = *fmt++) != '%') // #if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
goto literal; // char c;
// const char *bp;
// size_t len = 0;
again: switch (c = *fmt++) { // int alt_format, i, split_year = 0;
case '%': /* "%%" is converted to "%". */
literal : // bp = buf;
if (c != *bp++)
return (0); // while ((c = *fmt) != '\0') {
break; // /* Clear `alternate' modifier prior to new conversion. */
// alt_format = 0;
/*
* "Alternative" modifiers. Just set the appropriate flag // /* Eat up white-space. */
* and start over again. // if (isspace(c)) {
*/ // while (isspace(*bp))
case 'E': /* "%E?" alternative conversion modifier. */ // bp++;
LEGAL_ALT(0);
alt_format |= ALT_E; // fmt++;
goto again; // continue;
// }
case 'O': /* "%O?" alternative conversion modifier. */
LEGAL_ALT(0); // if ((c = *fmt++) != '%')
alt_format |= ALT_O; // goto literal;
goto again;
/* // again: switch (c = *fmt++) {
* "Complex" conversion rules, implemented through recursion. // case '%': /* "%%" is converted to "%". */
*/ // literal :
case 'c': /* Date and time, using the locale's format. */ // if (c != *bp++)
LEGAL_ALT(ALT_E); // return (0);
if (!(bp = strptime(bp, "%x %X", tm))) // break;
return (0);
break; // /*
// * "Alternative" modifiers. Just set the appropriate flag
case 'D': /* The date as "%m/%d/%y". */ // * and start over again.
LEGAL_ALT(0); // */
if (!(bp = strptime(bp, "%m/%d/%y", tm))) // case 'E': /* "%E?" alternative conversion modifier. */
return (0); // LEGAL_ALT(0);
break; // alt_format |= ALT_E;
// goto again;
case 'R': /* The time as "%H:%M". */
LEGAL_ALT(0); // case 'O': /* "%O?" alternative conversion modifier. */
if (!(bp = strptime(bp, "%H:%M", tm))) // LEGAL_ALT(0);
return (0); // alt_format |= ALT_O;
break; // goto again;
case 'r': /* The time in 12-hour clock representation. */ // /*
LEGAL_ALT(0); // * "Complex" conversion rules, implemented through recursion.
if (!(bp = strptime(bp, "%I:%M:%S %p", tm))) // */
return (0); // case 'c': /* Date and time, using the locale's format. */
break; // LEGAL_ALT(ALT_E);
// if (!(bp = taosStrpTime(bp, "%x %X", tm)))
case 'T': /* The time as "%H:%M:%S". */ // return (0);
LEGAL_ALT(0); // break;
if (!(bp = strptime(bp, "%H:%M:%S", tm)))
return (0); // case 'D': /* The date as "%m/%d/%y". */
break; // LEGAL_ALT(0);
// if (!(bp = taosStrpTime(bp, "%m/%d/%y", tm)))
case 'X': /* The time, using the locale's format. */ // return (0);
LEGAL_ALT(ALT_E); // break;
if (!(bp = strptime(bp, "%H:%M:%S", tm)))
return (0); // case 'R': /* The time as "%H:%M". */
break; // LEGAL_ALT(0);
// if (!(bp = taosStrpTime(bp, "%H:%M", tm)))
case 'x': /* The date, using the locale's format. */ // return (0);
LEGAL_ALT(ALT_E); // break;
if (!(bp = strptime(bp, "%m/%d/%y", tm)))
return (0); // case 'r': /* The time in 12-hour clock representation. */
break; // LEGAL_ALT(0);
// if (!(bp = taosStrpTime(bp, "%I:%M:%S %p", tm)))
/* // return (0);
* "Elementary" conversion rules. // break;
*/
case 'A': /* The day of week, using the locale's form. */ // case 'T': /* The time as "%H:%M:%S". */
case 'a': // LEGAL_ALT(0);
LEGAL_ALT(0); // if (!(bp = taosStrpTime(bp, "%H:%M:%S", tm)))
for (i = 0; i < 7; i++) { // return (0);
/* Full name. */ // break;
len = strlen(day[i]);
if (strncmp(day[i], bp, len) == 0) // case 'X': /* The time, using the locale's format. */
break; // LEGAL_ALT(ALT_E);
// if (!(bp = taosStrpTime(bp, "%H:%M:%S", tm)))
/* Abbreviated name. */ // return (0);
len = strlen(abday[i]); // break;
if (strncmp(abday[i], bp, len) == 0)
break; // case 'x': /* The date, using the locale's format. */
} // LEGAL_ALT(ALT_E);
// if (!(bp = taosStrpTime(bp, "%m/%d/%y", tm)))
/* Nothing matched. */ // return (0);
if (i == 7) // break;
return (0);
// /*
tm->tm_wday = i; // * "Elementary" conversion rules.
bp += len; // */
break; // case 'A': /* The day of week, using the locale's form. */
// case 'a':
case 'B': /* The month, using the locale's form. */ // LEGAL_ALT(0);
case 'b': // for (i = 0; i < 7; i++) {
case 'h': // /* Full name. */
LEGAL_ALT(0); // len = strlen(day[i]);
for (i = 0; i < 12; i++) { // if (strncmp(day[i], bp, len) == 0)
/* Full name. */ // break;
len = strlen(mon[i]);
if (strncmp(mon[i], bp, len) == 0) // /* Abbreviated name. */
break; // len = strlen(abday[i]);
// if (strncmp(abday[i], bp, len) == 0)
/* Abbreviated name. */ // break;
len = strlen(abmon[i]); // }
if (strncmp(abmon[i], bp, len) == 0)
break; // /* Nothing matched. */
} // if (i == 7)
// return (0);
/* Nothing matched. */
if (i == 12) // tm->tm_wday = i;
return (0); // bp += len;
// break;
tm->tm_mon = i;
bp += len; // case 'B': /* The month, using the locale's form. */
break; // case 'b':
// case 'h':
case 'C': /* The century number. */ // LEGAL_ALT(0);
LEGAL_ALT(ALT_E); // for (i = 0; i < 12; i++) {
if (!(conv_num(&bp, &i, 0, 99))) // /* Full name. */
return (0); // len = strlen(mon[i]);
// if (strncmp(mon[i], bp, len) == 0)
if (split_year) { // break;
tm->tm_year = (tm->tm_year % 100) + (i * 100);
} // /* Abbreviated name. */
else { // len = strlen(abmon[i]);
tm->tm_year = i * 100; // if (strncmp(abmon[i], bp, len) == 0)
split_year = 1; // break;
} // }
break;
// /* Nothing matched. */
case 'd': /* The day of month. */ // if (i == 12)
case 'e': // return (0);
LEGAL_ALT(ALT_O);
if (!(conv_num(&bp, &tm->tm_mday, 1, 31))) // tm->tm_mon = i;
return (0); // bp += len;
break; // break;
case 'k': /* The hour (24-hour clock representation). */ // case 'C': /* The century number. */
LEGAL_ALT(0); // LEGAL_ALT(ALT_E);
/* FALLTHROUGH */ // if (!(conv_num(&bp, &i, 0, 99)))
case 'H': // return (0);
LEGAL_ALT(ALT_O);
if (!(conv_num(&bp, &tm->tm_hour, 0, 23))) // if (split_year) {
return (0); // tm->tm_year = (tm->tm_year % 100) + (i * 100);
break; // }
// else {
case 'l': /* The hour (12-hour clock representation). */ // tm->tm_year = i * 100;
LEGAL_ALT(0); // split_year = 1;
/* FALLTHROUGH */ // }
case 'I': // break;
LEGAL_ALT(ALT_O);
if (!(conv_num(&bp, &tm->tm_hour, 1, 12))) // case 'd': /* The day of month. */
return (0); // case 'e':
if (tm->tm_hour == 12) // LEGAL_ALT(ALT_O);
tm->tm_hour = 0; // if (!(conv_num(&bp, &tm->tm_mday, 1, 31)))
break; // return (0);
// break;
case 'j': /* The day of year. */
LEGAL_ALT(0); // case 'k': /* The hour (24-hour clock representation). */
if (!(conv_num(&bp, &i, 1, 366))) // LEGAL_ALT(0);
return (0); // /* FALLTHROUGH */
tm->tm_yday = i - 1; // case 'H':
break; // LEGAL_ALT(ALT_O);
// if (!(conv_num(&bp, &tm->tm_hour, 0, 23)))
case 'M': /* The minute. */ // return (0);
LEGAL_ALT(ALT_O); // break;
if (!(conv_num(&bp, &tm->tm_min, 0, 59)))
return (0); // case 'l': /* The hour (12-hour clock representation). */
break; // LEGAL_ALT(0);
// /* FALLTHROUGH */
case 'm': /* The month. */ // case 'I':
LEGAL_ALT(ALT_O); // LEGAL_ALT(ALT_O);
if (!(conv_num(&bp, &i, 1, 12))) // if (!(conv_num(&bp, &tm->tm_hour, 1, 12)))
return (0); // return (0);
tm->tm_mon = i - 1; // if (tm->tm_hour == 12)
break; // tm->tm_hour = 0;
// break;
case 'p': /* The locale's equivalent of AM/PM. */
LEGAL_ALT(0); // case 'j': /* The day of year. */
/* AM? */ // LEGAL_ALT(0);
if (strcmp(am_pm[0], bp) == 0) { // if (!(conv_num(&bp, &i, 1, 366)))
if (tm->tm_hour > 11) // return (0);
return (0); // tm->tm_yday = i - 1;
// break;
bp += strlen(am_pm[0]);
break; // case 'M': /* The minute. */
} // LEGAL_ALT(ALT_O);
/* PM? */ // if (!(conv_num(&bp, &tm->tm_min, 0, 59)))
else if (strcmp(am_pm[1], bp) == 0) { // return (0);
if (tm->tm_hour > 11) // break;
return (0);
// case 'm': /* The month. */
tm->tm_hour += 12; // LEGAL_ALT(ALT_O);
bp += strlen(am_pm[1]); // if (!(conv_num(&bp, &i, 1, 12)))
break; // return (0);
} // tm->tm_mon = i - 1;
// break;
/* Nothing matched. */
return (0); // case 'p': /* The locale's equivalent of AM/PM. */
// LEGAL_ALT(0);
case 'S': /* The seconds. */ // /* AM? */
LEGAL_ALT(ALT_O); // if (strcmp(am_pm[0], bp) == 0) {
if (!(conv_num(&bp, &tm->tm_sec, 0, 61))) // if (tm->tm_hour > 11)
return (0); // return (0);
break;
// bp += strlen(am_pm[0]);
case 'U': /* The week of year, beginning on sunday. */ // break;
case 'W': /* The week of year, beginning on monday. */ // }
LEGAL_ALT(ALT_O); // /* PM? */
/* // else if (strcmp(am_pm[1], bp) == 0) {
* XXX This is bogus, as we can not assume any valid // if (tm->tm_hour > 11)
* information present in the tm structure at this // return (0);
* point to calculate a real value, so just check the
* range for now. // tm->tm_hour += 12;
*/ // bp += strlen(am_pm[1]);
if (!(conv_num(&bp, &i, 0, 53))) // break;
return (0); // }
break;
// /* Nothing matched. */
case 'w': /* The day of week, beginning on sunday. */ // return (0);
LEGAL_ALT(ALT_O);
if (!(conv_num(&bp, &tm->tm_wday, 0, 6))) // case 'S': /* The seconds. */
return (0); // LEGAL_ALT(ALT_O);
break; // if (!(conv_num(&bp, &tm->tm_sec, 0, 61)))
// return (0);
case 'Y': /* The year. */ // break;
LEGAL_ALT(ALT_E);
if (!(conv_num(&bp, &i, 0, 9999))) // case 'U': /* The week of year, beginning on sunday. */
return (0); // case 'W': /* The week of year, beginning on monday. */
// LEGAL_ALT(ALT_O);
tm->tm_year = i - TM_YEAR_BASE; // /*
break; // * XXX This is bogus, as we can not assume any valid
// * information present in the tm structure at this
case 'y': /* The year within 100 years of the epoch. */ // * point to calculate a real value, so just check the
LEGAL_ALT(ALT_E | ALT_O); // * range for now.
if (!(conv_num(&bp, &i, 0, 99))) // */
return (0); // if (!(conv_num(&bp, &i, 0, 53)))
// return (0);
if (split_year) { // break;
tm->tm_year = ((tm->tm_year / 100) * 100) + i;
break; // case 'w': /* The day of week, beginning on sunday. */
} // LEGAL_ALT(ALT_O);
split_year = 1; // if (!(conv_num(&bp, &tm->tm_wday, 0, 6)))
if (i <= 68) // return (0);
tm->tm_year = i + 2000 - TM_YEAR_BASE; // break;
else
tm->tm_year = i + 1900 - TM_YEAR_BASE; // case 'Y': /* The year. */
break; // LEGAL_ALT(ALT_E);
// if (!(conv_num(&bp, &i, 0, 9999)))
/* // return (0);
* Miscellaneous conversions.
*/ // tm->tm_year = i - TM_YEAR_BASE;
case 'n': /* Any kind of white-space. */ // break;
case 't':
LEGAL_ALT(0); // case 'y': /* The year within 100 years of the epoch. */
while (isspace(*bp)) // LEGAL_ALT(ALT_E | ALT_O);
bp++; // if (!(conv_num(&bp, &i, 0, 99)))
break; // return (0);
// if (split_year) {
default: /* Unknown/unsupported conversion. */ // tm->tm_year = ((tm->tm_year / 100) * 100) + i;
return (0); // break;
} // }
// split_year = 1;
// if (i <= 68)
} // tm->tm_year = i + 2000 - TM_YEAR_BASE;
// else
/* LINTED functional specification */ // tm->tm_year = i + 1900 - TM_YEAR_BASE;
return ((char *)bp); // break;
}
// /*
// * Miscellaneous conversions.
static int // */
conv_num(const char **buf, int *dest, int llim, int ulim) // case 'n': /* Any kind of white-space. */
{ // case 't':
int result = 0; // LEGAL_ALT(0);
// while (isspace(*bp))
/* The limit also determines the number of valid digits. */ // bp++;
int rulim = ulim; // break;
if (**buf < '0' || **buf > '9')
return (0); // default: /* Unknown/unsupported conversion. */
// return (0);
do { // }
result *= 10;
result += *(*buf)++ - '0';
rulim /= 10; // }
} while ((result * 10 <= ulim) && rulim && **buf >= '0' && **buf <= '9');
// /* LINTED functional specification */
if (result < llim || result > ulim) // return ((char *)bp);
return (0); // #elif defined(_TD_DARWIN_64)
// return strptime(buf, fmt, tm);
*dest = result; // #else
return (1); // return strptime(buf, fmt, tm);
} // #endif
// }
#endif
\ No newline at end of file
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#define ALLOW_FORBID_FUNC
#define _BSD_SOURCE #define _BSD_SOURCE
#ifdef DARWIN #ifdef DARWIN
...@@ -26,16 +27,373 @@ ...@@ -26,16 +27,373 @@
#include "os.h" #include "os.h"
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
/*
* windows implementation
*/
#include <time.h> #include <time.h>
#include <stdlib.h>
#include <string.h>
#include <winsock2.h> #include <winsock2.h>
//#define TM_YEAR_BASE 1970 //origin
#define TM_YEAR_BASE 1900 //slguan
/*
* We do not implement alternate representations. However, we always
* check whether a given modifier is allowed for a certain conversion.
*/
#define ALT_E 0x01
#define ALT_O 0x02
#define LEGAL_ALT(x) { if (alt_format & ~(x)) return (0); }
static int conv_num(const char **buf, int *dest, int llim, int ulim)
{
int result = 0;
/* The limit also determines the number of valid digits. */
int rulim = ulim;
if (**buf < '0' || **buf > '9')
return (0);
do {
result *= 10;
result += *(*buf)++ - '0';
rulim /= 10;
} while ((result * 10 <= ulim) && rulim && **buf >= '0' && **buf <= '9');
if (result < llim || result > ulim)
return (0);
*dest = result;
return (1);
}
static const char *day[7] = {
"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday",
"Friday", "Saturday"
};
static const char *abday[7] = {
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
};
static const char *mon[12] = {
"January", "February", "March", "April", "May", "June", "July",
"August", "September", "October", "November", "December"
};
static const char *abmon[12] = {
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
};
static const char *am_pm[2] = {
"AM", "PM"
};
#else
#include <sys/time.h>
#endif
char *taosStrpTime(const char *buf, const char *fmt, struct tm *tm) {
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
char c;
const char *bp;
size_t len = 0;
int alt_format, i, split_year = 0;
bp = buf;
while ((c = *fmt) != '\0') {
/* Clear `alternate' modifier prior to new conversion. */
alt_format = 0;
/* Eat up white-space. */
if (isspace(c)) {
while (isspace(*bp))
bp++;
fmt++;
continue;
}
if ((c = *fmt++) != '%')
goto literal;
again: switch (c = *fmt++) {
case '%': /* "%%" is converted to "%". */
literal :
if (c != *bp++)
return (0);
break;
/*
* "Alternative" modifiers. Just set the appropriate flag
* and start over again.
*/
case 'E': /* "%E?" alternative conversion modifier. */
LEGAL_ALT(0);
alt_format |= ALT_E;
goto again;
case 'O': /* "%O?" alternative conversion modifier. */
LEGAL_ALT(0);
alt_format |= ALT_O;
goto again;
/*
* "Complex" conversion rules, implemented through recursion.
*/
case 'c': /* Date and time, using the locale's format. */
LEGAL_ALT(ALT_E);
if (!(bp = taosStrpTime(bp, "%x %X", tm)))
return (0);
break;
case 'D': /* The date as "%m/%d/%y". */
LEGAL_ALT(0);
if (!(bp = taosStrpTime(bp, "%m/%d/%y", tm)))
return (0);
break;
case 'R': /* The time as "%H:%M". */
LEGAL_ALT(0);
if (!(bp = taosStrpTime(bp, "%H:%M", tm)))
return (0);
break;
case 'r': /* The time in 12-hour clock representation. */
LEGAL_ALT(0);
if (!(bp = taosStrpTime(bp, "%I:%M:%S %p", tm)))
return (0);
break;
case 'T': /* The time as "%H:%M:%S". */
LEGAL_ALT(0);
if (!(bp = taosStrpTime(bp, "%H:%M:%S", tm)))
return (0);
break;
case 'X': /* The time, using the locale's format. */
LEGAL_ALT(ALT_E);
if (!(bp = taosStrpTime(bp, "%H:%M:%S", tm)))
return (0);
break;
case 'x': /* The date, using the locale's format. */
LEGAL_ALT(ALT_E);
if (!(bp = taosStrpTime(bp, "%m/%d/%y", tm)))
return (0);
break;
/*
* "Elementary" conversion rules.
*/
case 'A': /* The day of week, using the locale's form. */
case 'a':
LEGAL_ALT(0);
for (i = 0; i < 7; i++) {
/* Full name. */
len = strlen(day[i]);
if (strncmp(day[i], bp, len) == 0)
break;
/* Abbreviated name. */
len = strlen(abday[i]);
if (strncmp(abday[i], bp, len) == 0)
break;
}
/* Nothing matched. */
if (i == 7)
return (0);
tm->tm_wday = i;
bp += len;
break;
case 'B': /* The month, using the locale's form. */
case 'b':
case 'h':
LEGAL_ALT(0);
for (i = 0; i < 12; i++) {
/* Full name. */
len = strlen(mon[i]);
if (strncmp(mon[i], bp, len) == 0)
break;
/* Abbreviated name. */
len = strlen(abmon[i]);
if (strncmp(abmon[i], bp, len) == 0)
break;
}
/* Nothing matched. */
if (i == 12)
return (0);
tm->tm_mon = i;
bp += len;
break;
case 'C': /* The century number. */
LEGAL_ALT(ALT_E);
if (!(conv_num(&bp, &i, 0, 99)))
return (0);
if (split_year) {
tm->tm_year = (tm->tm_year % 100) + (i * 100);
}
else {
tm->tm_year = i * 100;
split_year = 1;
}
break;
case 'd': /* The day of month. */
case 'e':
LEGAL_ALT(ALT_O);
if (!(conv_num(&bp, &tm->tm_mday, 1, 31)))
return (0);
break;
int taosGetTimeOfDay(struct timeval *tv, struct timezone *tz) { case 'k': /* The hour (24-hour clock representation). */
LEGAL_ALT(0);
/* FALLTHROUGH */
case 'H':
LEGAL_ALT(ALT_O);
if (!(conv_num(&bp, &tm->tm_hour, 0, 23)))
return (0);
break;
case 'l': /* The hour (12-hour clock representation). */
LEGAL_ALT(0);
/* FALLTHROUGH */
case 'I':
LEGAL_ALT(ALT_O);
if (!(conv_num(&bp, &tm->tm_hour, 1, 12)))
return (0);
if (tm->tm_hour == 12)
tm->tm_hour = 0;
break;
case 'j': /* The day of year. */
LEGAL_ALT(0);
if (!(conv_num(&bp, &i, 1, 366)))
return (0);
tm->tm_yday = i - 1;
break;
case 'M': /* The minute. */
LEGAL_ALT(ALT_O);
if (!(conv_num(&bp, &tm->tm_min, 0, 59)))
return (0);
break;
case 'm': /* The month. */
LEGAL_ALT(ALT_O);
if (!(conv_num(&bp, &i, 1, 12)))
return (0);
tm->tm_mon = i - 1;
break;
case 'p': /* The locale's equivalent of AM/PM. */
LEGAL_ALT(0);
/* AM? */
if (strcmp(am_pm[0], bp) == 0) {
if (tm->tm_hour > 11)
return (0);
bp += strlen(am_pm[0]);
break;
}
/* PM? */
else if (strcmp(am_pm[1], bp) == 0) {
if (tm->tm_hour > 11)
return (0);
tm->tm_hour += 12;
bp += strlen(am_pm[1]);
break;
}
/* Nothing matched. */
return (0);
case 'S': /* The seconds. */
LEGAL_ALT(ALT_O);
if (!(conv_num(&bp, &tm->tm_sec, 0, 61)))
return (0);
break;
case 'U': /* The week of year, beginning on sunday. */
case 'W': /* The week of year, beginning on monday. */
LEGAL_ALT(ALT_O);
/*
* XXX This is bogus, as we can not assume any valid
* information present in the tm structure at this
* point to calculate a real value, so just check the
* range for now.
*/
if (!(conv_num(&bp, &i, 0, 53)))
return (0);
break;
case 'w': /* The day of week, beginning on sunday. */
LEGAL_ALT(ALT_O);
if (!(conv_num(&bp, &tm->tm_wday, 0, 6)))
return (0);
break;
case 'Y': /* The year. */
LEGAL_ALT(ALT_E);
if (!(conv_num(&bp, &i, 0, 9999)))
return (0);
tm->tm_year = i - TM_YEAR_BASE;
break;
case 'y': /* The year within 100 years of the epoch. */
LEGAL_ALT(ALT_E | ALT_O);
if (!(conv_num(&bp, &i, 0, 99)))
return (0);
if (split_year) {
tm->tm_year = ((tm->tm_year / 100) * 100) + i;
break;
}
split_year = 1;
if (i <= 68)
tm->tm_year = i + 2000 - TM_YEAR_BASE;
else
tm->tm_year = i + 1900 - TM_YEAR_BASE;
break;
/*
* Miscellaneous conversions.
*/
case 'n': /* Any kind of white-space. */
case 't':
LEGAL_ALT(0);
while (isspace(*bp))
bp++;
break;
default: /* Unknown/unsupported conversion. */
return (0);
}
}
/* LINTED functional specification */
return ((char *)bp);
#else
return strptime(buf, fmt, tm);
#endif
}
FORCE_INLINE int32_t taosGetTimeOfDay(struct timeval *tv) {
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
time_t t; time_t t;
t = time(NULL); t = taosGetTimestampSec();
SYSTEMTIME st; SYSTEMTIME st;
GetLocalTime(&st); GetLocalTime(&st);
...@@ -43,26 +401,18 @@ int taosGetTimeOfDay(struct timeval *tv, struct timezone *tz) { ...@@ -43,26 +401,18 @@ int taosGetTimeOfDay(struct timeval *tv, struct timezone *tz) {
tv->tv_usec = st.wMilliseconds * 1000; tv->tv_usec = st.wMilliseconds * 1000;
return 0; return 0;
#else
return gettimeofday(tv, NULL);
#endif
} }
struct tm *localtime_r(const time_t *timep, struct tm *result) { struct tm *taosLocalTime(const time_t *timep, struct tm *result) {
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
localtime_s(result, timep); localtime_s(result, timep);
return result;
}
#else #else
localtime_r(timep, result);
/* #endif
* linux and darwin implementation return result;
*/
#include <sys/time.h>
// #include "monotonic.h"
FORCE_INLINE int32_t taosGetTimeOfDay(struct timeval *tv) {
return gettimeofday(tv, NULL);
} }
int32_t taosGetTimestampSec() { return (int32_t)time(NULL); } int32_t taosGetTimestampSec() { return (int32_t)time(NULL); }
#endif
...@@ -128,9 +128,9 @@ void taosGetSystemTimezone(char *outTimezone) { ...@@ -128,9 +128,9 @@ void taosGetSystemTimezone(char *outTimezone) {
* Enforce set the correct daylight saving time(DST) flag according * Enforce set the correct daylight saving time(DST) flag according
* to current time * to current time
*/ */
time_t tx1 = time(NULL); time_t tx1 = taosGetTimestampSec();
struct tm tm1; struct tm tm1;
localtime_r(&tx1, &tm1); taosLocalTime(&tx1, &tm1);
/* /*
* format example: * format example:
...@@ -147,9 +147,9 @@ void taosGetSystemTimezone(char *outTimezone) { ...@@ -147,9 +147,9 @@ void taosGetSystemTimezone(char *outTimezone) {
* Enforce set the correct daylight saving time(DST) flag according * Enforce set the correct daylight saving time(DST) flag according
* to current time * to current time
*/ */
time_t tx1 = time(NULL); time_t tx1 = taosGetTimestampSec();
struct tm tm1; struct tm tm1;
localtime_r(&tx1, &tm1); taosLocalTime(&tx1, &tm1);
/* load time zone string from /etc/timezone */ /* load time zone string from /etc/timezone */
// FILE *f = fopen("/etc/timezone", "r"); // FILE *f = fopen("/etc/timezone", "r");
......
...@@ -31,7 +31,7 @@ void process_message(uint8_t* message_piece, uint8_t* processed_piece, key_set* ...@@ -31,7 +31,7 @@ void process_message(uint8_t* message_piece, uint8_t* processed_piece, key_set*
#if 0 #if 0
int64_t taosDesGenKey() { int64_t taosDesGenKey() {
uint32_t iseed = (uint32_t)time(NULL); uint32_t iseed = (uint32_t)taosGetTimestampSec();
taosSeedRand(iseed); taosSeedRand(iseed);
uint8_t key[8] = {0}; uint8_t key[8] = {0};
......
...@@ -401,7 +401,7 @@ static inline int32_t taosBuildLogHead(char *buffer, const char *flags) { ...@@ -401,7 +401,7 @@ static inline int32_t taosBuildLogHead(char *buffer, const char *flags) {
taosGetTimeOfDay(&timeSecs); taosGetTimeOfDay(&timeSecs);
time_t curTime = timeSecs.tv_sec; time_t curTime = timeSecs.tv_sec;
ptm = localtime_r(&curTime, &Tm); ptm = taosLocalTime(&curTime, &Tm);
return sprintf(buffer, "%02d/%02d %02d:%02d:%02d.%06d %08" PRId64 " %s", ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, return sprintf(buffer, "%02d/%02d %02d:%02d:%02d.%06d %08" PRId64 " %s", ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour,
ptm->tm_min, ptm->tm_sec, (int32_t)timeSecs.tv_usec, taosGetSelfPthreadId(), flags); ptm->tm_min, ptm->tm_sec, (int32_t)timeSecs.tv_usec, taosGetSelfPthreadId(), flags);
......
...@@ -82,7 +82,7 @@ SSkipList *tSkipListCreate(uint8_t maxLevel, uint8_t keyType, uint16_t keyLen, _ ...@@ -82,7 +82,7 @@ SSkipList *tSkipListCreate(uint8_t maxLevel, uint8_t keyType, uint16_t keyLen, _
} }
} }
taosSeedRand((uint32_t)time(NULL)); taosSeedRand((uint32_t)taosGetTimestampSec());
#if SKIP_LIST_RECORD_PERFORMANCE #if SKIP_LIST_RECORD_PERFORMANCE
pSkipList->state.nTotalMemSize += sizeof(SSkipList); pSkipList->state.nTotalMemSize += sizeof(SSkipList);
......
...@@ -150,7 +150,7 @@ static bool test_variant_int64(int64_t value) { ...@@ -150,7 +150,7 @@ static bool test_variant_int64(int64_t value) {
} }
TEST(codingTest, fixed_encode_decode) { TEST(codingTest, fixed_encode_decode) {
taosSeedRand(time(0)); taosSeedRand(taosGetTimestampSec());
// uint16_t // uint16_t
for (uint16_t value = 0; value <= UINT16_MAX; value++) { for (uint16_t value = 0; value <= UINT16_MAX; value++) {
...@@ -204,7 +204,7 @@ TEST(codingTest, fixed_encode_decode) { ...@@ -204,7 +204,7 @@ TEST(codingTest, fixed_encode_decode) {
} }
TEST(codingTest, variant_encode_decode) { TEST(codingTest, variant_encode_decode) {
taosSeedRand(time(0)); taosSeedRand(taosGetTimestampSec());
// uint16_t // uint16_t
for (uint16_t value = 0; value <= UINT16_MAX; value++) { for (uint16_t value = 0; value <= UINT16_MAX; value++) {
......
...@@ -161,7 +161,7 @@ void recyclePageTest() { ...@@ -161,7 +161,7 @@ void recyclePageTest() {
TEST(testCase, resultBufferTest) { TEST(testCase, resultBufferTest) {
taosSeedRand(time(NULL)); taosSeedRand(taosGetTimestampSec());
simpleTest(); simpleTest();
writeDownTest(); writeDownTest();
recyclePageTest(); recyclePageTest();
......
...@@ -74,7 +74,7 @@ void randKeyTest() { ...@@ -74,7 +74,7 @@ void randKeyTest() {
false, getkey); false, getkey);
int32_t size = 200000; int32_t size = 200000;
taosSeedRand(time(NULL)); taosSeedRand(taosGetTimestampSec());
printf("generated %d keys is: \n", size); printf("generated %d keys is: \n", size);
...@@ -337,7 +337,7 @@ void duplicatedKeyTest() { ...@@ -337,7 +337,7 @@ void duplicatedKeyTest() {
TEST(testCase, skiplist_test) { TEST(testCase, skiplist_test) {
assert(sizeof(SSkipListKey) == 8); assert(sizeof(SSkipListKey) == 8);
taosSeedRand(time(NULL)); taosSeedRand(taosGetTimestampSec());
stringKeySkiplistTest(); stringKeySkiplistTest();
doubleSkipListTest(); doubleSkipListTest();
......
...@@ -18,7 +18,7 @@ void taosMsleep(int mseconds); ...@@ -18,7 +18,7 @@ void taosMsleep(int mseconds);
unsigned long long getCurrentTime(){ unsigned long long getCurrentTime(){
struct timeval tv; struct timeval tv;
if (gettimeofday(&tv, NULL) != 0) { if (taosGetTimeOfDay(&tv) != 0) {
perror("Failed to get current time in ms"); perror("Failed to get current time in ms");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
......
...@@ -42,7 +42,7 @@ int g_runTimes = 5; ...@@ -42,7 +42,7 @@ int g_runTimes = 5;
unsigned long long getCurrentTime(){ unsigned long long getCurrentTime(){
struct timeval tv; struct timeval tv;
if (gettimeofday(&tv, NULL) != 0) { if (taosGetTimeOfDay(&tv) != 0) {
perror("Failed to get current time in ms"); perror("Failed to get current time in ms");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
......
...@@ -609,7 +609,7 @@ void printParaIntoFile() { ...@@ -609,7 +609,7 @@ void printParaIntoFile() {
}; };
g_fp = pFile; g_fp = pFile;
time_t tTime = time(NULL); time_t tTime = taosGetTimestampSec();
struct tm tm = *localtime(&tTime); struct tm tm = *localtime(&tTime);
taosFprintfFile(pFile, "###################################################################\n"); taosFprintfFile(pFile, "###################################################################\n");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册