| Index: base/trace_event/v2/append_only_proto_message_perftest.cc
|
| diff --git a/base/trace_event/v2/append_only_proto_message_perftest.cc b/base/trace_event/v2/append_only_proto_message_perftest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..484af665d140d9ae5450033d84997c6125fec349
|
| --- /dev/null
|
| +++ b/base/trace_event/v2/append_only_proto_message_perftest.cc
|
| @@ -0,0 +1,129 @@
|
| +// 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 <stdlib.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/trace_event_argument.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 "base/trace_event/common/proto/event_args_test.tracing-pb.h"
|
| +
|
| +
|
| +namespace base {
|
| +namespace trace_event {
|
| +namespace v2 {
|
| +
|
| +int int_cmp(const void* pa, const void* pb) {
|
| + const uint64_t a = (uintptr_t)pa;
|
| + const uint64_t b = (uintptr_t)pb;
|
| + if (a > b) return 1;
|
| + if (a < b) return -1;
|
| + return 0;
|
| +}
|
| +
|
| +void RunPerfTest(bool use_tracing_v2, int num_args, int repetition_multiplier = 1) {
|
| + TraceLog::use_v2 = use_tracing_v2;
|
| +
|
| + const size_t kRuns = 1000 * repetition_multiplier;
|
| + const size_t kInnerLoop = 1000;
|
| + uint64_t * times = new uint64_t[kRuns];
|
| +
|
| + for (size_t i = 0; i < kRuns; ++i) {
|
| + TraceLog::GetInstance()->SetEnabled(TraceConfig("*", "record-as-much-as-possible"), TraceLog::RECORDING_MODE);
|
| + auto tstart = ThreadTicks::Now();
|
| + for (size_t j = 0; j < kInnerLoop; ++j) {
|
| + if (num_args == 0) {
|
| + TRACE_EVENT_BEGIN0("foo", "bar");
|
| + } else if (num_args == 1) {
|
| + TRACE_EVENT_BEGIN1("foo", "bar", "arg1", j);
|
| + } else if (num_args == 2) {
|
| + TRACE_EVENT_BEGIN2("foo", "bar", "arg", j, "arg2", j);
|
| + } else {
|
| + if (!use_tracing_v2) {
|
| + std::unique_ptr<TracedValue> tv(new TracedValue());
|
| + for (int k = 0; k < 3; ++k) {
|
| + const char* kStr = "123456";
|
| + tv->BeginDictionary(&kStr[i]);
|
| + tv->SetInteger("a", 1);
|
| + tv->SetInteger("b", 2);
|
| + tv->SetInteger("c", 3);
|
| + tv->SetStringWithCopiedName("d", "foooooooooo");
|
| + tv->EndDictionary();
|
| + }
|
| + TRACE_EVENT_BEGIN1("foo", "bar", "tv", std::move(tv));
|
| + } else {
|
| + 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");
|
| + }
|
| + }
|
| + }
|
| + }
|
| + auto tend = ThreadTicks::Now();
|
| + TraceLog::GetInstance()->SetDisabled();
|
| + times[i] = (tend - tstart).InMicroseconds();
|
| + }
|
| +
|
| + uint64_t tmin=9999 /*lol*/, tmax=0, tavg=0;
|
| + qsort(times, kRuns, sizeof(times[0]), int_cmp);
|
| + for (size_t i = 0; i < kRuns; ++i) {
|
| + tmin = std::min(tmin, times[i]);
|
| + tmax = std::max(tmax, times[i]);
|
| + tavg += times[i];
|
| + }
|
| + tavg /= kRuns;
|
| + printf("Using Tracing V=%d, N-args=%d ", use_tracing_v2 ? 2 : 1, num_args);
|
| + printf(" times (for %zu runs): min: %4lu, max: %4lu, avg: %4lu, med: %4lu \n", kInnerLoop, tmin, tmax, tavg, times[kRuns / 2]);
|
| + delete [] times;
|
| +}
|
| +
|
| +
|
| +} // namespace v2
|
| +} // namespace trace_event
|
| +} // namespace base
|
| +
|
| +int main(int argc, char** argv) {
|
| + base::MessageLoop ml;
|
| +
|
| + if (argc == 3) {
|
| + bool use_tracing_v2 = argv[1][0] == '1';
|
| + int num_args = atoi(argv[2]);
|
| + base::trace_event::v2::RunPerfTest(use_tracing_v2, num_args, 10);
|
| + return 0;
|
| + }
|
| +
|
| + using base::trace_event::v2::RunPerfTest;
|
| + RunPerfTest(false /* use_tracing_v2 */, 0 /* num_args */);
|
| + RunPerfTest(true /* use_tracing_v2 */, 0 /* num_args */);
|
| + printf("\n");
|
| +
|
| + RunPerfTest(false /* use_tracing_v2 */, 1 /* num_args */);
|
| + RunPerfTest(true /* use_tracing_v2 */, 1 /* num_args */);
|
| + printf("\n");
|
| +
|
| + RunPerfTest(false /* use_tracing_v2 */, 2 /* num_args */);
|
| + RunPerfTest(true /* use_tracing_v2 */, 2 /* num_args */);
|
| + printf("\n");
|
| +
|
| + RunPerfTest(false /* use_tracing_v2 */, 42 /* num_args */);
|
| + RunPerfTest(true /* use_tracing_v2 */, 42/* num_args */);
|
| + printf("\n");
|
| + return 0;
|
| +}
|
|
|