From: "Alex Bennée" <alex.bennee@linaro.org>
To: peter.maydell@linaro.org
Cc: qemu-devel@nongnu.org, "Alex Bennée" <alex.bennee@linaro.org>
Subject: [Qemu-devel] [RISU PATCH v6 08/10] risu: add support compressed tracefiles
Date: Wed, 21 Jun 2017 16:42:42 +0100 [thread overview]
Message-ID: <20170621154244.28309-9-alex.bennee@linaro.org> (raw)
In-Reply-To: <20170621154244.28309-1-alex.bennee@linaro.org>
This uses the magic of zlib's gzread/write interface to wrap the
tracefile in compression. The code changes are tiny. I spent more time
messing about with the configure/linker stuff to auto-detect bits.
As you need decent multi-arch support or a correctly setup cross
toolchain we fall back if we can't compile with zlib. This
unfortunately needs some #ifdef hackery around the zlib bits in
risu.c.
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
--
v5
- re-base
- also don't use zlib if using stdio fds
v4
- removed redundant config.h output, added HAVE_ZLIB
- added BUILD_INC to deal with out-of-tree builds
---
Makefile | 4 ++--
configure | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++--
risu.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++--
3 files changed, 101 insertions(+), 6 deletions(-)
diff --git a/Makefile b/Makefile
index 9a29bb4..ca80eef 100644
--- a/Makefile
+++ b/Makefile
@@ -17,7 +17,7 @@ VPATH=$(SRCDIR)
CFLAGS ?= -g
-ALL_CFLAGS = -Wall -D_GNU_SOURCE -DARCH=$(ARCH) $(CFLAGS) $(EXTRA_CFLAGS)
+ALL_CFLAGS = -Wall -D_GNU_SOURCE -DARCH=$(ARCH) $(BUILD_INC) $(CFLAGS) $(EXTRA_CFLAGS)
PROG=risu
SRCS=risu.c comms.c reginfo.c risu_$(ARCH).c risu_reginfo_$(ARCH).c
@@ -35,7 +35,7 @@ all: $(PROG) $(BINS)
dump: $(RISU_ASMS)
$(PROG): $(OBJS)
- $(CC) $(STATIC) $(ALL_CFLAGS) -o $@ $^
+ $(CC) $(STATIC) $(ALL_CFLAGS) -o $@ $^ $(LDFLAGS)
%.risu.asm: %.risu.bin
${OBJDUMP} -b binary -m $(ARCH) -D $^ > $@
diff --git a/configure b/configure
index c4b5adb..1dc527b 100755
--- a/configure
+++ b/configure
@@ -32,6 +32,10 @@ compile() {
$CC $CFLAGS -c -o ${1}.o ${1}.c 2>/dev/null
}
+link() {
+ $LD $LDFLAGS -l${2} -o ${1} ${1}.o 2>/dev/null
+}
+
check_define() {
c=${tmp_dir}/check_define_${1}
cat > ${c}.c <<EOF
@@ -58,6 +62,48 @@ guess_arch() {
fi
}
+check_type() {
+ c=${tmp_dir}/check_type_${1}
+ cat > ${c}.c <<EOF
+#include <inttypes.h>
+#include <stdint.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+
+int main(void) { $1 thisone; return 0; }
+EOF
+ compile $c
+}
+
+check_lib() {
+ c=${tmp_dir}/check_lib${1}
+ cat > ${c}.c <<EOF
+#include <stdint.h>
+#include <$2.h>
+
+int main(void) { $3; return 0; }
+EOF
+ compile $c && link $c $1
+}
+
+generate_config() {
+ cfg=config.h
+ echo "generating config.h..."
+
+ echo "/* config.h - generated by the 'configure' script */" > $cfg
+ echo "#ifndef CONFIG_H" >> $cfg
+ echo "#define CONFIG_H 1" >> $cfg
+
+ if check_lib z zlib "zlibVersion()"; then
+ echo "#define HAVE_ZLIB 1" >> $cfg
+ LDFLAGS=-lz
+ fi
+
+ echo "#endif /* CONFIG_H */" >> $cfg
+
+ echo "...done"
+}
+
generate_makefilein() {
m=Makefile.in
echo "generating Makefile.in..."
@@ -65,11 +111,13 @@ generate_makefilein() {
echo "# Makefile.in - generated by the 'configure' script" > $m
echo "ARCH:=${ARCH}" >> $m
echo "CC:=${CC}" >> $m
+ echo "LDFLAGS:=${LDFLAGS}" >> $m
echo "AS:=${AS}" >> $m
echo "OBJCOPY:=${OBJCOPY}" >> $m
echo "OBJDUMP:=${OBJDUMP}" >> $m
echo "STATIC:=${STATIC}" >> $m
echo "SRCDIR:=${SRCDIR}" >> $m
+ echo "BUILD_INC:=${BUILD_INC}" >> $m
echo "...done"
}
@@ -118,6 +166,7 @@ done
CC="${CC-${CROSS_PREFIX}gcc}"
AS="${AS-${CROSS_PREFIX}as}"
+LD="${LD-${CROSS_PREFIX}ld}"
OBJCOPY="${OBJCOPY-${CROSS_PREFIX}objcopy}"
OBJDUMP="${OBJDUMP-${CROSS_PREFIX}objdump}"
@@ -125,15 +174,17 @@ if test "x${ARCH}" = "x"; then
guess_arch
fi
-generate_makefilein
-
# Are we in a separate build tree? If so, link the Makefile
# so that 'make' works.
if test ! -e Makefile; then
echo "linking Makefile..."
+ BUILD_INC="-I $(pwd)"
ln -s "${SRCDIR}/Makefile" .
fi
+generate_config
+generate_makefilein
+
rm -r "$tmp_dir"
echo "type 'make' to start the build"
diff --git a/risu.c b/risu.c
index 476475c..47e50ad 100644
--- a/risu.c
+++ b/risu.c
@@ -26,6 +26,8 @@
#include <fcntl.h>
#include <string.h>
+#include "config.h"
+
#include "risu.h"
void *memblock;
@@ -34,6 +36,11 @@ int apprentice_fd, master_fd;
int trace;
size_t signal_count;
+#ifdef HAVE_ZLIB
+#include <zlib.h>
+gzFile gz_trace_file;
+#endif
+
sigjmp_buf jmpbuf;
/* Should we test for FP exception status bits? */
@@ -48,7 +55,17 @@ int read_sock(void *ptr, size_t bytes)
int write_trace(void *ptr, size_t bytes)
{
- size_t res = write(master_fd, ptr, bytes);
+ size_t res;
+
+#ifdef HAVE_ZLIB
+ if (master_fd == STDOUT_FILENO) {
+#endif
+ res = write(master_fd, ptr, bytes);
+#ifdef HAVE_ZLIB
+ } else {
+ res = gzwrite(gz_trace_file, ptr, bytes);
+ }
+#endif
return (res == bytes) ? 0 : 1;
}
@@ -66,7 +83,18 @@ int write_sock(void *ptr, size_t bytes)
int read_trace(void *ptr, size_t bytes)
{
- size_t res = read(apprentice_fd, ptr, bytes);
+ size_t res;
+
+#ifdef HAVE_ZLIB
+ if (apprentice_fd == STDIN_FILENO) {
+#endif
+ res = read(apprentice_fd, ptr, bytes);
+#ifdef HAVE_ZLIB
+ } else {
+ res = gzread(gz_trace_file, ptr, bytes);
+ }
+#endif
+
return (res == bytes) ? 0 : 1;
}
@@ -189,6 +217,11 @@ void load_image(const char *imgfile)
int master(void)
{
if (sigsetjmp(jmpbuf, 1)) {
+#ifdef HAVE_ZLIB
+ if (trace && master_fd != STDOUT_FILENO) {
+ gzclose(gz_trace_file);
+ }
+#endif
close(master_fd);
if (trace) {
fprintf(stderr, "trace complete after %zd checkpoints\n", signal_count);
@@ -209,6 +242,11 @@ int master(void)
int apprentice(void)
{
if (sigsetjmp(jmpbuf, 1)) {
+#ifdef HAVE_ZLIB
+ if (trace && apprentice_fd != STDIN_FILENO) {
+ gzclose(gz_trace_file);
+ }
+#endif
close(apprentice_fd);
fprintf(stderr, "finished early after %zd checkpoints\n", signal_count);
return report_match_status();
@@ -316,6 +354,9 @@ int main(int argc, char **argv)
master_fd = STDOUT_FILENO;
} else {
master_fd = open(trace_fn, O_WRONLY|O_CREAT, S_IRWXU);
+#ifdef HAVE_ZLIB
+ gz_trace_file = gzdopen(master_fd, "wb9");
+#endif
}
} else {
fprintf(stderr, "master port %d\n", port);
@@ -328,6 +369,9 @@ int main(int argc, char **argv)
apprentice_fd = STDIN_FILENO;
} else {
apprentice_fd = open(trace_fn, O_RDONLY);
+#ifdef HAVE_ZLIB
+ gz_trace_file = gzdopen(apprentice_fd, "rb");
+#endif
}
} else {
fprintf(stderr, "apprentice host %s port %d\n", hostname, port);
--
2.13.0
next prev parent reply other threads:[~2017-06-21 15:42 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-21 15:42 [Qemu-devel] [RISU PATCH v6 00/10] Record/replay patches Alex Bennée
2017-06-21 15:42 ` [Qemu-devel] [RISU PATCH v6 01/10] README: document the coding style used for risu Alex Bennée
2017-06-21 15:42 ` [Qemu-devel] [RISU PATCH v6 02/10] build-all-archs: support cross building via docker Alex Bennée
2017-06-29 13:07 ` Philippe Mathieu-Daudé
2017-06-29 13:27 ` Alex Bennée
2017-06-29 13:43 ` Philippe Mathieu-Daudé
2017-06-21 15:42 ` [Qemu-devel] [RISU PATCH v6 03/10] risu: a bit more verbosity when starting Alex Bennée
2017-06-21 15:42 ` [Qemu-devel] [RISU PATCH v6 04/10] risu: paramterise send/receive functions Alex Bennée
2017-06-21 15:42 ` [Qemu-devel] [RISU PATCH v6 05/10] risu: add header to trace stream Alex Bennée
2017-06-21 15:42 ` [Qemu-devel] [RISU PATCH v6 06/10] risu: add simple trace and replay support Alex Bennée
2017-06-21 15:42 ` [Qemu-devel] [RISU PATCH v6 07/10] risu: handle trace through stdin/stdout Alex Bennée
2017-06-21 15:42 ` Alex Bennée [this message]
2017-06-21 15:42 ` [Qemu-devel] [RISU PATCH v6 09/10] new: record_traces.sh helper script Alex Bennée
2017-06-21 15:42 ` [Qemu-devel] [RISU PATCH v6 10/10] new: run_risu.sh script Alex Bennée
2017-06-29 11:15 ` [Qemu-devel] [RISU PATCH v6 00/10] Record/replay patches Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170621154244.28309-9-alex.bennee@linaro.org \
--to=alex.bennee@linaro.org \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).