blob: da7dc6959c474d45ff90fdf1ab679cee5ee32470 [file] [log] [blame]
Avi Drissman8ba1bad2022-09-13 19:22:361// Copyright 2017 The Chromium Authors
brettwbd8214bf2017-06-20 03:47:032// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
erikchenfa983faa2018-04-05 18:56:425#ifndef COMPONENTS_SERVICES_HEAP_PROFILING_CONNECTION_MANAGER_H_
6#define COMPONENTS_SERVICES_HEAP_PROFILING_CONNECTION_MANAGER_H_
brettwbd8214bf2017-06-20 03:47:037
Alexei Filippov1b7b8802019-04-17 22:01:438#include <map>
brettwbd8214bf2017-06-20 03:47:039#include <string>
Alexei Filippov1b7b8802019-04-17 22:01:4310#include <unordered_map>
Erik Chene266c732017-08-12 02:27:1911#include <vector>
brettwbd8214bf2017-06-20 03:47:0312
13#include "base/containers/flat_map.h"
Erik Chene2d064472017-10-07 03:34:0714#include "base/memory/ref_counted.h"
erikchena4d19192017-08-23 17:33:1615#include "base/memory/weak_ptr.h"
erikchen66af0162017-08-02 19:53:1916#include "base/synchronization/lock.h"
erikchena6f3feb2018-02-14 16:21:5617#include "base/threading/thread.h"
Sebastien Marchandefda77e532019-01-25 22:53:5218#include "base/timer/timer.h"
brettwbd8214bf2017-06-20 03:47:0319#include "build/build_config.h"
Alexei Filippov0a194542019-04-22 22:45:4620#include "components/services/heap_profiling/allocation.h"
erikchen0d4a6012018-04-03 16:06:3321#include "components/services/heap_profiling/public/mojom/heap_profiling_service.mojom.h"
Ken Rockotced31272019-08-02 21:12:1822#include "mojo/public/cpp/bindings/pending_remote.h"
Ken Rockot95c888a42018-02-11 05:54:1123#include "services/resource_coordinator/public/mojom/memory_instrumentation/memory_instrumentation.mojom.h"
brettwbd8214bf2017-06-20 03:47:0324
erikchen102fe212018-04-06 13:02:1025namespace heap_profiling {
brettwbd8214bf2017-06-20 03:47:0326
Alexei Filippovda9fb732019-04-25 22:40:3227struct ExportParams;
28
erikchen53cddfe62018-02-14 23:31:2929using VmRegions =
Ken Rockot089427352018-04-24 14:51:3730 base::flat_map<base::ProcessId,
31 std::vector<memory_instrumentation::mojom::VmRegionPtr>>;
erikchen53cddfe62018-02-14 23:31:2932
brettwbd8214bf2017-06-20 03:47:0333// Manages all connections and logging for each process. Pipes are supplied by
34// the pipe server and this class will connect them to a parser and logger.
Albert J. Wong3432f462017-08-02 02:47:2435//
erikchenfa983faa2018-04-05 18:56:4236// Note |backtrace_storage| must outlive ConnectionManager.
Albert J. Wong3432f462017-08-02 02:47:2437//
38// This object is constructed on the UI thread, but the rest of the usage
39// (including deletion) is on the IO thread.
erikchenfa983faa2018-04-05 18:56:4240class ConnectionManager {
Alexei Filippov1b7b8802019-04-17 22:01:4341 using AddressToStringMap = std::unordered_map<uint64_t, std::string>;
42 using CompleteCallback = base::OnceClosure;
43 using ContextMap = std::map<std::string, int>;
erikchen67fff822018-02-21 18:53:4344 using DumpProcessesForTracingCallback = memory_instrumentation::mojom::
45 HeapProfiler::DumpProcessesForTracingCallback;
46
brettwbd8214bf2017-06-20 03:47:0347 public:
erikchenfa983faa2018-04-05 18:56:4248 ConnectionManager();
Peter Boström09c01822021-09-20 22:43:2749
50 ConnectionManager(const ConnectionManager&) = delete;
51 ConnectionManager& operator=(const ConnectionManager&) = delete;
52
erikchenfa983faa2018-04-05 18:56:4253 ~ConnectionManager();
brettwbd8214bf2017-06-20 03:47:0354
Erik Chene2d064472017-10-07 03:34:0755 // Dumping is asynchronous so will not be complete when this function
56 // returns. The dump is complete when the callback provided in the args is
57 // fired.
Alexei Filippove0245182019-03-08 20:17:0558 void DumpProcessesForTracing(bool strip_path_from_mapped_files,
ssid035cbfb2021-07-24 20:35:5759 bool write_proto,
erikchen67fff822018-02-21 18:53:4360 DumpProcessesForTracingCallback callback,
61 VmRegions vm_regions);
erikchen66af0162017-08-02 19:53:19