Changeset: 2671925a6153 for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=2671925a6153 Added Files: clients/R/MonetDB.R/src/mapisplit-r.c clients/R/MonetDB.R/src/mapisplit.h clients/R/MonetDB.R/src/profiler-r.c clients/R/MonetDB.R/src/profiler.h Modified Files: clients/R/MonetDB.R/R/dbi.R clients/R/MonetDB.R/src/mapisplit.c clients/R/MonetDB.R/src/profiler.c clients/mapiclient/Makefile.ag sql/scripts/16_tracelog.sql Branch: default Log Message:
Merge with default diffs (truncated from 454 to 300 lines): diff --git a/clients/R/MonetDB.R/R/dbi.R b/clients/R/MonetDB.R/R/dbi.R --- a/clients/R/MonetDB.R/R/dbi.R +++ b/clients/R/MonetDB.R/R/dbi.R @@ -126,12 +126,8 @@ setMethod("dbConnect", "MonetDBDriver", dbSendQuery(conn, "set optimizer='sequential_pipe'") } - # enable profiler, we use a MAL connection for this if (getOption("monetdb.profile", T)) { - msocket <- .mapiConnect(host, port, timeout) - .mapiAuthenticate(msocket, dbname, user, password, language="mal") - .profiler_enable(msocket) - .mapiDisconnect(msocket); + .profiler_enable(conn) } return(conn) diff --git a/clients/R/MonetDB.R/src/mapisplit-r.c b/clients/R/MonetDB.R/src/mapisplit-r.c new file mode 100644 --- /dev/null +++ b/clients/R/MonetDB.R/src/mapisplit-r.c @@ -0,0 +1,54 @@ +#include <assert.h> + +#include <R.h> +#include <Rdefines.h> + +void mapi_line_split(char* line, char** out, size_t ncols); + +char nullstr[] = "NULL"; +SEXP mapi_split(SEXP mapiLinesVector, SEXP numCols) { + assert(TYPEOF(mapiLinesVector) == CHARSXP); + + int cols = INTEGER_POINTER(AS_INTEGER(numCols))[0]; + int rows = LENGTH(mapiLinesVector); + + assert(rows > 0); + assert(cols > 0); + + SEXP colVec; + PROTECT(colVec = NEW_LIST(cols)); + + int col; + for (col = 0; col < cols; col++) { + SEXP colV = PROTECT(NEW_STRING(rows)); + assert(TYPEOF(colV) == STRSXP); + SET_ELEMENT(colVec, col, colV); + UNPROTECT(1); + } + + int cRow; + int cCol; + char* elems[cols]; + + for (cRow = 0; cRow < rows; cRow++) { + const char *rval = CHAR(STRING_ELT(mapiLinesVector, cRow)); + char *val = strdup(rval); + cCol = 0; + mapi_line_split(val, elems, cols); + + for (cCol = 0; cCol < cols; cCol++) { + SEXP colV = VECTOR_ELT(colVec, cCol); + size_t tokenLen = strlen(elems[cCol]); + if (tokenLen < 1 || strcmp(elems[cCol], nullstr) == 0) { + SET_STRING_ELT(colV, cRow, NA_STRING); + } + else { + SET_STRING_ELT(colV, cRow, mkCharLen(elems[cCol], tokenLen)); + } + } + free(val); + } + + UNPROTECT(1); + return colVec; +} diff --git a/clients/R/MonetDB.R/src/mapisplit.c b/clients/R/MonetDB.R/src/mapisplit.c --- a/clients/R/MonetDB.R/src/mapisplit.c +++ b/clients/R/MonetDB.R/src/mapisplit.c @@ -1,9 +1,7 @@ #include <assert.h> #include <string.h> #include <errno.h> - -#include <R.h> -#include <Rdefines.h> +#include "mapisplit.h" typedef enum { INQUOTES, ESCAPED, INTOKEN, INCRAP @@ -25,7 +23,7 @@ void mapi_unescape(char* in, char* out) } void mapi_line_split(char* line, char** out, size_t ncols) { - int cCol = 0; + size_t cCol = 0; int tokenStart = 2; int endQuote = 0; int curPos; @@ -79,52 +77,3 @@ void mapi_line_split(char* line, char** } } } - -char nullstr[] = "NULL"; - -SEXP mapi_split(SEXP mapiLinesVector, SEXP numCols) { - assert(TYPEOF(mapiLinesVector) == CHARSXP); - - int cols = INTEGER_POINTER(AS_INTEGER(numCols))[0]; - int rows = LENGTH(mapiLinesVector); - - assert(rows > 0); - assert(cols > 0); - - SEXP colVec; - PROTECT(colVec = NEW_LIST(cols)); - - int col; - for (col = 0; col < cols; col++) { - SEXP colV = PROTECT(NEW_STRING(rows)); - assert(TYPEOF(colV) == STRSXP); - SET_ELEMENT(colVec, col, colV); - UNPROTECT(1); - } - - int cRow; - int cCol; - char* elems[cols]; - - for (cRow = 0; cRow < rows; cRow++) { - const char *rval = CHAR(STRING_ELT(mapiLinesVector, cRow)); - char *val = strdup(rval); - cCol = 0; - mapi_line_split(val, elems, cols); - - for (cCol = 0; cCol < cols; cCol++) { - SEXP colV = VECTOR_ELT(colVec, cCol); - size_t tokenLen = strlen(elems[cCol]); - if (tokenLen < 1 || strcmp(elems[cCol], nullstr) == 0) { - SET_STRING_ELT(colV, cRow, NA_STRING); - } - else { - SET_STRING_ELT(colV, cRow, mkCharLen(elems[cCol], tokenLen)); - } - } - free(val); - } - - UNPROTECT(1); - return colVec; -} diff --git a/clients/R/MonetDB.R/src/mapisplit.h b/clients/R/MonetDB.R/src/mapisplit.h new file mode 100644 --- /dev/null +++ b/clients/R/MonetDB.R/src/mapisplit.h @@ -0,0 +1,2 @@ +void mapi_unescape(char* in, char* out); +void mapi_line_split(char* line, char** out, size_t ncols); diff --git a/clients/R/MonetDB.R/src/profiler-r.c b/clients/R/MonetDB.R/src/profiler-r.c new file mode 100644 --- /dev/null +++ b/clients/R/MonetDB.R/src/profiler-r.c @@ -0,0 +1,11 @@ +#include <R.h> +#include <Rdefines.h> + +int profiler_start(); + +SEXP profiler_start_listen() { + SEXP port; + port = NEW_INTEGER(1); + INTEGER_POINTER(port)[0] = profiler_start(); + return port; +} diff --git a/clients/R/MonetDB.R/src/profiler.c b/clients/R/MonetDB.R/src/profiler.c --- a/clients/R/MonetDB.R/src/profiler.c +++ b/clients/R/MonetDB.R/src/profiler.c @@ -7,14 +7,13 @@ #include <pthread.h> #include <signal.h> #include <unistd.h> +#include <math.h> +#include <stdlib.h> #include <sys/types.h> #include <sys/fcntl.h> #include <sys/time.h> -#include <R.h> -#include <Rdefines.h> - #ifdef __WIN32__ #include <winsock2.h> #include <ws2tcpip.h> @@ -23,6 +22,9 @@ #include <netinet/in.h> #endif +#include "mapisplit.h" +#include "profiler.h" + // trace output format and columns #define TRACE_NCOLS 14 #define TRACE_COL_QUERYID 2 @@ -43,25 +45,14 @@ static char* profiler_symb_trans = "V"; static char* profiler_symb_bfree = "_"; static char* profiler_symb_bfull = "#"; -int strupp(char *s) { - int i; +static int profiler_strupp(char *s) { + size_t i; for (i = 0; i < strlen(s); i++) s[i] = toupper(s[i]); return i; } /* standalone MAL function call parser */ -typedef enum { - ASSIGNMENT, FUNCTION, PARAM, QUOTED, ESCAPED -} mal_statement_state; - -typedef struct { - char* assignment; - char* function; - unsigned short nparams; - char** params; -} mal_statement; - void mal_statement_split(char* stmt, mal_statement *out, size_t maxparams) { #define TRIM(str) \ while (str[0] == ' ' || str[0] == '"') str++; endPos = curPos - 1; \ @@ -118,23 +109,19 @@ void mal_statement_split(char* stmt, mal break; } if (chr == '\\') { - state = ESCAPED; + state = ESCAPEDP; break; } break; - case ESCAPED: + case ESCAPEDP: state = QUOTED; break; } } } -// from mapisplit.c, the trace tuple format is similar(*) to the mapi tuple format -void mapi_line_split(char* line, char** out, size_t ncols); -void mapi_unescape(char* in, char* out); - -unsigned long profiler_tsms() { +static unsigned long profiler_tsms() { unsigned long ret = 0; struct timeval tv; gettimeofday(&tv, NULL); @@ -153,21 +140,23 @@ void profiler_clearbar() { void profiler_renderbar(size_t state, size_t total, char *symbol) { int bs; unsigned short percentage, symbols; - percentage = (unsigned short) round((1.0 * - state / total) * 100); - symbols = PROFILER_BARSYMB*(percentage/100.0); profiler_clearbar(); profiler_needcleanup = 1; + + percentage = (unsigned short) ceil((1.0 * + state / total) * 100); + symbols = PROFILER_BARSYMB*(percentage/100.0); + printf("%s ", symbol); for (bs=0; bs < symbols; bs++) printf("%s", profiler_symb_bfull); for (bs=0; bs < PROFILER_BARSYMB-symbols; bs++) printf("%s", profiler_symb_bfree); - printf(" %3u%% ", percentage); fflush(stdout); } -void *profiler_thread() { +static void* profiler_thread(void* params) { + params = (void*) params; char buf[BUFSIZ]; char* elems[TRACE_NCOLS]; // query ids are unlikely to be longer than BUFSIZ @@ -179,7 +168,7 @@ void *profiler_thread() { size_t profiler_msgs_done = 0; unsigned long profiler_querystart; - char* stmtbuf = malloc(65507); // maximum size of an IPv6 UDP packet + char* stmtbuf = malloc(65507); // maximum size of an IPv4 UDP packet mal_statement *stmt = malloc(sizeof(mal_statement)); stmt->params = malloc(TRACE_MAL_MAXPARAMS * sizeof(char*)); @@ -188,6 +177,9 @@ void *profiler_thread() { recvd = read(profiler_socket, buf, sizeof(buf)); _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list