fdaf1b59bf
Review URL: https://codereview.chromium.org//243583008 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@35208 260f80e4-7a28-3924-810f-c04153c831b5
62 lines
1.4 KiB
C++
62 lines
1.4 KiB
C++
// 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 {
|
|
int64_t micros;
|
|
char* message;
|
|
bool empty() const {
|
|
return message == NULL;
|
|
}
|
|
};
|
|
|
|
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 micros, 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, int64_t micros, char* msg);
|
|
void AppendTrace(int64_t micros, char* message);
|
|
|
|
TraceBufferEntry* ring_;
|
|
const intptr_t ring_capacity_;
|
|
intptr_t ring_cursor_;
|
|
|
|
intptr_t RingIndex(intptr_t i) const {
|
|
return i % ring_capacity_;
|
|
}
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(TraceBuffer);
|
|
};
|
|
|
|
|
|
} // namespace dart
|
|
|
|
#endif // VM_TRACE_BUFFER_H_
|