提交 d2b90718 编写于 作者: G Gerd Hoffmann

buffer: add tracing

Signed-off-by: NGerd Hoffmann <kraxel@redhat.com>
Reviewed-by: NPeter Lieven <pl@kamp.de>
Reviewed-by: NDaniel P. Berrange <berrange@redhat.com>
Message-id: 1446203414-4013-7-git-send-email-kraxel@redhat.com
上级 1ff36b5d
......@@ -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
......
......@@ -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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册