| 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 #ifndef VM_TRACE_BUFFER_H_ | 5 #ifndef VM_TRACE_BUFFER_H_ |
| 6 #define VM_TRACE_BUFFER_H_ | 6 #define VM_TRACE_BUFFER_H_ |
| 7 | 7 |
| 8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
| 9 #include "platform/globals.h" | 9 #include "platform/globals.h" |
| 10 #include "vm/json_stream.h" | 10 #include "vm/json_stream.h" |
| 11 | 11 |
| 12 namespace dart { | 12 namespace dart { |
| 13 | 13 |
| 14 class JSONObject; | |
| 15 class JSONStream; | 14 class JSONStream; |
| 16 | 15 |
| 17 struct TraceBufferEntry { | 16 struct TraceBufferEntry { |
| 18 int64_t micros; | 17 int64_t micros; |
| 19 char* message; | 18 char* message; |
| 20 bool empty() const { | 19 bool empty() const { |
| 21 return message == NULL; | 20 return message == NULL; |
| 22 } | 21 } |
| 23 }; | 22 }; |
| 24 | 23 |
| 25 class TraceBuffer { | 24 class TraceBuffer { |
| 26 public: | 25 public: |
| 27 static const intptr_t kInitialCapacity = 16; | 26 static const intptr_t kDefaultCapacity = 1024; |
| 28 static const intptr_t kMaximumCapacity = 1024; | |
| 29 | 27 |
| 30 // TraceBuffer starts with kInitialCapacity and will expand itself until | 28 explicit TraceBuffer(intptr_t capacity = kDefaultCapacity); |
| 31 // it reaches kMaximumCapacity. | |
| 32 TraceBuffer(intptr_t initial_capacity = kInitialCapacity, | |
| 33 intptr_t maximum_capacity = kMaximumCapacity); | |
| 34 ~TraceBuffer(); | 29 ~TraceBuffer(); |
| 35 | 30 |
| 36 void Clear(); | 31 void Clear(); |
| 37 | 32 |
| 38 // Internally message is copied. | 33 // Internally message is copied. |
| 39 void Trace(int64_t micros, const char* message); | 34 void Trace(int64_t micros, const char* message); |
| 40 // Internally message is copied. | 35 // Internally message is copied. |
| 41 void Trace(const char* message); | 36 void Trace(const char* message); |
| 42 void TraceF(const char* format, ...) PRINTF_ATTRIBUTE(2, 3); | 37 void TraceF(const char* format, ...) PRINTF_ATTRIBUTE(2, 3); |
| 43 | 38 |
| 44 void PrintToJSONObject(JSONObject* obj) const; | |
| 45 void PrintToJSONStream(JSONStream* stream) const; | 39 void PrintToJSONStream(JSONStream* stream) const; |
| 46 | 40 |
| 47 intptr_t capacity() const { return capacity_; } | |
| 48 | |
| 49 private: | 41 private: |
| 50 void Init(); | 42 void Init(); |
| 51 void Resize(intptr_t capacity); | |
| 52 void Cleanup(); | 43 void Cleanup(); |
| 53 void Fill(TraceBufferEntry* entry, int64_t micros, char* msg); | 44 void Fill(TraceBufferEntry* entry, int64_t micros, char* msg); |
| 54 void AppendTrace(int64_t micros, char* message); | 45 void AppendTrace(int64_t micros, char* message); |
| 55 | 46 |
| 56 TraceBufferEntry* ring_; | 47 TraceBufferEntry* ring_; |
| 57 intptr_t size_; | 48 const intptr_t ring_capacity_; |
| 58 intptr_t capacity_; | |
| 59 intptr_t ring_cursor_; | 49 intptr_t ring_cursor_; |
| 60 const intptr_t max_capacity_; | |
| 61 | 50 |
| 62 intptr_t RingIndex(intptr_t i) const { | 51 intptr_t RingIndex(intptr_t i) const { |
| 63 return i % capacity_; | 52 return i % ring_capacity_; |
| 64 } | 53 } |
| 65 | 54 |
| 66 DISALLOW_COPY_AND_ASSIGN(TraceBuffer); | 55 DISALLOW_COPY_AND_ASSIGN(TraceBuffer); |
| 67 }; | 56 }; |
| 68 | 57 |
| 69 | 58 |
| 70 } // namespace dart | 59 } // namespace dart |
| 71 | 60 |
| 72 #endif // VM_TRACE_BUFFER_H_ | 61 #endif // VM_TRACE_BUFFER_H_ |
| OLD | NEW |