blob: 25b300b271df8f2f4956f4dca2735e0d326d1faf [file] [log] [blame]
tommi@webrtc.org7c64ed22015-03-17 14:25:37 +00001/*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "rtc_base/event_tracer.h"
tommi@webrtc.org7c64ed22015-03-17 14:25:37 +000012
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020013#include "rtc_base/trace_event.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020014#include "test/gtest.h"
tommi@webrtc.org7c64ed22015-03-17 14:25:37 +000015
16namespace {
17
18class TestStatistics {
19 public:
20 TestStatistics() : events_logged_(0) {
21 }
22
23 void Reset() {
24 events_logged_ = 0;
25 }
26
27 void Increment() {
28 ++events_logged_;
29 }
30
31 int Count() const { return events_logged_; }
32
33 static TestStatistics* Get() {
deadbeef37f5ecf2017-02-27 14:06:41 -080034 static TestStatistics* test_stats = nullptr;
tommi@webrtc.org7c64ed22015-03-17 14:25:37 +000035 if (!test_stats)
36 test_stats = new TestStatistics();
37 return test_stats;
38 }
39
40 private:
41 int events_logged_;
42};
43
44static const unsigned char* GetCategoryEnabledHandler(const char* name) {
45 return reinterpret_cast<const unsigned char*>("test");
46}
47
48static void AddTraceEventHandler(char phase,
49 const unsigned char* category_enabled,
50 const char* name,
51 unsigned long long id,
52 int num_args,
53 const char** arg_names,
54 const unsigned char* arg_types,
55 const unsigned long long* arg_values,
56 unsigned char flags) {
57 TestStatistics::Get()->Increment();
58}
59
60} // namespace
61
62namespace webrtc {
63
64TEST(EventTracerTest, EventTracerDisabled) {
65 {
66 TRACE_EVENT0("test", "EventTracerDisabled");
67 }
68 EXPECT_FALSE(TestStatistics::Get()->Count());
69 TestStatistics::Get()->Reset();
70}
71
72TEST(EventTracerTest, ScopedTraceEvent) {
73 SetupEventTracer(&GetCategoryEnabledHandler, &AddTraceEventHandler);
74 {
75 TRACE_EVENT0("test", "ScopedTraceEvent");
76 }
77 EXPECT_EQ(2, TestStatistics::Get()->Count());
78 TestStatistics::Get()->Reset();
79}
80
81} // namespace webrtc