Bug 729182 - Implement visual event tracer, dns instrumentation, r=sworkman
authorHonza Bambas <honzab.moz@firemni.cz>
Tue, 10 Jul 2012 23:49:19 +0200
changeset 101586 ad2c42efbe57309ed037463c6a297c7358a64b10
parent 101585 30a4e0cf71304537eecdfeefc70310c9928e0430
child 101587 1f07f04ec01decf4086d97cd024cd324d5e9e698
push idunknown
push userunknown
push dateunknown
reviewerssworkman
bugs729182
milestone16.0a1
Bug 729182 - Implement visual event tracer, dns instrumentation, r=sworkman
netwerk/dns/nsDNSService2.cpp
netwerk/dns/nsHostResolver.cpp
--- a/netwerk/dns/nsDNSService2.cpp
+++ b/netwerk/dns/nsDNSService2.cpp
@@ -24,16 +24,17 @@
 #include "prmon.h"
 #include "prio.h"
 #include "plstr.h"
 #include "nsIOService.h"
 #include "nsCharSeparatedTokenizer.h"
 
 #include "mozilla/FunctionTimer.h"
 #include "mozilla/Attributes.h"
+#include "mozilla/VisualEventTracer.h"
 
 using namespace mozilla;
 
 static const char kPrefDnsCacheEntries[]    = "network.dnsCacheEntries";
 static const char kPrefDnsCacheExpiration[] = "network.dnsCacheExpiration";
 static const char kPrefDnsCacheGrace[]      = "network.dnsCacheExpirationGracePeriod";
 static const char kPrefEnableIDN[]          = "network.enableIDN";
 static const char kPrefIPv4OnlyDomains[]    = "network.dns.ipv4OnlyDomains";
@@ -273,16 +274,18 @@ nsDNSAsyncRequest::OnLookupComplete(nsHo
     nsCOMPtr<nsIDNSRecord> rec;
     if (NS_SUCCEEDED(status)) {
         NS_ASSERTION(hostRecord, "no host record");
         rec = new nsDNSRecord(hostRecord);
         if (!rec)
             status = NS_ERROR_OUT_OF_MEMORY;
     }
 
+    MOZ_EVENT_TRACER_DONE(this, "DNS");
+
     mListener->OnLookupComplete(this, rec, status);
     mListener = nsnull;
 
     // release the reference to ourselves that was added before we were
     // handed off to the host resolver.
     NS_RELEASE_THIS();
 }
 
@@ -600,16 +603,19 @@ nsDNSService::AsyncResolve(const nsACStr
     PRUint16 af = GetAFForLookup(*hostPtr, flags);
 
     nsDNSAsyncRequest *req =
             new nsDNSAsyncRequest(res, *hostPtr, listener, flags, af);
     if (!req)
         return NS_ERROR_OUT_OF_MEMORY;
     NS_ADDREF(*result = req);
 
+    MOZ_EVENT_TRACER_NAME_OBJECT(req, hostname.BeginReading());
+    MOZ_EVENT_TRACER_WAIT(req, "DNS");
+
     // addref for resolver; will be released when OnLookupComplete is called.
     NS_ADDREF(req);
     rv = res->ResolveHost(req->mHost.get(), flags, af, req);
     if (NS_FAILED(rv)) {
         NS_RELEASE(req);
         NS_RELEASE(*result);
     }
     return rv;
--- a/netwerk/dns/nsHostResolver.cpp
+++ b/netwerk/dns/nsHostResolver.cpp
@@ -32,16 +32,17 @@
 #include "plstr.h"
 #include "nsURLHelper.h"
 #include "nsThreadUtils.h"
 
 #include "mozilla/HashFunctions.h"
 #include "mozilla/FunctionTimer.h"
 #include "mozilla/TimeStamp.h"
 #include "mozilla/Telemetry.h"
+#include "mozilla/VisualEventTracer.h"
 
 using namespace mozilla;
 
 //----------------------------------------------------------------------------
 
 // Use a persistent thread pool in order to avoid spinning up new threads all the time.
 // In particular, thread creation results in a res_init() call from libc which is 
 // quite expensive.
@@ -175,16 +176,18 @@ nsHostRecord::Create(const nsHostKey *ke
     size_t hostLen = strlen(key->host) + 1;
     size_t size = hostLen + sizeof(nsHostRecord);
 
     // Use placement new to create the object with room for the hostname
     // allocated after it.
     void *place = ::operator new(size);
     *result = new(place) nsHostRecord(key);
     NS_ADDREF(*result);
+
+    MOZ_EVENT_TRACER_NAME_OBJECT(*result, key->host);
     return NS_OK;
 }
 
 nsHostRecord::~nsHostRecord()
 {
     if (addr)
         free(addr);
 }
@@ -707,16 +710,18 @@ nsHostResolver::ConditionallyCreateThrea
       LOG(("lookup waiting for thread - %s ...\n", rec->host));
 #endif
     return NS_OK;
 }
 
 nsresult
 nsHostResolver::IssueLookup(nsHostRecord *rec)
 {
+    MOZ_EVENT_TRACER_WAIT(rec, "nsHostResolver");
+
     nsresult rv = NS_OK;
     NS_ASSERTION(!rec->resolving, "record is already being resolved"); 
 
     // Add rec to one of the pending queues, possibly removing it from mEvictionQ.
     // If rec is on mEvictionQ, then we can just move the owning
     // reference over to the new active queue.
     if (rec->next == rec)
         NS_ADDREF(rec);
@@ -884,16 +889,18 @@ nsHostResolver::OnLookupComplete(nsHostR
                 }
 
                 // release reference to rec owned by mEvictionQ
                 NS_RELEASE(head);
             }
         }
     }
 
+    MOZ_EVENT_TRACER_DONE(rec, "nsHostResolver");
+
     if (!PR_CLIST_IS_EMPTY(&cbs)) {
         PRCList *node = cbs.next;
         while (node != &cbs) {
             nsResolveHostCallback *callback =
                     static_cast<nsResolveHostCallback *>(node);
             node = node->next;
             callback->OnLookupComplete(this, rec, status);
             // NOTE: callback must not be dereferenced after this point!!
@@ -967,16 +974,17 @@ nsHostResolver::ThreadFunc(void *arg)
         LOG(("resolving %s ...\n", rec->host));
 
         PRIntn flags = PR_AI_ADDRCONFIG;
         if (!(rec->flags & RES_CANON_NAME))
             flags |= PR_AI_NOCANONNAME;
 
         TimeStamp startTime = TimeStamp::Now();
 
+        MOZ_EVENT_TRACER_EXEC(rec, "nsHostResolver");
         ai = PR_GetAddrInfoByName(rec->host, rec->af, flags);
 #if defined(RES_RETRY_ON_FAILURE)
         if (!ai && rs.Reset())
             ai = PR_GetAddrInfoByName(rec->host, rec->af, flags);
 #endif
 
         TimeDuration elapsed = TimeStamp::Now() - startTime;
         PRUint32 millis = static_cast<PRUint32>(elapsed.ToMilliseconds());