Changeset: f06b7ae1e301 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=f06b7ae1e301
Modified Files:
common/stream/bs.c
common/stream/stream.c
common/stream/stream.h
sql/backends/monet5/sql.c
Branch: copybinary
Log Message:
Add bs tracing
diffs (254 lines):
diff --git a/common/stream/bs.c b/common/stream/bs.c
--- a/common/stream/bs.c
+++ b/common/stream/bs.c
@@ -10,6 +10,32 @@
#include "stream.h"
#include "stream_internal.h"
+void joerijoeri(char *func, const char *buf, size_t count, ssize_t result);
+
+#define SHOW (15)
+
+void
+joerijoeri(char *func, const char *buf, size_t count, ssize_t result)
+{
+ char hex[2 * SHOW + 1];
+ char txt[SHOW + 1];
+ char *h = hex;
+ char *t = txt;
+
+ if (count > 0) {
+ for (size_t i = 0; i < SHOW && i < count; i++) {
+ unsigned char c = buf[i];
+ h += snprintf(h, hex + sizeof(hex) - h, "%02x", c);
+ *t++ = isprint(c) ? c : '.';
+ }
+ }
+ *t = '\0';
+ *h = '\0';
+
+ joeri_log("%s %ld bytes -> %ld: %s '%s'\n", func, (long) count,
(long)result, hex, txt);
+
+
+}
/* ------------------------------------------------------------------ */
@@ -46,10 +72,13 @@ bs_write(stream *restrict ss, const void
bs *s;
size_t todo = cnt * elmsize;
uint16_t blksize;
+ size_t requested = todo;
s = (bs *) ss->stream_data.p;
- if (s == NULL)
+ if (s == NULL) {
+ joerijoeri("bs_write", buf, requested, -1);
return -1;
+ }
assert(!ss->readonly);
assert(s->nr < sizeof(s->buf));
while (todo > 0) {
@@ -88,12 +117,14 @@ bs_write(stream *restrict ss, const void
ss->inner->write(ss->inner, s->buf, 1, s->nr) !=
(ssize_t) s->nr) {
mnstr_copy_error(ss, ss->inner);
s->nr = 0; /* data is lost due to error */
+ joerijoeri("bs_write", buf, requested, -1);
return -1;
}
s->blks++;
s->nr = 0;
}
}
+ joerijoeri("bs_write", buf, requested, cnt);
return (ssize_t) cnt;
}
@@ -109,8 +140,10 @@ bs_flush(stream *ss, mnstr_flush_level f
bs *s;
s = (bs *) ss->stream_data.p;
- if (s == NULL)
+ if (s == NULL) {
+ joerijoeri("bs_flush", NULL, 0, -1);
return -1;
+ }
assert(!ss->readonly);
assert(s->nr < sizeof(s->buf));
if (!ss->readonly) {
@@ -141,6 +174,7 @@ bs_flush(stream *ss, mnstr_flush_level f
ss->inner->write(ss->inner, s->buf, 1, s->nr) !=
(ssize_t) s->nr))) {
mnstr_copy_error(ss, ss->inner);
s->nr = 0; /* data is lost due to error */
+ joerijoeri("bs_flush", NULL, 0, -1);
return -1;
}
// shouldn't we flush ss->inner too?
@@ -148,6 +182,7 @@ bs_flush(stream *ss, mnstr_flush_level f
s->blks++;
s->nr = 0;
}
+ joerijoeri("bs_flush", NULL, 0, 0);
return 0;
}
@@ -167,10 +202,13 @@ bs_read(stream *restrict ss, void *restr
bs *s;
size_t todo = cnt * elmsize;
size_t n;
+ size_t requested = todo;
s = (bs *) ss->stream_data.p;
- if (s == NULL)
+ if (s == NULL) {
+ joerijoeri("bs_read", buf, requested, -1);
return -1;
+ }
assert(ss->readonly);
assert(s->nr <= 1);
@@ -183,6 +221,7 @@ bs_read(stream *restrict ss, void *restr
* that we did by setting s->nr to 0. */
assert(s->nr == 1);
s->nr = 0;
+ joerijoeri("bs_read", buf, requested, 0);
return 0;
}
@@ -193,14 +232,17 @@ bs_read(stream *restrict ss, void *restr
switch (mnstr_readSht(ss->inner, &blksize)) {
case -1:
mnstr_copy_error(ss, ss->inner);
+ joerijoeri("bs_read", buf, requested, -1);
return -1;
case 0:
+ joerijoeri("bs_read", buf, requested, 0);
return 0;
case 1:
break;
}
if ((uint16_t) blksize > (BLOCK << 1 | 1)) {
mnstr_set_error(ss, MNSTR_READ_ERROR, "invalid block
size %d", blksize);
+ joerijoeri("bs_read", buf, requested, -1);
return -1;
}
#ifdef BSTREAM_DEBUG
@@ -225,6 +267,7 @@ bs_read(stream *restrict ss, void *restr
if (m <= 0) {
mnstr_copy_error(ss, ss->inner);
+ joerijoeri("bs_read", buf, requested, -1);
return -1;
}
#ifdef BSTREAM_DEBUG
@@ -259,14 +302,17 @@ bs_read(stream *restrict ss, void *restr
switch (mnstr_readSht(ss->inner, &blksize)) {
case -1:
mnstr_copy_error(ss, ss->inner);
+ joerijoeri("bs_read", buf, requested, -1);
return -1;
case 0:
+ joerijoeri("bs_read", buf, requested, 0);
return 0;
case 1:
break;
}
if ((uint16_t) blksize > (BLOCK << 1 | 1)) {
mnstr_set_error(ss, MNSTR_READ_ERROR, "invalid
block size %d", blksize);
+ joerijoeri("bs_read", buf, requested, -1);
return -1;
}
#ifdef BSTREAM_DEBUG
@@ -287,6 +333,7 @@ bs_read(stream *restrict ss, void *restr
* empty read */
if (todo > 0 && cnt == 0)
s->nr = 0;
+ joerijoeri("bs_read", buf, requested, (ssize_t) (elmsize > 0 ? cnt /
elmsize : 0));
return (ssize_t) (elmsize > 0 ? cnt / elmsize : 0);
}
diff --git a/common/stream/stream.c b/common/stream/stream.c
--- a/common/stream/stream.c
+++ b/common/stream/stream.c
@@ -54,6 +54,46 @@
#include "monetdb_config.h"
#include "stream.h"
#include "stream_internal.h"
+#include <stdio.h>
+
+static char *logfile_mode = "w";
+static FILE *logfile = NULL;
+
+void
+joeri_role(const char *role)
+{
+ if (logfile != NULL) {
+ fclose(logfile);
+ logfile = NULL;
+ }
+ if (role) {
+ const char *fmt = "/tmp/joeri_%s.log";
+ size_t needed = 2 + snprintf(NULL, 0, fmt, role);
+ char *buf = malloc(needed);
+ snprintf(buf, needed, fmt, role);
+ logfile = fopen(buf, logfile_mode);
+ if (!logfile) {
+ fprintf(stderr, "couldn't open logfile %s: %s", buf,
strerror(errno));
+ }
+ logfile_mode = "a";
+ free(buf);
+ }
+}
+
+void
+joeri_log(const char *fmt, ...)
+{
+ if (logfile == NULL)
+ return;
+
+ va_list ap;
+ va_start(ap, fmt);
+ vfprintf(logfile, fmt, ap);
+ fflush(logfile);
+ va_end(ap);
+}
+
+
#ifdef HAVE_PTHREAD_H
#include <pthread.h>
diff --git a/common/stream/stream.h b/common/stream/stream.h
--- a/common/stream/stream.h
+++ b/common/stream/stream.h
@@ -228,6 +228,10 @@ stream_export stream *block_stream(strea
stream_export bool isa_block_stream(const stream *s); // mapi.c, mal_client.c,
remote.c, sql_scenario.c/sqlReader, sql_scan.c
stream_export stream *bs_stream(stream *s); // unused
+stream_export void joeri_role(const char *role);
+stream_export void joeri_log(const char *fmt, ...)
+ __attribute__((__format__(__printf__, 1, 2)))
+;
typedef enum {
PROTOCOL_AUTO = 0, // unused
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
@@ -3310,6 +3310,8 @@ mvc_bin_import_table_wrap(Client cntxt,
if (tpe <= TYPE_str || tpe == TYPE_date || tpe == TYPE_daytime
|| tpe == TYPE_timestamp) {
if (onclient) {
+ joeri_role("server");
+ joeri_log("mvc_bin_import_table_wrap:
onclient\n");
mnstr_write(be->mvc->scanner.ws, PROMPT3,
sizeof(PROMPT3)-1, 1);
mnstr_printf(be->mvc->scanner.ws, "rb %s\n",
fname);
msg = MAL_SUCCEED;
@@ -3337,6 +3339,8 @@ mvc_bin_import_table_wrap(Client cntxt,
be->mvc->scanner.rs->eof = s->eof;
s->s = NULL;
bstream_destroy(s);
+ joeri_log("mvc_bin_import_table_wrap: onclient
done\n");
+ joeri_role(NULL);
} else if (tpe == TYPE_str) {
/* get the BAT and fill it with the strings */
c = COLnew(0, TYPE_str, 0, TRANSIENT);
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list