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

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: DISALLOW_COPY_AND_ASSIGN + cctype for isalnum 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;
27 static const uint32_t kBuildLegacyJSONEvents = 1 << 1;
28
29 explicit TraceBufferReader(uint32_t options);
30 ~TraceBufferReader();
31
32 // Parses a chunk and the events in it and appends data to the string table
33 // and/or the legacy events values depending on |options|.
34 //.The input buffer contain a valid protobuf EventsChunk message
35 // (see ../proto/events_chunk.proto). Chunks must be passed in order, as
36 // produced by the ring buffer, to ensure that all fragmented events are
37 // consistently processed.
38 void ParseChunk(const uint8_t* start, size_t length);
39
40 const InternedStringsMap& interned_strings() const {
41 return interned_strings_;
42 }
43
44 std::unique_ptr<base::ListValue>& legacy_events() { return legacy_events_; }
45
46 private:
47 // This struct keeps track of the evolution of the parser for each writer
48 // (read: for each thread). Each writer produces a sequence of chunks with
49 // contiguos |seq_id|s. However, some of these chunks might be discarded due
50 // to the wrapping logic of the ring buffer. The only problem here are
51 // events fragmented across different chunks. A fragment can be parsed only
52 // if we contiguously saw all the previous chunks and should be discarded
53 // otherwise.
54 struct WriterState {
55 WriterState();
56 ~WriterState();
57
58 void Reset();
59
60 bool last_fragment_is_valid;
61 uint32_t last_seq_id;
62 std::vector<uint8_t> partial_event_data;
63
64 private:
65 DISALLOW_COPY_AND_ASSIGN(WriterState);
66 };
67
68 void ParseEvent(const uint8_t* start, const uint8_t* end);
69
70 const uint32_t options_;
71 InternedStringsMap interned_strings_;
72 std::unique_ptr<base::ListValue> legacy_events_;
73 std::unordered_map<uint32_t, WriterState> writer_state_;
74
75 DISALLOW_COPY_AND_ASSIGN(TraceBufferReader);
76 };
77
78 } // namespace v2
79 } // namespace tracing
80
81 #endif // COMPONENTS_TRACING_CORE_TRACE_BUFFER_READER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698