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

Side by Side Diff: src/libplatform/tracing/trace-writer.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 | « src/libplatform/tracing/trace-object.cc ('k') | test/cctest/libplatform/test-tracing.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 "src/base/platform/platform.h" 10 #include "src/base/platform/platform.h"
11 11
12 namespace v8 { 12 namespace v8 {
13 namespace platform { 13 namespace platform {
14 namespace tracing { 14 namespace tracing {
15 15
16 // Currently we do not support JSON-escaping strings in trace arguments. 16 // Currently we do not support JSON-escaping strings in trace arguments.
17 // Thus we perform an IsJSONString() check before writing any string argument. 17 // Thus we perform an IsJSONString() check before writing any string argument.
18 // In particular, this means strings cannot have control characters or " or \. 18 // In particular, this means strings cannot have control characters or \.
19 V8_INLINE static bool IsJSONString(const char* str) { 19 V8_INLINE static bool IsJSONString(const char* str) {
20 size_t len = strlen(str); 20 size_t len = strlen(str);
21 for (size_t i = 0; i < len; ++i) { 21 for (size_t i = 0; i < len; ++i) {
22 if (iscntrl(str[i]) || str[i] == '\"' || str[i] == '\\') { 22 if (iscntrl(str[i]) || str[i] == '\\') {
23 return false; 23 return false;
24 } 24 }
25 } 25 }
26 return true; 26 return true;
27 } 27 }
28 28
29 void JSONTraceWriter::AppendArgValue(uint8_t type, 29 void JSONTraceWriter::AppendArgValue(uint8_t type,
30 TraceObject::ArgValue value) { 30 TraceObject::ArgValue value) {
31 switch (type) { 31 switch (type) {
32 case TRACE_VALUE_TYPE_BOOL: 32 case TRACE_VALUE_TYPE_BOOL:
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 } 67 }
68 case TRACE_VALUE_TYPE_POINTER: 68 case TRACE_VALUE_TYPE_POINTER:
69 // JSON only supports double and int numbers. 69 // JSON only supports double and int numbers.
70 // So as not to lose bits from a 64-bit pointer, output as a hex string. 70 // So as not to lose bits from a 64-bit pointer, output as a hex string.
71 stream_ << "\"" << value.as_pointer << "\""; 71 stream_ << "\"" << value.as_pointer << "\"";
72 break; 72 break;
73 case TRACE_VALUE_TYPE_STRING: 73 case TRACE_VALUE_TYPE_STRING:
74 case TRACE_VALUE_TYPE_COPY_STRING: 74 case TRACE_VALUE_TYPE_COPY_STRING:
75 // Strings are currently not JSON-escaped, so we need to perform a check 75 // Strings are currently not JSON-escaped, so we need to perform a check
76 // to see if they are valid JSON strings. 76 // to see if they are valid JSON strings.
77 CHECK(value.as_string == nullptr || IsJSONString(value.as_string)); 77 CHECK(value.as_string != nullptr && IsJSONString(value.as_string));
78 stream_ << "\"" << (value.as_string ? value.as_string : "NULL") << "\""; 78 stream_ << (value.as_string ? value.as_string : "NULL");
79 break; 79 break;
80 default: 80 default:
81 UNREACHABLE(); 81 UNREACHABLE();
82 break; 82 break;
83 } 83 }
84 } 84 }
85 85
86 JSONTraceWriter::JSONTraceWriter(std::ostream& stream) : stream_(stream) { 86 JSONTraceWriter::JSONTraceWriter(std::ostream& stream) : stream_(stream) {
87 stream_ << "{\"traceEvents\":["; 87 stream_ << "{\"traceEvents\":[";
88 } 88 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 125
126 void JSONTraceWriter::Flush() {} 126 void JSONTraceWriter::Flush() {}
127 127
128 TraceWriter* TraceWriter::CreateJSONTraceWriter(std::ostream& stream) { 128 TraceWriter* TraceWriter::CreateJSONTraceWriter(std::ostream& stream) {
129 return new JSONTraceWriter(stream); 129 return new JSONTraceWriter(stream);
130 } 130 }
131 131
132 } // namespace tracing 132 } // namespace tracing
133 } // namespace platform 133 } // namespace platform
134 } // namespace v8 134 } // namespace v8
OLDNEW
« no previous file with comments | « src/libplatform/tracing/trace-object.cc ('k') | test/cctest/libplatform/test-tracing.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698