summaryrefslogtreecommitdiff
path: root/src/third_party/wiredtiger/dist/log.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/third_party/wiredtiger/dist/log.py')
-rw-r--r--src/third_party/wiredtiger/dist/log.py97
1 files changed, 66 insertions, 31 deletions
diff --git a/src/third_party/wiredtiger/dist/log.py b/src/third_party/wiredtiger/dist/log.py
index feeb053db3e..6d35bf2e718 100644
--- a/src/third_party/wiredtiger/dist/log.py
+++ b/src/third_party/wiredtiger/dist/log.py
@@ -8,14 +8,15 @@ import log_data
tmp_file = '__tmp'
# Map log record types to:
-# (C type, pack type, printf format, printf arg(s), printf setup)
+# (C type, pack type, printf format, printf arg(s), list of setup functions)
field_types = {
- 'string' : ('const char *', 'S', '%s', 'arg', ''),
+ 'string' : ('const char *', 'S', '%s', 'arg', [ '' ]),
'item' : ('WT_ITEM *', 'u', '%s', 'escaped',
- 'WT_ERR(__logrec_jsonify_str(session, &escaped, &arg));'),
- 'recno' : ('uint64_t', 'r', '%" PRIu64 "', 'arg', ''),
- 'uint32' : ('uint32_t', 'I', '%" PRIu32 "', 'arg', ''),
- 'uint64' : ('uint64_t', 'Q', '%" PRIu64 "', 'arg', ''),
+ [ 'WT_ERR(__logrec_make_json_str(session, &escaped, &arg));',
+ 'WT_ERR(__logrec_make_hex_str(session, &escaped, &arg));']),
+ 'recno' : ('uint64_t', 'r', '%" PRIu64 "', 'arg', [ '' ]),
+ 'uint32' : ('uint32_t', 'I', '%" PRIu32 "', 'arg', [ '' ]),
+ 'uint64' : ('uint64_t', 'Q', '%" PRIu64 "', 'arg', [ '' ]),
}
def cintype(f):
@@ -38,15 +39,13 @@ def clocaltype(f):
return type
def escape_decl(fields):
- for f in fields:
- if 'escaped' in field_types[f[0]][4]:
- return '\n\tchar *escaped;'
- return ''
+ return '\n\tchar *escaped;' if has_escape(fields) else ''
def has_escape(fields):
for f in fields:
- if 'escaped' in field_types[f[0]][4]:
- return True
+ for setup in field_types[f[0]][4]:
+ if 'escaped' in setup:
+ return True
return False
def pack_fmt(fields):
@@ -65,10 +64,38 @@ def printf_arg(f):
arg = field_types[f[0]][3].replace('arg', f[1])
return ' ' + arg
-def printf_setup(f):
- stmt = field_types[f[0]][4].replace('arg', f[1])
- return '' if stmt == '' else stmt + '\n\t'
-
+def printf_setup(f, i, nl_indent):
+ stmt = field_types[f[0]][4][i].replace('arg', f[1])
+ return '' if stmt == '' else stmt + nl_indent
+
+def n_setup(f):
+ return len(field_types[f[0]][4])
+
+# Create a printf line, with an optional setup function.
+# ishex indicates that the the field name in the output is modified
+# (to add "-hex"), and that the setup and printf are conditional
+# in the generated code.
+def printf_line(f, optype, i, ishex):
+ ifbegin = ''
+ ifend = ''
+ nl_indent = '\n\t'
+ name = f[1]
+ postcomma = '' if i + 1 == len(optype.fields) else ',\\n'
+ precomma = ''
+ if ishex > 0:
+ name += '-hex'
+ ifend = nl_indent + '}'
+ nl_indent += '\t'
+ ifbegin = 'if (LF_ISSET(WT_TXN_PRINTLOG_HEX)) {' + nl_indent
+ if postcomma == '':
+ precomma = ',\\n'
+ body = '%s%s(__wt_fprintf(out,' % (
+ printf_setup(f, ishex, nl_indent),
+ 'WT_ERR' if has_escape(optype.fields) else 'WT_RET') + \
+ '%s "%s \\"%s\\": \\"%s\\"%s",%s));' % (
+ nl_indent, precomma, name, printf_fmt(f), postcomma,
+ printf_arg(f))
+ return ifbegin + body + ifend
#####################################################################
# Update log.h with #defines for types
@@ -176,7 +203,7 @@ __logrec_json_unpack_str(char *dest, size_t destlen, const char *src,
}
static int
-__logrec_jsonify_str(WT_SESSION_IMPL *session, char **destp, WT_ITEM *item)
+__logrec_make_json_str(WT_SESSION_IMPL *session, char **destp, WT_ITEM *item)
{
\tsize_t needed;
@@ -185,6 +212,17 @@ __logrec_jsonify_str(WT_SESSION_IMPL *session, char **destp, WT_ITEM *item)
\t(void)__logrec_json_unpack_str(*destp, needed, item->data, item->size);
\treturn (0);
}
+
+static int
+__logrec_make_hex_str(WT_SESSION_IMPL *session, char **destp, WT_ITEM *item)
+{
+\tsize_t needed;
+
+\tneeded = item->size * 2 + 1;
+\tWT_RET(__wt_realloc(session, NULL, needed, destp));
+\t__wt_fill_hex(item->data, item->size, (uint8_t *)*destp, needed, NULL);
+\treturn (0);
+}
''')
# Emit code to read, write and print log operations (within a log record)
@@ -255,11 +293,12 @@ __wt_logop_%(name)s_unpack(
tfile.write('''
int
__wt_logop_%(name)s_print(
- WT_SESSION_IMPL *session, const uint8_t **pp, const uint8_t *end, FILE *out)
+ WT_SESSION_IMPL *session, const uint8_t **pp, const uint8_t *end,
+ FILE *out, uint32_t flags)
{
%(arg_ret)s\t%(arg_decls)s
-\t%(arg_init)sWT_RET(__wt_logop_%(name)s_unpack(
+\t%(arg_unused)s%(arg_init)sWT_RET(__wt_logop_%(name)s_unpack(
\t session, pp, end%(arg_addrs)s));
\tWT_RET(__wt_fprintf(out, " \\"optype\\": \\"%(name)s\\",\\n"));
@@ -272,27 +311,22 @@ __wt_logop_%(name)s_print(
'arg_decls' : ('\n\t'.join('%s%s%s;' %
(clocaltype(f), '' if clocaltype(f)[-1] == '*' else ' ', f[1])
for f in optype.fields)) + escape_decl(optype.fields),
+ 'arg_unused' : ('' if has_escape(optype.fields)
+ else 'WT_UNUSED(flags);\n\t'),
'arg_init' : ('escaped = NULL;\n\t' if has_escape(optype.fields) else ''),
'arg_fini' : ('\nerr:\t__wt_free(session, escaped);\n\treturn (ret);'
if has_escape(optype.fields) else '\treturn (0);'),
'arg_addrs' : ''.join(', &%s' % f[1] for f in optype.fields),
- 'print_args' : '\n\t'.join(
- '%s%s(__wt_fprintf(out,\n\t " \\"%s\\": \\"%s\\",\\n",%s));' %
- (printf_setup(f),
- 'WT_ERR' if has_escape(optype.fields) else 'WT_RET',
- f[1], printf_fmt(f), printf_arg(f))
- for f in optype.fields[:-1]) + str(
- '\n\t%s%s(__wt_fprintf(out,\n\t " \\"%s\\": \\"%s\\"",%s));' %
- (printf_setup(last_field),
- 'WT_ERR' if has_escape(optype.fields) else 'WT_RET',
- last_field[1], printf_fmt(last_field), printf_arg(last_field))),
+ 'print_args' : '\n\t'.join(printf_line(f, optype, i, s)
+ for i,f in enumerate(optype.fields) for s in range(0, n_setup(f)))
})
# Emit the printlog entry point
tfile.write('''
int
__wt_txn_op_printlog(
- WT_SESSION_IMPL *session, const uint8_t **pp, const uint8_t *end, FILE *out)
+ WT_SESSION_IMPL *session, const uint8_t **pp, const uint8_t *end,
+ FILE *out, uint32_t flags)
{
\tuint32_t optype, opsize;
@@ -308,7 +342,8 @@ for optype in log_data.optypes:
tfile.write('''
\tcase %(macro)s:
-\t\tWT_RET(%(print_func)s(session, pp, end, out));
+\t\tWT_RET(%(print_func)s(session, pp, end, out,
+\t\t flags));
\t\tbreak;
''' % {
'macro' : optype.macro_name(),