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

Side by Side Diff: src/libplatform/tracing/trace-writer.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/tracing/trace-writer.h ('k') | src/libplatform/tracing/tracing-controller.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 "src/libplatform/tracing/trace-writer.h" 5 #include "src/libplatform/tracing/trace-writer.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #include "base/trace_event/common/trace_event_common.h" 9 #include "base/trace_event/common/trace_event_common.h"
10 #include "include/v8-platform.h"
10 #include "src/base/platform/platform.h" 11 #include "src/base/platform/platform.h"
11 12
12 namespace v8 { 13 namespace v8 {
13 namespace platform { 14 namespace platform {
14 namespace tracing { 15 namespace tracing {
15 16
16 // Writes the given string to a stream, taking care to escape characters 17 // Writes the given string to a stream, taking care to escape characters
17 // when necessary. 18 // when necessary.
18 V8_INLINE static void WriteJSONStringToStream(const char* str, 19 V8_INLINE static void WriteJSONStringToStream(const char* str,
19 std::ostream& stream) { 20 std::ostream& stream) {
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 } else { 106 } else {
106 WriteJSONStringToStream(value.as_string, stream_); 107 WriteJSONStringToStream(value.as_string, stream_);
107 } 108 }
108 break; 109 break;
109 default: 110 default:
110 UNREACHABLE(); 111 UNREACHABLE();
111 break; 112 break;
112 } 113 }
113 } 114 }
114 115
116 void JSONTraceWriter::AppendArgValue(ConvertableToTraceFormat* value) {
117 std::string arg_stringified;
118 value->AppendAsTraceFormat(&arg_stringified);
119 stream_ << arg_stringified;
120 }
121
115 JSONTraceWriter::JSONTraceWriter(std::ostream& stream) : stream_(stream) { 122 JSONTraceWriter::JSONTraceWriter(std::ostream& stream) : stream_(stream) {
116 stream_ << "{\"traceEvents\":["; 123 stream_ << "{\"traceEvents\":[";
117 } 124 }
118 125
119 JSONTraceWriter::~JSONTraceWriter() { stream_ << "]}"; } 126 JSONTraceWriter::~JSONTraceWriter() { stream_ << "]}"; }
120 127
121 void JSONTraceWriter::AppendTraceEvent(TraceObject* trace_event) { 128 void JSONTraceWriter::AppendTraceEvent(TraceObject* trace_event) {
122 if (append_comma_) stream_ << ","; 129 if (append_comma_) stream_ << ",";
123 append_comma_ = true; 130 append_comma_ = true;
124 stream_ << "{\"pid\":" << trace_event->pid() 131 stream_ << "{\"pid\":" << trace_event->pid()
(...skipping 11 matching lines...) Expand all
136 stream_ << ",\"scope\":\"" << trace_event->scope() << "\""; 143 stream_ << ",\"scope\":\"" << trace_event->scope() << "\"";
137 } 144 }
138 // So as not to lose bits from a 64-bit integer, output as a hex string. 145 // So as not to lose bits from a 64-bit integer, output as a hex string.
139 stream_ << ",\"id\":\"0x" << std::hex << trace_event->id() << "\"" 146 stream_ << ",\"id\":\"0x" << std::hex << trace_event->id() << "\""
140 << std::dec; 147 << std::dec;
141 } 148 }
142 stream_ << ",\"args\":{"; 149 stream_ << ",\"args\":{";
143 const char** arg_names = trace_event->arg_names(); 150 const char** arg_names = trace_event->arg_names();
144 const uint8_t* arg_types = trace_event->arg_types(); 151 const uint8_t* arg_types = trace_event->arg_types();
145 TraceObject::ArgValue* arg_values = trace_event->arg_values(); 152 TraceObject::ArgValue* arg_values = trace_event->arg_values();
153 std::unique_ptr<v8::ConvertableToTraceFormat>* arg_convertables =
154 trace_event->arg_convertables();
146 for (int i = 0; i < trace_event->num_args(); ++i) { 155 for (int i = 0; i < trace_event->num_args(); ++i) {
147 if (i > 0) stream_ << ","; 156 if (i > 0) stream_ << ",";
148 stream_ << "\"" << arg_names[i] << "\":"; 157 stream_ << "\"" << arg_names[i] << "\":";
149 AppendArgValue(arg_types[i], arg_values[i]); 158 if (arg_types[i] == TRACE_VALUE_TYPE_CONVERTABLE) {
159 AppendArgValue(arg_convertables[i].get());
160 } else {
161 AppendArgValue(arg_types[i], arg_values[i]);
162 }
150 } 163 }
151 stream_ << "}}"; 164 stream_ << "}}";
152 // TODO(fmeawad): Add support for Flow Events. 165 // TODO(fmeawad): Add support for Flow Events.
153 } 166 }
154 167
155 void JSONTraceWriter::Flush() {} 168 void JSONTraceWriter::Flush() {}
156 169
157 TraceWriter* TraceWriter::CreateJSONTraceWriter(std::ostream& stream) { 170 TraceWriter* TraceWriter::CreateJSONTraceWriter(std::ostream& stream) {
158 return new JSONTraceWriter(stream); 171 return new JSONTraceWriter(stream);
159 } 172 }
160 173
161 } // namespace tracing 174 } // namespace tracing
162 } // namespace platform 175 } // namespace platform
163 } // namespace v8 176 } // namespace v8
OLDNEW
« no previous file with comments | « src/libplatform/tracing/trace-writer.h ('k') | src/libplatform/tracing/tracing-controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698