queued_request.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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 SERVICES_RESOURCE_COORDINATOR_MEMORY_INSTRUMENTATION_QUEUED_REQUEST_H_
  5. #define SERVICES_RESOURCE_COORDINATOR_MEMORY_INSTRUMENTATION_QUEUED_REQUEST_H_
  6. #include <map>
  7. #include <memory>
  8. #include <set>
  9. #include <string>
  10. #include "base/containers/flat_map.h"
  11. #include "base/time/time.h"
  12. #include "base/trace_event/memory_dump_request_args.h"
  13. #include "services/resource_coordinator/public/mojom/memory_instrumentation/memory_instrumentation.mojom.h"
  14. #include "third_party/abseil-cpp/absl/types/optional.h"
  15. using base::trace_event::MemoryDumpDeterminism;
  16. using base::trace_event::MemoryDumpLevelOfDetail;
  17. using base::trace_event::MemoryDumpType;
  18. namespace memory_instrumentation {
  19. using OSMemDumpMap =
  20. base::flat_map<base::ProcessId,
  21. memory_instrumentation::mojom::RawOSMemDumpPtr>;
  22. // Holds data for pending requests enqueued via RequestGlobalMemoryDump().
  23. struct QueuedRequest {
  24. using RequestGlobalMemoryDumpInternalCallback = base::OnceCallback<
  25. void(bool, uint64_t, memory_instrumentation::mojom::GlobalMemoryDumpPtr)>;
  26. struct Args {
  27. Args(MemoryDumpType dump_type,
  28. MemoryDumpLevelOfDetail level_of_detail,
  29. MemoryDumpDeterminism determinism,
  30. const std::vector<std::string>& allocator_dump_names,
  31. bool add_to_trace,
  32. base::ProcessId pid,
  33. bool memory_footprint_only);
  34. Args(const Args&);
  35. ~Args();
  36. const MemoryDumpType dump_type;
  37. const MemoryDumpLevelOfDetail level_of_detail;
  38. const MemoryDumpDeterminism determinism;
  39. const std::vector<std::string> allocator_dump_names;
  40. const bool add_to_trace;
  41. const base::ProcessId pid;
  42. // If this member is |true|, then no MemoryDumpProviders are queried. The
  43. // only other relevant member is |pid|.
  44. const bool memory_footprint_only;
  45. };
  46. struct PendingResponse {
  47. enum Type {
  48. kChromeDump,
  49. kOSDump,
  50. };
  51. PendingResponse(base::ProcessId, const Type type);
  52. bool operator<(const PendingResponse& other) const;
  53. const base::ProcessId process_id;
  54. const Type type;
  55. };
  56. struct Response {
  57. Response();
  58. Response(Response&& other);
  59. ~Response();
  60. base::ProcessId process_id = base::kNullProcessId;
  61. mojom::ProcessType process_type = mojom::ProcessType::OTHER;
  62. absl::optional<std::string> service_name;
  63. std::unique_ptr<base::trace_event::ProcessMemoryDump> chrome_dump;
  64. OSMemDumpMap os_dumps;
  65. };
  66. QueuedRequest(const Args& args,
  67. uint64_t dump_guid,
  68. RequestGlobalMemoryDumpInternalCallback callback);
  69. ~QueuedRequest();
  70. base::trace_event::MemoryDumpRequestArgs GetRequestArgs();
  71. mojom::MemoryMapOption memory_map_option() const {
  72. return args.level_of_detail ==
  73. base::trace_event::MemoryDumpLevelOfDetail::DETAILED
  74. ? mojom::MemoryMapOption::FULL
  75. : mojom::MemoryMapOption::NONE;
  76. }
  77. bool should_return_summaries() const {
  78. return args.dump_type == base::trace_event::MemoryDumpType::SUMMARY_ONLY;
  79. }
  80. const Args args;
  81. const uint64_t dump_guid;
  82. RequestGlobalMemoryDumpInternalCallback callback;
  83. // When a dump, requested via RequestGlobalMemoryDump(), is in progress this
  84. // set contains a |PendingResponse| for each |RequestChromeMemoryDump| and
  85. // |RequestOSMemoryDump| call that has not yet replied or been canceled (due
  86. // to the client disconnecting).
  87. std::set<PendingResponse> pending_responses;
  88. std::map<base::ProcessId, Response> responses;
  89. int failed_memory_dump_count = 0;
  90. bool dump_in_progress = false;
  91. // This field is set to |true| before a heap dump is requested, and set to
  92. // |false| after the heap dump has been added to the trace.
  93. bool heap_dump_in_progress = false;
  94. // The time we started handling the request (does not including queuing
  95. // time).
  96. base::TimeTicks start_time;
  97. };
  98. // Holds data for pending requests enqueued via GetVmRegionsForHeapProfiler().
  99. struct QueuedVmRegionRequest {
  100. QueuedVmRegionRequest(
  101. uint64_t dump_guid,
  102. mojom::HeapProfilerHelper::GetVmRegionsForHeapProfilerCallback callback);
  103. ~QueuedVmRegionRequest();
  104. const uint64_t dump_guid;
  105. mojom::HeapProfilerHelper::GetVmRegionsForHeapProfilerCallback callback;
  106. struct Response {
  107. Response();
  108. ~Response();
  109. base::ProcessId process_id = base::kNullProcessId;
  110. OSMemDumpMap os_dumps;
  111. absl::optional<std::string> service_name;
  112. };
  113. std::set<base::ProcessId> pending_responses;
  114. std::map<base::ProcessId, Response> responses;
  115. };
  116. } // namespace memory_instrumentation
  117. #endif // SERVICES_RESOURCE_COORDINATOR_MEMORY_INSTRUMENTATION_QUEUED_REQUEST_H_