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

Side by Side Diff: base/trace_event/v2/append_only_proto_message.h

Issue 1947373002: Tracing V2 prototype [NOT FOR REVIEW] Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: WORKS Created 4 years, 6 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
« no previous file with comments | « base/trace_event/trace_log.cc ('k') | base/trace_event/v2/append_only_proto_message.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 BASE_TRACE_EVENT_V2_APPEND_ONLY_PROTO_MESSAGE_H_
6 #define BASE_TRACE_EVENT_V2_APPEND_ONLY_PROTO_MESSAGE_H_
7
8 #include <inttypes.h>
9
10 #include <memory>
11 #include <vector>
12
13 #include "base/base_export.h"
14 #include "base/macros.h"
15 #include "base/trace_event/v2/scattered_buffer.h"
16
17 namespace base {
18 namespace trace_event {
19 namespace v2 {
20
21 class BASE_EXPORT AppendOnlyProtoMessage {
22 public:
23 static const size_t kMaxMessageLengthFieldSize = 4;
24 static const size_t kMaxMessageLength;
25
26 virtual ~AppendOnlyProtoMessage();
27
28 ScatteredBuffer::ContiguousMemoryRange size_field() const { return size_field_ ; }
29 void set_write_size_field_on_finalization(
30 const ScatteredBuffer::ContiguousMemoryRange &reserved_range) {
31 size_field_ = reserved_range;
32 write_size_field_on_finalization_ = true;
33 }
34 void inc_size_already_written(size_t size) { size_already_written_ += size; }
35 void set_buffer_writer(ScatteredBuffer* buffer) { buffer_ = buffer; }
36 ScatteredBuffer* buffer_writer() const { return buffer_; }
37
38 // returns the number of bytes written to buffer_ by this message, excluding
39 // optional size_field_ (which is counted by the parent message).
40 // Finalize is idempotent and can be called several times w/o side effects.
41 size_t Finalize();
42
43 protected:
44 AppendOnlyProtoMessage();
45
46 void AppendVarIntSigned(uint32_t field_id, int64_t value);
47 void AppendVarIntUnsigned(uint32_t field_id, uint64_t value);
48 void AppendFloat(uint32_t field_id, float value);
49 void AppendDouble(uint32_t field_id, double value);
50 void AppendString(uint32_t field_id, const char* str);
51 void AppendBytes(uint32_t field_id, const void* value, size_t size);
52
53 // Ends as soon as an Append* method is called in the parent.
54 template <class T>
55 T* BeginNestedMessage(uint32_t field_id) {
56 T* message = new (nested_messages_arena_) T();
57 // T* message = new T();
58 BeginNestedMessage(field_id, message);
59 return message;
60 }
61
62 void EndNestedMessage();
63
64 private:
65 void BeginNestedMessage(uint32_t field_id, AppendOnlyProtoMessage* message);
66 void WriteToBuffer(const uint8_t* src, size_t size);
67
68 // Only PODs allowed. This class dtor is never called.
69 ScatteredBuffer* buffer_;
70 size_t size_;
71 bool write_size_field_on_finalization_;
72 ScatteredBuffer::ContiguousMemoryRange size_field_;
73 size_t size_already_written_;
74 // std::vector<std::unique_ptr<AppendOnlyProtoMessage>> nested_messages_;
75 AppendOnlyProtoMessage* current_nested_message_;
76 bool sealed_;
77
78 // TODO explain this black magic trick.
79 uint8_t nested_messages_arena_[640];
80
81 DISALLOW_COPY_AND_ASSIGN(AppendOnlyProtoMessage);
82 };
83
84 } // namespace v2
85 } // namespace trace_event
86 } // namespace base
87
88 #endif // BASE_TRACE_EVENT_V2_APPEND_ONLY_PROTO_MESSAGE_H_
OLDNEW
« no previous file with comments | « base/trace_event/trace_log.cc ('k') | base/trace_event/v2/append_only_proto_message.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698