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

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

Issue 2444783002: Add trace event for complete network request (Closed)
Patch Set: Calm down compiler with return value Created 4 years, 1 month 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 | « third_party/WebKit/Source/platform/network/NetworkInstrumentation.h ('k') | 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
new file mode 100644
index 0000000000000000000000000000000000000000..bb2a7d232488411a64581b04fb068c5efe9621f2
--- /dev/null
+++ b/third_party/WebKit/Source/platform/network/NetworkInstrumentation.cpp
@@ -0,0 +1,75 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "platform/network/NetworkInstrumentation.h"
+
+#include "base/trace_event/trace_event.h"
+#include "platform/network/ResourceLoadPriority.h"
+#include "platform/network/ResourceRequest.h"
+#include "platform/tracing/TracedValue.h"
+
+namespace network_instrumentation {
+
+using network_instrumentation::RequestOutcome;
+using blink::TracedValue;
+
+const char kBlinkResourceID[] = "BlinkResourceID";
+const char kResourceLoadTitle[] = "ResourceLoad";
+const char kResourcePrioritySetTitle[] = "ResourcePrioritySet";
+const char kNetInstrumentationCategory[] = TRACE_DISABLED_BY_DEFAULT("network");
+
+const char* RequestOutcomeToString(RequestOutcome outcome) {
+ switch (outcome) {
+ case RequestOutcome::Success:
+ return "Success";
+ case RequestOutcome::Fail:
+ return "Fail";
+ default:
+ NOTREACHED();
+ // We need to return something to avoid compiler warning.
+ return "This should never happen";
+ }
+}
+
+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));
+}
+
+ScopedResourceLoadTracker::~ScopedResourceLoadTracker() {
+ if (!m_resourceLoadContinuesBeyondScope)
+ endResourceLoad(m_resourceID, RequestOutcome::Fail);
+}
+
+void ScopedResourceLoadTracker::resourceLoadContinuesBeyondScope() {
+ m_resourceLoadContinuesBeyondScope = true;
+}
+
+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));
+}
+
+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));
+}
+
+} // namespace network_instrumentation
« no previous file with comments | « third_party/WebKit/Source/platform/network/NetworkInstrumentation.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698