OLD | NEW |
---|---|
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "vm/isolate.h" | 5 #include "vm/isolate.h" |
6 #include "vm/json_stream.h" | 6 #include "vm/json_stream.h" |
7 #include "vm/object.h" | |
7 #include "vm/os.h" | 8 #include "vm/os.h" |
8 #include "vm/trace_buffer.h" | 9 #include "vm/trace_buffer.h" |
9 | 10 |
10 namespace dart { | 11 namespace dart { |
11 | 12 |
12 TraceBuffer::TraceBuffer(Isolate* isolate, intptr_t capacity) | 13 TraceBuffer::TraceBuffer(Isolate* isolate, intptr_t capacity) |
13 : isolate_(isolate), ring_capacity_(capacity) { | 14 : isolate_(isolate), ring_capacity_(capacity) { |
14 ring_cursor_ = 0; | 15 ring_cursor_ = 0; |
15 ring_ = reinterpret_cast<TraceBufferEntry*>( | 16 ring_ = reinterpret_cast<TraceBufferEntry*>( |
16 calloc(ring_capacity_, sizeof(TraceBufferEntry))); // NOLINT | 17 calloc(ring_capacity_, sizeof(TraceBufferEntry))); // NOLINT |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
69 AppendTrace(micros, message_copy); | 70 AppendTrace(micros, message_copy); |
70 } | 71 } |
71 | 72 |
72 | 73 |
73 void TraceBuffer::Trace(const char* message) { | 74 void TraceBuffer::Trace(const char* message) { |
74 Trace(OS::GetCurrentTimeMicros(), message); | 75 Trace(OS::GetCurrentTimeMicros(), message); |
75 } | 76 } |
76 | 77 |
77 | 78 |
78 void TraceBuffer::TraceF(const char* format, ...) { | 79 void TraceBuffer::TraceF(const char* format, ...) { |
79 int64_t micros = OS::GetCurrentTimeMicros(); | 80 const int64_t micros = OS::GetCurrentTimeMicros(); |
80 va_list args; | 81 va_list args; |
81 va_start(args, format); | 82 va_start(args, format); |
82 intptr_t len = OS::VSNPrint(NULL, 0, format, args); | 83 const intptr_t len = OS::VSNPrint(NULL, 0, format, args); |
83 va_end(args); | 84 va_end(args); |
84 char* p = reinterpret_cast<char*>(malloc(len+1)); | 85 char* p = reinterpret_cast<char*>(malloc(len+1)); |
85 va_start(args, format); | 86 va_start(args, format); |
86 intptr_t len2 = OS::VSNPrint(p, len+1, format, args); | 87 const intptr_t len2 = OS::VSNPrint(p, len+1, format, args); |
87 va_end(args); | 88 va_end(args); |
88 ASSERT(len == len2); | 89 ASSERT(len == len2); |
89 AppendTrace(micros, p); | 90 AppendTrace(micros, p); |
90 } | 91 } |
91 | 92 |
92 | 93 |
94 void TraceBuffer::TraceWarningF(Isolate* isolate, | |
95 const Script& script, intptr_t token_pos, | |
96 const char* format, ...) { | |
97 va_list args; | |
98 va_start(args, format); | |
99 TraceWarningV(isolate, script, token_pos, format, args); | |
100 va_end(args); | |
101 } | |
102 | |
103 | |
104 void TraceBuffer::TraceWarningV(Isolate* isolate, | |
Cutch
2014/06/11 21:45:03
JSONStream js;
{
JSONObject trace_warning(&j
regis
2014/06/11 23:48:35
Done.
| |
105 const Script& script, intptr_t token_pos, | |
106 const char* format, va_list args) { | |
107 const int64_t micros = OS::GetCurrentTimeMicros(); | |
108 TraceBuffer* trace_buffer = isolate->trace_buffer(); | |
109 if (trace_buffer == NULL) { | |
110 Init(isolate); | |
111 trace_buffer = isolate->trace_buffer(); | |
112 } | |
113 JSONStream js; | |
114 JSONObject trace_warning(&js); | |
115 trace_warning.AddProperty("type", "TraceBufferWarning"); | |
116 const String& script_url = String::Handle(script.url()); | |
117 trace_warning.AddProperty("script_url", script_url.ToCString()); | |
118 trace_warning.AddProperty("token_pos", token_pos); | |
119 va_list args_copy; | |
120 va_copy(args_copy, args); | |
121 const intptr_t len = OS::VSNPrint(NULL, 0, format, args_copy); | |
122 va_end(args_copy); | |
123 char* msg = reinterpret_cast<char*>(malloc(len + 1)); | |
124 va_copy(args_copy, args); | |
125 OS::VSNPrint(msg, len + 1, format, args_copy); | |
126 va_end(args_copy); | |
127 trace_warning.AddProperty("message", msg); | |
128 char* message_copy = strdup(js.ToCString()); | |
129 trace_buffer->AppendTrace(micros, message_copy); | |
130 } | |
131 | |
132 | |
93 void TraceBuffer::PrintToJSONStream(JSONStream* stream) const { | 133 void TraceBuffer::PrintToJSONStream(JSONStream* stream) const { |
94 JSONObject json_trace_buffer(stream); | 134 JSONObject json_trace_buffer(stream); |
95 json_trace_buffer.AddProperty("type", "TraceBuffer"); | 135 json_trace_buffer.AddProperty("type", "TraceBuffer"); |
96 // TODO(johnmccutchan): Send cursor position in response. | 136 // TODO(johnmccutchan): Send cursor position in response. |
97 JSONArray json_trace_buffer_array(&json_trace_buffer, "members"); | 137 JSONArray json_trace_buffer_array(&json_trace_buffer, "members"); |
98 // Scan forward until we find the first entry which isn't empty. | 138 // Scan forward until we find the first entry which isn't empty. |
99 // TODO(johnmccutchan): Accept cursor start position as input. | 139 // TODO(johnmccutchan): Accept cursor start position as input. |
100 intptr_t start = -1; | 140 intptr_t start = -1; |
101 for (intptr_t i = 0; i < ring_capacity_; i++) { | 141 for (intptr_t i = 0; i < ring_capacity_; i++) { |
102 intptr_t index = RingIndex(i + ring_cursor_); | 142 intptr_t index = RingIndex(i + ring_cursor_); |
(...skipping 11 matching lines...) Expand all Loading... | |
114 const TraceBufferEntry& entry = ring_[index]; | 154 const TraceBufferEntry& entry = ring_[index]; |
115 if (entry.empty()) { | 155 if (entry.empty()) { |
116 // Empty entry, stop. | 156 // Empty entry, stop. |
117 break; | 157 break; |
118 } | 158 } |
119 JSONObject trace_entry(&json_trace_buffer_array); | 159 JSONObject trace_entry(&json_trace_buffer_array); |
120 trace_entry.AddProperty("type", "TraceBufferEntry"); | 160 trace_entry.AddProperty("type", "TraceBufferEntry"); |
121 double seconds = static_cast<double>(entry.micros) / | 161 double seconds = static_cast<double>(entry.micros) / |
122 static_cast<double>(kMicrosecondsPerSecond); | 162 static_cast<double>(kMicrosecondsPerSecond); |
123 trace_entry.AddProperty("time", seconds); | 163 trace_entry.AddProperty("time", seconds); |
124 trace_entry.AddProperty("message", entry.message); | 164 trace_entry.AddProperty("message", entry.message); |
Cutch
2014/06/11 21:45:03
Here, we can do:
if (entry.message_is_escaped) {
regis
2014/06/11 23:48:35
Done.
| |
125 } | 165 } |
126 } | 166 } |
127 | 167 |
128 } // namespace dart | 168 } // namespace dart |
OLD | NEW |