From 5e77d162aad35f6f660a9fe236c7329bb4177ac0 Mon Sep 17 00:00:00 2001 From: Shuduo Sang Date: Thu, 25 Mar 2021 19:02:50 +0800 Subject: [PATCH] [TD-3402] : taosdemo version. (#5574) feature completed. Co-authored-by: Shuduo Sang --- src/kit/taosdemo/CMakeLists.txt | 47 +++++++++++++++++++++++++++++++++ src/kit/taosdemo/taosdemo.c | 46 +++++++++++++++++++++++++++----- 2 files changed, 87 insertions(+), 6 deletions(-) diff --git a/src/kit/taosdemo/CMakeLists.txt b/src/kit/taosdemo/CMakeLists.txt index a75157b94c..79a520b1b7 100644 --- a/src/kit/taosdemo/CMakeLists.txt +++ b/src/kit/taosdemo/CMakeLists.txt @@ -3,6 +3,53 @@ PROJECT(TDengine) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/client/inc) +FIND_PACKAGE(Git) +IF (GIT_FOUND) + MESSAGE("Git found") + EXECUTE_PROCESS( + COMMAND ${GIT_EXECUTABLE} log --pretty=oneline -n 1 ../src/kit/taosdemo/taosdemo.c + RESULT_VARIABLE RESULT + OUTPUT_VARIABLE TAOSDEMO_COMMIT) + EXECUTE_PROCESS( + COMMAND bash "-c" "echo '${TAOSDEMO_COMMIT}' | awk '{print $1}' | cut -c -9" + RESULT_VARIABLE RESULT + OUTPUT_VARIABLE TAOSDEMO_COMMIT_SHA1) + EXECUTE_PROCESS( + COMMAND ${GIT_EXECUTABLE} status -z -s ../src/kit/taosdemo/taosdemo.c + RESULT_VARIABLE RESULT + OUTPUT_VARIABLE TAOSDEMO_STATUS) + EXECUTE_PROCESS( + COMMAND bash "-c" "echo '${TAOSDEMO_STATUS}' | awk '{print $1}'" + RESULT_VARIABLE RESULT + OUTPUT_VARIABLE TAOSDEMO_STATUS) + MESSAGE("taosdemo.c status: " ${TAOSDEMO_STATUS}) +ELSE() + MESSAGE("Git not found") + SET(TAOSDEMO_COMMIT_SHA1 "unknown") + SET(TAOSDEMO_STATUS "unknown") +ENDIF (GIT_FOUND) + +STRING(STRIP ${TAOSDEMO_COMMIT_SHA1} TAOSDEMO_COMMIT_SHA1) +MESSAGE("taosdemo's latest commit in short is:" ${TAOSDEMO_COMMIT_SHA1}) +STRING(STRIP ${TAOSDEMO_STATUS} TAOSDEMO_STATUS) + +IF (TAOSDEMO_STATUS MATCHES "M") + SET(TAOSDEMO_STATUS "modified") +ELSE() + SET(TAOSDEMO_STATUS "") +ENDIF () +MESSAGE("taosdemo's status is:" ${TAOSDEMO_STATUS}) + +ADD_DEFINITIONS(-DTAOSDEMO_COMMIT_SHA1="${TAOSDEMO_COMMIT_SHA1}") +ADD_DEFINITIONS(-DTAOSDEMO_STATUS="${TAOSDEMO_STATUS}") + +MESSAGE("VERNUMBER is:" ${VERNUMBER}) +IF (VERNUMBER MATCHES "") + ADD_DEFINITIONS(-DTD_VERNUMBER="TDengie-version-unknown") +ELSE() + ADD_DEFINITIONS(-DTD_VERNUMBER="${VERNUMBER}") +ENDIF () + IF (TD_LINUX) AUX_SOURCE_DIRECTORY(. SRC) ADD_EXECUTABLE(taosdemo ${SRC}) diff --git a/src/kit/taosdemo/taosdemo.c b/src/kit/taosdemo/taosdemo.c index 7aad2b4b52..ebb7fba786 100644 --- a/src/kit/taosdemo/taosdemo.c +++ b/src/kit/taosdemo/taosdemo.c @@ -94,6 +94,7 @@ enum TEST_MODE { #define DEFAULT_TIMESTAMP_STEP 1 + typedef enum CREATE_SUB_TALBE_MOD_EN { PRE_CREATE_SUBTBL, AUTO_CREATE_SUBTBL, @@ -590,6 +591,32 @@ static FILE * g_fpOfInsertResult = NULL; static void ERROR_EXIT(const char *msg) { perror(msg); exit(-1); } +#ifndef TAOSDEMO_COMMIT_SHA1 +#define TAOSDEMO_COMMIT_SHA1 "unknown" +#endif + +#ifndef TD_VERNUMBER +#define TD_VERNUMBER "unknown" +#endif + +#ifndef TAOSDEMO_STATUS +#define TAOSDEMO_STATUS "unknown" +#endif + +static void printVersion() { + char tdengine_ver[] = TD_VERNUMBER; + char taosdemo_ver[] = TAOSDEMO_COMMIT_SHA1; + char taosdemo_status[] = TAOSDEMO_STATUS; + + if (strlen(taosdemo_status) == 0) { + printf("taosdemo verison %s-%s\n", + tdengine_ver, taosdemo_ver); + } else { + printf("taosdemo verison %s-%s, status:%s\n", + tdengine_ver, taosdemo_ver, taosdemo_status); + } +} + static void printHelp() { char indent[10] = " "; printf("%s%s%s%s\n", indent, "-f", indent, @@ -647,6 +674,8 @@ static void printHelp() { "Out of order data's range, ms, default is 1000."); printf("%s%s%s%s\n", indent, "-g", indent, "Print debug info."); + printf("%s%s%s%s\n", indent, "-V, --version", indent, + "Print version info."); /* printf("%s%s%s%s\n", indent, "-D", indent, "if elete database if exists. 0: no, 1: yes, default is 1"); */ @@ -788,6 +817,10 @@ static void parse_args(int argc, char *argv[], SArguments *arguments) { || arguments->method_of_delete > 3) { arguments->method_of_delete = 0; } + } else if ((strcmp(argv[i], "--version") == 0) || + (strcmp(argv[i], "-V") == 0)){ + printVersion(); + exit(0); } else if (strcmp(argv[i], "--help") == 0) { printHelp(); exit(0); @@ -4876,7 +4909,7 @@ static void *asyncWrite(void *sarg) { winfo->et = 0; winfo->lastTs = winfo->start_time; - int insert_interval = + int insert_interval = superTblInfo?superTblInfo->insertInterval:g_args.insert_interval; if (insert_interval) { winfo->st = taosGetTimestampUs(); @@ -4946,7 +4979,7 @@ static void startMultiThreadInsertData(int threads, char* db_name, } } - int64_t start_time; + int64_t start_time; if (superTblInfo) { if (0 == strncasecmp(superTblInfo->startTimestamp, "now", 3)) { start_time = taosGetTimestamp(timePrec); @@ -4973,7 +5006,7 @@ static void startMultiThreadInsertData(int threads, char* db_name, startFrom = 0; // read sample data from file first - if ((superTblInfo) && (0 == strncasecmp(superTblInfo->dataSource, + if ((superTblInfo) && (0 == strncasecmp(superTblInfo->dataSource, "sample", strlen("sample")))) { if (0 != prepareSampleDataForSTable(superTblInfo)) { errorPrint("%s() LN%d, prepare sample data for stable failed!\n", __func__, __LINE__); @@ -4982,7 +5015,7 @@ static void startMultiThreadInsertData(int threads, char* db_name, } // read sample data from file first - if ((superTblInfo) && (0 == strncasecmp(superTblInfo->dataSource, + if ((superTblInfo) && (0 == strncasecmp(superTblInfo->dataSource, "sample", strlen("sample")))) { if (0 != prepareSampleDataForSTable(superTblInfo)) { errorPrint("%s() LN%d, prepare sample data for stable failed!\n", __func__, __LINE__); @@ -5144,7 +5177,7 @@ static void startMultiThreadInsertData(int threads, char* db_name, avgDelay/1000.0, (double)maxDelay/1000.0, (double)minDelay/1000.0); fprintf(g_fpOfInsertResult, "insert delay, avg:%10.6fms, max: %10.6fms, min: %10.6fms\n\n", avgDelay/1000.0, (double)maxDelay/1000.0, (double)minDelay/1000.0); - + //taos_close(taos); free(pids); @@ -5187,7 +5220,8 @@ static void *readTable(void *sarg) { double totalT = 0; int count = 0; for (int i = 0; i < num_of_tables; i++) { - sprintf(command, "select %s from %s%d where ts>= %" PRId64, aggreFunc[j], tb_prefix, i, sTime); + sprintf(command, "select %s from %s%d where ts>= %" PRId64, + aggreFunc[j], tb_prefix, i, sTime); double t = getCurrentTime(); TAOS_RES *pSql = taos_query(taos, command); -- GitLab