From: Michael Vrable Date: Tue, 23 Nov 2010 23:48:41 +0000 (-0800) Subject: Add locking, thread-ID tracking to profiling. X-Git-Url: https://git.vrable.net/?a=commitdiff_plain;h=e9da632729d04d23ae7f4be4c3fcdd7c1c432e85;p=bluesky.git Add locking, thread-ID tracking to profiling. --- diff --git a/bluesky/bluesky.h b/bluesky/bluesky.h index 6bbf4a2..653adc8 100644 --- a/bluesky/bluesky.h +++ b/bluesky/bluesky.h @@ -368,6 +368,7 @@ void bluesky_debug_dump(BlueSkyFS *fs); /* Request response time tracking. */ typedef struct BlueSkyProfile { + GMutex *lock; char *description; GList *events; } BlueSkyProfile; diff --git a/bluesky/util.c b/bluesky/util.c index 90eda70..99e341f 100644 --- a/bluesky/util.c +++ b/bluesky/util.c @@ -6,11 +6,15 @@ * TODO: Licensing */ +#define _GNU_SOURCE #include #include #include #include +#include #include +#include +#include #include "bluesky-private.h" @@ -340,13 +344,16 @@ void bluesky_rangeset_get_extents(BlueSkyRangeset *rangeset, /**** Request response-time tracking. ****/ /* TODO: Locking */ typedef struct { + int tid; bluesky_time_hires timestamp; char *message; } RTEvent; BlueSkyProfile *bluesky_profile_new() { - return g_new0(BlueSkyProfile, 1); + BlueSkyProfile *profile = g_new0(BlueSkyProfile, 1); + profile->lock = g_mutex_new(); + return profile; } void bluesky_profile_free(BlueSkyProfile *profile) @@ -357,6 +364,7 @@ void bluesky_profile_free(BlueSkyProfile *profile) g_free(event); profile->events = g_list_delete_link(profile->events, profile->events); } + g_mutex_free(profile->lock); g_free(profile->description); g_free(profile); } @@ -365,26 +373,32 @@ void bluesky_profile_add_event(BlueSkyProfile *profile, char *message) { g_return_if_fail(profile != NULL); + g_mutex_lock(profile->lock); RTEvent *event = g_new(RTEvent, 1); event->timestamp = bluesky_now_hires(); + /* FIXME: Non-portable */ + event->tid = syscall(SYS_gettid); event->message = message; profile->events = g_list_prepend(profile->events, event); + g_mutex_unlock(profile->lock); } void bluesky_profile_print(BlueSkyProfile *profile) { g_return_if_fail(profile != NULL); + g_mutex_lock(profile->lock); g_print("Event Timeline: %s\n", profile->description); GList *link = g_list_last(profile->events); bluesky_time_hires last_time = 0; while (link != NULL) { RTEvent *event = (RTEvent *)link->data; - g_print(" [%"PRIi64" ns]: %s\n", - event->timestamp - last_time, event->message); + g_print(" [%d] [%"PRIi64" ns]: %s\n", + event->tid, event->timestamp - last_time, event->message); last_time = event->timestamp; link = link->prev; } + g_mutex_unlock(profile->lock); } static GStaticPrivate per_thread_profile = G_STATIC_PRIVATE_INIT;