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

Side by Side Diff: src/libplatform/tracing/trace-object.cc

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

Powered by Google App Engine
This is Rietveld 408576698