From 60973fe5d1da545b0c993df1261e6b649c7b4dd9 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Fri, 21 Feb 2014 11:43:48 +0000 Subject: [PATCH] Make llcache debugging less invasive --- content/llcache.c | 100 +++++++++++++++------------------------------- 1 file changed, 33 insertions(+), 67 deletions(-) diff --git a/content/llcache.c b/content/llcache.c index b5e293002..bd7ae937e 100644 --- a/content/llcache.c +++ b/content/llcache.c @@ -38,6 +38,12 @@ /** Define to enable tracing of llcache operations. */ #undef LLCACHE_TRACE +#ifdef LLCACHE_TRACE +#define LLCACHE_LOG(x) LOG(x) +#else +#define LLCACHE_LOG(x) +#endif + /** State of a low-level cache object fetch */ typedef enum { LLCACHE_FETCH_INIT, /**< Initial state, before fetch */ @@ -200,9 +206,7 @@ static nserror llcache_object_user_new(llcache_handle_callback cb, void *pw, u->handle = h; -#ifdef LLCACHE_TRACE - LOG(("Created user %p (%p, %p, %p)", u, h, (void *) cb, pw)); -#endif + LLCACHE_LOG(("Created user %p (%p, %p, %p)", u, h, (void *) cb, pw)); *user = u; @@ -219,9 +223,7 @@ static nserror llcache_object_user_new(llcache_handle_callback cb, void *pw, */ static nserror llcache_object_user_destroy(llcache_object_user *user) { -#ifdef LLCACHE_TRACE - LOG(("Destroyed user %p", user)); -#endif + LLCACHE_LOG(("Destroyed user %p", user)); assert(user->next == NULL); assert(user->prev == NULL); @@ -260,9 +262,7 @@ static nserror llcache_object_remove_user(llcache_object *object, user->next = user->prev = NULL; -#ifdef LLCACHE_TRACE - LOG(("Removing user %p from %p", user, object)); -#endif + LLCACHE_LOG(("Removing user %p from %p", user, object)); return NSERROR_OK; } @@ -318,9 +318,7 @@ static nserror llcache_object_new(nsurl *url, llcache_object **result) if (obj == NULL) return NSERROR_NOMEM; -#ifdef LLCACHE_TRACE - LOG(("Created object %p (%s)", obj, nsurl_access(url))); -#endif + LLCACHE_LOG(("Created object %p (%s)", obj, nsurl_access(url))); obj->url = nsurl_ref(url); @@ -703,9 +701,7 @@ static nserror llcache_object_refetch(llcache_object *object) /* Reset fetch state */ object->fetch.state = LLCACHE_FETCH_INIT; -#ifdef LLCACHE_TRACE - LOG(("Refetching %p", object)); -#endif + LLCACHE_LOG(("Refetching %p", object)); /* Kick off fetch */ object->fetch.fetch = fetch_start(object->url, object->fetch.referer, @@ -751,9 +747,7 @@ static nserror llcache_object_fetch(llcache_object *object, uint32_t flags, nsurl *referer_clone = NULL; llcache_post_data *post_clone = NULL; -#ifdef LLCACHE_TRACE - LOG(("Starting fetch for %p", object)); -#endif + LLCACHE_LOG(("Starting fetch for %p", object)); if (post != NULL) { error = llcache_post_data_clone(post, &post_clone); @@ -786,9 +780,7 @@ static nserror llcache_object_destroy(llcache_object *object) { size_t i; -#ifdef LLCACHE_TRACE - LOG(("Destroying object %p", object)); -#endif + LLCACHE_LOG(("Destroying object %p", object)); nsurl_unref(object->url); free(object->source_data); @@ -872,9 +864,7 @@ llcache_object_rfc2616_remaining_lifetime(const llcache_cache_control *cd) else freshness_lifetime = 0; -#ifdef LLCACHE_TRACE - LOG(("%d:%d", freshness_lifetime, current_age)); -#endif + LLCACHE_LOG(("%d:%d", freshness_lifetime, current_age)); if ((cd->no_cache == LLCACHE_VALIDATE_FRESH) && (freshness_lifetime > current_age)) { @@ -903,11 +893,9 @@ static bool llcache_object_is_fresh(const llcache_object *object) remaining_lifetime = llcache_object_rfc2616_remaining_lifetime(cd); -#ifdef LLCACHE_TRACE - LOG(("%p: (%d > 0 || %d != %d)", object, + LLCACHE_LOG(("%p: (%d > 0 || %d != %d)", object, remaining_lifetime, object->fetch.state, LLCACHE_FETCH_COMPLETE)); -#endif /* The object is fresh if: * - it was not forbidden from being returned from the cache @@ -995,9 +983,8 @@ static nserror llcache_object_retrieve_from_cache(nsurl *url, uint32_t flags, nserror error; llcache_object *obj, *newest = NULL; -#ifdef LLCACHE_TRACE - LOG(("Searching cache for %s (%x %s %p)", url, flags, referer, post)); -#endif + LLCACHE_LOG(("Searching cache for %s (%x %p %p)", + nsurl_access(url), flags, referer, post)); /* Search for the most recently fetched matching object */ for (obj = llcache->cached_objects; obj != NULL; obj = obj->next) { @@ -1014,9 +1001,7 @@ static nserror llcache_object_retrieve_from_cache(nsurl *url, uint32_t flags, /* Found a suitable object, and it's still fresh, so use it */ obj = newest; -#ifdef LLCACHE_TRACE - LOG(("Found fresh %p", obj)); -#endif + LLCACHE_LOG(("Found fresh %p", obj)); /* The client needs to catch up with the object's state. * This will occur the next time that llcache_poll is called. @@ -1029,9 +1014,7 @@ static nserror llcache_object_retrieve_from_cache(nsurl *url, uint32_t flags, if (error != NSERROR_OK) return error; -#ifdef LLCACHE_TRACE - LOG(("Found candidate %p (%p)", obj, newest)); -#endif + LLCACHE_LOG(("Found candidate %p (%p)", obj, newest)); /* Clone candidate's cache data */ error = llcache_object_clone_cache_data(newest, obj, true); @@ -1062,9 +1045,7 @@ static nserror llcache_object_retrieve_from_cache(nsurl *url, uint32_t flags, if (error != NSERROR_OK) return error; -#ifdef LLCACHE_TRACE - LOG(("Not found %p", obj)); -#endif + LLCACHE_LOG(("Not found %p", obj)); /* Attempt to kick-off fetch */ error = llcache_object_fetch(obj, flags, referer, post, @@ -1103,9 +1084,8 @@ static nserror llcache_object_retrieve(nsurl *url, uint32_t flags, bool has_query; nsurl *defragmented_url; -#ifdef LLCACHE_TRACE - LOG(("Retrieve %s (%x, %s, %p)", url, flags, referer, post)); -#endif + LLCACHE_LOG(("Retrieve %s (%x, %p, %p)", + nsurl_access(url), flags, referer, post)); /** * Caching Rules: @@ -1158,9 +1138,7 @@ static nserror llcache_object_retrieve(nsurl *url, uint32_t flags, obj->has_query = has_query; -#ifdef LLCACHE_TRACE - LOG(("Retrieved %p", obj)); -#endif + LLCACHE_LOG(("Retrieved %p", obj)); *result = obj; @@ -1192,9 +1170,7 @@ static nserror llcache_object_add_user(llcache_object *object, object->users->prev = user; object->users = user; -#ifdef LLCACHE_TRACE - LOG(("Adding user %p to %p", user, object)); -#endif + LLCACHE_LOG(("Adding user %p to %p", user, object)); return NSERROR_OK; } @@ -1636,9 +1612,7 @@ static void llcache_fetch_callback(const fetch_msg *msg, void *p) llcache_object *object = p; llcache_event event; -#ifdef LLCACHE_TRACE - LOG(("Fetch event %d for %p", msg->type, object)); -#endif + LLCACHE_LOG(("Fetch event %d for %p", msg->type, object)); switch (msg->type) { case FETCH_HEADER: @@ -2180,9 +2154,7 @@ void llcache_clean(void) uint32_t llcache_size = 0; int remaining_lifetime; -#ifdef LLCACHE_TRACE - LOG(("Attempting cache clean")); -#endif + LLCACHE_LOG(("Attempting cache clean")); /* Candidates for cleaning are (in order of priority): * @@ -2200,9 +2172,8 @@ void llcache_clean(void) (object->candidate_count == 0) && (object->fetch.fetch == NULL) && (object->fetch.outstanding_query == false)) { -#ifdef LLCACHE_TRACE - LOG(("Found victim %p", object)); -#endif + LLCACHE_LOG(("Found victim %p", object)); + llcache_object_remove_from_list(object, &llcache->uncached_objects); llcache_object_destroy(object); @@ -2227,9 +2198,8 @@ void llcache_clean(void) llcache_size += object->source_len + sizeof(*object); } else { /* object is not fresh */ -#ifdef LLCACHE_TRACE - LOG(("Found stale cacheable object (%p) with no users or pending fetches", object)); -#endif + LLCACHE_LOG(("Found stale cacheable object (%p) with no users or pending fetches", object)); + llcache_object_remove_from_list(object, &llcache->cached_objects); llcache_object_destroy(object); @@ -2251,9 +2221,8 @@ void llcache_clean(void) (object->candidate_count == 0) && (object->fetch.fetch == NULL) && (object->fetch.outstanding_query == false)) { -#ifdef LLCACHE_TRACE - LOG(("Found victim %p", object)); -#endif + LLCACHE_LOG(("Found victim %p", object)); + llcache_size -= object->source_len + sizeof(*object); @@ -2264,10 +2233,7 @@ void llcache_clean(void) } } -#ifdef LLCACHE_TRACE - LOG(("Size: %u", llcache_size)); -#endif - + LLCACHE_LOG(("Size: %u", llcache_size)); } /* See llcache.h for documentation */