feat: taos shell websocket support network/execute/total timing info (#15630)

* feat: taos shell websocket support network/execute/toal timing info

* chore: update taosws-rs

* feat: update taosws 24b199e

* fix: git clean in jenkinsfile2

Co-authored-by: Shuduo Sang <sangshuduo@gmail.com>
This commit is contained in:
Yang Zhao 2022-08-02 11:09:34 +08:00 committed by GitHub
parent 5f3432cfc4
commit e5bb1fe787
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 13 deletions

View File

@ -40,6 +40,7 @@ def pre_test(){
git reset --hard git reset --hard
cd ${WKC} cd ${WKC}
git reset --hard git reset --hard
git clean -fxd
''' '''
script { script {
if (env.CHANGE_TARGET == 'master') { if (env.CHANGE_TARGET == 'master') {

View File

@ -2,7 +2,7 @@
# taosws-rs # taosws-rs
ExternalProject_Add(taosws-rs ExternalProject_Add(taosws-rs
GIT_REPOSITORY https://github.com/taosdata/taosws-rs.git GIT_REPOSITORY https://github.com/taosdata/taosws-rs.git
GIT_TAG 9de599d GIT_TAG 24b199e
SOURCE_DIR "${TD_SOURCE_DIR}/tools/taosws-rs" SOURCE_DIR "${TD_SOURCE_DIR}/tools/taosws-rs"
BINARY_DIR "" BINARY_DIR ""
#BUILD_IN_SOURCE TRUE #BUILD_IN_SOURCE TRUE

View File

@ -33,10 +33,11 @@ int shell_conn_ws_server(bool first) {
return 0; return 0;
} }
static int horizontalPrintWebsocket(WS_RES* wres) { static int horizontalPrintWebsocket(WS_RES* wres, double* execute_time) {
const void* data = NULL; const void* data = NULL;
int rows; int rows;
ws_fetch_block(wres, &data, &rows); ws_fetch_block(wres, &data, &rows);
*execute_time += (double)(ws_take_timing(wres)/1E6);
if (!rows) { if (!rows) {
return 0; return 0;
} }
@ -72,10 +73,11 @@ static int horizontalPrintWebsocket(WS_RES* wres) {
return numOfRows; return numOfRows;
} }
static int verticalPrintWebsocket(WS_RES* wres) { static int verticalPrintWebsocket(WS_RES* wres, double* pexecute_time) {
int rows = 0; int rows = 0;
const void* data = NULL; const void* data = NULL;
ws_fetch_block(wres, &data, &rows); ws_fetch_block(wres, &data, &rows);
*pexecute_time += (double)(ws_take_timing(wres)/1E6);
if (!rows) { if (!rows) {
return 0; return 0;
} }
@ -112,7 +114,7 @@ static int verticalPrintWebsocket(WS_RES* wres) {
return numOfRows; return numOfRows;
} }
static int dumpWebsocketToFile(const char* fname, WS_RES* wres) { static int dumpWebsocketToFile(const char* fname, WS_RES* wres, double* pexecute_time) {
char fullname[PATH_MAX] = {0}; char fullname[PATH_MAX] = {0};
if (taosExpandDir(fname, fullname, PATH_MAX) != 0) { if (taosExpandDir(fname, fullname, PATH_MAX) != 0) {
tstrncpy(fullname, fname, PATH_MAX); tstrncpy(fullname, fname, PATH_MAX);
@ -127,6 +129,7 @@ static int dumpWebsocketToFile(const char* fname, WS_RES* wres) {
int rows = 0; int rows = 0;
const void* data = NULL; const void* data = NULL;
ws_fetch_block(wres, &data, &rows); ws_fetch_block(wres, &data, &rows);
*pexecute_time += (double)(ws_take_timing(wres)/1E6);
if (!rows) { if (!rows) {
taosCloseFile(&pFile); taosCloseFile(&pFile);
return 0; return 0;
@ -162,14 +165,14 @@ static int dumpWebsocketToFile(const char* fname, WS_RES* wres) {
return numOfRows; return numOfRows;
} }
static int shellDumpWebsocket(WS_RES *wres, char *fname, int *error_no, bool vertical) { static int shellDumpWebsocket(WS_RES *wres, char *fname, int *error_no, bool vertical, double* pexecute_time) {
int numOfRows = 0; int numOfRows = 0;
if (fname != NULL) { if (fname != NULL) {
numOfRows = dumpWebsocketToFile(fname, wres); numOfRows = dumpWebsocketToFile(fname, wres, pexecute_time);
} else if (vertical) { } else if (vertical) {
numOfRows = verticalPrintWebsocket(wres); numOfRows = verticalPrintWebsocket(wres, pexecute_time);
} else { } else {
numOfRows = horizontalPrintWebsocket(wres); numOfRows = horizontalPrintWebsocket(wres, pexecute_time);
} }
*error_no = ws_errno(wres); *error_no = ws_errno(wres);
return numOfRows; return numOfRows;
@ -225,6 +228,8 @@ void shellRunSingleCommandWebsocketImp(char *command) {
return; return;
} }
double execute_time = ws_take_timing(res)/1E6;
if (shellRegexMatch(command, "^\\s*use\\s+[a-zA-Z0-9_]+\\s*;\\s*$", REG_EXTENDED | REG_ICASE)) { if (shellRegexMatch(command, "^\\s*use\\s+[a-zA-Z0-9_]+\\s*;\\s*$", REG_EXTENDED | REG_ICASE)) {
fprintf(stdout, "Database changed.\r\n\r\n"); fprintf(stdout, "Database changed.\r\n\r\n");
fflush(stdout); fflush(stdout);
@ -236,22 +241,27 @@ void shellRunSingleCommandWebsocketImp(char *command) {
if (ws_is_update_query(res)) { if (ws_is_update_query(res)) {
numOfRows = ws_affected_rows(res); numOfRows = ws_affected_rows(res);
et = taosGetTimestampUs(); et = taosGetTimestampUs();
printf("Query Ok, %d of %d row(s) in database (%.6fs)\n", numOfRows, numOfRows, double total_time = (et - st)/1E3;
(et - st)/1E6); double net_time = total_time - (double)execute_time;
printf("Query Ok, %d of %d row(s) in database\n", numOfRows, numOfRows);
printf("Execute: %.2f ms Network: %.2f ms Total: %.2f ms\n", execute_time, net_time, total_time);
} else { } else {
int error_no = 0; int error_no = 0;
numOfRows = shellDumpWebsocket(res, fname, &error_no, printMode); numOfRows = shellDumpWebsocket(res, fname, &error_no, printMode, &execute_time);
if (numOfRows < 0) { if (numOfRows < 0) {
ws_free_result(res); ws_free_result(res);
return; return;
} }
et = taosGetTimestampUs(); et = taosGetTimestampUs();
double total_time = (et - st) / 1E3;
double net_time = total_time - execute_time;
if (error_no == 0 && !shell.stop_query) { if (error_no == 0 && !shell.stop_query) {
printf("Query OK, %d row(s) in set (%.6fs)\n", numOfRows, printf("Query OK, %d row(s) in set\n", numOfRows);
(et - st)/1E6); printf("Execute: %.2f ms Network: %.2f ms Total: %.2f ms\n", execute_time, net_time, total_time);
} else { } else {
printf("Query interrupted, %d row(s) in set (%.6fs)\n", numOfRows, printf("Query interrupted, %d row(s) in set (%.6fs)\n", numOfRows,
(et - st)/1E6); (et - st)/1E6);
printf("Execute: %.2f ms Network: %.2f ms Total: %.2f ms\n", execute_time, net_time, total_time);
} }
} }
printf("\n"); printf("\n");