trace_test_utils.h 1.6 KB

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