Changeset: 55556f5a1a5a for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/55556f5a1a5a
Modified Files:
        monetdb5/mal/mal_client.c
        monetdb5/mal/mal_profiler.c
        monetdb5/mal/mal_profiler.h
        sql/backends/monet5/sql.c
        sql/backends/monet5/sql_scenario.c
        sql/server/sql_mvc.c
        sql/storage/sql_storage.h
        sql/storage/store.c
Branch: Jul2021_prof_ext
Log Message:

Us enum to designate event phase.


diffs (243 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
@@ -207,7 +207,7 @@ MCexitClient(Client c)
                lng Tend = GDKusec();
                profilerEvent((struct MalEvent) {0},
                                          (struct NonMalEvent)
-                                         {"client_connection", c, Tend,  NULL, 
0, Tend-(c->session)});
+                                         {CLIENT_CONNECTION, c, Tend,  NULL, 
0, Tend-(c->session)});
        }
        setClientContext(NULL);
 }
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
@@ -169,8 +169,22 @@ logadd(struct logbuf *logbuf, const char
        return true;
 }
 
+static str phase_descriptions[] = {
+       [CLIENT_CONNECTION] = "client_connection",
+       [TEXT_TO_SQL]           = "text_to_sql",
+       [SQL_TO_REL]            = "sql_to_rel",
+       [REL_OPT]                       = "rel_opt",
+       [REL_TO_MAL]            = "rel_to_mal",
+       [MAL_OPT]                       = "rel_to_mal",
+       [MAL_ENGINE]            = "mal_engine",
+       [TRANSACTION_START]     = "trans_start",
+       [COMMIT]                        = "trans_commit",
+       [ROLLBACK]                      = "trans_rollback",
+       [TRANSACTION_END]       = "trans_end"
+};
+
 static str
-prepareNonMalEvent(Client cntxt, str phase, ulng clk, ulng *tid, ulng *ts, int 
state, ulng duration)
+prepareNonMalEvent(Client cntxt, enum event_phase phase, ulng clk, ulng *tid, 
ulng *ts, int state, ulng duration)
 {
        oid* tag = NULL;
        str query = NULL;
@@ -191,7 +205,7 @@ prepareNonMalEvent(Client cntxt, str pha
        if (!logadd(&logbuf, ", \"clk\":"ULLFMT"", mclk))
                goto cleanup_and_exit;
        if (!logadd(&logbuf, ", \"thread\":%d, \"phase\":\"%s\"",
-                               THRgettid(), phase))
+                               THRgettid(), phase_descriptions[phase]))
                goto cleanup_and_exit;
        if (tid && !logadd(&logbuf, ", \"tid\":"ULLFMT, *tid))
                goto cleanup_and_exit;
@@ -253,13 +267,14 @@ prepareMalEvent(Client cntxt, MalBlkPtr 
                                "\"sessionid\":\"%d\""
                                ",\"clk\":%"PRIu64""
                                ",\"thread\":%d"
-                               ",\"phase\":\"mal_engine\""
+                               ",\"phase\":\"%s\""
                                ",\"program\":\"%s.%s\""
                                ",\"pc\":%d"
                                ",\"tag\":"OIDFMT,
                                cntxt->idx,
                                mclk,
                                THRgettid(),
+                               phase_descriptions[MAL_ENGINE],
                                getModuleId(getInstrPtr(mb, 0)), 
getFunctionId(getInstrPtr(mb, 0)),
                                mb?getPC(mb,pci):0,
                                stk?stk->tag:0))
