Chromium Code Reviews| Index: runtime/vm/trace_buffer.h |
| diff --git a/runtime/vm/trace_buffer.h b/runtime/vm/trace_buffer.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..4040e60d03a4c05e32c2c2267b63041027b41c91 |
| --- /dev/null |
| +++ b/runtime/vm/trace_buffer.h |
| @@ -0,0 +1,59 @@ |
| +// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +#ifndef VM_TRACE_BUFFER_H_ |
| +#define VM_TRACE_BUFFER_H_ |
| + |
| +#include "platform/assert.h" |
| +#include "platform/globals.h" |
| +#include "vm/json_stream.h" |
| + |
| +namespace dart { |
| + |
| +class JSONStream; |
| + |
| +struct TraceBufferEntry { |
| + double seconds; |
| + char* message; |
| +}; |
| + |
| +class TraceBuffer { |
| + public: |
| + static const intptr_t kDefaultCapacity = 1024; |
| + |
| + explicit TraceBuffer(intptr_t capacity = kDefaultCapacity); |
| + ~TraceBuffer(); |
| + |
| + void Clear(); |
| + |
| + // Internally message is copied. |
| + void Trace(int64_t time, const char* message); |
| + // Internally message is copied. |
| + void Trace(const char* message); |
| + void TraceF(const char* format, ...) PRINTF_ATTRIBUTE(2, 3); |
| + |
| + void PrintToJSONStream(JSONStream* stream) const; |
| + |
| + private: |
| + void Init(); |
| + void Cleanup(); |
| + void Fill(TraceBufferEntry* entry, double seconds, char* msg); |
| + void AppendTrace(int64_t time, char* message); |
| + |
| + TraceBufferEntry* ring_; |
| + intptr_t ring_capacity_; |
|
srdjan
2013/11/07 22:53:00
const?
Cutch
2013/11/13 17:33:14
Done.
|
| + intptr_t ring_start_; |
|
Ivan Posva
2013/11/07 22:36:28
Single index should suffice.
Cutch
2013/11/13 17:33:14
Done.
|
| + intptr_t ring_size_; |
| + |
| + intptr_t RingIndex(intptr_t i) const { |
| + return i % ring_capacity_; |
| + } |
| + |
| + DISALLOW_COPY_AND_ASSIGN(TraceBuffer); |
| +}; |
| + |
| + |
| +} // namespace dart |
| + |
| +#endif // VM_TRACE_BUFFER_H_ |