Changeset: 572952a00ce6 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/572952a00ce6
Modified Files:
        monetdb5/mal/mal_client.c
        monetdb5/mal/mal_profiler.c
        monetdb5/mal/mal_profiler.h
        monetdb5/mal/mal_runtime.c
        sql/backends/monet5/sql.c
        sql/backends/monet5/sql_scenario.c
        sql/server/sql_mvc.c
Branch: Sep2022
Log Message:

Do not use struct as arguments when not needed, use pointer to struct.
Use NULL pointer for unused struct, not struct filled with zeros.
Also, release lock before return.
This also fixes a compilation issues with the Intel compiler on Windows.


diffs (197 lines):

diff --git a/monetdb5/mal/mal_client.c b/monetdb5/mal/mal_client.c
--- a/monetdb5/mal/mal_client.c
+++ b/monetdb5/mal/mal_client.c
@@ -212,8 +212,8 @@ MCexitClient(Client c)
        assert(c->query == NULL);
        if(profilerStatus > 0) {
                lng Tend = GDKusec();
-               profilerEvent((struct MalEvent) {0},
-                                         (struct NonMalEvent)
+               profilerEvent(NULL,
+                                         &(struct NonMalEvent)
                                          {CLIENT_END, c, Tend,  NULL, NULL, 0, 
Tend-(c->session)});
        }
        setClientContext(NULL);
@@ -309,8 +309,8 @@ MCinitClient(oid user, bstream *fin, str
        }
        MT_lock_unset(&mal_contextLock);
 
-       profilerEvent((struct MalEvent) {0},
-                                 (struct NonMalEvent)
+       profilerEvent(NULL,
+                                 &(struct NonMalEvent)
                                  {CLIENT_START, c, c->session,  NULL, NULL, 0, 
0});
        return c;
 }
diff --git a/monetdb5/mal/mal_profiler.c b/monetdb5/mal/mal_profiler.c
--- a/monetdb5/mal/mal_profiler.c
+++ b/monetdb5/mal/mal_profiler.c
@@ -643,25 +643,27 @@ profilerHeartbeatEvent(char *alter)
 }
 
 void
