| OLD | NEW |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project 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 "include/libplatform/v8-tracing.h" | 5 #include "include/libplatform/v8-tracing.h" |
| 6 | 6 |
| 7 #include "base/trace_event/common/trace_event_common.h" | 7 #include "base/trace_event/common/trace_event_common.h" |
| 8 #include "include/v8-platform.h" | |
| 9 #include "src/base/platform/platform.h" | 8 #include "src/base/platform/platform.h" |
| 10 #include "src/base/platform/time.h" | 9 #include "src/base/platform/time.h" |
| 11 | 10 |
| 12 namespace v8 { | 11 namespace v8 { |
| 13 namespace platform { | 12 namespace platform { |
| 14 namespace tracing { | 13 namespace tracing { |
| 15 | 14 |
| 16 // We perform checks for NULL strings since it is possible that a string arg | 15 // We perform checks for NULL strings since it is possible that a string arg |
| 17 // value is NULL. | 16 // value is NULL. |
| 18 V8_INLINE static size_t GetAllocLength(const char* str) { | 17 V8_INLINE static size_t GetAllocLength(const char* str) { |
| 19 return str ? strlen(str) + 1 : 0; | 18 return str ? strlen(str) + 1 : 0; |
| 20 } | 19 } |
| 21 | 20 |
| 22 // Copies |*member| into |*buffer|, sets |*member| to point to this new | 21 // Copies |*member| into |*buffer|, sets |*member| to point to this new |
| 23 // location, and then advances |*buffer| by the amount written. | 22 // location, and then advances |*buffer| by the amount written. |
| 24 V8_INLINE static void CopyTraceObjectParameter(char** buffer, | 23 V8_INLINE static void CopyTraceObjectParameter(char** buffer, |
| 25 const char** member) { | 24 const char** member) { |
| 26 if (*member) { | 25 if (*member) { |
| 27 size_t length = strlen(*member) + 1; | 26 size_t length = strlen(*member) + 1; |
| 28 strncpy(*buffer, *member, length); | 27 strncpy(*buffer, *member, length); |
| 29 *member = *buffer; | 28 *member = *buffer; |
| 30 *buffer += length; | 29 *buffer += length; |
| 31 } | 30 } |
| 32 } | 31 } |
| 33 | 32 |
| 34 void TraceObject::Initialize( | 33 void TraceObject::Initialize(char phase, const uint8_t* category_enabled_flag, |
| 35 char phase, const uint8_t* category_enabled_flag, const char* name, | 34 const char* name, const char* scope, uint64_t id, |
| 36 const char* scope, uint64_t id, uint64_t bind_id, int num_args, | 35 uint64_t bind_id, int num_args, |
| 37 const char** arg_names, const uint8_t* arg_types, | 36 const char** arg_names, const uint8_t* arg_types, |
| 38 const uint64_t* arg_values, | 37 const uint64_t* arg_values, unsigned int flags) { |
| 39 std::unique_ptr<v8::ConvertableToTraceFormat>* arg_convertables, | |
| 40 unsigned int flags) { | |
| 41 pid_ = base::OS::GetCurrentProcessId(); | 38 pid_ = base::OS::GetCurrentProcessId(); |
| 42 tid_ = base::OS::GetCurrentThreadId(); | 39 tid_ = base::OS::GetCurrentThreadId(); |
| 43 phase_ = phase; | 40 phase_ = phase; |
| 44 category_enabled_flag_ = category_enabled_flag; | 41 category_enabled_flag_ = category_enabled_flag; |
| 45 name_ = name; | 42 name_ = name; |
| 46 scope_ = scope; | 43 scope_ = scope; |
| 47 id_ = id; | 44 id_ = id; |
| 48 bind_id_ = bind_id; | 45 bind_id_ = bind_id; |
| 49 flags_ = flags; | 46 flags_ = flags; |
| 50 ts_ = base::TimeTicks::HighResolutionNow().ToInternalValue(); | 47 ts_ = base::TimeTicks::HighResolutionNow().ToInternalValue(); |
| 51 tts_ = base::ThreadTicks::Now().ToInternalValue(); | 48 tts_ = base::ThreadTicks::Now().ToInternalValue(); |
| 52 duration_ = 0; | 49 duration_ = 0; |
| 53 cpu_duration_ = 0; | 50 cpu_duration_ = 0; |
| 54 | 51 |
| 55 // Clamp num_args since it may have been set by a third-party library. | 52 // Clamp num_args since it may have been set by a third-party library. |
| 56 num_args_ = (num_args > kTraceMaxNumArgs) ? kTraceMaxNumArgs : num_args; | 53 num_args_ = (num_args > kTraceMaxNumArgs) ? kTraceMaxNumArgs : num_args; |
| 57 for (int i = 0; i < num_args_; ++i) { | 54 for (int i = 0; i < num_args_; ++i) { |
| 58 arg_names_[i] = arg_names[i]; | 55 arg_names_[i] = arg_names[i]; |
| 59 arg_values_[i].as_uint = arg_values[i]; | 56 arg_values_[i].as_uint = arg_values[i]; |
| 60 arg_types_[i] = arg_types[i]; | 57 arg_types_[i] = arg_types[i]; |
| 61 if (arg_types[i] == TRACE_VALUE_TYPE_CONVERTABLE) | |
| 62 arg_convertables_[i] = std::move(arg_convertables[i]); | |
| 63 } | 58 } |
| 64 | 59 |
| 65 bool copy = !!(flags & TRACE_EVENT_FLAG_COPY); | 60 bool copy = !!(flags & TRACE_EVENT_FLAG_COPY); |
| 66 // Allocate a long string to fit all string copies. | 61 // Allocate a long string to fit all string copies. |
| 67 size_t alloc_size = 0; | 62 size_t alloc_size = 0; |
| 68 if (copy) { | 63 if (copy) { |
| 69 alloc_size += GetAllocLength(name) + GetAllocLength(scope); | 64 alloc_size += GetAllocLength(name) + GetAllocLength(scope); |
| 70 for (int i = 0; i < num_args_; ++i) { | 65 for (int i = 0; i < num_args_; ++i) { |
| 71 alloc_size += GetAllocLength(arg_names_[i]); | 66 alloc_size += GetAllocLength(arg_names_[i]); |
| 72 if (arg_types_[i] == TRACE_VALUE_TYPE_STRING) | 67 if (arg_types_[i] == TRACE_VALUE_TYPE_STRING) |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 | 100 |
| 106 void TraceObject::UpdateDuration() { | 101 void TraceObject::UpdateDuration() { |
| 107 duration_ = base::TimeTicks::HighResolutionNow().ToInternalValue() - ts_; | 102 duration_ = base::TimeTicks::HighResolutionNow().ToInternalValue() - ts_; |
| 108 cpu_duration_ = base::ThreadTicks::Now().ToInternalValue() - tts_; | 103 cpu_duration_ = base::ThreadTicks::Now().ToInternalValue() - tts_; |
| 109 } | 104 } |
| 110 | 105 |
| 111 void TraceObject::InitializeForTesting( | 106 void TraceObject::InitializeForTesting( |
| 112 char phase, const uint8_t* category_enabled_flag, const char* name, | 107 char phase, const uint8_t* category_enabled_flag, const char* name, |
| 113 const char* scope, uint64_t id, uint64_t bind_id, int num_args, | 108 const char* scope, uint64_t id, uint64_t bind_id, int num_args, |
| 114 const char** arg_names, const uint8_t* arg_types, | 109 const char** arg_names, const uint8_t* arg_types, |
| 115 const uint64_t* arg_values, | 110 const uint64_t* arg_values, unsigned int flags, int pid, int tid, |
| 116 std::unique_ptr<v8::ConvertableToTraceFormat>* arg_convertables, | 111 int64_t ts, int64_t tts, uint64_t duration, uint64_t cpu_duration) { |
| 117 unsigned int flags, int pid, int tid, int64_t ts, int64_t tts, | |
| 118 uint64_t duration, uint64_t cpu_duration) { | |
| 119 pid_ = pid; | 112 pid_ = pid; |
| 120 tid_ = tid; | 113 tid_ = tid; |
| 121 phase_ = phase; | 114 phase_ = phase; |
| 122 category_enabled_flag_ = category_enabled_flag; | 115 category_enabled_flag_ = category_enabled_flag; |
| 123 name_ = name; | 116 name_ = name; |
| 124 scope_ = scope; | 117 scope_ = scope; |
| 125 id_ = id; | 118 id_ = id; |
| 126 bind_id_ = bind_id; | 119 bind_id_ = bind_id; |
| 127 num_args_ = num_args; | 120 num_args_ = num_args; |
| 128 flags_ = flags; | 121 flags_ = flags; |
| 129 ts_ = ts; | 122 ts_ = ts; |
| 130 tts_ = tts; | 123 tts_ = tts; |
| 131 duration_ = duration; | 124 duration_ = duration; |
| 132 cpu_duration_ = cpu_duration; | 125 cpu_duration_ = cpu_duration; |
| 133 } | 126 } |
| 134 | 127 |
| 135 } // namespace tracing | 128 } // namespace tracing |
| 136 } // namespace platform | 129 } // namespace platform |
| 137 } // namespace v8 | 130 } // namespace v8 |
| OLD | NEW |