• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2015 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_TRACE_EVENT_MEMORY_DUMP_REQUEST_ARGS_H_
6 #define BASE_TRACE_EVENT_MEMORY_DUMP_REQUEST_ARGS_H_
7 
8 // This file defines the types and structs used to issue memory dump requests.
9 // These are also used in the IPCs for coordinating inter-process memory dumps.
10 
11 #include <stdint.h>
12 
13 #include <memory>
14 #include <string>
15 
16 #include "base/base_export.h"
17 #include "base/functional/callback.h"
18 #include "base/process/process_handle.h"
19 
20 namespace base {
21 namespace trace_event {
22 
23 class ProcessMemoryDump;
24 
25 // Captures the reason why a memory dump is being requested. This is to allow
26 // selective enabling of dumps, filtering and post-processing. Keep this
27 // consistent with memory_instrumentation.mojo and
28 // memory_instrumentation_struct_traits.{h,cc}
29 enum class MemoryDumpType {
30   kPeriodicInterval,     // Dumping memory at periodic intervals.
31   kExplicitlyTriggered,  // Non maskable dump request.
32   kSummaryOnly,          // Calculate just the summary & don't add to the trace.
33   kLast = kSummaryOnly
34 };
35 
36 // Tells the MemoryDumpProvider(s) how much detailed their dumps should be.
37 // Keep this consistent with memory_instrumentation.mojo and
38 // memory_instrumentation_struct_traits.{h,cc}
39 enum class MemoryDumpLevelOfDetail : uint32_t {
40   kFirst,
41 
42   // For background tracing mode. The dump time is quick, and typically just the
43   // totals are expected. Suballocations need not be specified. Dump name must
44   // contain only pre-defined strings and string arguments cannot be added.
45   kBackground = kFirst,
46 
47   // For the levels below, MemoryDumpProvider instances must guarantee that the
48   // total size reported in the root node is consistent. Only the granularity of
49   // the child MemoryAllocatorDump(s) differs with the levels.
50 
51   // Few entries, typically a fixed number, per dump.
52   kLight,
53 
54   // Unrestricted amount of entries per dump.
55   kDetailed,
56 
57   kLast = kDetailed
58 };
59 
60 // Tells the MemoryDumpProvider(s) if they should try to make the result
61 // more deterministic by forcing garbage collection.
62 // Keep this consistent with memory_instrumentation.mojo and
63 // memory_instrumentation_struct_traits.{h,cc}
64 enum class MemoryDumpDeterminism : uint32_t { kNone, kForceGc };
65 
66 // Keep this consistent with memory_instrumentation.mojo and
67 // memory_instrumentation_struct_traits.{h,cc}
68 struct BASE_EXPORT MemoryDumpRequestArgs {
69   // Globally unique identifier. In multi-process dumps, all processes issue a
70   // local dump with the same guid. This allows the trace importers to
71   // reconstruct the global dump.
72   uint64_t dump_guid;
73 
74   MemoryDumpType dump_type;
75   MemoryDumpLevelOfDetail level_of_detail;
76   MemoryDumpDeterminism determinism;
77 };
78 
79 // Args for ProcessMemoryDump and passed to OnMemoryDump calls for memory dump
80 // providers. Dump providers are expected to read the args for creating dumps.
81 struct MemoryDumpArgs {
82   // Specifies how detailed the dumps should be.
83   MemoryDumpLevelOfDetail level_of_detail;
84   // Specifies whether the dumps should be more deterministic.
85   MemoryDumpDeterminism determinism;
86 
87   // Globally unique identifier. In multi-process dumps, all processes issue a
88   // local dump with the same guid. This allows the trace importers to
89   // reconstruct the global dump.
90   uint64_t dump_guid;
91 };
92 
93 using ProcessMemoryDumpCallback = OnceCallback<
94     void(bool success, uint64_t dump_guid, std::unique_ptr<ProcessMemoryDump>)>;
95 
96 BASE_EXPORT const char* MemoryDumpTypeToString(const MemoryDumpType& dump_type);
97 
98 BASE_EXPORT MemoryDumpType StringToMemoryDumpType(const std::string& str);
99 
100 BASE_EXPORT const char* MemoryDumpLevelOfDetailToString(
101     const MemoryDumpLevelOfDetail& level_of_detail);
102 
103 BASE_EXPORT MemoryDumpLevelOfDetail
104 StringToMemoryDumpLevelOfDetail(const std::string& str);
105 
106 }  // namespace trace_event
107 }  // namespace base
108 
109 #endif  // BASE_TRACE_EVENT_MEMORY_DUMP_REQUEST_ARGS_H_
110