tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit cbe7ee8b10c8f12c5056d4f1ba23e119d5ad437c
parent 8e988ae55dddbc4019bb498c39b20080183b10ac
Author: acreskeyMoz <acreskey@mozilla.com>
Date:   Mon, 10 Nov 2025 14:45:39 +0000

Bug 1992479 - Add profiler markers for dns resolution r=necko-reviewers,canaltinova,jesup,valentin

Add profiler interval markers to help in debugging dns performance.

Differential Revision: https://phabricator.services.mozilla.com/D267450

Diffstat:
Mnetwerk/dns/TRRService.cpp | 5+++++
Mnetwerk/dns/nsHostRecord.cpp | 41+++++++++++++++++++++++++++++++++++++++++
Mnetwerk/dns/nsHostResolver.cpp | 45---------------------------------------------
3 files changed, 46 insertions(+), 45 deletions(-)

diff --git a/netwerk/dns/TRRService.cpp b/netwerk/dns/TRRService.cpp @@ -27,6 +27,7 @@ #include "mozilla/glean/NetwerkMetrics.h" #include "mozilla/net/NeckoParent.h" #include "mozilla/net/TRRServiceChild.h" +#include "mozilla/ProfilerMarkers.h" // Put DNSLogging.h at the end to avoid LOG being overwritten by other headers. #include "DNSLogging.h" @@ -1299,8 +1300,12 @@ void TRRService::ConfirmationContext::CompleteConfirmation(nsresult aStatus, MOZ_ASSERT(mTask); if (NS_SUCCEEDED(aStatus)) { + profiler_add_marker("TRR Confirmation Success", + geckoprofiler::category::NETWORK); HandleEvent(ConfirmationEvent::ConfirmOK, lock); } else { + profiler_add_marker("TRR Confirmation Failure", + geckoprofiler::category::NETWORK); HandleEvent(ConfirmationEvent::ConfirmFail, lock); } diff --git a/netwerk/dns/nsHostRecord.cpp b/netwerk/dns/nsHostRecord.cpp @@ -11,6 +11,7 @@ #include "mozilla/glean/NetwerkDnsMetrics.h" #include "mozilla/ThreadSafety.h" #include "TRRService.h" +#include "mozilla/ProfilerMarkers.h" //---------------------------------------------------------------------------- // this macro filters out any flags that are not used when constructing the @@ -32,6 +33,34 @@ using namespace mozilla; using namespace mozilla::net; +struct HostResolverMarker { + static constexpr mozilla::Span<const char> MarkerTypeName() { + return mozilla::MakeStringSpan("HostResolver"); + } + static void StreamJSONMarkerData( + mozilla::baseprofiler::SpliceableJSONWriter& aWriter, + const mozilla::ProfilerString8View& aHost, + const mozilla::ProfilerString8View& aOriginSuffix, uint16_t aType, + uint32_t aFlags) { + aWriter.StringProperty("host", aHost); + aWriter.StringProperty("originSuffix", aOriginSuffix); + aWriter.IntProperty("qtype", aType); + aWriter.StringProperty("flags", nsPrintfCString("0x%x", aFlags)); + } + static MarkerSchema MarkerTypeDisplay() { + using MS = MarkerSchema; + MS schema{MS::Location::MarkerChart, MS::Location::MarkerTable}; + schema.SetTableLabel("{marker.data.host}"); + schema.AddKeyFormat("host", MS::Format::SanitizedString, + MS::PayloadFlags::Searchable); + schema.AddKeyFormat("originSuffix", MS::Format::SanitizedString, + MS::PayloadFlags::Searchable); + schema.AddKeyFormat("qtype", MS::Format::Integer); + schema.AddKeyFormat("flags", MS::Format::String); + return schema; + } +}; + nsHostKey::nsHostKey(const nsACString& aHost, const nsACString& aTrrServer, uint16_t aType, nsIDNSService::DNSFlags aFlags, uint16_t aAf, bool aPb, const nsACString& aOriginsuffix) @@ -286,9 +315,16 @@ void AddrHostRecord::NotifyRetryingTrr() { } void AddrHostRecord::ResolveComplete() { + TimeStamp now = TimeStamp::Now(); + if (LoadNativeUsed()) { if (mNativeSuccess) { glean::dns::native_lookup_time.AccumulateRawDuration(mNativeDuration); + profiler_add_marker( + "Native DNS Lookup", geckoprofiler::category::NETWORK, + MarkerOptions(MarkerTiming::Interval(mNativeStart, now), + MarkerThreadId::MainThread()), + HostResolverMarker{}, host, originSuffix, type, flags); } glean::dns::lookup_disposition .Get(TRRService::ProviderKey(), @@ -302,6 +338,11 @@ void AddrHostRecord::ResolveComplete() { mozilla::net::TRRSkippedReason::TRR_OK); glean::dns::trr_lookup_time.Get(TRRService::ProviderKey()) .AccumulateRawDuration(mTrrDuration); + profiler_add_marker( + "TRR DNS Lookup", geckoprofiler::category::NETWORK, + MarkerOptions(MarkerTiming::Interval(now - mTrrDuration, now), + MarkerThreadId::MainThread()), + HostResolverMarker{}, host, originSuffix, type, flags); } glean::dns::lookup_disposition .Get(TRRService::ProviderKey(), mTRRSuccess ? "trrOK"_ns : "trrFail"_ns) diff --git a/netwerk/dns/nsHostResolver.cpp b/netwerk/dns/nsHostResolver.cpp @@ -91,40 +91,6 @@ static const unsigned int NEGATIVE_RECORD_LIFETIME = 60; using namespace mozilla; -namespace geckoprofiler::markers { - -struct HostResolverMarker { - static constexpr Span<const char> MarkerTypeName() { - return MakeStringSpan("HostResolver"); - } - static void StreamJSONMarkerData( - mozilla::baseprofiler::SpliceableJSONWriter& aWriter, - const mozilla::ProfilerString8View& aHost, - const mozilla::ProfilerString8View& aOriginSuffix, uint16_t aType, - uint32_t aFlags) { - aWriter.StringProperty("host", aHost); - aWriter.StringProperty("originSuffix", aOriginSuffix); - aWriter.IntProperty("qtype", aType); - aWriter.StringProperty("flags", nsPrintfCString("0x%x", aFlags)); - } - static MarkerSchema MarkerTypeDisplay() { - using MS = MarkerSchema; - MS schema(MS::Location::MarkerChart, MS::Location::MarkerTable); - schema.SetTableLabel("{marker.data.host}"); - schema.AddKeyFormat("host", MS::Format::SanitizedString, - MS::PayloadFlags::Searchable); - schema.AddKeyFormat("originSuffix", MS::Format::SanitizedString, - MS::PayloadFlags::Searchable); - schema.AddKeyFormat("qtype", MS::Format::Integer); - schema.AddKeyFormat("flags", MS::Format::String); - return schema; - } -}; - -} // namespace geckoprofiler::markers - -//---------------------------------------------------------------------------- - namespace mozilla::net { LazyLogModule gHostResolverLog("nsHostResolver"); } // namespace mozilla::net @@ -484,9 +450,6 @@ nsresult nsHostResolver::ResolveHost(const nsACString& aHost, flags & nsIDNSService::RESOLVE_REFRESH_CACHE ? " - refresh cache" : "", type, this)); - PROFILER_MARKER("nsHostResolver::ResolveHost", NETWORK, {}, - HostResolverMarker, host, originSuffix, type, flags); - // When this pref is set, we always set the flag, to make sure consumers // that forget to set the flag don't end up being a cache miss. if (StaticPrefs::network_dns_always_ai_canonname()) { @@ -1626,10 +1589,6 @@ nsHostResolver::LookupStatus nsHostResolver::CompleteLookupLocked( } } - PROFILER_MARKER("nsHostResolver::CompleteLookupLocked", NETWORK, {}, - HostResolverMarker, addrRec->host, addrRec->originSuffix, - addrRec->type, addrRec->flags); - // get the list of pending callbacks for this lookup, and notify // them that the lookup is complete. mozilla::LinkedList<RefPtr<nsResolveHostCallback>> cbs = @@ -1745,10 +1704,6 @@ nsHostResolver::LookupStatus nsHostResolver::CompleteLookupByTypeLocked( typeRec->RecordReason(aReason); } - PROFILER_MARKER("nsHostResolver::CompleteLookupByTypeLocked", NETWORK, {}, - HostResolverMarker, typeRec->host, typeRec->originSuffix, - typeRec->type, typeRec->flags); - mozilla::LinkedList<RefPtr<nsResolveHostCallback>> cbs = std::move(typeRec->mCallbacks);