Chromium Code Reviews| Index: runtime/vm/trace_buffer.cc |
| diff --git a/runtime/vm/trace_buffer.cc b/runtime/vm/trace_buffer.cc |
| index 831e95d6abd74a5d45a79d9ff3a807a25fb9f004..8ed484263608b663d60ed787e436af3c85c0297e 100644 |
| --- a/runtime/vm/trace_buffer.cc |
| +++ b/runtime/vm/trace_buffer.cc |
| @@ -8,7 +8,10 @@ |
| namespace dart { |
| -TraceBuffer::TraceBuffer(intptr_t capacity) : ring_capacity_(capacity) { |
| +TraceBuffer::TraceBuffer(intptr_t initial_capacity, intptr_t maximum_capacity) |
| + : ring_capacity_(initial_capacity), |
| + ring_max_capacity_(maximum_capacity) { |
|
turnidge
2014/04/15 21:35:20
ring_capacity -> capacity, etc.
Cutch
2014/04/21 15:39:19
Done.
|
| + ring_size_ = 0; |
| ring_cursor_ = 0; |
| Init(); |
| } |
| @@ -27,6 +30,24 @@ void TraceBuffer::Init() { |
| } |
| +void TraceBuffer::Resize(intptr_t capacity) { |
|
turnidge
2014/04/15 21:35:20
capacity -> new_capacity?
Cutch
2014/04/21 15:39:19
Done.
|
| + ASSERT(capacity > ring_capacity_); |
| + if (capacity > ring_max_capacity_) { |
| + // Clamp to ring_max_capacity_. |
| + capacity = ring_max_capacity_; |
| + } |
| + ASSERT(capacity <= ring_max_capacity_); |
| + ring_ = reinterpret_cast<TraceBufferEntry*>( |
| + realloc(ring_, sizeof(*ring_) * capacity)); |
| + // Initialize new TraceBufferEntries. |
| + for (intptr_t i = ring_capacity_; i < capacity; i++) { |
| + ring_[i].micros = 0; |
| + ring_[i].message = NULL; |
| + } |
| + ring_capacity_ = capacity; |
| +} |
| + |
| + |
| void TraceBuffer::Clear() { |
| for (intptr_t i = 0; i < ring_capacity_; i++) { |
| TraceBufferEntry& entry = ring_[i]; |
| @@ -35,6 +56,7 @@ void TraceBuffer::Clear() { |
| entry.message = NULL; |
| } |
| ring_cursor_ = 0; |
| + ring_size_ = 0; |
| } |
| @@ -49,6 +71,14 @@ void TraceBuffer::Fill(TraceBufferEntry* entry, int64_t micros, char* msg) { |
| void TraceBuffer::AppendTrace(int64_t micros, char* message) { |
| + if (ring_size_ < ring_capacity_) { |
| + ring_size_++; |
| + if ((ring_size_ == ring_capacity_) && |
| + (ring_capacity_ < ring_max_capacity_)) { |
| + // Double size. |
| + Resize(ring_capacity_ * 2); |
| + } |
| + } |
| const intptr_t index = ring_cursor_; |
| TraceBufferEntry* trace_entry = &ring_[index]; |
| Fill(trace_entry, micros, message); |
| @@ -83,11 +113,11 @@ void TraceBuffer::TraceF(const char* format, ...) { |
| } |
| -void TraceBuffer::PrintToJSONStream(JSONStream* stream) const { |
| - JSONObject json_trace_buffer(stream); |
| - json_trace_buffer.AddProperty("type", "TraceBuffer"); |
| +void TraceBuffer::PrintToJSONObject(JSONObject* json_trace_buffer) const { |
| + json_trace_buffer->AddProperty("type", "TraceBuffer"); |
| + json_trace_buffer->AddProperty("id", ""); |
| // TODO(johnmccutchan): Send cursor position in response. |
| - JSONArray json_trace_buffer_array(&json_trace_buffer, "members"); |
| + JSONArray json_trace_buffer_array(json_trace_buffer, "members"); |
| // Scan forward until we find the first entry which isn't empty. |
| // TODO(johnmccutchan): Accept cursor start position as input. |
| intptr_t start = -1; |
| @@ -111,11 +141,18 @@ void TraceBuffer::PrintToJSONStream(JSONStream* stream) const { |
| } |
| JSONObject trace_entry(&json_trace_buffer_array); |
| trace_entry.AddProperty("type", "TraceBufferEntry"); |
| - double seconds = static_cast<double>(entry.micros) / |
| - static_cast<double>(kMicrosecondsPerSecond); |
| - trace_entry.AddProperty("time", seconds); |
| + trace_entry.AddProperty("id", ""); |
| + intptr_t millis = |
| + static_cast<intptr_t>(entry.micros / kMicrosecondsPerMillisecond); |
| + trace_entry.AddProperty("time", millis); |
| trace_entry.AddProperty("message", entry.message); |
| } |
| } |
| + |
| +void TraceBuffer::PrintToJSONStream(JSONStream* stream) const { |
| + JSONObject json_trace_buffer(stream); |
| + PrintToJSONObject(&json_trace_buffer); |
| +} |
| + |
| } // namespace dart |