[Spice-devel] [PATCH 3/5] server: add prefix argument to red_printf_debug
Yonit Halperin
yhalperi at redhat.com
Mon Nov 7 00:23:22 PST 2011
Ack
On 11/06/2011 06:49 PM, Alon Levy wrote:
> printed before function name. No central location for prefixes.
> Adding "WORKER", "ASYNC", "MAIN" since those were the current users.
> ---
> common/spice_common.h | 4 ++--
> server/main_channel.c | 2 +-
> server/red_dispatcher.c | 17 ++++++++++++-----
> server/red_worker.c | 18 ++++++++++--------
> 4 files changed, 25 insertions(+), 16 deletions(-)
>
> diff --git a/common/spice_common.h b/common/spice_common.h
> index f6205a3..d13a94f 100644
> --- a/common/spice_common.h
> +++ b/common/spice_common.h
> @@ -65,13 +65,13 @@
> } \
> } while (0)
>
> -#define red_printf_debug(debug, format, ...) do { \
> +#define red_printf_debug(debug, prefix, format, ...) do { \
> static int debug_level = -1; \
> if (debug_level == -1) { \
> debug_level = getenv("SPICE_DEBUG_LEVEL") != NULL ? atoi(getenv("SPICE_DEBUG_LEVEL")) : 0; \
> } \
> if (debug<= debug_level) { \
> - printf("%s: " format "\n", __FUNCTION__, ## __VA_ARGS__ ); \
> + printf("%s: %s: " format "\n", prefix, __FUNCTION__, ## __VA_ARGS__ ); \
> } \
> } while(0)
>
> diff --git a/server/main_channel.c b/server/main_channel.c
> index b2439b2..24cdaea 100644
> --- a/server/main_channel.c
> +++ b/server/main_channel.c
> @@ -695,7 +695,7 @@ static void main_channel_release_pipe_item(RedChannelClient *rcc,
> case SPICE_MSG_MAIN_AGENT_DATA: {
> AgentDataPipeItem *data = (AgentDataPipeItem*)base;
> if (!--data->refs->refs) {
> - red_printf_debug(1, "SPICE_MSG_MAIN_AGENT_DATA %p %p, %d",
> + red_printf_debug(1, "MAIN", "SPICE_MSG_MAIN_AGENT_DATA %p %p, %d",
> data, data->refs, data->refs->refs);
> free(data->refs);
> data->free_data(data->data, data->opaque);
> diff --git a/server/red_dispatcher.c b/server/red_dispatcher.c
> index 6a6a9a3..10e6126 100644
> --- a/server/red_dispatcher.c
> +++ b/server/red_dispatcher.c
> @@ -44,6 +44,11 @@ static int num_active_workers = 0;
>
> //volatile
>
> +#define DBG_ASYNC(s, ...) \
> + do { \
> + red_printf_debug(2, "ASYNC", s, ##__VA_ARGS__); \
> + } while (0);
> +
> struct AsyncCommand {
> RingItem link;
> RedWorkerMessage message;
> @@ -281,6 +286,7 @@ static AsyncCommand *async_command_alloc(RedDispatcher *dispatcher,
> async_command->message = message;
> ring_add(&dispatcher->async_commands,&async_command->link);
> pthread_mutex_unlock(&dispatcher->async_lock);
> + DBG_ASYNC("%p", async_command);
> return async_command;
> }
>
> @@ -385,7 +391,7 @@ red_dispatcher_destroy_primary_surface(RedDispatcher *dispatcher,
> uint32_t surface_id, int async, uint64_t cookie)
> {
> RedWorkerMessage message;
> - AsyncCommand *cmd;
> + AsyncCommand *cmd = NULL;
>
> if (async) {
> message = RED_WORKER_MESSAGE_DESTROY_PRIMARY_SURFACE_ASYNC;
> @@ -429,7 +435,7 @@ red_dispatcher_create_primary_surface(RedDispatcher *dispatcher, uint32_t surfac
> QXLDevSurfaceCreate *surface, int async, uint64_t cookie)
> {
> RedWorkerMessage message;
> - AsyncCommand *cmd;
> + AsyncCommand *cmd = NULL;
>
> if (async) {
> message = RED_WORKER_MESSAGE_CREATE_PRIMARY_SURFACE_ASYNC;
> @@ -490,7 +496,7 @@ static void red_dispatcher_destroy_surface_wait(RedDispatcher *dispatcher, uint3
> int async, uint64_t cookie)
> {
> RedWorkerMessage message;
> - AsyncCommand *cmd;
> + AsyncCommand *cmd = NULL;
>
> if (async ) {
> message = RED_WORKER_MESSAGE_DESTROY_SURFACE_WAIT_ASYNC;
> @@ -835,9 +841,9 @@ void red_dispatcher_async_complete(struct RedDispatcher *dispatcher,
> {
> pthread_mutex_lock(&dispatcher->async_lock);
> ring_remove(&async_command->link);
> - red_printf_debug(2, "%p: cookie %" PRId64, async_command, async_command->cookie);
> + DBG_ASYNC("%p: cookie %" PRId64, async_command, async_command->cookie);
> if (ring_is_empty(&dispatcher->async_commands)) {
> - red_printf_debug(2, "%s: no more async commands", __func__);
> + red_printf_debug(2, "ASYNC", "no more async commands");
> }
> pthread_mutex_unlock(&dispatcher->async_lock);
> switch (async_command->message) {
> @@ -918,6 +924,7 @@ RedDispatcher *red_dispatcher_init(QXLInstance *qxl)
> dispatcher = spice_new0(RedDispatcher, 1);
> dispatcher->channel = channels[0];
> ring_init(&dispatcher->async_commands);
> + DBG_ASYNC("dispatcher->async_commands.next %p", dispatcher->async_commands.next);
> init_data.qxl = dispatcher->qxl = qxl;
> init_data.id = qxl->id;
> init_data.channel = channels[1];
> diff --git a/server/red_worker.c b/server/red_worker.c
> index a5c2df3..de8a820 100644
> --- a/server/red_worker.c
> +++ b/server/red_worker.c
> @@ -4778,9 +4778,9 @@ static void red_free_some(RedWorker *worker)
> DisplayChannelClient *dcc;
> RingItem *item;
>
> - red_printf_debug(3, "#draw=%d, #red_draw=%d, #glz_draw=%d", worker->drawable_count,
> - worker->red_drawable_count,
> - worker->glz_drawable_count);
> + red_printf_debug(3, "WORKER",
> + "#draw=%d, #red_draw=%d, #glz_draw=%d", worker->drawable_count,
> + worker->red_drawable_count, worker->glz_drawable_count);
> WORKER_FOREACH_DCC(worker, item, dcc) {
> GlzSharedDictionary *glz_dict = dcc ? dcc->glz_dict : NULL;
>
> @@ -8651,9 +8651,9 @@ static void display_channel_client_on_disconnect(RedChannelClient *rcc)
> if (!red_channel_is_connected(rcc->channel)) {
> red_display_destroy_compress_bufs(display_channel);
> }
> - red_printf_debug(3, "#draw=%d, #red_draw=%d, #glz_draw=%d", worker->drawable_count,
> - worker->red_drawable_count,
> - worker->glz_drawable_count);
> + red_printf_debug(3, "WORKER", "#draw=%d, #red_draw=%d, #glz_draw=%d",
> + worker->drawable_count, worker->red_drawable_count,
> + worker->glz_drawable_count);
> }
>
> void red_disconnect_all_display_TODO_remove_me(RedChannel *channel)
> @@ -10433,7 +10433,8 @@ static void handle_dev_input(EventListener *listener, uint32_t events)
> case RED_WORKER_MESSAGE_OOM:
> ASSERT(worker->running);
> // streams? but without streams also leak
> - red_printf_debug(1, "OOM1 #draw=%u, #red_draw=%u, #glz_draw=%u current %u pipes %u",
> + red_printf_debug(1, "WORKER",
> + "OOM1 #draw=%u, #red_draw=%u, #glz_draw=%u current %u pipes %u",
> worker->drawable_count,
> worker->red_drawable_count,
> worker->glz_drawable_count,
> @@ -10447,7 +10448,8 @@ static void handle_dev_input(EventListener *listener, uint32_t events)
> red_free_some(worker);
> worker->qxl->st->qif->flush_resources(worker->qxl);
> }
> - red_printf_debug(1, "OOM2 #draw=%u, #red_draw=%u, #glz_draw=%u current %u pipes %u",
> + red_printf_debug(1, "WORKER",
> + "OOM2 #draw=%u, #red_draw=%u, #glz_draw=%u current %u pipes %u",
> worker->drawable_count,
> worker->red_drawable_count,
> worker->glz_drawable_count,
More information about the Spice-devel
mailing list