• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef INCLUDE_PERFETTO_EXT_TRACING_IPC_PRODUCER_IPC_CLIENT_H_
18 #define INCLUDE_PERFETTO_EXT_TRACING_IPC_PRODUCER_IPC_CLIENT_H_
19 
20 #include <memory>
21 #include <string>
22 
23 #include "perfetto/base/export.h"
24 #include "perfetto/ext/tracing/core/shared_memory.h"
25 #include "perfetto/ext/tracing/core/shared_memory_arbiter.h"
26 #include "perfetto/ext/tracing/core/tracing_service.h"
27 
28 namespace perfetto {
29 
30 class Producer;
31 
32 // Allows to connect to a remote Service through a UNIX domain socket.
33 // Exposed to:
34 //   Producer(s) of the tracing library.
35 // Implemented in:
36 //   src/tracing/ipc/producer/producer_ipc_client_impl.cc
37 class PERFETTO_EXPORT ProducerIPCClient {
38  public:
39   // Connects to the producer port of the Service listening on the given
40   // |service_sock_name|. If the connection is successful, the OnConnect()
41   // method will be invoked asynchronously on the passed Producer interface. If
42   // the connection fails, OnDisconnect() will be invoked instead. The returned
43   // ProducerEndpoint serves also to delimit the scope of the callbacks invoked
44   // on the Producer interface: no more Producer callbacks are invoked
45   // immediately after its destruction and any pending callback will be dropped.
46   // To provide a producer-allocated shared memory buffer, both |shm| and
47   // |shm_arbiter| should be set. |shm_arbiter| should be an unbound
48   // SharedMemoryArbiter instance. When |shm| and |shm_arbiter| are provided,
49   // the service will attempt to adopt the provided SMB. If this fails, the
50   // ProducerEndpoint will disconnect, but the SMB and arbiter will remain valid
51   // until the client is destroyed.
52   //
53   // TODO(eseckler): Support adoption failure more gracefully.
54   static std::unique_ptr<TracingService::ProducerEndpoint> Connect(
55       const char* service_sock_name,
56       Producer*,
57       const std::string& producer_name,
58       base::TaskRunner*,
59       TracingService::ProducerSMBScrapingMode smb_scraping_mode =
60           TracingService::ProducerSMBScrapingMode::kDefault,
61       size_t shared_memory_size_hint_bytes = 0,
62       size_t shared_memory_page_size_hint_bytes = 0,
63       std::unique_ptr<SharedMemory> shm = nullptr,
64       std::unique_ptr<SharedMemoryArbiter> shm_arbiter = nullptr);
65 
66  protected:
67   ProducerIPCClient() = delete;
68 };
69 
70 }  // namespace perfetto
71 
72 #endif  // INCLUDE_PERFETTO_EXT_TRACING_IPC_PRODUCER_IPC_CLIENT_H_
73