json_exporter.h 2.5 KB

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