| 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 <stdlib.h> |
| 8 #include <string.h> |
| 9 #include <vector> |
| 10 |
| 11 #include "base/logging.h" |
| 12 #include "base/trace_event/trace_log.h" |
| 13 #include "base/trace_event/trace_event.h" |
| 14 #include "base/trace_event/trace_event_argument.h" |
| 15 #include "base/trace_event/v2/ring_buffer.h" |
| 16 #include "base/trace_event/v2/append_only_proto_message.h" |
| 17 #include "base/trace_event/v2/scattered_buffer.h" |
| 18 #include "base/trace_event/common/proto/event_args_test.tracing-pb.h" |
| 19 |
| 20 |
| 21 namespace base { |
| 22 namespace trace_event { |
| 23 namespace v2 { |
| 24 |
| 25 int int_cmp(const void* pa, const void* pb) { |
| 26 const uint64_t a = (uintptr_t)pa; |
| 27 const uint64_t b = (uintptr_t)pb; |
| 28 if (a > b) return 1; |
| 29 if (a < b) return -1; |
| 30 return 0; |
| 31 } |
| 32 |
| 33 void RunPerfTest(bool use_tracing_v2, int num_args, int repetition_multiplier =
1) { |
| 34 TraceLog::use_v2 = use_tracing_v2; |
| 35 |
| 36 const size_t kRuns = 1000 * repetition_multiplier; |
| 37 const size_t kInnerLoop = 1000; |
| 38 uint64_t * times = new uint64_t[kRuns]; |
| 39 |
| 40 for (size_t i = 0; i < kRuns; ++i) { |
| 41 TraceLog::GetInstance()->SetEnabled(TraceConfig("*", "record-as-much-as-possi
ble"), TraceLog::RECORDING_MODE); |
| 42 auto tstart = ThreadTicks::Now(); |
| 43 for (size_t j = 0; j < kInnerLoop; ++j) { |
| 44 if (num_args == 0) { |
| 45 TRACE_EVENT_BEGIN0("foo", "bar"); |
| 46 } else if (num_args == 1) { |
| 47 TRACE_EVENT_BEGIN1("foo", "bar", "arg1", j); |
| 48 } else if (num_args == 2) { |
| 49 TRACE_EVENT_BEGIN2("foo", "bar", "arg", j, "arg2", j); |
| 50 } else { |
| 51 if (!use_tracing_v2) { |
| 52 std::unique_ptr<TracedValue> tv(new TracedValue()); |
| 53 for (int k = 0; k < 3; ++k) { |
| 54 const char* kStr = "123456"; |
| 55 tv->BeginDictionary(&kStr[i]); |
| 56 tv->SetInteger("a", 1); |
| 57 tv->SetInteger("b", 2); |
| 58 tv->SetInteger("c", 3); |
| 59 tv->SetStringWithCopiedName("d", "foooooooooo"); |
| 60 tv->EndDictionary(); |
| 61 } |
| 62 TRACE_EVENT_BEGIN1("foo", "bar", "tv", std::move(tv)); |
| 63 } else { |
| 64 v2::TraceEventHandle handle; |
| 65 TRACE_EVENT_BEGIN1("foo", "bar", "tv", &handle); |
| 66 auto args = handle->add_args_test(); |
| 67 for (int k = 0; k < 3; ++k) { |
| 68 const char* kStr = "123456"; |
| 69 auto obj = args->add_things(); |
| 70 obj->set_name(&kStr[i]); |
| 71 obj->set_a(1); |
| 72 obj->set_b(2); |
| 73 obj->set_c(3); |
| 74 obj->set_d("foooooooooo"); |
| 75 } |
| 76 } |
| 77 } |
| 78 } |
| 79 auto tend = ThreadTicks::Now(); |
| 80 TraceLog::GetInstance()->SetDisabled(); |
| 81 times[i] = (tend - tstart).InMicroseconds(); |
| 82 } |
| 83 |
| 84 uint64_t tmin=9999 /*lol*/, tmax=0, tavg=0; |
| 85 qsort(times, kRuns, sizeof(times[0]), int_cmp); |
| 86 for (size_t i = 0; i < kRuns; ++i) { |
| 87 tmin = std::min(tmin, times[i]); |
| 88 tmax = std::max(tmax, times[i]); |
| 89 tavg += times[i]; |
| 90 } |
| 91 tavg /= kRuns; |
| 92 printf("Using Tracing V=%d, N-args=%d ", use_tracing_v2 ? 2 : 1, num_args); |
| 93 printf(" times (for %zu runs): min: %4lu, max: %4lu, avg: %4lu, med: %4lu \n
", kInnerLoop, tmin, tmax, tavg, times[kRuns / 2]); |
| 94 delete [] times; |
| 95 } |
| 96 |
| 97 |
| 98 } // namespace v2 |
| 99 } // namespace trace_event |
| 100 } // namespace base |
| 101 |
| 102 int main(int argc, char** argv) { |
| 103 base::MessageLoop ml; |
| 104 |
| 105 if (argc == 3) { |
| 106 bool use_tracing_v2 = argv[1][0] == '1'; |
| 107 int num_args = atoi(argv[2]); |
| 108 base::trace_event::v2::RunPerfTest(use_tracing_v2, num_args, 10); |
| 109 return 0; |
| 110 } |
| 111 |
| 112 using base::trace_event::v2::RunPerfTest; |
| 113 RunPerfTest(false /* use_tracing_v2 */, 0 /* num_args */); |
| 114 RunPerfTest(true /* use_tracing_v2 */, 0 /* num_args */); |
| 115 printf("\n"); |
| 116 |
| 117 RunPerfTest(false /* use_tracing_v2 */, 1 /* num_args */); |
| 118 RunPerfTest(true /* use_tracing_v2 */, 1 /* num_args */); |
| 119 printf("\n"); |
| 120 |
| 121 RunPerfTest(false /* use_tracing_v2 */, 2 /* num_args */); |
| 122 RunPerfTest(true /* use_tracing_v2 */, 2 /* num_args */); |
| 123 printf("\n"); |
| 124 |
| 125 RunPerfTest(false /* use_tracing_v2 */, 42 /* num_args */); |
| 126 RunPerfTest(true /* use_tracing_v2 */, 42/* num_args */); |
| 127 printf("\n"); |
| 128 return 0; |
| 129 } |
| OLD | NEW |