Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(635)

Side by Side Diff: components/tracing/core/trace_buffer_reader.h

Issue 2308583003: tracing v2: Introduce TraceBufferReader to read-back the trace buffer (Closed)
Patch Set: some fixes + moar tests Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef COMPONENTS_TRACING_CORE_TRACE_BUFFER_READER_H_
6 #define COMPONENTS_TRACING_CORE_TRACE_BUFFER_READER_H_
7
8 #include <memory>
9 #include <unordered_map>
10
11 #include "base/values.h"
12 #include "components/tracing/core/trace_ring_buffer.h"
13 #include "components/tracing/tracing_export.h"
14
15 namespace tracing {
16 namespace v2 {
17
18 // Reads back chunks from the proto-encoded tracing buffer and:
19 // - Extracts a table of interned strings, when kBuildInternedStringsTable is
20 // enabled.
21 // - Reconstructs a JSON-serializable ListValue which is backwards compatible
22 // with Tracing v1, when kBuildLegacyJSONEvents.
23 class TRACING_EXPORT TraceBufferReader {
24 public:
25 using InternedStringsMap = std::unordered_map<int32_t, const char*>;
26 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
27 static const uint32_t kBuildLegacyJSONEvents = 1 << 1;
28
29 explicit TraceBufferReader(uint32_t options);
30 ~TraceBufferReader();
31
32 void ParseChunk(const TraceRingBuffer::Chunk*);
33 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
34
35 const InternedStringsMap& interned_strings() const {
36 return interned_strings_;
37 }
38
39 std::unique_ptr<base::ListValue>& legacy_events() { return legacy_events_; }
40
41 private:
42 struct WriterState {
43 WriterState();
44 ~WriterState();
45
46 void Reset();
47
48 bool last_fragment_is_valid;
49 uint32_t last_seq_id;
50 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
51 };
52
53 void ParseEvent(const uint8_t* start, const uint8_t* end);
54
55 const uint32_t options_;
56 InternedStringsMap interned_strings_;
57 std::unique_ptr<base::ListValue> legacy_events_;
58 std::unordered_map<uint32_t, WriterState> writer_state_;
59
60 DISALLOW_COPY_AND_ASSIGN(TraceBufferReader);
61 };
62
63 } // namespace v2
64 } // namespace tracing
65
66 #endif // COMPONENTS_TRACING_CORE_TRACE_BUFFER_READER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698