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

Side by Side Diff: third_party/WebKit/Source/platform/network/NetworkInstrumentation.cpp

Issue 2537143005: Only create network_instrumentation TracedValue if tracing enabled (Closed)
Patch Set: typo 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "platform/network/NetworkInstrumentation.h" 5 #include "platform/network/NetworkInstrumentation.h"
6 6
7 #include "base/trace_event/trace_event.h" 7 #include "base/trace_event/trace_event.h"
8 #include "platform/network/ResourceLoadPriority.h" 8 #include "platform/network/ResourceLoadPriority.h"
9 #include "platform/network/ResourceRequest.h" 9 #include "platform/network/ResourceRequest.h"
10 #include "platform/tracing/TracedValue.h" 10 #include "platform/tracing/TracedValue.h"
(...skipping 14 matching lines...) Expand all
25 return "Success"; 25 return "Success";
26 case RequestOutcome::Fail: 26 case RequestOutcome::Fail:
27 return "Fail"; 27 return "Fail";
28 default: 28 default:
29 NOTREACHED(); 29 NOTREACHED();
30 // We need to return something to avoid compiler warning. 30 // We need to return something to avoid compiler warning.
31 return "This should never happen"; 31 return "This should never happen";
32 } 32 }
33 } 33 }
34 34
35 // Note: network_instrumentation code should do as much work as possible inside
36 // the arguments of trace macros so that very little instrumentation overhead is
37 // incurred if the trace category is disabled. See https://crbug.com/669666.
38
39 std::unique_ptr<TracedValue> scopedResourceTrackerBeginData(
caseq 2016/12/01 18:10:24 All three could be in anonymous namespace -- unles
40 const blink::ResourceRequest& request) {
41 std::unique_ptr<TracedValue> data = TracedValue::create();
42 data->setString("url", request.url().getString());
43 return data;
44 }
45
46 std::unique_ptr<TracedValue> resourcePrioritySetData(
47 blink::ResourceLoadPriority priority) {
48 std::unique_ptr<TracedValue> data = TracedValue::create();
49 data->setInteger("priority", priority);
50 return data;
51 }
52
53 std::unique_ptr<TracedValue> endResourceLoadData(RequestOutcome outcome) {
54 std::unique_ptr<TracedValue> data = TracedValue::create();
55 data->setString("outcome", RequestOutcomeToString(outcome));
56 return data;
57 }
58
35 ScopedResourceLoadTracker::ScopedResourceLoadTracker( 59 ScopedResourceLoadTracker::ScopedResourceLoadTracker(
36 unsigned long resourceID, 60 unsigned long resourceID,
37 const blink::ResourceRequest& request) 61 const blink::ResourceRequest& request)
38 : m_resourceLoadContinuesBeyondScope(false), m_resourceID(resourceID) { 62 : m_resourceLoadContinuesBeyondScope(false), m_resourceID(resourceID) {
39 std::unique_ptr<TracedValue> beginData = TracedValue::create();
40 beginData->setString("url", request.url().getString());
41 TRACE_EVENT_NESTABLE_ASYNC_BEGIN1( 63 TRACE_EVENT_NESTABLE_ASYNC_BEGIN1(
42 kNetInstrumentationCategory, kResourceLoadTitle, 64 kNetInstrumentationCategory, kResourceLoadTitle,
43 TRACE_ID_WITH_SCOPE(kBlinkResourceID, TRACE_ID_LOCAL(resourceID)), 65 TRACE_ID_WITH_SCOPE(kBlinkResourceID, TRACE_ID_LOCAL(resourceID)),
44 "beginData", std::move(beginData)); 66 "beginData", scopedResourceTrackerBeginData(request));
45 } 67 }
46 68
47 ScopedResourceLoadTracker::~ScopedResourceLoadTracker() { 69 ScopedResourceLoadTracker::~ScopedResourceLoadTracker() {
48 if (!m_resourceLoadContinuesBeyondScope) 70 if (!m_resourceLoadContinuesBeyondScope)
49 endResourceLoad(m_resourceID, RequestOutcome::Fail); 71 endResourceLoad(m_resourceID, RequestOutcome::Fail);
50 } 72 }
51 73
52 void ScopedResourceLoadTracker::resourceLoadContinuesBeyondScope() { 74 void ScopedResourceLoadTracker::resourceLoadContinuesBeyondScope() {
53 m_resourceLoadContinuesBeyondScope = true; 75 m_resourceLoadContinuesBeyondScope = true;
54 } 76 }
55 77
56 void resourcePrioritySet(unsigned long resourceID, 78 void resourcePrioritySet(unsigned long resourceID,
57 blink::ResourceLoadPriority priority) { 79 blink::ResourceLoadPriority priority) {
58 std::unique_ptr<TracedValue> data = TracedValue::create();
59 data->setInteger("priority", priority);
60 TRACE_EVENT_NESTABLE_ASYNC_INSTANT1( 80 TRACE_EVENT_NESTABLE_ASYNC_INSTANT1(
61 kNetInstrumentationCategory, kResourcePrioritySetTitle, 81 kNetInstrumentationCategory, kResourcePrioritySetTitle,
62 TRACE_ID_WITH_SCOPE(kBlinkResourceID, TRACE_ID_LOCAL(resourceID)), "data", 82 TRACE_ID_WITH_SCOPE(kBlinkResourceID, TRACE_ID_LOCAL(resourceID)), "data",
63 std::move(data)); 83 resourcePrioritySetData(priority));
64 } 84 }
65 85
66 void endResourceLoad(unsigned long resourceID, RequestOutcome outcome) { 86 void endResourceLoad(unsigned long resourceID, RequestOutcome outcome) {
67 std::unique_ptr<TracedValue> endData = TracedValue::create();
68 endData->setString("outcome", RequestOutcomeToString(outcome));
69 TRACE_EVENT_NESTABLE_ASYNC_END1( 87 TRACE_EVENT_NESTABLE_ASYNC_END1(
70 kNetInstrumentationCategory, kResourceLoadTitle, 88 kNetInstrumentationCategory, kResourceLoadTitle,
71 TRACE_ID_WITH_SCOPE(kBlinkResourceID, TRACE_ID_LOCAL(resourceID)), 89 TRACE_ID_WITH_SCOPE(kBlinkResourceID, TRACE_ID_LOCAL(resourceID)),
72 "endData", std::move(endData)); 90 "endData", endResourceLoadData(outcome));
73 } 91 }
74 92
75 } // namespace network_instrumentation 93 } // namespace network_instrumentation
OLDNEW
« 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