summaryrefslogtreecommitdiff
path: root/base/trace_event/trace_event_filter_test_utils.cc
blob: 85b4cfa276835502b58b0f8a8de7ca0079ec8994 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// 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/trace_event_filter_test_utils.h"

#include "base/logging.h"

namespace base {
namespace trace_event {

namespace {
TestEventFilter::HitsCounter* g_hits_counter;
}  // namespace;

// static
const char TestEventFilter::kName[] = "testing_predicate";
bool TestEventFilter::filter_return_value_;

// static
std::unique_ptr<TraceEventFilter> TestEventFilter::Factory(
    const std::string& predicate_name) {
  std::unique_ptr<TraceEventFilter> res;
  if (predicate_name == kName)
    res.reset(new TestEventFilter());
  return res;
}

TestEventFilter::TestEventFilter() = default;
TestEventFilter::~TestEventFilter() = default;

bool TestEventFilter::FilterTraceEvent(const TraceEvent& trace_event) const {
  if (g_hits_counter)
    g_hits_counter->filter_trace_event_hit_count++;
  return filter_return_value_;
}

void TestEventFilter::EndEvent(const char* category_name,
                               const char* name) const {
  if (g_hits_counter)
    g_hits_counter->end_event_hit_count++;
}

TestEventFilter::HitsCounter::HitsCounter() {
  Reset();
  DCHECK(!g_hits_counter);
  g_hits_counter = this;
}

TestEventFilter::HitsCounter::~HitsCounter() {
  DCHECK(g_hits_counter);
  g_hits_counter = nullptr;
}

void TestEventFilter::HitsCounter::Reset() {
  filter_trace_event_hit_count = 0;
  end_event_hit_count = 0;
}

}  // namespace trace_event
}  // namespace base