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

Unified Diff: base/trace_event/v2/append_only_proto_message_unittest.cc

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/v2/append_only_proto_message_perftest.cc ('k') | base/trace_event/v2/proto_utils.h » ('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_unittest.cc
diff --git a/base/trace_event/v2/append_only_proto_message_unittest.cc b/base/trace_event/v2/append_only_proto_message_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..17abb7b480c71a16cd3f1062f4d04bac0906a8c9
--- /dev/null
+++ b/base/trace_event/v2/append_only_proto_message_unittest.cc
@@ -0,0 +1,79 @@
+// 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.
+
+#include "base/trace_event/v2/append_only_proto_message.h"
+
+#include <string.h>
+#include <vector>
+
+#include "base/logging.h"
+#include "base/trace_event/trace_log.h"
+#include "base/trace_event/trace_event.h"
+#include "base/trace_event/v2/ring_buffer.h"
+#include "base/trace_event/v2/append_only_proto_message.h"
+#include "base/trace_event/v2/scattered_buffer.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+
+namespace base {
+namespace trace_event {
+namespace v2 {
+
+void HexDumpBuffer(const uint8_t* buf, size_t size) {
+ fprintf(stderr, "\n");
+ for(size_t i = 0; i < size; ++i) {
+ if (i % 64 == 0)
+ fprintf(stderr, "\n");
+ fprintf(stderr, "%02x ", buf[i]);
+ if (buf[i + 1 ] == 0 && buf[i+2] == 0 && buf[i + 3] == 0 && buf[i + 8] == 0 && buf[i + 32] == 0)
+ break;
+ }
+ fprintf(stderr, "\n");
+}
+
+TEST(AppendOnlyProtoMessage, Simple) {
+ const size_t kBufSize = 256 * 1024;
+ std::unique_ptr<uint8_t[]> buf(new uint8_t[kBufSize]);
+ memset(&buf[0], 0, kBufSize);
+ {
+ RingBuffer rb(&buf[0], kBufSize);
+ ZeroCopyTraceBufferWriter wr(&rb, 0x42);
+ for (int i = 0; i < 200; ++i) {
+ TraceEventHandle e = wr.AddEvent();
+ e->set_type(tracing::Event_Type_COMPLETE);
+ e->set_process_id(0x7);
+ e->set_name_str("abcdefghijklmnopqrstuvwx");
+ }
+ wr.GetNewContiguousMemoryBuffer();
+ }
+ HexDumpBuffer(buf.get(), kBufSize);
+}
+
+TEST(AppendOnlyProtoMessage, Long) {
+ MessageLoop loop;
+ TraceLog::use_v2 = true;
+ TraceLog::GetInstance()->SetEnabled(
+ TraceConfig("*", "record-as-much-as-possible"), TraceLog::RECORDING_MODE);
+ for (size_t i=0; i < 1; ++i) {
+ v2::TraceEventHandle handle;
+ TRACE_EVENT_BEGIN1("foo", "bar", "tv", &handle);
+ auto args = handle->add_args_test();
+ for (int k = 0; k < 3; ++k) {
+ const char* kStr = "123456";
+ auto obj = args->add_things();
+ obj->set_name(&kStr[i]);
+ obj->set_a(1);
+ obj->set_b(2);
+ obj->set_c(3);
+ obj->set_d("foooooooooo");
+ }
+ }
+ TraceLog::GetInstance()->SetDisabled();
+ HexDumpBuffer(TraceLog::GetInstance()->v2_buf, sizeof(TraceLog::v2_buf));
+}
+
+
+} // namespace v2
+} // namespace trace_event
+} // namespace base
« no previous file with comments | « base/trace_event/v2/append_only_proto_message_perftest.cc ('k') | base/trace_event/v2/proto_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698