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

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

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