From patchwork Fri Dec 2 15:59:30 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 86331 Delivered-To: patch@linaro.org Received: by 10.182.112.6 with SMTP id im6csp399259obb; Fri, 2 Dec 2016 08:07:32 -0800 (PST) X-Received: by 10.200.38.102 with SMTP id v35mr38197331qtv.100.1480694852713; Fri, 02 Dec 2016 08:07:32 -0800 (PST) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id q185si3282691qke.330.2016.12.02.08.07.32 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 02 Dec 2016 08:07:32 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:35315 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cCqN1-0008Pp-Fr for patch@linaro.org; Fri, 02 Dec 2016 11:07:31 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60475) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cCqFY-0002xC-0F for qemu-devel@nongnu.org; Fri, 02 Dec 2016 10:59:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cCqFW-0004xY-IG for qemu-devel@nongnu.org; Fri, 02 Dec 2016 10:59:48 -0500 Received: from mail-wm0-x234.google.com ([2a00:1450:400c:c09::234]:37081) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cCqFW-0004x7-B2 for qemu-devel@nongnu.org; Fri, 02 Dec 2016 10:59:46 -0500 Received: by mail-wm0-x234.google.com with SMTP id t79so19701192wmt.0 for ; Fri, 02 Dec 2016 07:59:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Pd+h89h653HrT6+m0uiJxfr1z5CLtuQzZkvex5UZKLY=; b=KBFgloxQ2h1+hFDfIWe6iV0UsApXCg7ZO/Qt7Lo4L94pdZZtaxs8dfp1EXmtJ4gecs wiG4s5NFXMIfPJIWx65C3UrbAhBwq52hTc0MlAWs1WDqZ62VUvJFCSa8+l+N/0VdICZE veVx8VvRJJdRHsxdXVveWPlFdSH1y1R/aQ9f0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Pd+h89h653HrT6+m0uiJxfr1z5CLtuQzZkvex5UZKLY=; b=JeMlHQSS3I22L5ZeGBZ847w243csgrlSI9PhpZ+HpwmtjQFvj014IGkHs91Lco9p8d KIZpxLG9B3ls5HD9IUbcXzvuxSvDXI4UFmGItCg/2ZORdntAOHI2sunhHAnJeQV8cuzr 5SdFXosHcQpb8r69qrDSqCEN3SczqEZpGn9EZuhP5Z/W+ZewFApIp0w/w6gmwruR4sKa z32oKLe/r+t/JTfhYk8zizWJun/lijIJbwLedociUg5zemaIS59xaXMl+wx1IQK3FHep 3fEe6yKXmMTXHppEmMsRula/wRy7cZWfp/FrPyEp0B6srTRtzno5FgkO7brel3CQryuI TTSw== X-Gm-Message-State: AKaTC03zzTTV1Xo0sKvHkyoUKlCVkRwT3GD2J9FZ4WLiiIXsnS3UzNZj4Ie++bcnqt+9Zk0l X-Received: by 10.28.63.150 with SMTP id m144mr3520659wma.96.1480694385080; Fri, 02 Dec 2016 07:59:45 -0800 (PST) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id g184sm3852227wme.23.2016.12.02.07.59.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Dec 2016 07:59:43 -0800 (PST) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 7409E3E03AC; Fri, 2 Dec 2016 15:59:40 +0000 (GMT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: peter.maydell@linaro.org Date: Fri, 2 Dec 2016 15:59:30 +0000 Message-Id: <20161202155935.3130-5-alex.bennee@linaro.org> X-Mailer: git-send-email 2.10.2 In-Reply-To: <20161202155935.3130-1-alex.bennee@linaro.org> References: <20161202155935.3130-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::234 Subject: [Qemu-devel] [RISU PATCH 4/9] risu: add support compressed tracefiles X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , joserz@linux.vnet.ibm.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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. Signed-off-by: Alex Bennée --- Makefile | 3 ++- configure | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ risu.c | 13 +++++++++---- 3 files changed, 66 insertions(+), 5 deletions(-) -- 2.10.2 diff --git a/Makefile b/Makefile index 4202c35..4a2ef02 100644 --- a/Makefile +++ b/Makefile @@ -14,6 +14,7 @@ include Makefile.in CFLAGS ?= -g -Wall +LDFLAGS += -lz PROG=risu SRCS=risu.c comms.c risu_$(ARCH).c risu_reginfo_$(ARCH).c @@ -31,7 +32,7 @@ all: $(PROG) $(BINS) dump: $(RISU_ASMS) $(PROG): $(OBJS) - $(CC) $(STATIC) $(CFLAGS) -o $@ $^ + $(CC) $(STATIC) $(CFLAGS) -o $@ $^ $(LDFLAGS) %.risu.asm: %.risu.bin ${OBJDUMP} -b binary -m $(ARCH) -D $^ > $@ diff --git a/configure b/configure index f81bdb5..d11680f 100755 --- a/configure +++ b/configure @@ -6,6 +6,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 < ${c}.c < +#include +#include +#include + +int main(void) { $1 thisone; return 0; } +EOF + compile $c +} + +check_lib() { + c=${tmp_dir}/check_lib${1} + cat > ${c}.c < +#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_type uintptr_t ; then + echo "#define HAVE_UINTPTR_T 1" >> $cfg + fi + if check_type socklen_t ; then + echo "#define HAVE_SOCKLEN_T 1" >> $cfg + fi + + echo "#endif /* CONFIG_H */" >> $cfg + + echo "...done" +} + generate_makefilein() { m=Makefile.in echo "generating Makefile.in..." @@ -93,6 +141,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}" @@ -100,6 +149,12 @@ if test "x${ARCH}" = "x"; then guess_arch fi +if ! check_lib z zlib "zlibVersion()"; then + echo "Cannot find libz compression library" + exit 1 +fi + +generate_config generate_makefilein echo "type 'make' to start the build" diff --git a/risu.c b/risu.c index f36b4c6..1d58d4f 100644 --- a/risu.c +++ b/risu.c @@ -25,6 +25,7 @@ #include #include #include +#include #include "risu.h" @@ -32,6 +33,7 @@ void *memblock = 0; int apprentice_socket, master_socket; int trace_file = 0; +gzFile gz_trace_file; sigjmp_buf jmpbuf; @@ -52,13 +54,13 @@ void report_test_status(void *pc) int write_trace(void *ptr, size_t bytes) { - size_t res = write(trace_file, ptr, bytes); + size_t res = gzwrite(gz_trace_file, ptr, bytes); return res == bytes; } int read_trace(void *ptr, size_t bytes) { - size_t res = read(trace_file, ptr, bytes); + size_t res = gzread(gz_trace_file, ptr, bytes); return res == bytes; } @@ -166,8 +168,9 @@ int master(int sock) { if (sigsetjmp(jmpbuf, 1)) { - if (trace_file) { - close(trace_file); + if (trace_file) + { + gzclose(gz_trace_file); fprintf(stderr,"Done...\n"); return 0; } else { @@ -284,6 +287,7 @@ int main(int argc, char **argv) if (trace_fn) { trace_file = open(trace_fn, O_WRONLY|O_CREAT, S_IRWXU); + gz_trace_file = gzdopen(trace_file, "wb9"); } else { fprintf(stderr, "master port %d\n", port); sock = master_connect(port); @@ -295,6 +299,7 @@ int main(int argc, char **argv) if (trace_fn) { trace_file = open(trace_fn, O_RDONLY); + gz_trace_file = gzdopen(trace_file, "rb"); } else { fprintf(stderr, "apprentice host %s port %d\n", hostname, port); sock = apprentice_connect(hostname, port);