1 // Copyright 2015 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 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 #include <map> 13 #include <memory> 14 #include <string> 15 16 #include "base/base_export.h" 17 #include "base/callback.h" 18 #include "base/optional.h" 19 #include "base/process/process_handle.h" 20 21 namespace base { 22 namespace trace_event { 23 24 class ProcessMemoryDump; 25 26 // Captures the reason why a memory dump is being requested. This is to allow 27 // selective enabling of dumps, filtering and post-processing. Keep this 28 // consistent with memory_instrumentation.mojo and 29 // memory_instrumentation_struct_traits.{h,cc} 30 enum class MemoryDumpType { 31 PERIODIC_INTERVAL, // Dumping memory at periodic intervals. 32 EXPLICITLY_TRIGGERED, // Non maskable dump request. 33 SUMMARY_ONLY, // Calculate just the summary & don't add to the trace. 34 LAST = SUMMARY_ONLY 35 }; 36 37 // Tells the MemoryDumpProvider(s) how much detailed their dumps should be. 38 // Keep this consistent with memory_instrumentation.mojo and 39 // memory_instrumentation_struct_traits.{h,cc} 40 enum class MemoryDumpLevelOfDetail : uint32_t { 41 FIRST, 42 43 // For background tracing mode. The dump time is quick, and typically just the 44 // totals are expected. Suballocations need not be specified. Dump name must 45 // contain only pre-defined strings and string arguments cannot be added. 46 BACKGROUND = FIRST, 47 48 // For the levels below, MemoryDumpProvider instances must guarantee that the 49 // total size reported in the root node is consistent. Only the granularity of 50 // the child MemoryAllocatorDump(s) differs with the levels. 51 52 // Few entries, typically a fixed number, per dump. 53 LIGHT, 54 55 // Unrestricted amount of entries per dump. 56 DETAILED, 57 58 LAST = DETAILED 59 }; 60 61 // Keep this consistent with memory_instrumentation.mojo and 62 // memory_instrumentation_struct_traits.{h,cc} 63 struct BASE_EXPORT MemoryDumpRequestArgs { 64 // Globally unique identifier. In multi-process dumps, all processes issue a 65 // local dump with the same guid. This allows the trace importers to 66 // reconstruct the global dump. 67 uint64_t dump_guid; 68 69 MemoryDumpType dump_type; 70 MemoryDumpLevelOfDetail level_of_detail; 71 }; 72 73 // Args for ProcessMemoryDump and passed to OnMemoryDump calls for memory dump 74 // providers. Dump providers are expected to read the args for creating dumps. 75 struct MemoryDumpArgs { 76 // Specifies how detailed the dumps should be. 77 MemoryDumpLevelOfDetail level_of_detail; 78 79 // Globally unique identifier. In multi-process dumps, all processes issue a 80 // local dump with the same guid. This allows the trace importers to 81 // reconstruct the global dump. 82 uint64_t dump_guid; 83 }; 84 85 using ProcessMemoryDumpCallback = Callback< 86 void(bool success, uint64_t dump_guid, std::unique_ptr<ProcessMemoryDump>)>; 87 88 BASE_EXPORT const char* MemoryDumpTypeToString(const MemoryDumpType& dump_type); 89 90 BASE_EXPORT MemoryDumpType StringToMemoryDumpType(const std::string& str); 91 92 BASE_EXPORT const char* MemoryDumpLevelOfDetailToString( 93 const MemoryDumpLevelOfDetail& level_of_detail); 94 95 BASE_EXPORT MemoryDumpLevelOfDetail 96 StringToMemoryDumpLevelOfDetail(const std::string& str); 97 98 } // namespace trace_event 99 } // namespace base 100 101 #endif // BASE_TRACE_EVENT_MEMORY_DUMP_REQUEST_ARGS_H_ 102