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

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

Issue 2232683002: [Tracing] Minor bugs fix. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: remove end Created 4 years, 4 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 | « no previous file | src/libplatform/tracing/trace-writer.cc » ('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 "src/base/platform/platform.h" 8 #include "src/base/platform/platform.h"
9 #include "src/base/platform/time.h" 9 #include "src/base/platform/time.h"
10 10
11 namespace v8 { 11 namespace v8 {
12 namespace platform { 12 namespace platform {
13 namespace tracing { 13 namespace tracing {
14 14
15 // 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
16 // value is NULL. 16 // value is NULL.
17 V8_INLINE static size_t GetAllocLength(const char* str) { 17 V8_INLINE static size_t GetAllocLength(const char* str) {
18 return str ? strlen(str) + 1 : 0; 18 return str ? strlen(str) + 1 : 0;
19 } 19 }
20 20
21 // Copies |*member| into |*buffer|, sets |*member| to point to this new 21 // Copies |*member| into |*buffer|, sets |*member| to point to this new
22 // location, and then advances |*buffer| by the amount written. 22 // location, and then advances |*buffer| by the amount written.
23 V8_INLINE static void CopyTraceObjectParameter(char** buffer, 23 V8_INLINE static void CopyTraceObjectParameter(char** buffer,
24 const char** member, 24 const char** member) {
25 const char* end) {
26 if (*member) { 25 if (*member) {
27 strncpy(*buffer, *member, end - *buffer); 26 size_t length = strlen(*member) + 1;
27 strncpy(*buffer, *member, length);
28 *member = *buffer; 28 *member = *buffer;
29 *buffer += strlen(*member) + 1; 29 *buffer += length;
30 } 30 }
31 } 31 }
32 32
33 void TraceObject::Initialize(char phase, const uint8_t* category_enabled_flag, 33 void TraceObject::Initialize(char phase, const uint8_t* category_enabled_flag,
34 const char* name, const char* scope, uint64_t id, 34 const char* name, const char* scope, uint64_t id,
35 uint64_t bind_id, int num_args, 35 uint64_t bind_id, int num_args,
36 const char** arg_names, const uint8_t* arg_types, 36 const char** arg_names, const uint8_t* arg_types,
37 const uint64_t* arg_values, unsigned int flags) { 37 const uint64_t* arg_values, unsigned int flags) {
38 pid_ = base::OS::GetCurrentProcessId(); 38 pid_ = base::OS::GetCurrentProcessId();
39 tid_ = base::OS::GetCurrentThreadId(); 39 tid_ = base::OS::GetCurrentThreadId();
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 // We only take a copy of arg_vals if they are of type COPY_STRING. 74 // We only take a copy of arg_vals if they are of type COPY_STRING.
75 arg_is_copy[i] = (arg_types_[i] == TRACE_VALUE_TYPE_COPY_STRING); 75 arg_is_copy[i] = (arg_types_[i] == TRACE_VALUE_TYPE_COPY_STRING);
76 if (arg_is_copy[i]) alloc_size += GetAllocLength(arg_values_[i].as_string); 76 if (arg_is_copy[i]) alloc_size += GetAllocLength(arg_values_[i].as_string);
77 } 77 }
78 78
79 if (alloc_size) { 79 if (alloc_size) {
80 // Since TraceObject can be initialized multiple times, we might need 80 // Since TraceObject can be initialized multiple times, we might need
81 // to free old memory. 81 // to free old memory.
82 delete[] parameter_copy_storage_; 82 delete[] parameter_copy_storage_;
83 char* ptr = parameter_copy_storage_ = new char[alloc_size]; 83 char* ptr = parameter_copy_storage_ = new char[alloc_size];
84 const char* end = ptr + alloc_size;
85 if (copy) { 84 if (copy) {
86 CopyTraceObjectParameter(&ptr, &name_, end); 85 CopyTraceObjectParameter(&ptr, &name_);
87 CopyTraceObjectParameter(&ptr, &scope_, end); 86 CopyTraceObjectParameter(&ptr, &scope_);
88 for (int i = 0; i < num_args_; ++i) { 87 for (int i = 0; i < num_args_; ++i) {
89 CopyTraceObjectParameter(&ptr, &arg_names_[i], end); 88 CopyTraceObjectParameter(&ptr, &arg_names_[i]);
90 } 89 }
91 } 90 }
92 for (int i = 0; i < num_args_; ++i) { 91 for (int i = 0; i < num_args_; ++i) {
93 if (arg_is_copy[i]) { 92 if (arg_is_copy[i]) {
94 CopyTraceObjectParameter(&ptr, &arg_values_[i].as_string, end); 93 CopyTraceObjectParameter(&ptr, &arg_values_[i].as_string);
95 } 94 }
96 } 95 }
97 } 96 }
98 } 97 }
99 98
100 TraceObject::~TraceObject() { delete[] parameter_copy_storage_; } 99 TraceObject::~TraceObject() { delete[] parameter_copy_storage_; }
101 100
102 void TraceObject::UpdateDuration() { 101 void TraceObject::UpdateDuration() {
103 duration_ = base::TimeTicks::HighResolutionNow().ToInternalValue() - ts_; 102 duration_ = base::TimeTicks::HighResolutionNow().ToInternalValue() - ts_;
104 cpu_duration_ = base::ThreadTicks::Now().ToInternalValue() - tts_; 103 cpu_duration_ = base::ThreadTicks::Now().ToInternalValue() - tts_;
(...skipping 17 matching lines...) Expand all
122 flags_ = flags; 121 flags_ = flags;
123 ts_ = ts; 122 ts_ = ts;
124 tts_ = tts; 123 tts_ = tts;
125 duration_ = duration; 124 duration_ = duration;
126 cpu_duration_ = cpu_duration; 125 cpu_duration_ = cpu_duration;
127 } 126 }
128 127
129 } // namespace tracing 128 } // namespace tracing
130 } // namespace platform 129 } // namespace platform
131 } // namespace v8 130 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | src/libplatform/tracing/trace-writer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698