-profilerEvent(MalEvent me, NonMalEvent nme)
+profilerEvent(MalEvent *me, NonMalEvent *nme)
 {
        str event = NULL;
+       assert(me == NULL || nme == NULL);
        /* ignore profiler monitoring cmds */
-       if (me.cntxt != NULL && getModuleId(me.pci) == myname) return;
+       if (me != NULL && me->cntxt != NULL && getModuleId(me->pci) == myname)
+               return;
 
        if (maleventstream) {
                MT_lock_set(&mal_profileLock);
-               if (me.mb != NULL && nme.phase == MAL_ENGINE) {
-                       if (me.stk == NULL) return;
-                       if (me.pci == NULL) return;
-                       if (profilerMode && me.mb && (getPC(me.mb, me.pci) != 
0)) {
+               if (me != NULL && me->mb != NULL && nme == NULL) {
+                       if (me->stk == NULL ||
+                               me->pci == NULL ||
+                               (profilerMode && me->mb && getPC(me->mb, 
me->pci) != 0)) {
                                MT_lock_unset(&mal_profileLock);
                                return; /* minimal mode */
                        }
-                       event = prepareMalEvent(me.cntxt, me.mb, me.stk, 
me.pci);
+                       event = prepareMalEvent(me->cntxt, me->mb, me->stk, 
me->pci);
                }
-               if (me.mb == NULL && nme.phase != MAL_ENGINE) {
-                       event = prepareNonMalEvent(nme.cntxt, nme.phase, 
nme.clk, nme.tid, nme.ts, nme.state, nme.duration);
+               if (me == NULL && nme != NULL && nme->phase != MAL_ENGINE) {
+                       event = prepareNonMalEvent(nme->cntxt, nme->phase, 
nme->clk, nme->tid, nme->ts, nme->state, nme->duration);
                }
                if (event) {
                        logjsonInternal(event, true);
@@ -718,8 +720,8 @@ openProfilerStream(Client cntxt, str s)
                if (c && m && s && p) {
                        /* show the event  assuming the quadruple is aligned*/
                        MT_lock_unset(&mal_profileLock);
-                       profilerEvent((struct MalEvent) {c, m, s, p},
-                                                 (struct NonMalEvent) {0});
+                       profilerEvent(&(struct MalEvent) {c, m, s, p},
+                                                 NULL);
                        MT_lock_set(&mal_profileLock);
                }
        }
diff --git a/monetdb5/mal/mal_profiler.h b/monetdb5/mal/mal_profiler.h
--- a/monetdb5/mal/mal_profiler.h
+++ b/monetdb5/mal/mal_profiler.h
@@ -59,7 +59,7 @@ mal_export void initProfiler(void);
 mal_export str openProfilerStream(Client cntxt, str s);
 mal_export str closeProfilerStream(Client cntxt);
 
-mal_export void profilerEvent(MalEvent me, NonMalEvent nme);
+mal_export void profilerEvent(MalEvent *me, NonMalEvent *nme);
 mal_export void sqlProfilerEvent(Client cntxt, MalBlkPtr mb, MalStkPtr stk, 
InstrPtr pci);
 
 mal_export str startProfiler(Client cntxt);
diff --git a/monetdb5/mal/mal_runtime.c b/monetdb5/mal/mal_runtime.c
--- a/monetdb5/mal/mal_runtime.c
+++ b/monetdb5/mal/mal_runtime.c
@@ -416,8 +416,8 @@ runtimeProfileExit(Client cntxt, MalBlkP
        pci->totticks += pci->ticks;
 
        if(profilerStatus > 0 )
-               profilerEvent((struct MalEvent) {cntxt, mb, stk, pci},
-                                         (struct NonMalEvent) {0});
+               profilerEvent(&(struct MalEvent) {cntxt, mb, stk, pci},
+                                         NULL);
        if(cntxt->sqlprofiler)
                sqlProfilerEvent(cntxt, mb, stk, pci);
        if(profilerStatus < 0){
diff --git a/sql/backends/monet5/sql.c b/sql/backends/monet5/sql.c
--- a/sql/backends/monet5/sql.c
+++ b/sql/backends/monet5/sql.c
@@ -133,8 +133,8 @@ sql_symbol2relation(backend *be, symbol 
        rel = rel_semantic(query, sym);
        Tend = GDKusec();
        if(profilerStatus > 0 )
-               profilerEvent((struct MalEvent) {0},
-                                         (struct NonMalEvent)
+               profilerEvent(NULL,
+                                         &(struct NonMalEvent)
                                          {SQL_TO_REL, c, Tend, NULL, NULL, 
rel?0:1, Tend-Tbegin});
 
        storage_based_opt = value_based_opt && rel && !is_ddl(rel->op);
@@ -149,8 +149,8 @@ sql_symbol2relation(backend *be, symbol 
        be->reloptimizer = Tend - Tbegin;
 
        if(profilerStatus > 0)
-               profilerEvent((struct MalEvent) {0},
-                                         (struct NonMalEvent)
+               profilerEvent(NULL,
+                                         &(struct NonMalEvent)
                                          {REL_OPT, c, Tend, NULL, NULL, 
rel?0:1, be->reloptimizer});
        return rel;
 }
diff --git a/sql/backends/monet5/sql_scenario.c 
b/sql/backends/monet5/sql_scenario.c
--- a/sql/backends/monet5/sql_scenario.c
+++ b/sql/backends/monet5/sql_scenario.c
@@ -1132,8 +1132,8 @@ SQLparser(Client c)
 
        Tend = GDKusec();
        if(profilerStatus > 0) {
-               profilerEvent((struct MalEvent) {0},
-                                         (struct NonMalEvent)
+               profilerEvent(NULL,
+                                         &(struct NonMalEvent)
                                          {TEXT_TO_SQL, c, Tend, 
&m->session->tr->ts, NULL, c->query?0:1, Tend-Tbegin});
        }
 
@@ -1201,8 +1201,8 @@ SQLparser(Client c)
 
                        Tend = GDKusec();
                        if(profilerStatus > 0)
-                               profilerEvent((struct MalEvent) {0},
-                                                         (struct NonMalEvent)
+                               profilerEvent(NULL,
+                                                         &(struct NonMalEvent)
                                                          {REL_TO_MAL, c, Tend, 
NULL, NULL, c->query?0:1, Tend-Tbegin});
                } else {
                        char *q_copy = sa_strdup(m->sa, c->query);
@@ -1285,8 +1285,8 @@ SQLparser(Client c)
                        msg = SQLoptimizeQuery(c, c->curprg->def);
                        Tend = GDKusec();
                        if(profilerStatus > 0)
-                               profilerEvent((struct MalEvent) {0},
-                                                         (struct NonMalEvent)
+                               profilerEvent(NULL,
+                                                         &(struct NonMalEvent)
                                                          {MAL_OPT, c, Tend, 
NULL, NULL, msg==MAL_SUCCEED?0:1, Tend-Tbegin});
                        if (msg != MAL_SUCCEED) {
                                str other = c->curprg->def->errors;
diff --git a/sql/server/sql_mvc.c b/sql/server/sql_mvc.c
--- a/sql/server/sql_mvc.c
+++ b/sql/server/sql_mvc.c
@@ -547,8 +547,8 @@ mvc_commit(mvc *m, int chain, const char
                if(profilerStatus > 0) {
                        lng Tend = GDKusec();
                        Client  c = getClientContext();
-                       profilerEvent((struct MalEvent) {0},
-                                                 (struct NonMalEvent)
+                       profilerEvent(NULL,
+                                                 &(struct NonMalEvent)
                                                  { state == SQL_CONFLICT ? 
CONFLICT : COMMIT , c, Tend, &ts_start, &m->session->tr->ts, state == SQL_ERR, 
log_usec?Tend-Tbegin:0});
                }
                switch (state) {
@@ -686,7 +686,7 @@ mvc_rollback(mvc *m, int chain, const ch
                if (!list_empty(tr->changes))
                        tr->status = 1;
 
-               
+
                lng Tbegin = 0;
                ulng ts_start = 0;
                bool log_usec = profilerMode == 0 || m->session->auto_commit;
@@ -699,8 +699,8 @@ mvc_rollback(mvc *m, int chain, const ch
                if(profilerStatus > 0) {
                        lng Tend = GDKusec();
                        Client  c = getClientContext();
-                       profilerEvent((struct MalEvent) {0},
-                                                 (struct NonMalEvent)
+                       profilerEvent(NULL,
+                                                 &(struct NonMalEvent)
                                                  { ROLLBACK , c, Tend, 
&ts_start, &m->session->tr->ts, 0, log_usec?Tend-Tbegin:0});
                }
                if (chain) {
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to