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

Collapse all transaction messages into a single message for commits, conflicts 
and errors.


diffs (257 lines):

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
@@ -179,14 +179,14 @@ static str phase_descriptions[] = {
        [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"
+       // [TRANSACTION_START]  = "trans_start",
+       // [COMMIT]                     = "trans_commit",
+       // [ROLLBACK]                   = "trans_rollback",
+       [TRANSACTION_END]       = "transaction"
 };
 
 static str
-prepareNonMalEvent(Client cntxt, enum event_phase phase, ulng clk, ulng *tid, 
ulng *ts, int state, ulng duration)
+prepareNonMalEvent(Client cntxt, enum event_phase phase, ulng clk, ulng 
*tstart, ulng *tend, int state, ulng duration)
 {
        oid* tag = NULL;
        str query = NULL;
@@ -209,9 +209,9 @@ prepareNonMalEvent(Client cntxt, enum ev
        if (!logadd(&logbuf, ", \"thread\":%d, \"phase\":\"%s\"",
                                THRgettid(), phase_descriptions[phase]))
                goto cleanup_and_exit;
-       if (tid && !logadd(&logbuf, ", \"tid\":"ULLFMT, *tid))
+       if (tstart && !logadd(&logbuf, ", \"tstart\":"ULLFMT, *tstart))
                goto cleanup_and_exit;
-       if (ts && !logadd(&logbuf, ", \"ts\":"ULLFMT, *ts))
+       if (tend && !logadd(&logbuf, ", \"tend\":"ULLFMT, *tend))
                goto cleanup_and_exit;
        if (tag && !logadd(&logbuf, ", \"tag\":"OIDFMT, *tag))
                goto cleanup_and_exit;
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
@@ -29,9 +29,9 @@ enum event_phase {
        REL_OPT,
        REL_TO_MAL,
        MAL_OPT,
-       TRANSACTION_START = 7,
-       COMMIT,
-       ROLLBACK,
+       // TRANSACTION_START,
+       // COMMIT,
+       // ROLLBACK,
        TRANSACTION_END
 };
 
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
@@ -1134,7 +1134,7 @@ SQLparser(Client c)
        if(malProfileMode > 0) {
                profilerEvent((struct MalEvent) {0},
                                          (struct NonMalEvent)
-                                         {TEXT_TO_SQL, c, Tend, NULL, NULL, 
c->query?0:1, Tend-Tbegin});
+                                         {TEXT_TO_SQL, c, Tend, 
&m->session->tr->ts, NULL, c->query?0:1, Tend-Tbegin});
        }
 
        if (c->query == NULL) {
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,17 +124,6 @@ mvc_fix_depend(mvc *m, sql_column *depid
        }
 }
 
-static void
-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)
-                                         {(enum event_phase) phase, c, clk, 
tid, ts, state, usec});
-}
-
 sql_store
 mvc_init(int debug, store_type store_tpe, int ro, int su)
 {
@@ -151,7 +140,7 @@ mvc_init(int debug, store_type store_tpe
                return NULL;
        }
 
-       if ((store = store_init(debug, store_tpe, ro, su, 
&profiler_event_wrapper)) == NULL) {
+       if ((store = store_init(debug, store_tpe, ro, su)) == NULL) {
                keyword_exit();
                TRC_CRITICAL(SQL_TRANS, "Unable to create system tables\n");
                return NULL;
@@ -545,11 +534,28 @@ mvc_commit(mvc *m, int chain, const char
        }
 
        if (!tr->parent && !name) {
-               switch (sql_trans_end(m->session, ok)) {
+               lng Tbegin;
+               ulng ts_start;
+               if(malProfileMode > 0) {
+                       Tbegin = GDKusec();
+                       ts_start = m->session->tr->ts;
+               }
+
+               const int state = sql_trans_end(m->session, ok);
+
+               if(malProfileMode > 0) {
+                       lng Tend = GDKusec();
+                       Client  c = getClientContext();
+                       profilerEvent((struct MalEvent) {0},
+                                               (struct NonMalEvent)
+                                               {TRANSACTION_END, c, Tend, 
&ts_start, &m->session->tr->ts, state == SQL_OK ? 0 : 1, Tend - Tbegin});
+               }
+               switch (state) {
                        case SQL_ERR:
                                GDKfatal("%s transaction commit failed; exiting 
(kernel error: %s)", operation, GDKerrbuf);
                                break;
                        case SQL_CONFLICT:
+
                                /* transaction conflict */
                                return createException(SQL, "sql.commit", 
SQLSTATE(40001) "%s transaction is aborted because of concurrency conflicts, 
will ROLLBACK instead", operation);
                        default:
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
@@ -331,8 +331,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) (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 struct sqlstore *store_init(int debug, store_type store, int readonly, 
int singleuser);
 extern void store_exit(struct sqlstore *store);
 
 extern void store_suspend_log(struct sqlstore *store);
@@ -509,7 +508,6 @@ typedef struct sqlstore {
        table_functions table_api;
        logger_functions logger_api;
        void *logger;                   /* space to keep logging structure of 
storage backend */
-       profiler_event_wrapper_fptr profiler_event_wrapper;
 } sqlstore;
 
 typedef enum sql_dependency_change_type {
diff --git a/sql/storage/store.c b/sql/storage/store.c
--- a/sql/storage/store.c
+++ b/sql/storage/store.c
@@ -2062,7 +2062,7 @@ store_load(sqlstore *store, sql_allocato
 }
 
 sqlstore *
-store_init(int debug, store_type store_tpe, int readonly, int singleuser, 
profiler_event_wrapper_fptr event_wrapper)
+store_init(int debug, store_type store_tpe, int readonly, int singleuser)
 {
        sql_allocator *pa;
        sqlstore *store = MNEW(sqlstore);
@@ -2105,8 +2105,6 @@ store_init(int debug, store_type store_t
        MT_lock_set(&store->flush);
        MT_lock_set(&store->lock);
 
-       store->profiler_event_wrapper = event_wrapper;
-
        /* initialize empty bats */
        switch (store_tpe) {
        case store_bat:
@@ -3576,19 +3574,10 @@ clean_predicates_and_propagate_to_parent
        return res;
 }
 
-enum event_phase {
-       TRANSACTION_START = 7,
-       COMMIT,
-       ROLLBACK,
-       TRANSACTION_END
-};
-
 static void
 sql_trans_rollback(sql_trans *tr, bool commit_lock)
 {
        sqlstore *store = tr->store;
-       lng Tbegin = GDKusec();
-       lng Tend;
 
        /* move back deleted */
        if (tr->localtmps.dset) {
@@ -3685,9 +3674,6 @@ sql_trans_rollback(sql_trans *tr, bool c
                list_destroy(tr->depchanges);
                tr->depchanges = NULL;
        }
-
-       Tend = GDKusec();
-       store->profiler_event_wrapper(ROLLBACK, Tend, &tr->tid, NULL, 0, 
Tend-Tbegin);
 }
 
 sql_trans *
@@ -3893,8 +3879,6 @@ sql_trans_commit(sql_trans *tr)
 {
        int ok = LOG_OK;
        sqlstore *store = tr->store;
-       lng Tbegin = 0;
-       lng Tend = 0;
 
        if (!list_empty(tr->changes)) {
                int flush = 0;
@@ -3922,8 +3906,6 @@ sql_trans_commit(sql_trans *tr)
                        }
                }
 
-               Tbegin = GDKusec();
-
                /* log changes should only be done if there is something to log 
*/
                const bool log = !tr->parent && tr->logchanges > 0;
 
@@ -4027,7 +4009,6 @@ sql_trans_commit(sql_trans *tr)
                list_destroy(tr->changes);
                tr->changes = NULL;
        } else if (ATOMIC_GET(&store->nr_active) == 1) { /* just me cleanup */
-               Tbegin = GDKusec();
                MT_lock_set(&store->commit);
                store_lock(store);
                ulng oldest = store_timestamp(store);
@@ -4035,8 +4016,6 @@ sql_trans_commit(sql_trans *tr)
                store_unlock(store);
                MT_lock_unset(&store->commit);
        }
-       else
-               Tbegin = GDKusec();
        /* drop local temp tables with commit action CA_DROP, after cleanup */
        if (cs_size(&tr->localtmps)) {
                for(node *n=tr->localtmps.set->h; n; ) {
@@ -4057,9 +4036,6 @@ sql_trans_commit(sql_trans *tr)
        if (ok == LOG_OK)
                ok = clean_predicates_and_propagate_to_parent(tr);
 
-       Tend = GDKusec();
-       store->profiler_event_wrapper(COMMIT, Tend, &tr->tid, &tr->ts, ok, 
Tend-Tbegin);
-
        return (ok==LOG_OK)?SQL_OK:SQL_ERR;
 }
 
@@ -7063,7 +7039,6 @@ 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(TRANSACTION_START, GDKusec(), 
&s->tr->tid, &s->tr->ts, 0, 0);
        return 0;
 }
 
@@ -7096,8 +7071,6 @@ sql_trans_end(sql_session *s, int ok)
        store->oldest = oldest;
        assert(list_length(store->active) == (int) 
ATOMIC_GET(&store->nr_active));
        store_unlock(store);
-       lng Tend = GDKusec();
-       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