memory_dump_manager_test_utils.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Copyright 2017 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_TRACE_EVENT_MEMORY_DUMP_MANAGER_TEST_UTILS_H_
  5. #define BASE_TRACE_EVENT_MEMORY_DUMP_MANAGER_TEST_UTILS_H_
  6. #include "base/bind.h"
  7. #include "base/trace_event/memory_dump_manager.h"
  8. #include "base/trace_event/memory_dump_request_args.h"
  9. namespace base {
  10. namespace trace_event {
  11. void RequestGlobalDumpForInProcessTesting(
  12. base::trace_event::MemoryDumpType dump_type,
  13. base::trace_event::MemoryDumpLevelOfDetail level_of_detail) {
  14. MemoryDumpRequestArgs local_args = {0 /* dump_guid */, dump_type,
  15. level_of_detail};
  16. MemoryDumpManager::GetInstance()->CreateProcessDump(
  17. local_args, ProcessMemoryDumpCallback());
  18. }
  19. // Short circuits the RequestGlobalDumpFunction() to CreateProcessDump(),
  20. // effectively allowing to use both in unittests with the same behavior.
  21. // Unittests are in-process only and don't require all the multi-process
  22. // dump handshaking (which would require bits outside of base).
  23. void InitializeMemoryDumpManagerForInProcessTesting(bool is_coordinator) {
  24. MemoryDumpManager* instance = MemoryDumpManager::GetInstance();
  25. instance->set_dumper_registrations_ignored_for_testing(true);
  26. instance->Initialize(BindRepeating(&RequestGlobalDumpForInProcessTesting),
  27. is_coordinator);
  28. }
  29. } // namespace trace_event
  30. } // namespace base
  31. #endif // BASE_TRACE_EVENT_MEMORY_DUMP_MANAGER_TEST_UTILS_H_