Changeset: d96cd1ea02c3 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=d96cd1ea02c3
Modified Files:
        ChangeLog
        gdk/gdk_tracer.c
        gdk/gdk_tracer.h
        tools/merovingian/ChangeLog
        tools/merovingian/daemon/forkmserver.c
        tools/merovingian/utils/properties.c
        tools/mserver/mserver5.c
Branch: default
Log Message:

Added option for setting the output directory for the produced tracefiles 
(mserver5 and merovingian)


diffs (212 lines):

diff --git a/ChangeLog b/ChangeLog
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,10 @@
 # ChangeLog file for devel
 # This file is updated with Maddlog
 
+* Tue Feb 18 2020 Thodoris Zois <thodoris.z...@monetdbsolutions.com>
+- Added mserver5 option (--dbtrace=<path>) in order to be able to
+  specify the output directory of the produced traces.
+
 * Thu Feb  6 2020 Panagiotis Koutsourakis <kutsu...@monetdbsolutions.com>
 - Add port and host as fields in the .monetdb file.
 
diff --git a/gdk/gdk_tracer.c b/gdk/gdk_tracer.c
--- a/gdk/gdk_tracer.c
+++ b/gdk/gdk_tracer.c
@@ -34,20 +34,25 @@ LOG_LEVEL LVL_PER_COMPONENT[] = {
 static gdk_return
 _GDKtracer_init_basic_adptr(void)
 {
-       char file_name[FILENAME_MAX];
-       snprintf(file_name, sizeof(file_name), "%s%c%s%c%s%s", 
GDKgetenv("gdk_dbpath"), DIR_SEP, FILE_NAME, NAME_SEP, 
GDKtracer_get_timestamp("%Y%m%d_%H%M%S", (char[20]){0}, 20), ".log");
+       char file_name[FILENAME_MAX];   
+       const char* TRACE_PATH = GDKgetenv("gdk_dbpath");
 
-       output_file = fopen(file_name, "w");
+       if(GDKgetenv("gdk_dbtrace") != NULL)
+               TRACE_PATH = GDKgetenv("gdk_dbtrace");
+
+       snprintf(file_name, sizeof(file_name), "%s%c%s", TRACE_PATH, DIR_SEP, 
FILE_NAME);
+       output_file = fopen(file_name, "a");
 
        // Even if creating the file failed, the adapter has 
        // still tried to initialize and we shouldn't retry it
        INIT_BASIC_ADAPTER = true;
-
-       if (!output_file) {
+       
+       if(!output_file)
+       {
                GDK_TRACER_EXCEPTION(BASIC_INIT_FAILED ": %s\n", file_name);
                return GDK_FAIL;
        }
-
+       
        return GDK_SUCCEED;
 }
 
diff --git a/gdk/gdk_tracer.h b/gdk/gdk_tracer.h
--- a/gdk/gdk_tracer.h
+++ b/gdk/gdk_tracer.h
@@ -38,7 +38,7 @@
 #define DEFAULT_LOG_LEVEL M_ERROR
 #define DEFAULT_FLUSH_LEVEL M_INFO
 
-#define FILE_NAME "trace"
+#define FILE_NAME "mdbtrace.log"
 #define NAME_SEP '_'
 #define NULL_CHAR '\0'
 #define NEW_LINE '\n'
diff --git a/tools/merovingian/ChangeLog b/tools/merovingian/ChangeLog
--- a/tools/merovingian/ChangeLog
+++ b/tools/merovingian/ChangeLog
@@ -1,3 +1,7 @@
 # ChangeLog file for sql/src/backends/monet5/merovingian
 # This file is updated with mchangelog
 
+* Tue Feb 18 2020 Thodoris Zois <thodoris.z...@monetdbsolutions.com>
+- Added dbtrace mserver5 option to the daemon in order to set
+  mserver5's output directory for the produced traces.
+
diff --git a/tools/merovingian/daemon/forkmserver.c 
b/tools/merovingian/daemon/forkmserver.c
--- a/tools/merovingian/daemon/forkmserver.c
+++ b/tools/merovingian/daemon/forkmserver.c
@@ -201,6 +201,7 @@ forkMserver(char *database, sabdb** stat
        char *sabdbfarm;
        char dbpath[1024];
        char dbextra_path[1024];
+       char dbtrace_path[1024];
        char port[32];
        char listenaddr[512];
        char muri[512]; /* possibly undersized */
@@ -218,6 +219,7 @@ forkMserver(char *database, sabdb** stat
        char *raw_strings = NULL;
        char *ipv6 = NULL;
        char *dbextra = NULL;
+       char *dbtrace = NULL;
        char *mserver5_extra = NULL;
        char *mserver5_extra_token = NULL;
        char *argv[MAX_NR_ARGS+1];      /* for the exec arguments */
@@ -522,6 +524,10 @@ forkMserver(char *database, sabdb** stat
                dbextra = kv->val;
        }
 
+       kv = findConfKey(ckv, "dbtrace");
+       if (kv != NULL && kv->val != NULL)
+               dbtrace = kv->val;
+
        kv = findConfKey(ckv, "listenaddr");
        if (kv->val != NULL) {
                if (mydoproxy) {
@@ -561,6 +567,13 @@ forkMserver(char *database, sabdb** stat
                                 "--dbextra=%s", dbextra);
                argv[c++] = dbextra_path;
        }
+
+       if (dbtrace != NULL) {
+               snprintf(dbtrace_path, sizeof(dbtrace_path),
+                                "--dbtrace=%s", dbtrace);
+               argv[c++] = dbtrace_path;
+       }
+       
        if (mydoproxy) {
                argv[c++] = set; argv[c++] = "mapi_open=false";
                /* we "proxy", so we can just solely use UNIX domain sockets
diff --git a/tools/merovingian/utils/properties.c 
b/tools/merovingian/utils/properties.c
--- a/tools/merovingian/utils/properties.c
+++ b/tools/merovingian/utils/properties.c
@@ -39,6 +39,7 @@ static const confkeyval _internal_prop_k
        {"nclients",    NULL, 0, INT},
        {"mfunnel",     NULL, 0, STR},
        {"dbextra",     NULL, 0, STR},
+       {"dbtrace",     NULL, 0, STR},
        {"memmaxsize",  NULL, 0, INT},
        {"vmmaxsize",   NULL, 0, INT},
        {"raw_strings", NULL, 0, BOOLEAN},
diff --git a/tools/mserver/mserver5.c b/tools/mserver/mserver5.c
--- a/tools/mserver/mserver5.c
+++ b/tools/mserver/mserver5.c
@@ -89,6 +89,7 @@ usage(char *prog, int xit)
        fprintf(stderr, "Usage: %s [options]\n", prog);
        fprintf(stderr, "    --dbpath=<directory>      Specify database 
location\n");
        fprintf(stderr, "    --dbextra=<directory>     Directory for transient 
BATs\n");
+       fprintf(stderr, "    --dbtrace=<directory>     Directory for produced 
traces\n");
        fprintf(stderr, "    --in-memory               Run database in-memory 
only\n");
        fprintf(stderr, "    --config=<config_file>    Use config_file to read 
options from\n");
        fprintf(stderr, "    --single-user             Allow only one user at a 
time\n");
@@ -258,6 +259,7 @@ handler(int sig)
 int
 main(int argc, char **av)
 {
+       DIR *dirp;
        char *prog = *av;
        opt *set = NULL;
        int grpdebug = 0, debug = 0, setlen = 0;
@@ -267,11 +269,13 @@ main(int argc, char **av)
        char *binpath = NULL;
        char *dbpath = NULL;
        char *dbextra = NULL;
+       char *dbtrace = NULL;
        bool inmemory = false;
        static struct option long_options[] = {
                { "config", required_argument, NULL, 'c' },
                { "dbpath", required_argument, NULL, 0 },
                { "dbextra", required_argument, NULL, 0 },
+               { "dbtrace", optional_argument, NULL, 0 },
                { "debug", optional_argument, NULL, 'd' },
                { "help", no_argument, NULL, '?' },
                { "version", no_argument, NULL, 0 },
@@ -358,6 +362,22 @@ main(int argc, char **av)
                                        dbextra = optarg;
                                break;
                        }
+
+                       if (strcmp(long_options[option_index].name, "dbtrace") 
== 0) {
+                               size_t optarglen = strlen(optarg);
+                               /* remove trailing directory separator */
+                               while (optarglen > 0 &&
+                                      (optarg[optarglen - 1] == '/' ||
+                                       optarg[optarglen - 1] == '\\'))
+                                       optarg[--optarglen] = '\0';
+                               dbtrace = absolute_path(optarg);
+                               if(dbtrace == NULL)
+                                       fprintf(stderr, "#error: can not 
allocate memory for dbtrace\n");
+                               else
+                                       setlen = mo_add_option(&set, setlen, 
opt_cmdline, "gdk_dbtrace", dbtrace);
+                               break;
+                       }
+
                        if (strcmp(long_options[option_index].name, 
"single-user") == 0) {
                                setlen = mo_add_option(&set, setlen, 
opt_cmdline, "gdk_single_user", "yes");
                                break;
@@ -492,6 +512,28 @@ main(int argc, char **av)
                }
        }
        GDKfree(dbpath);
+
+       if (dbtrace) {
+               /* GDKcreatedir makes sure that all parent directories of 
dbtrace exist */
+               if (GDKcreatedir(dbtrace) != GDK_SUCCEED) {
+                       fprintf(stderr, "!ERROR: cannot create directory for 
%s\n", dbtrace);
+                       exit(1);
+               }
+               /* create the actual dir for db-trace */
+               if (mkdir(dbtrace, MONETDB_DIRMODE) < 0) {
+                       if (errno != EEXIST) {
+                               fprintf(stderr, "!ERROR: cannot create 
directory for %s\n", dbtrace);
+                               exit(1);
+                       }
+                       if ((dirp = opendir(dbtrace)) == NULL) {
+                               fprintf(stderr, "!ERROR: cannot create 
directory for %s\n", dbtrace);
+                               exit(1);
+                       }
+                       closedir(dirp);
+               }
+               GDKfree(dbtrace);
+       }
+
        if (monet_init(set, setlen) == 0) {
                mo_free_options(set, setlen);
                if (GDKerrbuf && *GDKerrbuf)
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to