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

Unified 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, 7 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/trace_event/v2/append_only_proto_message.h
diff --git a/base/trace_event/v2/append_only_proto_message.h b/base/trace_event/v2/append_only_proto_message.h
new file mode 100644
index 0000000000000000000000000000000000000000..621b74c7a0ef04d53244b92af151fbed23a1b284
--- /dev/null
+++ b/base/trace_event/v2/append_only_proto_message.h
@@ -0,0 +1,88 @@
+// 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 BASE_TRACE_EVENT_V2_APPEND_ONLY_PROTO_MESSAGE_H_
+#define BASE_TRACE_EVENT_V2_APPEND_ONLY_PROTO_MESSAGE_H_
+
+#include <inttypes.h>
+
+#include <memory>
+#include <vector>
+
+#include "base/base_export.h"
+#include "base/macros.h"
+#include "base/trace_event/v2/scattered_buffer.h"
+
+namespace base {
+namespace trace_event {
+namespace v2 {
+
+class BASE_EXPORT AppendOnlyProtoMessage {
+ public:
+ static const size_t kMaxMessageLengthFieldSize = 4;
+ static const size_t kMaxMessageLength;
+
+ virtual ~AppendOnlyProtoMessage();
+
+ ScatteredBuffer::ContiguousMemoryRange size_field() const { return size_field_; }
+ void set_write_size_field_on_finalization(
+ const ScatteredBuffer::ContiguousMemoryRange &reserved_range) {
+ size_field_ = reserved_range;
+ write_size_field_on_finalization_ = true;
+ }
+ void inc_size_already_written(size_t size) { size_already_written_ += size; }
+ void set_buffer_writer(ScatteredBuffer* buffer) { buffer_ = buffer; }
+ ScatteredBuffer* buffer_writer() const { return buffer_; }
+
+ // returns the number of bytes written to buffer_ by this message, excluding
+ // optional size_field_ (which is counted by the parent message).
+ // Finalize is idempotent and can be called several times w/o side effects.
+ size_t Finalize();
+
+ protected:
+ AppendOnlyProtoMessage();
+
+ void AppendVarIntSigned(uint32_t field_id, int64_t value);
+ void AppendVarIntUnsigned(uint32_t field_id, uint64_t value);
+ void AppendFloat(uint32_t field_id, float value);
+ void AppendDouble(uint32_t field_id, double value);
+ void AppendString(uint32_t field_id, const char* str);
+ void AppendBytes(uint32_t field_id, const void* value, size_t size);
+
+ // Ends as soon as an Append* method is called in the parent.
+ template <class T>
+ T* BeginNestedMessage(uint32_t field_id) {
+ T* message = new (nested_messages_arena_) T();
+ // T* message = new T();
+ BeginNestedMessage(field_id, message);
+ return message;
+ }
+
+ void EndNestedMessage();
+
+ private:
+ void BeginNestedMessage(uint32_t field_id, AppendOnlyProtoMessage* message);
+ void WriteToBuffer(const uint8_t* src, size_t size);
+
+ // Only PODs allowed. This class dtor is never called.
+ ScatteredBuffer* buffer_;
+ size_t size_;
+ bool write_size_field_on_finalization_;
+ ScatteredBuffer::ContiguousMemoryRange size_field_;
+ size_t size_already_written_;
+ // std::vector<std::unique_ptr<AppendOnlyProtoMessage>> nested_messages_;
+ AppendOnlyProtoMessage* current_nested_message_;
+ bool sealed_;
+
+ // TODO explain this black magic trick.
+ uint8_t nested_messages_arena_[640];
+
+ DISALLOW_COPY_AND_ASSIGN(AppendOnlyProtoMessage);
+};
+
+} // namespace v2
+} // namespace trace_event
+} // namespace base
+
+#endif // BASE_TRACE_EVENT_V2_APPEND_ONLY_PROTO_MESSAGE_H_
« 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