| OLD | NEW |
| 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 Loading... |
| 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 namespace { |
| 40 |
| 41 std::unique_ptr<TracedValue> scopedResourceTrackerBeginData( |
| 42 const blink::ResourceRequest& request) { |
| 43 std::unique_ptr<TracedValue> data = TracedValue::create(); |
| 44 data->setString("url", request.url().getString()); |
| 45 return data; |
| 46 } |
| 47 |
| 48 std::unique_ptr<TracedValue> resourcePrioritySetData( |
| 49 blink::ResourceLoadPriority priority) { |
| 50 std::unique_ptr<TracedValue> data = TracedValue::create(); |
| 51 data->setInteger("priority", priority); |
| 52 return data; |
| 53 } |
| 54 |
| 55 std::unique_ptr<TracedValue> endResourceLoadData(RequestOutcome outcome) { |
| 56 std::unique_ptr<TracedValue> data = TracedValue::create(); |
| 57 data->setString("outcome", RequestOutcomeToString(outcome)); |
| 58 return data; |
| 59 } |
| 60 |
| 61 } // namespace |
| 62 |
| 35 ScopedResourceLoadTracker::ScopedResourceLoadTracker( | 63 ScopedResourceLoadTracker::ScopedResourceLoadTracker( |
| 36 unsigned long resourceID, | 64 unsigned long resourceID, |
| 37 const blink::ResourceRequest& request) | 65 const blink::ResourceRequest& request) |
| 38 : m_resourceLoadContinuesBeyondScope(false), m_resourceID(resourceID) { | 66 : 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( | 67 TRACE_EVENT_NESTABLE_ASYNC_BEGIN1( |
| 42 kNetInstrumentationCategory, kResourceLoadTitle, | 68 kNetInstrumentationCategory, kResourceLoadTitle, |
| 43 TRACE_ID_WITH_SCOPE(kBlinkResourceID, TRACE_ID_LOCAL(resourceID)), | 69 TRACE_ID_WITH_SCOPE(kBlinkResourceID, TRACE_ID_LOCAL(resourceID)), |
| 44 "beginData", std::move(beginData)); | 70 "beginData", scopedResourceTrackerBeginData(request)); |
| 45 } | 71 } |
| 46 | 72 |
| 47 ScopedResourceLoadTracker::~ScopedResourceLoadTracker() { | 73 ScopedResourceLoadTracker::~ScopedResourceLoadTracker() { |
| 48 if (!m_resourceLoadContinuesBeyondScope) | 74 if (!m_resourceLoadContinuesBeyondScope) |
| 49 endResourceLoad(m_resourceID, RequestOutcome::Fail); | 75 endResourceLoad(m_resourceID, RequestOutcome::Fail); |
| 50 } | 76 } |
| 51 | 77 |
| 52 void ScopedResourceLoadTracker::resourceLoadContinuesBeyondScope() { | 78 void ScopedResourceLoadTracker::resourceLoadContinuesBeyondScope() { |
| 53 m_resourceLoadContinuesBeyondScope = true; | 79 m_resourceLoadContinuesBeyondScope = true; |
| 54 } | 80 } |
| 55 | 81 |
| 56 void resourcePrioritySet(unsigned long resourceID, | 82 void resourcePrioritySet(unsigned long resourceID, |
| 57 blink::ResourceLoadPriority priority) { | 83 blink::ResourceLoadPriority priority) { |
| 58 std::unique_ptr<TracedValue> data = TracedValue::create(); | |
| 59 data->setInteger("priority", priority); | |
| 60 TRACE_EVENT_NESTABLE_ASYNC_INSTANT1( | 84 TRACE_EVENT_NESTABLE_ASYNC_INSTANT1( |
| 61 kNetInstrumentationCategory, kResourcePrioritySetTitle, | 85 kNetInstrumentationCategory, kResourcePrioritySetTitle, |
| 62 TRACE_ID_WITH_SCOPE(kBlinkResourceID, TRACE_ID_LOCAL(resourceID)), "data", | 86 TRACE_ID_WITH_SCOPE(kBlinkResourceID, TRACE_ID_LOCAL(resourceID)), "data", |
| 63 std::move(data)); | 87 resourcePrioritySetData(priority)); |
| 64 } | 88 } |
| 65 | 89 |
| 66 void endResourceLoad(unsigned long resourceID, RequestOutcome outcome) { | 90 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( | 91 TRACE_EVENT_NESTABLE_ASYNC_END1( |
| 70 kNetInstrumentationCategory, kResourceLoadTitle, | 92 kNetInstrumentationCategory, kResourceLoadTitle, |
| 71 TRACE_ID_WITH_SCOPE(kBlinkResourceID, TRACE_ID_LOCAL(resourceID)), | 93 TRACE_ID_WITH_SCOPE(kBlinkResourceID, TRACE_ID_LOCAL(resourceID)), |
| 72 "endData", std::move(endData)); | 94 "endData", endResourceLoadData(outcome)); |
| 73 } | 95 } |
| 74 | 96 |
| 75 } // namespace network_instrumentation | 97 } // namespace network_instrumentation |
| OLD | NEW |