Chromium Code Reviews| Index: components/tracing/core/trace_buffer_reader.h |
| diff --git a/components/tracing/core/trace_buffer_reader.h b/components/tracing/core/trace_buffer_reader.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d37173a8f746806dc3a0d4037b7ec6376b08a35c |
| --- /dev/null |
| +++ b/components/tracing/core/trace_buffer_reader.h |
| @@ -0,0 +1,66 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef COMPONENTS_TRACING_CORE_TRACE_BUFFER_READER_H_ |
| +#define COMPONENTS_TRACING_CORE_TRACE_BUFFER_READER_H_ |
| + |
| +#include <memory> |
| +#include <unordered_map> |
| + |
| +#include "base/values.h" |
| +#include "components/tracing/core/trace_ring_buffer.h" |
| +#include "components/tracing/tracing_export.h" |
| + |
| +namespace tracing { |
| +namespace v2 { |
| + |
| +// Reads back chunks from the proto-encoded tracing buffer and: |
| +// - Extracts a table of interned strings, when kBuildInternedStringsTable is |
| +// enabled. |
| +// - Reconstructs a JSON-serializable ListValue which is backwards compatible |
| +// with Tracing v1, when kBuildLegacyJSONEvents. |
| +class TRACING_EXPORT TraceBufferReader { |
| + public: |
| + using InternedStringsMap = std::unordered_map<int32_t, const char*>; |
| + static const uint32_t kBuildInternedStringsTable = 1 << 0; |
|
kraynov
2016/09/08 16:10:01
I don't see any point to use bit options. Is it ex
oystein (OOO til 10th of July)
2016/09/09 00:27:35
Ditto; are there actually any cases where both wou
Primiano Tucci (use gerrit)
2016/09/13 14:40:25
This is intended to be or-able (see the test).
In
|
| + static const uint32_t kBuildLegacyJSONEvents = 1 << 1; |
| + |
| + explicit TraceBufferReader(uint32_t options); |
| + ~TraceBufferReader(); |
| + |
| + void ParseChunk(const TraceRingBuffer::Chunk*); |
| + void ParseChunk(const uint8_t* start, size_t length); |
|
kraynov
2016/09/08 16:10:01
This pair of overloaded methods looks confusing. I
Primiano Tucci (use gerrit)
2016/09/13 14:40:25
ok. Lemme just leave the start/length one for the
|
| + |
| + const InternedStringsMap& interned_strings() const { |
| + return interned_strings_; |
| + } |
| + |
| + std::unique_ptr<base::ListValue>& legacy_events() { return legacy_events_; } |
| + |
| + private: |
| + struct WriterState { |
| + WriterState(); |
| + ~WriterState(); |
| + |
| + void Reset(); |
| + |
| + bool last_fragment_is_valid; |
| + uint32_t last_seq_id; |
| + std::vector<uint8_t> partial_event_data; |
|
kraynov
2016/09/08 16:10:01
We took an effort to use dynamic allocation as lea
Primiano Tucci (use gerrit)
2016/09/13 14:40:25
This happens when the trace is finalized, at this
|
| + }; |
| + |
| + void ParseEvent(const uint8_t* start, const uint8_t* end); |
| + |
| + const uint32_t options_; |
| + InternedStringsMap interned_strings_; |
| + std::unique_ptr<base::ListValue> legacy_events_; |
| + std::unordered_map<uint32_t, WriterState> writer_state_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(TraceBufferReader); |
| +}; |
| + |
| +} // namespace v2 |
| +} // namespace tracing |
| + |
| +#endif // COMPONENTS_TRACING_CORE_TRACE_BUFFER_READER_H_ |