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

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

Issue 2444783002: Add trace event for complete network request (Closed)
Patch Set: Nuke old tracepoints. Add priority instant events. Add TracedValue. 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..edc8b8981d6594061fb33246b1891d4ae8e3f385
--- /dev/null
+++ b/third_party/WebKit/Source/platform/network/NetworkInstrumentation.cpp
@@ -0,0 +1,83 @@
+// 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/tracing/TracedValue.h"
+
+namespace network_instrumentation {
+
+using network_instrumentation::RequestOutcome;
+using blink::TracedValue;
+
+const char kBlinkResourceID[] = "BlinkResourceID";
+const char kResourceLoadTitle[] = "ResourceLoad";
+const char kInitialResourcePrioritySetTitle[] = "InitialResourcePrioritySet";
+const char kResourcePriorityChangedTitle[] = "ResourcePriorityChanged";
+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();
+ }
+}
+
+ScopedResourceLoadTracker::ScopedResourceLoadTracker(
+ unsigned long resourceID,
+ const blink::ResourceRequest& request)
+ : closeSliceAtEndOfScope(true), 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 (this->closeSliceAtEndOfScope)
caseq 2016/11/08 18:24:32 we generally don't mention this-> explicitly.
dproy 2016/11/09 20:44:00 Done for all the `this` cases.
+ endResourceLoad(this->resourceID, RequestOutcome::Fail);
caseq 2016/11/08 18:24:32 ditto.
+}
+
+void ScopedResourceLoadTracker::doNotCloseSliceAtEndOfScope() {
+ this->closeSliceAtEndOfScope = false;
caseq 2016/11/08 18:24:32 ditto.
+}
+
+void initialResourcePrioritySet(unsigned long resourceID,
+ blink::ResourceLoadPriority priority) {
+ std::unique_ptr<TracedValue> data = TracedValue::create();
+ data->setInteger("initialPriority", priority);
caseq 2016/11/08 18:24:32 ditto.
+ TRACE_EVENT_NESTABLE_ASYNC_INSTANT1(
+ kNetInstrumentationCategory, kInitialResourcePrioritySetTitle,
+ TRACE_ID_WITH_SCOPE(kBlinkResourceID, TRACE_ID_LOCAL(resourceID)), "data",
+ std::move(data));
+}
+
+void resourcePriorityChanged(unsigned long resourceID,
+ blink::ResourceLoadPriority priority) {
+ std::unique_ptr<TracedValue> data = TracedValue::create();
+ data->setInteger("newPriority", priority);
+ TRACE_EVENT_NESTABLE_ASYNC_INSTANT1(
+ kNetInstrumentationCategory, kResourcePriorityChangedTitle,
+ 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

Powered by Google App Engine
This is Rietveld 408576698