Changeset: 62f68b717d17 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/62f68b717d17
Modified Files:
monetdb5/mal/mal_interpreter.c
monetdb5/mal/mal_profiler.c
Branch: Dec2025
Log Message:
Some profiler cleanup.
diffs (209 lines):
diff --git a/monetdb5/mal/mal_interpreter.c b/monetdb5/mal/mal_interpreter.c
--- a/monetdb5/mal/mal_interpreter.c
+++ b/monetdb5/mal/mal_interpreter.c
@@ -498,12 +498,10 @@ runMALsequence(Client cntxt, MalBlkPtr m
ValPtr backup;
int garbages[16], *garbage;
int stkpc = 0;
- RuntimeProfileRecord runtimeProfile, runtimeProfileFunction;
+ RuntimeProfileRecord runtimeProfile = {0}, runtimeProfileFunction = {0};
lng lastcheck = 0;
bool startedProfileQueue = false;
#define CHECKINTERVAL 1000 /* how often do we check for client
disconnect */
- runtimeProfile.ticks = runtimeProfileFunction.ticks = 0;
-
if (stk == NULL)
throw(MAL, "mal.interpreter", MAL_STACK_FAIL);
@@ -824,8 +822,6 @@ runMALsequence(Client cntxt, MalBlkPtr m
break;
case ENDsymbol:
runtimeProfileExit(cntxt, mb, stk, pci,
&runtimeProfile);
- runtimeProfileExit(cntxt, mb, stk, getInstrPtr(mb, 0),
-
&runtimeProfileFunction);
if (pcicaller && garbageControl(getInstrPtr(mb, 0)))
garbageCollector(cntxt, mb, stk, TRUE);
if (cntxt->qryctx.endtime == QRY_TIMEOUT) {
@@ -1193,9 +1189,6 @@ runMALsequence(Client cntxt, MalBlkPtr m
}
}
if (stkpc == mb->stop) {
- runtimeProfileExit(cntxt, mb, stk, pci,
&runtimeProfile);
- runtimeProfileExit(cntxt, mb, stk,
getInstrPtr(mb, 0),
-
&runtimeProfileFunction);
break;
}
break;
@@ -1217,9 +1210,6 @@ runMALsequence(Client cntxt, MalBlkPtr m
if (garbageControl(getInstrPtr(mb, 0)))
garbageCollector(cntxt, mb, stk, TRUE);
/* reset the clock */
- runtimeProfileExit(cntxt, mb, stk, pp,
&runtimeProfile);
- runtimeProfileExit(cntxt, mb, stk,
getInstrPtr(mb, 0),
-
&runtimeProfileFunction);
}
stkpc = mb->stop;
continue;
@@ -1237,6 +1227,10 @@ runMALsequence(Client cntxt, MalBlkPtr m
}
}
+ if (startpc == 1 && startpc < mb->stop)
+ runtimeProfileExit(cntxt, mb, stk, getInstrPtr(mb, 0),
+ &runtimeProfileFunction);
+
/* if we could not find the exception variable, cascade a new one */
/* don't add 'exception not caught' extra message for MAL sequences
besides main function calls */
if (exceptionVar >= 0 && (ret == MAL_SUCCEED || !pcicaller)) {
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
@@ -72,30 +72,13 @@ static struct timeval startup_time;
*/
struct logbuf {
char *logbuffer;
- char *logbase;
size_t loglen;
size_t logcap;
+ allocator *ma;
};
-static inline void
-lognew(struct logbuf *logbuf)
-{
- logbuf->loglen = 0;
- logbuf->logbase = logbuf->logbuffer;
- *logbuf->logbase = 0;
-}
-
-static inline void
-logdel(struct logbuf *logbuf)
-{
- GDKfree(logbuf->logbuffer);
- logbuf->logbuffer = NULL;
-}
-
-static bool logadd(struct logbuf *logbuf,
- _In_z_ _Printf_format_string_ const char
*fmt, ...)
- __attribute__((__format__(__printf__, 2, 3)))
- __attribute__((__warn_unused_result__));
+__attribute__((__format__(__printf__, 2, 3)))
+__attribute__((__warn_unused_result__))
static bool
logadd(struct logbuf *logbuf, const char *fmt, ...)
{
@@ -107,27 +90,34 @@ logadd(struct logbuf *logbuf, const char
tmp_len = vsnprintf(tmp_buff, sizeof(tmp_buff), fmt, va);
va_end(va);
if (tmp_len < 0) {
- logdel(logbuf);
return false;
}
if (logbuf->loglen + (size_t) tmp_len >= logbuf->logcap) {
char *alloc_buff;
+ size_t oldcap = logbuf->logcap;
logbuf->logcap += (size_t) tmp_len + (size_t) tmp_len / 2;
if (logbuf->logcap < LOGLEN)
logbuf->logcap = LOGLEN;
- alloc_buff = GDKrealloc(logbuf->logbuffer, logbuf->logcap);
- if (alloc_buff == NULL) {
- TRC_ERROR(MAL_SERVER,
- "Profiler JSON buffer reallocation
failure\n");
- logdel(logbuf);
- return false;
+ if (logbuf->logbuffer == NULL)
+ logbuf->logbuffer = ma_alloc(logbuf->ma,
logbuf->logcap);
+ else {
+ alloc_buff = ma_realloc(logbuf->ma, logbuf->logbuffer,
+
logbuf->logcap, oldcap);
+ if (alloc_buff == NULL) {
+ TRC_ERROR(MAL_SERVER,
+ "Profiler JSON buffer
reallocation failure\n");
+ return false;
+ }
+ logbuf->logbuffer = alloc_buff;
}
- logbuf->logbuffer = alloc_buff;
- lognew(logbuf);
}
- if (tmp_len > 0) {
+ if ((size_t) tmp_len < sizeof(tmp_buff)) {
+ logbuf->loglen += strcpy_len(logbuf->logbuffer + logbuf->loglen,
+
tmp_buff,
+
logbuf->logcap - logbuf->loglen);
+ } else {
va_start(va, fmt);
- logbuf->loglen += vsnprintf(logbuf->logbase + logbuf->loglen,
+ logbuf->loglen += vsnprintf(logbuf->logbuffer + logbuf->loglen,
logbuf->logcap - logbuf->loglen, fmt, va);
va_end(va);
}
@@ -149,15 +139,13 @@ static str phase_descriptions[] = {
};
static str
-prepareMalEvent(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci,
- lng clk, lng ticks)
+prepareMalEvent(allocator *ma, Client cntxt, MalBlkPtr mb, MalStkPtr stk,
+ InstrPtr pci, lng clk, lng ticks)
{
- struct logbuf logbuf;
+ struct logbuf logbuf = {.ma = ma};
uint64_t mclk;
const char *algo = MT_thread_getalgorithm();
- logbuf = (struct logbuf) { 0 };
-
mclk = (uint64_t) clk - ((uint64_t) startup_time.tv_sec * 1000000 -
(uint64_t)
startup_time.tv_usec);
/* make profile event tuple */
@@ -196,7 +184,6 @@ prepareMalEvent(Client cntxt, MalBlkPtr
goto cleanup_and_exit;
return logbuf.logbuffer;
cleanup_and_exit:
- logdel(&logbuf);
return NULL;
}
@@ -384,7 +371,6 @@ sqlProfilerEvent(Client cntxt, MalBlkPtr
lng clk, lng ticks)
{
str stmt, c, ev;
- int errors = 0;
if (cntxt->profticks == NULL)
return;
@@ -398,24 +384,26 @@ sqlProfilerEvent(Client cntxt, MalBlkPtr
c++;
*/
- ev = prepareMalEvent(cntxt, mb, stk, pci, clk, ticks);
+ allocator *ta = MT_thread_getallocator();
+ allocator_state ta_state = ma_open(ta);
+
+ ev = prepareMalEvent(ta, cntxt, mb, stk, pci, clk, ticks);
// keep it a short transaction
MT_lock_set(&mal_profileLock);
if (cntxt->profticks == NULL) {
MT_lock_unset(&mal_profileLock);
+ ma_close(&ta_state);
return;
}
- errors += BUNappend(cntxt->profticks, &ticks, false) != GDK_SUCCEED;
- errors += BUNappend(cntxt->profstmt, c, false) != GDK_SUCCEED;
- errors += BUNappend(cntxt->profevents, ev ? ev : str_nil,
- false) != GDK_SUCCEED;
- if (errors > 0) {
+ if (BUNappend(cntxt->profticks, &ticks, false) != GDK_SUCCEED ||
+ BUNappend(cntxt->profstmt, c, false) != GDK_SUCCEED ||
+ BUNappend(cntxt->profevents, ev ? ev : str_nil, false) !=
GDK_SUCCEED) {
/* stop profiling if an error occurred */
cntxt->sqlprofiler = false;
}
MT_lock_unset(&mal_profileLock);
- GDKfree(ev);
+ ma_close(&ta_state);
}
/* Calculate a pessimistic size of the disk storage */
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]