• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2021 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef BASE_TEST_TRACE_TEST_UTILS_H_
6 #define BASE_TEST_TRACE_TEST_UTILS_H_
7 
8 #include "base/memory/raw_ptr.h"
9 #include "base/task/thread_pool.h"
10 #include "base/test/task_environment.h"
11 #include "base/trace_event/trace_log.h"
12 #include "third_party/perfetto/protos/perfetto/config/trace_config.gen.h"
13 
14 namespace base {
15 
16 namespace test {
17 
18 // A scoped class that sets up and tears down tracing support for unit tests.
19 // Note that only in-process tracing is supported by this harness. See
20 // //services/tracing for recording traces in multiprocess configurations.
21 class TracingEnvironment {
22  public:
23   // Construct a tracing environment using the default Perfetto tracing
24   // platform.
25   TracingEnvironment();
26 
27   // Constructs a tracing environment with the given task runner and Perfetto
28   // tracing platform.
29   explicit TracingEnvironment(TaskEnvironment&,
30                               scoped_refptr<SequencedTaskRunner> =
31                                   ThreadPool::CreateSequencedTaskRunner({}));
32   ~TracingEnvironment();
33 
34   // Builds a default Perfetto trace config with track events enabled.
35   static perfetto::protos::gen::TraceConfig GetDefaultTraceConfig();
36 
37  private:
38   raw_ptr<TaskEnvironment> task_environment_ = nullptr;
39 };
40 
41 }  // namespace test
42 }  // namespace base
43 
44 #endif  // BASE_TEST_TRACE_TEST_UTILS_H_
45