| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "platform/EventTracer.h" | 31 #include "platform/EventTracer.h" |
| 32 | 32 |
| 33 #include "base/time/time.h" | 33 #include "base/time/time.h" |
| 34 #include "base/trace_event/trace_event.h" | 34 #include "base/trace_event/trace_event.h" |
| 35 #include "base/trace_event/trace_event_argument.h" |
| 36 #include "platform/TracedValue.h" |
| 35 #include "public/platform/Platform.h" | 37 #include "public/platform/Platform.h" |
| 36 #include "wtf/Assertions.h" | 38 #include "wtf/Assertions.h" |
| 37 #include "wtf/text/StringUTF8Adaptor.h" | 39 #include "wtf/text/StringUTF8Adaptor.h" |
| 38 #include <stdio.h> | 40 #include <stdio.h> |
| 39 | 41 |
| 40 namespace blink { | 42 namespace blink { |
| 41 | 43 |
| 42 static_assert(sizeof(TraceEvent::TraceEventHandle) == sizeof(base::trace_event::
TraceEventHandle), "TraceEventHandle types must be the same"); | 44 static_assert(sizeof(TraceEvent::TraceEventHandle) == sizeof(base::trace_event::
TraceEventHandle), "TraceEventHandle types must be the same"); |
| 43 static_assert(sizeof(TraceEvent::TraceEventAPIAtomicWord) == sizeof(const char*)
, "TraceEventAPIAtomicWord must be pointer-sized."); | 45 static_assert(sizeof(TraceEvent::TraceEventAPIAtomicWord) == sizeof(const char*)
, "TraceEventAPIAtomicWord must be pointer-sized."); |
| 44 | 46 |
| 45 namespace { | |
| 46 | |
| 47 class ConvertableToTraceFormatWrapper : public base::trace_event::ConvertableToT
raceFormat { | |
| 48 public: | |
| 49 // We move a reference pointer from |convertable| to |m_convertable|, | |
| 50 // rather than copying, for thread safety. https://crbug.com/478149 | |
| 51 explicit ConvertableToTraceFormatWrapper(PassRefPtr<blink::TraceEvent::Conve
rtableToTraceFormat> convertable) | |
| 52 : m_convertable(convertable) | |
| 53 { | |
| 54 ASSERT(m_convertable); | |
| 55 } | |
| 56 void AppendAsTraceFormat(std::string* out) const override | |
| 57 { | |
| 58 // TODO(bashi): Avoid copying. | |
| 59 String traceFormat = m_convertable->asTraceFormat(); | |
| 60 StringUTF8Adaptor utf8(traceFormat); | |
| 61 out->append(utf8.data(), utf8.length()); | |
| 62 } | |
| 63 void EstimateTraceMemoryOverhead(base::trace_event::TraceEventMemoryOverhead
* overhead) | |
| 64 { | |
| 65 m_convertable->estimateTraceMemoryOverhead(overhead); | |
| 66 } | |
| 67 | |
| 68 private: | |
| 69 ~ConvertableToTraceFormatWrapper() override {} | |
| 70 | |
| 71 RefPtr<blink::TraceEvent::ConvertableToTraceFormat> m_convertable; | |
| 72 }; | |
| 73 | |
| 74 } // namespace | |
| 75 | |
| 76 // The dummy variable is needed to avoid a crash when someone updates the state
variables | 47 // The dummy variable is needed to avoid a crash when someone updates the state
variables |
| 77 // before EventTracer::initialize() is called. | 48 // before EventTracer::initialize() is called. |
| 78 TraceEvent::TraceEventAPIAtomicWord dummyTraceSamplingState = 0; | 49 TraceEvent::TraceEventAPIAtomicWord dummyTraceSamplingState = 0; |
| 79 TraceEvent::TraceEventAPIAtomicWord* traceSamplingState[3] = {&dummyTraceSamplin
gState, &dummyTraceSamplingState, &dummyTraceSamplingState }; | 50 TraceEvent::TraceEventAPIAtomicWord* traceSamplingState[3] = {&dummyTraceSamplin
gState, &dummyTraceSamplingState, &dummyTraceSamplingState }; |
| 80 | 51 |
| 81 void EventTracer::initialize() | 52 void EventTracer::initialize() |
| 82 { | 53 { |
| 83 traceSamplingState[0] = reinterpret_cast<TraceEvent::TraceEventAPIAtomicWord
*>(&TRACE_EVENT_API_THREAD_BUCKET(0)); | 54 traceSamplingState[0] = reinterpret_cast<TraceEvent::TraceEventAPIAtomicWord
*>(&TRACE_EVENT_API_THREAD_BUCKET(0)); |
| 84 // FIXME: traceSamplingState[0] can be 0 in split-dll build. http://crbug.co
m/256965 | 55 // FIXME: traceSamplingState[0] can be 0 in split-dll build. http://crbug.co
m/256965 |
| 85 if (!traceSamplingState[0]) | 56 if (!traceSamplingState[0]) |
| 86 traceSamplingState[0] = &dummyTraceSamplingState; | 57 traceSamplingState[0] = &dummyTraceSamplingState; |
| 87 traceSamplingState[1] = reinterpret_cast<TraceEvent::TraceEventAPIAtomicWord
*>(&TRACE_EVENT_API_THREAD_BUCKET(1)); | 58 traceSamplingState[1] = reinterpret_cast<TraceEvent::TraceEventAPIAtomicWord
*>(&TRACE_EVENT_API_THREAD_BUCKET(1)); |
| 88 if (!traceSamplingState[1]) | 59 if (!traceSamplingState[1]) |
| 89 traceSamplingState[1] = &dummyTraceSamplingState; | 60 traceSamplingState[1] = &dummyTraceSamplingState; |
| 90 traceSamplingState[2] = reinterpret_cast<TraceEvent::TraceEventAPIAtomicWord
*>(&TRACE_EVENT_API_THREAD_BUCKET(2)); | 61 traceSamplingState[2] = reinterpret_cast<TraceEvent::TraceEventAPIAtomicWord
*>(&TRACE_EVENT_API_THREAD_BUCKET(2)); |
| 91 if (!traceSamplingState[2]) | 62 if (!traceSamplingState[2]) |
| 92 traceSamplingState[2] = &dummyTraceSamplingState; | 63 traceSamplingState[2] = &dummyTraceSamplingState; |
| 93 } | 64 } |
| 94 | 65 |
| 95 const unsigned char* EventTracer::getTraceCategoryEnabledFlag(const char* catego
ryName) | 66 const unsigned char* EventTracer::getTraceCategoryEnabledFlag(const char* catego
ryName) |
| 96 { | 67 { |
| 97 return TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(categoryName); | 68 return TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(categoryName); |
| 98 } | 69 } |
| 99 | 70 |
| 100 TraceEvent::TraceEventHandle EventTracer::addTraceEvent(char phase, const unsign
ed char* categoryEnabledFlag, | 71 TraceEvent::TraceEventHandle EventTracer::addTraceEvent(char phase, const unsign
ed char* categoryEnabledFlag, |
| 101 const char* name, unsigned long long id, unsigned long long bindId, double t
imestamp, | 72 const char* name, unsigned long long id, unsigned long long bindId, double t
imestamp, |
| 102 int numArgs, const char* argNames[], const unsigned char argTypes[], | 73 int numArgs, const char* argNames[], const unsigned char argTypes[], |
| 103 const unsigned long long argValues[], | 74 const unsigned long long argValues[], |
| 104 PassRefPtr<TraceEvent::ConvertableToTraceFormat> convertableValue1, | 75 PassRefPtr<TracedValue> tracedValue1, |
| 105 PassRefPtr<TraceEvent::ConvertableToTraceFormat> convertableValue2, | 76 PassRefPtr<TracedValue> tracedValue2, |
| 106 unsigned flags) | 77 unsigned flags) |
| 107 { | 78 { |
| 108 scoped_refptr<base::trace_event::ConvertableToTraceFormat> wrappers[2]; | 79 scoped_refptr<base::trace_event::ConvertableToTraceFormat> convertables[2]; |
| 109 ASSERT(numArgs <= 2); | 80 ASSERT(numArgs <= 2); |
| 81 // We move m_tracedValues from TracedValues for thread safety. |
| 82 // https://crbug.com/478149 |
| 110 if (numArgs >= 1 && argTypes[0] == TRACE_VALUE_TYPE_CONVERTABLE) | 83 if (numArgs >= 1 && argTypes[0] == TRACE_VALUE_TYPE_CONVERTABLE) |
| 111 wrappers[0] = new ConvertableToTraceFormatWrapper(convertableValue1); | 84 convertables[0] = std::move(tracedValue1->m_tracedValue); |
| 112 if (numArgs >= 2 && argTypes[1] == TRACE_VALUE_TYPE_CONVERTABLE) | 85 if (numArgs >= 2 && argTypes[1] == TRACE_VALUE_TYPE_CONVERTABLE) |
| 113 wrappers[1] = new ConvertableToTraceFormatWrapper(convertableValue2); | 86 convertables[1] = std::move(tracedValue2->m_tracedValue); |
| 114 return addTraceEvent(phase, categoryEnabledFlag, name, id, bindId, timestamp
, numArgs, argNames, argTypes, argValues, wrappers, flags); | 87 return addTraceEvent(phase, categoryEnabledFlag, name, id, bindId, timestamp
, numArgs, argNames, argTypes, argValues, convertables, flags); |
| 115 } | 88 } |
| 116 | 89 |
| 117 TraceEvent::TraceEventHandle EventTracer::addTraceEvent(char phase, const unsign
ed char* categoryEnabledFlag, | 90 TraceEvent::TraceEventHandle EventTracer::addTraceEvent(char phase, const unsign
ed char* categoryEnabledFlag, |
| 118 const char* name, unsigned long long id, unsigned long long bindId, double t
imestamp, | 91 const char* name, unsigned long long id, unsigned long long bindId, double t
imestamp, |
| 119 int numArgs, const char** argNames, const unsigned char* argTypes, | 92 int numArgs, const char** argNames, const unsigned char* argTypes, |
| 120 const unsigned long long* argValues, unsigned flags) | 93 const unsigned long long* argValues, unsigned flags) |
| 121 { | 94 { |
| 122 return addTraceEvent(phase, categoryEnabledFlag, name, id, bindId, timestamp
, numArgs, argNames, argTypes, argValues, nullptr, flags); | 95 return addTraceEvent(phase, categoryEnabledFlag, name, id, bindId, timestamp
, numArgs, argNames, argTypes, argValues, nullptr, flags); |
| 123 } | 96 } |
| 124 | 97 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 140 memcpy(&traceEventHandle, &handle, sizeof(handle)); | 113 memcpy(&traceEventHandle, &handle, sizeof(handle)); |
| 141 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(categoryEnabledFlag, name, trace
EventHandle); | 114 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(categoryEnabledFlag, name, trace
EventHandle); |
| 142 } | 115 } |
| 143 | 116 |
| 144 double EventTracer::systemTraceTime() | 117 double EventTracer::systemTraceTime() |
| 145 { | 118 { |
| 146 return (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF(); | 119 return (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF(); |
| 147 } | 120 } |
| 148 | 121 |
| 149 } // namespace blink | 122 } // namespace blink |
| OLD | NEW |