From patchwork Mon Nov 16 17:25:21 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 545281 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id A62C214145B for ; Tue, 17 Nov 2015 10:47:15 +1100 (AEDT) Received: from localhost ([::1]:52262 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZyTUP-0005EI-NU for incoming@patchwork.ozlabs.org; Mon, 16 Nov 2015 18:47:13 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56490) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZyNXF-0003Mz-JF for qemu-devel@nongnu.org; Mon, 16 Nov 2015 12:25:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZyNXC-0000Qb-BF for qemu-devel@nongnu.org; Mon, 16 Nov 2015 12:25:45 -0500 Received: from mx1.redhat.com ([209.132.183.28]:45078) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZyNXC-0000Q2-1f for qemu-devel@nongnu.org; Mon, 16 Nov 2015 12:25:42 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (Postfix) with ESMTPS id B87A2C0DCCFA for ; Mon, 16 Nov 2015 17:25:41 +0000 (UTC) Received: from nilsson.home.kraxel.org (ovpn-116-57.ams2.redhat.com [10.36.116.57]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id tAGHPeep007005; Mon, 16 Nov 2015 12:25:40 -0500 Received: by nilsson.home.kraxel.org (Postfix, from userid 500) id 1CF7F819B1; Mon, 16 Nov 2015 18:25:38 +0100 (CET) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Mon, 16 Nov 2015 18:25:21 +0100 Message-Id: <1447694735-3420-7-git-send-email-kraxel@redhat.com> In-Reply-To: <1447694735-3420-1-git-send-email-kraxel@redhat.com> References: <1447694735-3420-1-git-send-email-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Gerd Hoffmann Subject: [Qemu-devel] [PULL 06/20] buffer: add tracing X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Gerd Hoffmann Reviewed-by: Peter Lieven Reviewed-by: Daniel P. Berrange Message-id: 1446203414-4013-7-git-send-email-kraxel@redhat.com --- trace-events | 6 ++++++ util/buffer.c | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/trace-events b/trace-events index 72136b9..e67ad81 100644 --- a/trace-events +++ b/trace-events @@ -1387,6 +1387,12 @@ ppc_tb_adjust(uint64_t offs1, uint64_t offs2, int64_t diff, int64_t seconds) "ad prep_io_800_writeb(uint32_t addr, uint32_t val) "0x%08" PRIx32 " => 0x%02" PRIx32 prep_io_800_readb(uint32_t addr, uint32_t retval) "0x%08" PRIx32 " <= 0x%02" PRIx32 +# io/buffer.c +buffer_resize(const char *buf, size_t olen, size_t len) "%s: old %zd, new %zd" +buffer_move_empty(const char *buf, size_t len, const char *from) "%s: %zd bytes from %s" +buffer_move(const char *buf, size_t len, const char *from) "%s: %zd bytes from %s" +buffer_free(const char *buf, size_t len) "%s: capacity %zd" + # util/hbitmap.c hbitmap_iter_skip_words(const void *hb, void *hbi, uint64_t pos, unsigned long cur) "hb %p hbi %p pos %"PRId64" cur 0x%lx" hbitmap_reset(void *hb, uint64_t start, uint64_t count, uint64_t sbit, uint64_t ebit) "hb %p items %"PRIu64",%"PRIu64" bits %"PRIu64"..%"PRIu64 diff --git a/util/buffer.c b/util/buffer.c index 234e33d..ae2907e 100644 --- a/util/buffer.c +++ b/util/buffer.c @@ -19,6 +19,7 @@ */ #include "qemu/buffer.h" +#include "trace.h" #define BUFFER_MIN_INIT_SIZE 4096 #define BUFFER_MIN_SHRINK_SIZE 65536 @@ -34,6 +35,8 @@ void buffer_init(Buffer *buffer, const char *name, ...) void buffer_shrink(Buffer *buffer) { + size_t old; + /* * Only shrink in case the used size is *much* smaller than the * capacity, to avoid bumping up & down the buffers all the time. @@ -44,17 +47,25 @@ void buffer_shrink(Buffer *buffer) return; } + old = buffer->capacity; buffer->capacity = pow2ceil(buffer->offset); buffer->capacity = MAX(buffer->capacity, BUFFER_MIN_SHRINK_SIZE); buffer->buffer = g_realloc(buffer->buffer, buffer->capacity); + trace_buffer_resize(buffer->name ?: "unnamed", + old, buffer->capacity); } void buffer_reserve(Buffer *buffer, size_t len) { + size_t old; + if ((buffer->capacity - buffer->offset) < len) { + old = buffer->capacity; buffer->capacity = pow2ceil(buffer->offset + len); buffer->capacity = MAX(buffer->capacity, BUFFER_MIN_INIT_SIZE); buffer->buffer = g_realloc(buffer->buffer, buffer->capacity); + trace_buffer_resize(buffer->name ?: "unnamed", + old, buffer->capacity); } } @@ -75,6 +86,7 @@ void buffer_reset(Buffer *buffer) void buffer_free(Buffer *buffer) { + trace_buffer_free(buffer->name ?: "unnamed", buffer->capacity); g_free(buffer->buffer); g_free(buffer->name); buffer->offset = 0; @@ -98,6 +110,9 @@ void buffer_advance(Buffer *buffer, size_t len) void buffer_move_empty(Buffer *to, Buffer *from) { + trace_buffer_move_empty(to->name ?: "unnamed", + from->offset, + from->name ?: "unnamed"); assert(to->offset == 0); g_free(to->buffer); @@ -117,6 +132,9 @@ void buffer_move(Buffer *to, Buffer *from) return; } + trace_buffer_move(to->name ?: "unnamed", + from->offset, + from->name ?: "unnamed"); buffer_reserve(to, from->offset); buffer_append(to, from->buffer, from->offset);