From patchwork Fri Dec 9 11:48:25 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: 87447 Delivered-To: patch@linaro.org Received: by 10.140.20.101 with SMTP id 92csp264317qgi; Fri, 9 Dec 2016 03:56:12 -0800 (PST) X-Received: by 10.200.47.140 with SMTP id l12mr76387538qta.51.1481284572082; Fri, 09 Dec 2016 03:56:12 -0800 (PST) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [208.118.235.17]) by mx.google.com with ESMTPS id g46si19876545qtg.137.2016.12.09.03.56.12 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 09 Dec 2016 03:56:12 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; 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 208.118.235.17 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]:46057 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cFJmd-0004oW-MB for patch@linaro.org; Fri, 09 Dec 2016 06:56:11 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41806) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cFJgQ-0007J0-92 for qemu-devel@nongnu.org; Fri, 09 Dec 2016 06:49:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cFJgM-0007p8-44 for qemu-devel@nongnu.org; Fri, 09 Dec 2016 06:49:46 -0500 Received: from mail-wm0-f51.google.com ([74.125.82.51]:36594) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cFJgL-0007of-Ug for qemu-devel@nongnu.org; Fri, 09 Dec 2016 06:49:42 -0500 Received: by mail-wm0-f51.google.com with SMTP id g23so23076328wme.1 for ; Fri, 09 Dec 2016 03:49:41 -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=nx8wHP3dGcwGzRYHV6Mz+X0NUKIpSe128Z+EOkYfmmw=; b=QxD90Yi4gpzCM3YT8W0lXeWzKGgi3yI7qoc3NJkOZKsXQ5An6CvaWkw1xMUH14u2Z2 ju1BlMrt3MVljEjqb+lZy1vCYKI2CTUs8wCt6wXsmgmkD36CPFMIesz/Ok2si443jyOr eEz1H27CSAlyprPfUKq1ysy9nG/DBYWQUbmBY= 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=nx8wHP3dGcwGzRYHV6Mz+X0NUKIpSe128Z+EOkYfmmw=; b=dOz4VDxug6Muaz71UyomQ3tfonFKeCXQhrTkMraqLEUthJ11529W/26azSPRGb6l7+ rOWu3lzUajVrAyglWsetMkvONjWhbefcaBBFszzoJX2LBOd4/yVD8m/eBti6uuR6lrMj a3ru1utfh9MjOVo5LkP9yzNrPC3e0owGS36OtPPCvJuClC64Ggz0k10eBdqRWBG5F9Av byZZlwkgSpWQh8y2ttEjF9etm3v3xnQFm3gP1f0DICpdxhwrjfGFH87kLCa0H9oESRi8 Z/D8Vl44GFQ0/bHhdP1gphe8lLnNv0xv83tlzTdaGZ3cWeuL49sCx3EoVTQ0ZLRprbb6 Hzaw== X-Gm-Message-State: AKaTC01mNNDLV9fStkbxd7UJpZhUATQzQ/P5rT6PmFa4Tanejk3/6CZXCYCpOFQwtJuMEikk X-Received: by 10.28.37.2 with SMTP id l2mr6895179wml.86.1481284120772; Fri, 09 Dec 2016 03:48:40 -0800 (PST) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id w79sm20165869wmw.0.2016.12.09.03.48.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 09 Dec 2016 03:48:38 -0800 (PST) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id BE55B3E06F6; Fri, 9 Dec 2016 11:48:34 +0000 (GMT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: peter.maydell@linaro.org Date: Fri, 9 Dec 2016 11:48:25 +0000 Message-Id: <20161209114830.9158-6-alex.bennee@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20161209114830.9158-1-alex.bennee@linaro.org> References: <20161209114830.9158-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] [fuzzy] X-Received-From: 74.125.82.51 Subject: [Qemu-devel] [RISU PATCH v3 05/10] 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 | 15 ++++++++++----- 3 files changed, 67 insertions(+), 6 deletions(-) -- 2.11.0 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 173dd3c..3670bb1 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; @@ -59,7 +61,7 @@ int read_sock(void *ptr, size_t bytes) 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) ? 0 : 1; } @@ -77,7 +79,7 @@ int write_sock(void *ptr, size_t 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) ? 0 : 1; } @@ -203,9 +205,10 @@ int master(int sock) { if (sigsetjmp(jmpbuf, 1)) { - if (trace_file) { - close(trace_file); - fprintf(stderr,"\nDone...\n"); + if (trace_file) + { + gzclose(gz_trace_file); + fprintf(stderr,"Done...\n"); return 0; } else { return report_match_status(); @@ -321,6 +324,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); @@ -332,6 +336,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);