Commit 02efb805 authored by dproy's avatar dproy Committed by Commit bot

Only create network_instrumentation TracedValue if tracing enabled

Currently the TracedValues were being created even when the tracing category was
disabled. This CL moves the creation of the TracedValues into a function, which
is called only when the TRACE macro arguments are evaluated, which, in turn,
only happens when the tracing category is enabled.

Measuring on a linux workstation using the linux perf tools, the instrumentation
overhead with the tracing category disabled is now below 2% of the cost of the
ResourceFetcher::requestResource function, as opposed to the 12% measured
before.

Review-Url: https://codereview.chromium.org/2537143005
Cr-Commit-Position: refs/heads/master@{#437657}
parent 3b607160
...@@ -32,16 +32,42 @@ const char* RequestOutcomeToString(RequestOutcome outcome) { ...@@ -32,16 +32,42 @@ const char* RequestOutcomeToString(RequestOutcome outcome) {
} }
} }
// Note: network_instrumentation code should do as much work as possible inside
// the arguments of trace macros so that very little instrumentation overhead is
// incurred if the trace category is disabled. See https://crbug.com/669666.
namespace {
std::unique_ptr<TracedValue> scopedResourceTrackerBeginData(
const blink::ResourceRequest& request) {
std::unique_ptr<TracedValue> data = TracedValue::create();
data->setString("url", request.url().getString());
return data;
}
std::unique_ptr<TracedValue> resourcePrioritySetData(
blink::ResourceLoadPriority priority) {
std::unique_ptr<TracedValue> data = TracedValue::create();
data->setInteger("priority", priority);
return data;
}
std::unique_ptr<TracedValue> endResourceLoadData(RequestOutcome outcome) {
std::unique_ptr<TracedValue> data = TracedValue::create();
data->setString("outcome", RequestOutcomeToString(outcome));
return data;
}
} // namespace
ScopedResourceLoadTracker::ScopedResourceLoadTracker( ScopedResourceLoadTracker::ScopedResourceLoadTracker(
unsigned long resourceID, unsigned long resourceID,
const blink::ResourceRequest& request) const blink::ResourceRequest& request)
: m_resourceLoadContinuesBeyondScope(false), m_resourceID(resourceID) { : m_resourceLoadContinuesBeyondScope(false), m_resourceID(resourceID) {
std::unique_ptr<TracedValue> beginData = TracedValue::create();
beginData->setString("url", request.url().getString());
TRACE_EVENT_NESTABLE_ASYNC_BEGIN1( TRACE_EVENT_NESTABLE_ASYNC_BEGIN1(
kNetInstrumentationCategory, kResourceLoadTitle, kNetInstrumentationCategory, kResourceLoadTitle,
TRACE_ID_WITH_SCOPE(kBlinkResourceID, TRACE_ID_LOCAL(resourceID)), TRACE_ID_WITH_SCOPE(kBlinkResourceID, TRACE_ID_LOCAL(resourceID)),
"beginData", std::move(beginData)); "beginData", scopedResourceTrackerBeginData(request));
} }
ScopedResourceLoadTracker::~ScopedResourceLoadTracker() { ScopedResourceLoadTracker::~ScopedResourceLoadTracker() {
...@@ -55,21 +81,17 @@ void ScopedResourceLoadTracker::resourceLoadContinuesBeyondScope() { ...@@ -55,21 +81,17 @@ void ScopedResourceLoadTracker::resourceLoadContinuesBeyondScope() {
void resourcePrioritySet(unsigned long resourceID, void resourcePrioritySet(unsigned long resourceID,
blink::ResourceLoadPriority priority) { blink::ResourceLoadPriority priority) {
std::unique_ptr<TracedValue> data = TracedValue::create();
data->setInteger("priority", priority);
TRACE_EVENT_NESTABLE_ASYNC_INSTANT1( TRACE_EVENT_NESTABLE_ASYNC_INSTANT1(
kNetInstrumentationCategory, kResourcePrioritySetTitle, kNetInstrumentationCategory, kResourcePrioritySetTitle,
TRACE_ID_WITH_SCOPE(kBlinkResourceID, TRACE_ID_LOCAL(resourceID)), "data", TRACE_ID_WITH_SCOPE(kBlinkResourceID, TRACE_ID_LOCAL(resourceID)), "data",
std::move(data)); resourcePrioritySetData(priority));
} }
void endResourceLoad(unsigned long resourceID, RequestOutcome outcome) { void endResourceLoad(unsigned long resourceID, RequestOutcome outcome) {
std::unique_ptr<TracedValue> endData = TracedValue::create();
endData->setString("outcome", RequestOutcomeToString(outcome));
TRACE_EVENT_NESTABLE_ASYNC_END1( TRACE_EVENT_NESTABLE_ASYNC_END1(
kNetInstrumentationCategory, kResourceLoadTitle, kNetInstrumentationCategory, kResourceLoadTitle,
TRACE_ID_WITH_SCOPE(kBlinkResourceID, TRACE_ID_LOCAL(resourceID)), TRACE_ID_WITH_SCOPE(kBlinkResourceID, TRACE_ID_LOCAL(resourceID)),
"endData", std::move(endData)); "endData", endResourceLoadData(outcome));
} }
} // namespace network_instrumentation } // namespace network_instrumentation
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment