| OLD | NEW |
| (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 #include "base/trace_event/v2/append_only_proto_message.h" |
| 6 |
| 7 #include <string.h> |
| 8 #include <vector> |
| 9 |
| 10 #include "base/logging.h" |
| 11 #include "base/trace_event/trace_log.h" |
| 12 #include "base/trace_event/trace_event.h" |
| 13 #include "base/trace_event/v2/ring_buffer.h" |
| 14 #include "base/trace_event/v2/append_only_proto_message.h" |
| 15 #include "base/trace_event/v2/scattered_buffer.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 |
| 18 |
| 19 namespace base { |
| 20 namespace trace_event { |
| 21 namespace v2 { |
| 22 |
| 23 void HexDumpBuffer(const uint8_t* buf, size_t size) { |
| 24 fprintf(stderr, "\n"); |
| 25 for(size_t i = 0; i < size; ++i) { |
| 26 if (i % 64 == 0) |
| 27 fprintf(stderr, "\n"); |
| 28 fprintf(stderr, "%02x ", buf[i]); |
| 29 if (buf[i + 1 ] == 0 && buf[i+2] == 0 && buf[i + 3] == 0 && buf[i + 8] == 0
&& buf[i + 32] == 0) |
| 30 break; |
| 31 } |
| 32 fprintf(stderr, "\n"); |
| 33 } |
| 34 |
| 35 TEST(AppendOnlyProtoMessage, Simple) { |
| 36 const size_t kBufSize = 256 * 1024; |
| 37 std::unique_ptr<uint8_t[]> buf(new uint8_t[kBufSize]); |
| 38 memset(&buf[0], 0, kBufSize); |
| 39 { |
| 40 RingBuffer rb(&buf[0], kBufSize); |
| 41 ZeroCopyTraceBufferWriter wr(&rb, 0x42); |
| 42 for (int i = 0; i < 200; ++i) { |
| 43 TraceEventHandle e = wr.AddEvent(); |
| 44 e->set_type(tracing::Event_Type_COMPLETE); |
| 45 e->set_process_id(0x7); |
| 46 e->set_name_str("abcdefghijklmnopqrstuvwx"); |
| 47 } |
| 48 wr.GetNewContiguousMemoryBuffer(); |
| 49 } |
| 50 HexDumpBuffer(buf.get(), kBufSize); |
| 51 } |
| 52 |
| 53 TEST(AppendOnlyProtoMessage, Long) { |
| 54 MessageLoop loop; |
| 55 TraceLog::use_v2 = true; |
| 56 TraceLog::GetInstance()->SetEnabled( |
| 57 TraceConfig("*", "record-as-much-as-possible"), TraceLog::RECORDING_MODE); |
| 58 for (size_t i=0; i < 1; ++i) { |
| 59 v2::TraceEventHandle handle; |
| 60 TRACE_EVENT_BEGIN1("foo", "bar", "tv", &handle); |
| 61 auto args = handle->add_args_test(); |
| 62 for (int k = 0; k < 3; ++k) { |
| 63 const char* kStr = "123456"; |
| 64 auto obj = args->add_things(); |
| 65 obj->set_name(&kStr[i]); |
| 66 obj->set_a(1); |
| 67 obj->set_b(2); |
| 68 obj->set_c(3); |
| 69 obj->set_d("foooooooooo"); |
| 70 } |
| 71 } |
| 72 TraceLog::GetInstance()->SetDisabled(); |
| 73 HexDumpBuffer(TraceLog::GetInstance()->v2_buf, sizeof(TraceLog::v2_buf)); |
| 74 } |
| 75 |
| 76 |
| 77 } // namespace v2 |
| 78 } // namespace trace_event |
| 79 } // namespace base |
| OLD | NEW |