1 /*
2 * Copyright (C) 2019 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 #include "perfetto/tracing/internal/system_tracing_backend.h"
18
19 #include "perfetto/base/logging.h"
20 #include "perfetto/base/task_runner.h"
21 #include "perfetto/ext/tracing/core/tracing_service.h"
22 #include "perfetto/ext/tracing/ipc/consumer_ipc_client.h"
23 #include "perfetto/ext/tracing/ipc/default_socket.h"
24 #include "perfetto/ext/tracing/ipc/producer_ipc_client.h"
25
26 namespace perfetto {
27 namespace internal {
28
29 // static
GetInstance()30 TracingBackend* SystemTracingBackend::GetInstance() {
31 static auto* instance = new SystemTracingBackend();
32 return instance;
33 }
34
SystemTracingBackend()35 SystemTracingBackend::SystemTracingBackend() {}
36
ConnectProducer(const ConnectProducerArgs & args)37 std::unique_ptr<ProducerEndpoint> SystemTracingBackend::ConnectProducer(
38 const ConnectProducerArgs& args) {
39 PERFETTO_DCHECK(args.task_runner->RunsTasksOnCurrentThread());
40
41 auto endpoint = ProducerIPCClient::Connect(
42 GetProducerSocket(), args.producer, args.producer_name, args.task_runner,
43 TracingService::ProducerSMBScrapingMode::kEnabled,
44 args.shmem_size_hint_bytes, args.shmem_page_size_hint_bytes, nullptr,
45 nullptr, ProducerIPCClient::ConnectionFlags::kRetryIfUnreachable);
46 PERFETTO_CHECK(endpoint);
47 return endpoint;
48 }
49
ConnectConsumer(const ConnectConsumerArgs & args)50 std::unique_ptr<ConsumerEndpoint> SystemTracingBackend::ConnectConsumer(
51 const ConnectConsumerArgs& args) {
52 auto endpoint = ConsumerIPCClient::Connect(GetConsumerSocket(), args.consumer,
53 args.task_runner);
54 PERFETTO_CHECK(endpoint);
55 return endpoint;
56 }
57
58 } // namespace internal
59 } // namespace perfetto
60