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

Unified Diff: components/tracing/test/trace_event_perftest.cc

Issue 2450953003: Tracing macros perftests. (Closed)
Patch Set: nit Created 4 years, 1 month 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/tracing/test/trace_event_perftest.cc
diff --git a/components/tracing/test/trace_event_perftest.cc b/components/tracing/test/trace_event_perftest.cc
index 4c93e2fb0cfefbc34bf495d40036bebe2543f0f2..f893cce48b56ebc1addd79261e10a6e7ad141860 100644
--- a/components/tracing/test/trace_event_perftest.cc
+++ b/components/tracing/test/trace_event_perftest.cc
@@ -3,20 +3,28 @@
// found in the LICENSE file.
#include "base/bind.h"
+#include "base/memory/ptr_util.h"
#include "base/memory/ref_counted_memory.h"
#include "base/run_loop.h"
+#include "base/threading/thread.h"
#include "base/trace_event/trace_event.h"
+#include "base/trace_event/trace_event_argument.h"
#include "perf_test_helpers.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace tracing {
namespace {
+using base::Bind;
+using base::Thread;
+using base::Unretained;
+using base::WaitableEvent;
using base::trace_event::TraceConfig;
using base::trace_event::TraceLog;
using base::trace_event::TraceRecordMode;
+using base::trace_event::TracedValue;
-const int kNumRuns = 100;
+const int kNumRuns = 10;
class TraceEventPerfTest : public ::testing::Test {
public:
@@ -43,6 +51,34 @@ class TraceEventPerfTest : public ::testing::Test {
if (!has_more_events)
quit_closure.Run();
}
+
+ std::unique_ptr<TracedValue> MakeTracedValue(int counter) {
+ auto value = base::MakeUnique<TracedValue>();
+ value->SetInteger("counter", counter);
+ value->BeginDictionary("test_dict");
+ value->BeginArray("nodes");
+ for (int i = 0; i < 10; i++) {
+ value->BeginDictionary();
+ value->SetInteger("id", i);
+ value->SetBoolean("valid", true);
+ value->SetString("value", "foo");
+ value->EndDictionary();
+ }
+ value->EndArray();
+ value->SetInteger("count", 10);
+ value->EndDictionary();
+ return value;
+ }
+
+ static void SubmitTraceEventsAndSignal(WaitableEvent* complete_event) {
+ for (int i = 0; i < 10000; i++) {
+ TRACE_EVENT0("test_category", "some call");
+ }
+ complete_event->Signal();
+ }
+
+ private:
+ base::MessageLoop _message_loop;
};
TEST_F(TraceEventPerfTest, Submit_10000_TRACE_EVENT0) {
@@ -57,5 +93,77 @@ TEST_F(TraceEventPerfTest, Submit_10000_TRACE_EVENT0) {
EndTraceAndFlush();
}
+TEST_F(TraceEventPerfTest, Long_TRACE_EVENT0) {
+ BeginTrace();
+ IterableStopwatch stopwatch("long_event");
+ for (int lap = 0; lap < kNumRuns; lap++) {
+ TRACE_EVENT0("test_category", "Outer event");
+ for (int i = 0; i < 10000; i++) {
+ TRACE_EVENT0("test_category", "TRACE_EVENT0 call");
+ }
+ stopwatch.NextLap();
+ }
+ EndTraceAndFlush();
+}
+
+TEST_F(TraceEventPerfTest, Create_10000_TracedValue) {
+ std::unique_ptr<TracedValue> value;
+ {
+ ScopedStopwatch value_sw("create_traced_values");
+ for (int i = 0; i < 10000; i++) {
+ value = MakeTracedValue(i);
+ }
+ }
+}
+
+TEST_F(TraceEventPerfTest, Submit_10000_TRACE_EVENT_with_TracedValue) {
+ BeginTrace();
+ // Time reported by this timer includes TracedValue creation as well.
+ IterableStopwatch trace_sw("events_with_value");
+ for (int lap = 0; lap < kNumRuns; lap++) {
+ for (int i = 0; i < 10000; i++) {
+ TRACE_EVENT_INSTANT1("test_category", "event_with_value",
+ TRACE_EVENT_SCOPE_THREAD, "value", MakeTracedValue(i));
+ }
+ trace_sw.NextLap();
+ }
+ EndTraceAndFlush();
+}
+
+TEST_F(TraceEventPerfTest, Submit_10000_TRACE_EVENT0_multithreaded) {
+ BeginTrace();
+ const int kNumThreads = 4;
+
+ std::vector<std::unique_ptr<Thread>> threads;
+ std::vector<std::unique_ptr<WaitableEvent>> complete_events;
+
+ for (int i = 0; i < kNumThreads; i++) {
+ Thread* thread = new Thread(std::string("thread_%d") + std::to_string(i));
+ WaitableEvent* complete_event =
+ new WaitableEvent(WaitableEvent::ResetPolicy::AUTOMATIC,
+ WaitableEvent::InitialState::NOT_SIGNALED);
+ threads.push_back(base::WrapUnique(thread));
+ complete_events.push_back(base::WrapUnique(complete_event));
+ thread->Start();
+ }
+
+ {
+ ScopedStopwatch stopwatch("events_over_multiple_threads");
+ for (int i = 0; i < kNumThreads; i++) {
+ threads[i]->task_runner()->PostTask(
+ FROM_HERE,
+ base::Bind(&SubmitTraceEventsAndSignal, complete_events[i].get()));
+ }
+ for (int i = 0; i < kNumThreads; i++) {
+ complete_events[i]->Wait();
+ }
+ }
+
+ EndTraceAndFlush();
+ for (int i = 0; i < kNumThreads; i++) {
+ threads[i]->Stop();
+ }
+}
+
} // namespace
} // namespace tracing
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698