blob: 9c6afb3c49f9e638fd72f7078e62d8414ce7c6a8 [file] [log] [blame]
brettwbd8214bf2017-06-20 03:47:031// 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 CHROME_PROFILING_MEMLOG_CONNECTION_MANAGER_H_
6#define CHROME_PROFILING_MEMLOG_CONNECTION_MANAGER_H_
7
8#include <string>
9
10#include "base/containers/flat_map.h"
erikchen66af0162017-08-02 19:53:1911#include "base/files/file.h"
Albert J. Wong3432f462017-08-02 02:47:2412#include "base/files/platform_file.h"
brettwbd8214bf2017-06-20 03:47:0313#include "base/macros.h"
erikchen66af0162017-08-02 19:53:1914#include "base/synchronization/lock.h"
brettwbd8214bf2017-06-20 03:47:0315#include "build/build_config.h"
16#include "chrome/profiling/backtrace_storage.h"
brettwbd8214bf2017-06-20 03:47:0317
18namespace base {
Albert J. Wong3432f462017-08-02 02:47:2419class SequencedTaskRunner;
brettwbd8214bf2017-06-20 03:47:0320class SingleThreadTaskRunner;
21}
22
23namespace profiling {
24
25// Manages all connections and logging for each process. Pipes are supplied by
26// the pipe server and this class will connect them to a parser and logger.
Albert J. Wong3432f462017-08-02 02:47:2427//
28// Note |backtrace_storage| must outlive MemlogConnectionManager.
29//
30// This object is constructed on the UI thread, but the rest of the usage
31// (including deletion) is on the IO thread.
32class MemlogConnectionManager {
brettwbd8214bf2017-06-20 03:47:0333 public:
Albert J. Wong3432f462017-08-02 02:47:2434 MemlogConnectionManager(scoped_refptr<base::SequencedTaskRunner> io_runner,
35 BacktraceStorage* backtrace_storage);
36 ~MemlogConnectionManager();
brettwbd8214bf2017-06-20 03:47:0337
erikchen66af0162017-08-02 19:53:1938 // Dumps the memory log for the given process into |output_file|.
39 void DumpProcess(int32_t sender_id, base::File output_file);
40
Albert J. Wong3432f462017-08-02 02:47:2441 void OnNewConnection(base::ScopedPlatformFile file, int sender_id);
brettwbd8214bf2017-06-20 03:47:0342
43 private:
44 struct Connection;
45
brettwbd8214bf2017-06-20 03:47:0346 // Notification that a connection is complete. Unlike OnNewConnection which
47 // is signaled by the pipe server, this is signaled by the allocation tracker
48 // to ensure that the pipeline for this process has been flushed of all
49 // messages.
Albert J. Wong3432f462017-08-02 02:47:2450 void OnConnectionComplete(int sender_id);
brettwbd8214bf2017-06-20 03:47:0351
52 void OnConnectionCompleteThunk(
53 scoped_refptr<base::SingleThreadTaskRunner> main_loop,
54 int process_id);
55
Albert J. Wong3432f462017-08-02 02:47:2456 scoped_refptr<base::SequencedTaskRunner> io_runner_;
57 BacktraceStorage* backtrace_storage_; // Not owned.
58
brettwbd8214bf2017-06-20 03:47:0359 // Maps process ID to the connection information for it.
60 base::flat_map<int, std::unique_ptr<Connection>> connections_;
erikchen66af0162017-08-02 19:53:1961 base::Lock connections_lock_;
brettwbd8214bf2017-06-20 03:47:0362
63 DISALLOW_COPY_AND_ASSIGN(MemlogConnectionManager);
64};
65
66} // namespace profiling
67
68#endif // CHROME_PROFILING_MEMLOG_CONNECTION_MANAGER_H_