Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1279)

Unified Diff: third_party/WebKit/Source/platform/network/NetworkInstrumentation.cpp

Issue 2537143005: Only create network_instrumentation TracedValue if tracing enabled (Closed)
Patch Set: Use anonymous namespace Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/platform/network/NetworkInstrumentation.cpp
diff --git a/third_party/WebKit/Source/platform/network/NetworkInstrumentation.cpp b/third_party/WebKit/Source/platform/network/NetworkInstrumentation.cpp
index bb2a7d232488411a64581b04fb068c5efe9621f2..f5aa72412a84f42d98e136cddbcb6c2d0295370c 100644
--- a/third_party/WebKit/Source/platform/network/NetworkInstrumentation.cpp
+++ b/third_party/WebKit/Source/platform/network/NetworkInstrumentation.cpp
@@ -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(
unsigned long resourceID,
const blink::ResourceRequest& request)
: m_resourceLoadContinuesBeyondScope(false), m_resourceID(resourceID) {
- std::unique_ptr<TracedValue> beginData = TracedValue::create();
- beginData->setString("url", request.url().getString());
TRACE_EVENT_NESTABLE_ASYNC_BEGIN1(
kNetInstrumentationCategory, kResourceLoadTitle,
TRACE_ID_WITH_SCOPE(kBlinkResourceID, TRACE_ID_LOCAL(resourceID)),
- "beginData", std::move(beginData));
+ "beginData", scopedResourceTrackerBeginData(request));
}
ScopedResourceLoadTracker::~ScopedResourceLoadTracker() {
@@ -55,21 +81,17 @@ void ScopedResourceLoadTracker::resourceLoadContinuesBeyondScope() {
void resourcePrioritySet(unsigned long resourceID,
blink::ResourceLoadPriority priority) {
- std::unique_ptr<TracedValue> data = TracedValue::create();
- data->setInteger("priority", priority);
TRACE_EVENT_NESTABLE_ASYNC_INSTANT1(
kNetInstrumentationCategory, kResourcePrioritySetTitle,
TRACE_ID_WITH_SCOPE(kBlinkResourceID, TRACE_ID_LOCAL(resourceID)), "data",
- std::move(data));
+ resourcePrioritySetData(priority));
}
void endResourceLoad(unsigned long resourceID, RequestOutcome outcome) {
- std::unique_ptr<TracedValue> endData = TracedValue::create();
- endData->setString("outcome", RequestOutcomeToString(outcome));
TRACE_EVENT_NESTABLE_ASYNC_END1(
kNetInstrumentationCategory, kResourceLoadTitle,
TRACE_ID_WITH_SCOPE(kBlinkResourceID, TRACE_ID_LOCAL(resourceID)),
- "endData", std::move(endData));
+ "endData", endResourceLoadData(outcome));
}
} // namespace network_instrumentation
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698