* TODO: Licensing
*/
+#define _GNU_SOURCE
#include <stdio.h>
#include <stdint.h>
#include <glib.h>
#include <string.h>
+#include <unistd.h>
#include <sys/mman.h>
+#include <sys/syscall.h>
+#include <sys/types.h>
#include "bluesky-private.h"
/**** 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)
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);
}
{
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;