@@ -603,12 +618,12 @@ profilerEvent(MalEvent me, NonMalEvent n
 
        if (maleventstream) {
                MT_lock_set(&mal_profileLock);
-               if (me.mb != NULL && nme.phase == NULL) {
+               if (me.mb != NULL && nme.phase == MAL_ENGINE) {
                        if (me.stk == NULL) return;
                        if (me.pci == NULL) return;
                        event = prepareMalEvent(me.cntxt, me.mb, me.stk, 
me.pci);
                }
-               if (me.mb == NULL && nme.phase != NULL) {
+               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 (event) {
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
@@ -20,8 +20,23 @@
 typedef struct rusage Rusage;
 #endif
 
+
+enum event_phase {
+       MAL_ENGINE = 0,
+       CLIENT_CONNECTION,
+       TEXT_TO_SQL,
+       SQL_TO_REL,
+       REL_OPT,
+       REL_TO_MAL,
+       MAL_OPT,
+       TRANSACTION_START = 100,
+       COMMIT,
+       ROLLBACK,
+       TRANSACTION_END
+};
+
 typedef struct NonMalEvent {
-       str phase;
+       enum event_phase phase;
        Client cntxt;
        ulng clk;
        ulng* tid;
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
@@ -135,7 +135,7 @@ sql_symbol2relation(backend *be, symbol 
        if(malProfileMode > 0 )
                profilerEvent((struct MalEvent) {0},
                                          (struct NonMalEvent)
-                                         {"sql_to_rel", c, Tend, NULL, NULL, 
rel?0:1, Tend-Tbegin});
+                                         {SQL_TO_REL, c, Tend, NULL, NULL, 
rel?0:1, Tend-Tbegin});
 
        Tbegin = Tend;
        if (rel)
@@ -152,7 +152,7 @@ sql_symbol2relation(backend *be, symbol 
        if(malProfileMode > 0)
                profilerEvent((struct MalEvent) {0},
                                          (struct NonMalEvent)
-                                         {"rel_opt", c, Tend, NULL, NULL, 
rel?0:1, be->reloptimizer});
+                                         {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
@@ -1149,7 +1149,7 @@ SQLparser(Client c)
        if(malProfileMode > 0) {
                profilerEvent((struct MalEvent) {0},
                                          (struct NonMalEvent)
-                                         {"sql_parser", c, Tend, NULL, NULL, 
c->query?0:1, Tend-Tbegin});
+                                         {TEXT_TO_SQL, c, Tend, NULL, NULL, 
c->query?0:1, Tend-Tbegin});
        }
 
        if (c->query == NULL) {
@@ -1208,7 +1208,7 @@ SQLparser(Client c)
                        if(malProfileMode > 0)
                                profilerEvent((struct MalEvent) {0},
                                                          (struct NonMalEvent)
-                                                         {"rel_to_mal", c, 
Tend, NULL, NULL, c->query?0:1, Tend-Tbegin});
+                                                         {REL_TO_MAL, c, Tend, 
NULL, NULL, c->query?0:1, Tend-Tbegin});
                } else {
                        char *q_copy = sa_strdup(m->sa, c->query);
 
@@ -1282,7 +1282,7 @@ SQLparser(Client c)
                        if(malProfileMode > 0)
                                profilerEvent((struct MalEvent) {0},
                                                          (struct NonMalEvent)
-                                                         {"mal_opt", c, Tend, 
NULL, NULL, msg==MAL_SUCCEED?0:1, Tend-Tbegin});
+                                                         {MAL_OPT, c, Tend, 
NULL, NULL, msg==MAL_SUCCEED?0:1, Tend-Tbegin});
                        if (msg != MAL_SUCCEED) {
                                str other = c->curprg->def->errors;
                                /* In debugging mode you may want to assess 
what went wrong in the optimizers*/
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
@@ -124,14 +124,14 @@ mvc_fix_depend(mvc *m, sql_column *depid
 }
 
 static void
-profiler_event_wrapper(str phase, lng clk, ulng *tid, ulng *ts, int state, lng 
usec)
+profiler_event_wrapper(int phase, lng clk, ulng *tid, ulng *ts, int state, lng 
usec)
 {
        Client  c = getClientContext();
 
        if(malProfileMode > 0)
                profilerEvent((struct MalEvent) {0},
                                          (struct NonMalEvent)
-                                         {phase, c, clk, tid, ts, state, 
usec});
+                                         {(enum event_phase) phase, c, clk, 
tid, ts, state, usec});
 }
 
 sql_store
diff --git a/sql/storage/sql_storage.h b/sql/storage/sql_storage.h
--- a/sql/storage/sql_storage.h
+++ b/sql/storage/sql_storage.h
@@ -309,7 +309,7 @@ extern res_table *res_tables_remove(res_
 sql_export void res_tables_destroy(res_table *results);
 extern res_table *res_tables_find(res_table *results, int res_id);
 
-typedef void (*profiler_event_wrapper_fptr) (str phase, lng clk, ulng *tid, 
ulng *ts, int state, lng usec);
+typedef void (*profiler_event_wrapper_fptr) (int phase, lng clk, ulng *tid, 
ulng *ts, int state, lng usec);
 extern struct sqlstore *store_init(int debug, store_type store, int readonly, 
int singleuser, profiler_event_wrapper_fptr event_wrapper);
 extern void store_exit(struct sqlstore *store);
 
diff --git a/sql/storage/store.c b/sql/storage/store.c
--- a/sql/storage/store.c
+++ b/sql/storage/store.c
@@ -3482,6 +3482,13 @@ clean_predicates_and_propagate_to_parent
        return res;
 }
 
+enum event_phase {
+       TRANSACTION_START = 100,
+       COMMIT,
+       ROLLBACK,
+       TRANSACTION_END
+};
+
 static void
 sql_trans_rollback(sql_trans *tr, bool commit_lock)
 {
@@ -3586,7 +3593,7 @@ sql_trans_rollback(sql_trans *tr, bool c
        }
 
        Tend = GDKusec();
-       store->profiler_event_wrapper("rollback", Tend, &tr->tid, NULL, 0, 
Tend-Tbegin);
+       store->profiler_event_wrapper(ROLLBACK, Tend, &tr->tid, NULL, 0, 
Tend-Tbegin);
 }
 
 sql_trans *
@@ -3938,7 +3945,7 @@ sql_trans_commit(sql_trans *tr)
                ok = clean_predicates_and_propagate_to_parent(tr);
 
        Tend = GDKusec();
-       store->profiler_event_wrapper("commit", Tend, &tr->tid, NULL, ok, 
Tend-Tbegin);
+       store->profiler_event_wrapper(COMMIT, Tend, &tr->tid, &tr->ts, ok, 
Tend-Tbegin);
 
        return (ok==LOG_OK)?SQL_OK:SQL_ERR;
 }
@@ -6874,7 +6881,7 @@ sql_trans_begin(sql_session *s)
        TRC_DEBUG(SQL_STORE, "Exit sql_trans_begin for transaction: " ULLFMT 
"\n", tr->tid);
        store_unlock(store);
        s->status = tr->status = 0;
-       store->profiler_event_wrapper("start transaction", GDKusec(), 
&s->tr->tid, &s->tr->ts, 0, 0);
+       store->profiler_event_wrapper(TRANSACTION_START, GDKusec(), 
&s->tr->tid, &s->tr->ts, 0, 0);
        return 0;
 }
 
@@ -6907,7 +6914,7 @@ sql_trans_end(sql_session *s, int ok)
        assert(list_length(store->active) == (int) 
ATOMIC_GET(&store->nr_active));
        store_unlock(store);
        lng Tend = GDKusec();
-       store->profiler_event_wrapper("end transaction", Tend, &s->tr->tid, 
&s->tr->ts, ok==SQL_OK?0:1, 0);
+       store->profiler_event_wrapper(TRANSACTION_END, Tend, &s->tr->tid, 
&s->tr->ts, ok==SQL_OK?0:1, 0);
 
        return ok;
 }
_______________________________________________
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org

Reply via email to