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

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

Issue 2444783002: Add trace event for complete network request (Closed)
Patch Set: Address review comments 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..7fcd07739c6572c784d6eb0911bed66fc54b1b43
--- /dev/null
+++ b/third_party/WebKit/Source/platform/network/NetworkInstrumentation.cpp
@@ -0,0 +1,61 @@
+// 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 "wtf/text/CString.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");
+
+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), request(request) {
+ beginResourceLoad(resourceID, request);
+}
+
+ScopedResourceLoadTracker::~ScopedResourceLoadTracker() {
+ if (this->closeSliceAtEndOfScope)
+ endResourceLoad(this->resourceID, RequestOutcome::Fail);
+}
+
+void ScopedResourceLoadTracker::doNotCloseSliceAtEndOfScope() {
+ this->closeSliceAtEndOfScope = false;
+}
+
+void beginResourceLoad(unsigned long resourceID,
chiniforooshan 2016/11/03 15:50:36 Is it necessary to have this function? I would mov
dproy 2016/11/03 16:27:19 I moved it inside.
+ const blink::ResourceRequest& request) {
+ const String urlString = request.url().getString();
+ TRACE_EVENT_NESTABLE_ASYNC_BEGIN1(
+ kNetInstrumentationCategory, kResourceLoadTitle,
+ TRACE_ID_WITH_SCOPE(kBlinkResourceID, TRACE_ID_LOCAL(resourceID)), "url",
+ TRACE_STR_COPY(urlString.utf8().data()));
chiniforooshan 2016/11/03 15:50:36 is TRACE_STR_COPY(request.url().getString().utf8()
dproy 2016/11/03 16:27:19 Done.
+}
+
+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