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 JSONStream; | 14 class JSONStream; |
15 | 15 |
16 struct TraceBufferEntry { | 16 struct TraceBufferEntry { |
17 int64_t micros; | 17 int64_t micros; |
18 char* message; | 18 char* message; |
19 bool empty() const { | 19 bool empty() const { |
20 return message == NULL; | 20 return message == NULL; |
21 } | 21 } |
22 }; | 22 }; |
23 | 23 |
24 class TraceBuffer { | 24 class TraceBuffer { |
25 public: | 25 public: |
26 static const intptr_t kDefaultCapacity = 1024; | 26 static const intptr_t kDefaultCapacity = 1024; |
27 | 27 |
28 explicit TraceBuffer(intptr_t capacity = kDefaultCapacity); | 28 static void Init(Isolate* isolate, intptr_t capacity = kDefaultCapacity); |
| 29 |
29 ~TraceBuffer(); | 30 ~TraceBuffer(); |
30 | 31 |
31 void Clear(); | 32 void Clear(); |
32 | 33 |
33 // Internally message is copied. | 34 // Internally message is copied. |
34 void Trace(int64_t micros, const char* message); | 35 void Trace(int64_t micros, const char* message); |
35 // Internally message is copied. | 36 // Internally message is copied. |
36 void Trace(const char* message); | 37 void Trace(const char* message); |
37 void TraceF(const char* format, ...) PRINTF_ATTRIBUTE(2, 3); | 38 void TraceF(const char* format, ...) PRINTF_ATTRIBUTE(2, 3); |
38 | 39 |
39 void PrintToJSONStream(JSONStream* stream) const; | 40 void PrintToJSONStream(JSONStream* stream) const; |
40 | 41 |
41 private: | 42 private: |
42 void Init(); | 43 TraceBuffer(Isolate* isolate, intptr_t capacity); |
43 void Cleanup(); | 44 void Cleanup(); |
44 void Fill(TraceBufferEntry* entry, int64_t micros, char* msg); | 45 void Fill(TraceBufferEntry* entry, int64_t micros, char* msg); |
45 void AppendTrace(int64_t micros, char* message); | 46 void AppendTrace(int64_t micros, char* message); |
46 | 47 |
| 48 Isolate* isolate_; |
47 TraceBufferEntry* ring_; | 49 TraceBufferEntry* ring_; |
48 const intptr_t ring_capacity_; | 50 const intptr_t ring_capacity_; |
49 intptr_t ring_cursor_; | 51 intptr_t ring_cursor_; |
50 | 52 |
51 intptr_t RingIndex(intptr_t i) const { | 53 intptr_t RingIndex(intptr_t i) const { |
52 return i % ring_capacity_; | 54 return i % ring_capacity_; |
53 } | 55 } |
54 | 56 |
55 DISALLOW_COPY_AND_ASSIGN(TraceBuffer); | 57 DISALLOW_COPY_AND_ASSIGN(TraceBuffer); |
56 }; | 58 }; |
57 | 59 |
58 | 60 |
59 } // namespace dart | 61 } // namespace dart |
60 | 62 |
61 #endif // VM_TRACE_BUFFER_H_ | 63 #endif // VM_TRACE_BUFFER_H_ |
OLD | NEW |