| 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/instrumentation/tracing/TracedValue.h" | 8 #include "platform/instrumentation/tracing/TracedValue.h" |
| 9 #include "platform/loader/fetch/ResourceLoadPriority.h" | 9 #include "platform/loader/fetch/ResourceLoadPriority.h" |
| 10 #include "platform/loader/fetch/ResourceRequest.h" | 10 #include "platform/loader/fetch/ResourceRequest.h" |
| 11 | 11 |
| 12 namespace blink { |
| 12 namespace network_instrumentation { | 13 namespace network_instrumentation { |
| 13 | 14 |
| 14 using network_instrumentation::RequestOutcome; | 15 using network_instrumentation::RequestOutcome; |
| 15 using blink::TracedValue; | 16 using blink::TracedValue; |
| 16 | 17 |
| 17 const char kBlinkResourceID[] = "BlinkResourceID"; | 18 const char kBlinkResourceID[] = "BlinkResourceID"; |
| 18 const char kResourceLoadTitle[] = "ResourceLoad"; | 19 const char kResourceLoadTitle[] = "ResourceLoad"; |
| 19 const char kResourcePrioritySetTitle[] = "ResourcePrioritySet"; | 20 const char kResourcePrioritySetTitle[] = "ResourcePrioritySet"; |
| 20 const char kNetInstrumentationCategory[] = TRACE_DISABLED_BY_DEFAULT("network"); | 21 const char kNetInstrumentationCategory[] = TRACE_DISABLED_BY_DEFAULT("network"); |
| 21 | 22 |
| 22 const char* RequestOutcomeToString(RequestOutcome outcome) { | 23 const char* RequestOutcomeToString(RequestOutcome outcome) { |
| 23 switch (outcome) { | 24 switch (outcome) { |
| 24 case RequestOutcome::Success: | 25 case RequestOutcome::kSuccess: |
| 25 return "Success"; | 26 return "Success"; |
| 26 case RequestOutcome::Fail: | 27 case RequestOutcome::kFail: |
| 27 return "Fail"; | 28 return "Fail"; |
| 28 default: | 29 default: |
| 29 NOTREACHED(); | 30 NOTREACHED(); |
| 30 // We need to return something to avoid compiler warning. | 31 // We need to return something to avoid compiler warning. |
| 31 return "This should never happen"; | 32 return "This should never happen"; |
| 32 } | 33 } |
| 33 } | 34 } |
| 34 | 35 |
| 35 // Note: network_instrumentation code should do as much work as possible inside | 36 // 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 // 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 // incurred if the trace category is disabled. See https://crbug.com/669666. |
| 38 | 39 |
| 39 namespace { | 40 namespace { |
| 40 | 41 |
| 41 std::unique_ptr<TracedValue> scopedResourceTrackerBeginData( | 42 std::unique_ptr<TracedValue> ScopedResourceTrackerBeginData( |
| 42 const blink::ResourceRequest& request) { | 43 const blink::ResourceRequest& request) { |
| 43 std::unique_ptr<TracedValue> data = TracedValue::Create(); | 44 std::unique_ptr<TracedValue> data = TracedValue::Create(); |
| 44 data->SetString("url", request.Url().GetString()); | 45 data->SetString("url", request.Url().GetString()); |
| 45 return data; | 46 return data; |
| 46 } | 47 } |
| 47 | 48 |
| 48 std::unique_ptr<TracedValue> resourcePrioritySetData( | 49 std::unique_ptr<TracedValue> ResourcePrioritySetData( |
| 49 blink::ResourceLoadPriority priority) { | 50 blink::ResourceLoadPriority priority) { |
| 50 std::unique_ptr<TracedValue> data = TracedValue::Create(); | 51 std::unique_ptr<TracedValue> data = TracedValue::Create(); |
| 51 data->SetInteger("priority", priority); | 52 data->SetInteger("priority", priority); |
| 52 return data; | 53 return data; |
| 53 } | 54 } |
| 54 | 55 |
| 55 std::unique_ptr<TracedValue> endResourceLoadData(RequestOutcome outcome) { | 56 std::unique_ptr<TracedValue> EndResourceLoadData(RequestOutcome outcome) { |
| 56 std::unique_ptr<TracedValue> data = TracedValue::Create(); | 57 std::unique_ptr<TracedValue> data = TracedValue::Create(); |
| 57 data->SetString("outcome", RequestOutcomeToString(outcome)); | 58 data->SetString("outcome", RequestOutcomeToString(outcome)); |
| 58 return data; | 59 return data; |
| 59 } | 60 } |
| 60 | 61 |
| 61 } // namespace | 62 } // namespace |
| 62 | 63 |
| 63 ScopedResourceLoadTracker::ScopedResourceLoadTracker( | 64 ScopedResourceLoadTracker::ScopedResourceLoadTracker( |
| 64 unsigned long resourceID, | 65 unsigned long resource_id, |
| 65 const blink::ResourceRequest& request) | 66 const blink::ResourceRequest& request) |
| 66 : m_resourceLoadContinuesBeyondScope(false), m_resourceID(resourceID) { | 67 : resource_load_continues_beyond_scope_(false), resource_id_(resource_id) { |
| 67 TRACE_EVENT_NESTABLE_ASYNC_BEGIN1( | 68 TRACE_EVENT_NESTABLE_ASYNC_BEGIN1( |
| 68 kNetInstrumentationCategory, kResourceLoadTitle, | 69 kNetInstrumentationCategory, kResourceLoadTitle, |
| 69 TRACE_ID_WITH_SCOPE(kBlinkResourceID, TRACE_ID_LOCAL(resourceID)), | 70 TRACE_ID_WITH_SCOPE(kBlinkResourceID, TRACE_ID_LOCAL(resource_id)), |
| 70 "beginData", scopedResourceTrackerBeginData(request)); | 71 "beginData", ScopedResourceTrackerBeginData(request)); |
| 71 } | 72 } |
| 72 | 73 |
| 73 ScopedResourceLoadTracker::~ScopedResourceLoadTracker() { | 74 ScopedResourceLoadTracker::~ScopedResourceLoadTracker() { |
| 74 if (!m_resourceLoadContinuesBeyondScope) | 75 if (!resource_load_continues_beyond_scope_) |
| 75 endResourceLoad(m_resourceID, RequestOutcome::Fail); | 76 EndResourceLoad(resource_id_, RequestOutcome::kFail); |
| 76 } | 77 } |
| 77 | 78 |
| 78 void ScopedResourceLoadTracker::resourceLoadContinuesBeyondScope() { | 79 void ScopedResourceLoadTracker::ResourceLoadContinuesBeyondScope() { |
| 79 m_resourceLoadContinuesBeyondScope = true; | 80 resource_load_continues_beyond_scope_ = true; |
| 80 } | 81 } |
| 81 | 82 |
| 82 void resourcePrioritySet(unsigned long resourceID, | 83 void ResourcePrioritySet(unsigned long resource_id, |
| 83 blink::ResourceLoadPriority priority) { | 84 blink::ResourceLoadPriority priority) { |
| 84 TRACE_EVENT_NESTABLE_ASYNC_INSTANT1( | 85 TRACE_EVENT_NESTABLE_ASYNC_INSTANT1( |
| 85 kNetInstrumentationCategory, kResourcePrioritySetTitle, | 86 kNetInstrumentationCategory, kResourcePrioritySetTitle, |
| 86 TRACE_ID_WITH_SCOPE(kBlinkResourceID, TRACE_ID_LOCAL(resourceID)), "data", | 87 TRACE_ID_WITH_SCOPE(kBlinkResourceID, TRACE_ID_LOCAL(resource_id)), |
| 87 resourcePrioritySetData(priority)); | 88 "data", ResourcePrioritySetData(priority)); |
| 88 } | 89 } |
| 89 | 90 |
| 90 void endResourceLoad(unsigned long resourceID, RequestOutcome outcome) { | 91 void EndResourceLoad(unsigned long resource_id, RequestOutcome outcome) { |
| 91 TRACE_EVENT_NESTABLE_ASYNC_END1( | 92 TRACE_EVENT_NESTABLE_ASYNC_END1( |
| 92 kNetInstrumentationCategory, kResourceLoadTitle, | 93 kNetInstrumentationCategory, kResourceLoadTitle, |
| 93 TRACE_ID_WITH_SCOPE(kBlinkResourceID, TRACE_ID_LOCAL(resourceID)), | 94 TRACE_ID_WITH_SCOPE(kBlinkResourceID, TRACE_ID_LOCAL(resource_id)), |
| 94 "endData", endResourceLoadData(outcome)); | 95 "endData", EndResourceLoadData(outcome)); |
| 95 } | 96 } |
| 96 | 97 |
| 97 } // namespace network_instrumentation | 98 } // namespace network_instrumentation |
| 99 } // namespace blink |
| OLD | NEW |