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 5 #ifndef COMPONENTS_SERVICES_HEAP_PROFILING_JSON_EXPORTER_H_ 6 #define COMPONENTS_SERVICES_HEAP_PROFILING_JSON_EXPORTER_H_ 7 8 #include <map> 9 #include <string> 10 #include <unordered_map> 11 #include <vector> 12 13 #include "components/services/heap_profiling/allocation.h" 14 #include "components/services/heap_profiling/public/mojom/heap_profiling_service.mojom.h" 15 #include "services/resource_coordinator/public/mojom/memory_instrumentation/memory_instrumentation.mojom.h" 16 17 namespace heap_profiling { 18 19 // Configuration passed to the export functions because they take many 20 // arguments. All parameters must be set. 21 struct ExportParams { 22 ExportParams(); 23 ~ExportParams(); 24 25 // Allocation events to export. 26 AllocationMap allocs; 27 28 // VM map of all regions in the process. 29 std::vector<memory_instrumentation::mojom::VmRegionPtr> maps; 30 31 // Map from context string to context ID. A reverse-mapping will tell you 32 // what the context_id in the allocation mean. 33 std::map<std::string, int> context_map; 34 35 // Some addresses represent strings rather than instruction pointers. 36 // The strings are assumed to already be escaped for JSON. 37 std::unordered_map<uint64_t, std::string> mapped_strings; 38 39 // The type of browser [browser, renderer, gpu] that is being heap-dumped. 40 mojom::ProcessType process_type = mojom::ProcessType::OTHER; 41 42 // Whether or not the paths should be stripped from mapped files. Doing so 43 // anonymizes the trace, since the paths could potentially contain a username. 44 // However, it prevents symbolization of locally built instances of Chrome. 45 bool strip_path_from_mapped_files = false; 46 47 // The heaps_v2 trace format requires that ids are unique across heap dumps in 48 // a single trace. This class is currently stateless, and does not know 49 // whether a heap dump will be in a trace with other heap dumps. To work 50 // around this, just make all IDs unique. The parameter is an input parameter 51 // that tells the exporter which ID to start from. It is also an output 52 // parameter, and tells the caller the next unused ID. 53 // See https://crbug.com/808066. 54 size_t next_id = 1; 55 }; 56 57 // Creates a JSON string representing a JSON dictionary that contains memory 58 // maps and v2 format stack traces. 59 std::string ExportMemoryMapsAndV2StackTraceToJSON(ExportParams* params); 60 61 } // namespace heap_profiling 62 63 #endif // COMPONENTS_SERVICES_HEAP_PROFILING_JSON_EXPORTER_H_ 64