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

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

Issue 2444783002: Add trace event for complete network request (Closed)
Patch Set: Remove empty beginResourceLoad function 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
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..be3ba623bf07dcbc288a93a03b8d850738812abe
--- /dev/null
+++ b/third_party/WebKit/Source/platform/network/NetworkInstrumentation.cpp
@@ -0,0 +1,54 @@
+// 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"
+
+namespace network_instrumentation {
+
+using network_instrumentation::RequestOutcome;
+
+const char kBlinkResourceID[] = "BlinkResourceID";
+const char kResourceLoadTitle[] = "ResourceLoad";
+const char kNetInstrumentationCategory[] = TRACE_DISABLED_BY_DEFAULT("net.v2");
fmeawad 2016/11/03 22:18:58 Can you use a category name that does not include
dproy 2016/11/04 20:41:55 Done.
+
+const char* RequestOutcomeToString(RequestOutcome outcome) {
+ switch (outcome) {
+ case RequestOutcome::Success:
+ return "Success";
+ case RequestOutcome::Fail:
+ return "Fail";
+ default:
+ NOTREACHED();
+ }
+}
+
+ScopedResourceLoadTracker::ScopedResourceLoadTracker(
+ unsigned long resourceID,
+ const blink::ResourceRequest& request)
+ : closeSliceAtEndOfScope(true), resourceID(resourceID) {
+ TRACE_EVENT_NESTABLE_ASYNC_BEGIN1(
+ kNetInstrumentationCategory, kResourceLoadTitle,
+ TRACE_ID_WITH_SCOPE(kBlinkResourceID, TRACE_ID_LOCAL(resourceID)), "url",
+ TRACE_STR_COPY(request.url().getString().utf8().data()));
+}
+
+ScopedResourceLoadTracker::~ScopedResourceLoadTracker() {
+ if (this->closeSliceAtEndOfScope)
+ endResourceLoad(this->resourceID, RequestOutcome::Fail);
+}
+
+void ScopedResourceLoadTracker::doNotCloseSliceAtEndOfScope() {
+ this->closeSliceAtEndOfScope = false;
+}
+
+void endResourceLoad(unsigned long resourceID, RequestOutcome outcome) {
+ TRACE_EVENT_NESTABLE_ASYNC_END1(
+ kNetInstrumentationCategory, kResourceLoadTitle,
+ TRACE_ID_WITH_SCOPE(kBlinkResourceID, TRACE_ID_LOCAL(resourceID)),
+ "outcome", TRACE_STR_COPY(RequestOutcomeToString(outcome)));
+}
+
+} // namespace network_instrumentation

Powered by Google App Engine
This is Rietveld 408576698