1 /*
2 * Copyright (C) 2018 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 "src/traced/probes/probes_producer.h"
18
19 #include <stdio.h>
20 #include <sys/stat.h>
21
22 #include <algorithm>
23 #include <queue>
24 #include <string>
25
26 #include "perfetto/base/logging.h"
27 #include "perfetto/ext/base/utils.h"
28 #include "perfetto/ext/base/watchdog.h"
29 #include "perfetto/ext/base/weak_ptr.h"
30 #include "perfetto/ext/traced/traced.h"
31 #include "perfetto/ext/tracing/core/trace_packet.h"
32 #include "perfetto/ext/tracing/ipc/producer_ipc_client.h"
33 #include "perfetto/tracing/core/data_source_config.h"
34 #include "perfetto/tracing/core/data_source_descriptor.h"
35 #include "perfetto/tracing/core/trace_config.h"
36 #include "src/traced/probes/android_log/android_log_data_source.h"
37 #include "src/traced/probes/common/cpu_freq_info.h"
38 #include "src/traced/probes/filesystem/inode_file_data_source.h"
39 #include "src/traced/probes/ftrace/ftrace_data_source.h"
40 #include "src/traced/probes/initial_display_state/initial_display_state_data_source.h"
41 #include "src/traced/probes/metatrace/metatrace_data_source.h"
42 #include "src/traced/probes/packages_list/packages_list_data_source.h"
43 #include "src/traced/probes/power/android_power_data_source.h"
44 #include "src/traced/probes/probes_data_source.h"
45 #include "src/traced/probes/ps/process_stats_data_source.h"
46 #include "src/traced/probes/sys_stats/sys_stats_data_source.h"
47 #include "src/traced/probes/system_info/system_info_data_source.h"
48
49 #include "protos/perfetto/config/ftrace/ftrace_config.gen.h"
50 #include "protos/perfetto/trace/filesystem/inode_file_map.pbzero.h"
51 #include "protos/perfetto/trace/ftrace/ftrace_event_bundle.pbzero.h"
52 #include "protos/perfetto/trace/ftrace/ftrace_stats.pbzero.h"
53 #include "protos/perfetto/trace/trace_packet.pbzero.h"
54
55 namespace perfetto {
56 namespace {
57
58 constexpr uint32_t kInitialConnectionBackoffMs = 100;
59 constexpr uint32_t kMaxConnectionBackoffMs = 30 * 1000;
60
61 // Should be larger than FtraceController::kControllerFlushTimeoutMs.
62 constexpr uint32_t kFlushTimeoutMs = 1000;
63
64 constexpr size_t kTracingSharedMemSizeHintBytes = 1024 * 1024;
65 constexpr size_t kTracingSharedMemPageSizeHintBytes = 32 * 1024;
66
67 ProbesDataSource::Descriptor const* const kAllDataSources[]{
68 &FtraceDataSource::descriptor, //
69 &ProcessStatsDataSource::descriptor, //
70 &InodeFileDataSource::descriptor, //
71 &SysStatsDataSource::descriptor, //
72 &AndroidPowerDataSource::descriptor, //
73 &AndroidLogDataSource::descriptor, //
74 &PackagesListDataSource::descriptor, //
75 &MetatraceDataSource::descriptor, //
76 &SystemInfoDataSource::descriptor, //
77 &InitialDisplayStateDataSource::descriptor, //
78 };
79 } // namespace
80
81 // State transition diagram:
82 // +----------------------------+
83 // v +
84 // NotStarted -> NotConnected -> Connecting -> Connected
85 // ^ +
86 // +--------------+
87 //
88
ProbesProducer()89 ProbesProducer::ProbesProducer() : weak_factory_(this) {}
~ProbesProducer()90 ProbesProducer::~ProbesProducer() {
91 // The ftrace data sources must be deleted before the ftrace controller.
92 data_sources_.clear();
93 ftrace_.reset();
94 }
95
OnConnect()96 void ProbesProducer::OnConnect() {
97 PERFETTO_DCHECK(state_ == kConnecting);
98 state_ = kConnected;
99 ResetConnectionBackoff();
100 PERFETTO_LOG("Connected to the service");
101
102 // Register all the data sources.
103 for (const FtraceDataSource::Descriptor* desc : kAllDataSources) {
104 DataSourceDescriptor proto_desc;
105 proto_desc.set_name(desc->name);
106 proto_desc.set_will_notify_on_start(true);
107 proto_desc.set_will_notify_on_stop(true);
108 using Flags = ProbesDataSource::Descriptor::Flags;
109 if (desc->flags & Flags::kHandlesIncrementalState)
110 proto_desc.set_handles_incremental_state_clear(true);
111 endpoint_->RegisterDataSource(proto_desc);
112 }
113 }
114
OnDisconnect()115 void ProbesProducer::OnDisconnect() {
116 PERFETTO_DCHECK(state_ == kConnected || state_ == kConnecting);
117 PERFETTO_LOG("Disconnected from tracing service");
118 if (state_ == kConnected)
119 return task_runner_->PostTask([this] { this->Restart(); });
120
121 state_ = kNotConnected;
122 IncreaseConnectionBackoff();
123 task_runner_->PostDelayedTask([this] { this->Connect(); },
124 connection_backoff_ms_);
125 }
126
Restart()127 void ProbesProducer::Restart() {
128 // We lost the connection with the tracing service. At this point we need
129 // to reset all the data sources. Trying to handle that manually is going to
130 // be error prone. What we do here is simply destroying the instance and
131 // recreating it again.
132 // TODO(hjd): Add e2e test for this.
133
134 base::TaskRunner* task_runner = task_runner_;
135 const char* socket_name = socket_name_;
136
137 // Invoke destructor and then the constructor again.
138 this->~ProbesProducer();
139 new (this) ProbesProducer();
140
141 ConnectWithRetries(socket_name, task_runner);
142 }
143
SetupDataSource(DataSourceInstanceID instance_id,const DataSourceConfig & config)144 void ProbesProducer::SetupDataSource(DataSourceInstanceID instance_id,
145 const DataSourceConfig& config) {
146 PERFETTO_DLOG("SetupDataSource(id=%" PRIu64 ", name=%s)", instance_id,
147 config.name().c_str());
148 PERFETTO_DCHECK(data_sources_.count(instance_id) == 0);
149 TracingSessionID session_id = config.tracing_session_id();
150 PERFETTO_CHECK(session_id > 0);
151
152 std::unique_ptr<ProbesDataSource> data_source;
153 if (config.name() == FtraceDataSource::descriptor.name) {
154 data_source = CreateFtraceDataSource(session_id, config);
155 } else if (config.name() == InodeFileDataSource::descriptor.name) {
156 data_source = CreateInodeFileDataSource(session_id, config);
157 } else if (config.name() == ProcessStatsDataSource::descriptor.name) {
158 data_source = CreateProcessStatsDataSource(session_id, config);
159 } else if (config.name() == SysStatsDataSource::descriptor.name) {
160 data_source = CreateSysStatsDataSource(session_id, config);
161 } else if (config.name() == AndroidPowerDataSource::descriptor.name) {
162 data_source = CreateAndroidPowerDataSource(session_id, config);
163 } else if (config.name() == AndroidLogDataSource::descriptor.name) {
164 data_source = CreateAndroidLogDataSource(session_id, config);
165 } else if (config.name() == PackagesListDataSource::descriptor.name) {
166 data_source = CreatePackagesListDataSource(session_id, config);
167 } else if (config.name() == MetatraceDataSource::descriptor.name) {
168 data_source = CreateMetatraceDataSource(session_id, config);
169 } else if (config.name() == SystemInfoDataSource::descriptor.name) {
170 data_source = CreateSystemInfoDataSource(session_id, config);
171 } else if (config.name() == InitialDisplayStateDataSource::descriptor.name) {
172 data_source = CreateInitialDisplayStateDataSource(session_id, config);
173 }
174
175 if (!data_source) {
176 PERFETTO_ELOG("Failed to create data source '%s'", config.name().c_str());
177 return;
178 }
179
180 session_data_sources_.emplace(session_id, data_source.get());
181 data_sources_[instance_id] = std::move(data_source);
182 }
183
StartDataSource(DataSourceInstanceID instance_id,const DataSourceConfig & config)184 void ProbesProducer::StartDataSource(DataSourceInstanceID instance_id,
185 const DataSourceConfig& config) {
186 PERFETTO_DLOG("StartDataSource(id=%" PRIu64 ", name=%s)", instance_id,
187 config.name().c_str());
188 auto it = data_sources_.find(instance_id);
189 if (it == data_sources_.end()) {
190 // Can happen if SetupDataSource() failed (e.g. ftrace was busy).
191 PERFETTO_ELOG("Data source id=%" PRIu64 " not found", instance_id);
192 return;
193 }
194 ProbesDataSource* data_source = it->second.get();
195 if (data_source->started)
196 return;
197 if (config.trace_duration_ms() != 0) {
198 uint32_t timeout = 5000 + 2 * config.trace_duration_ms();
199 watchdogs_.emplace(
200 instance_id, base::Watchdog::GetInstance()->CreateFatalTimer(timeout));
201 }
202 data_source->started = true;
203 data_source->Start();
204 endpoint_->NotifyDataSourceStarted(instance_id);
205 }
206
CreateFtraceDataSource(TracingSessionID session_id,const DataSourceConfig & config)207 std::unique_ptr<ProbesDataSource> ProbesProducer::CreateFtraceDataSource(
208 TracingSessionID session_id,
209 const DataSourceConfig& config) {
210 // Don't retry if FtraceController::Create() failed once.
211 // This can legitimately happen on user builds where we cannot access the
212 // debug paths, e.g., because of SELinux rules.
213 if (ftrace_creation_failed_)
214 return nullptr;
215
216 // Lazily create on the first instance.
217 if (!ftrace_) {
218 ftrace_ = FtraceController::Create(task_runner_, this);
219
220 if (!ftrace_) {
221 PERFETTO_ELOG("Failed to create FtraceController");
222 ftrace_creation_failed_ = true;
223 return nullptr;
224 }
225
226 ftrace_->DisableAllEvents();
227 ftrace_->ClearTrace();
228 }
229
230 PERFETTO_LOG("Ftrace setup (target_buf=%" PRIu32 ")", config.target_buffer());
231 const BufferID buffer_id = static_cast<BufferID>(config.target_buffer());
232 FtraceConfig ftrace_config;
233 ftrace_config.ParseFromString(config.ftrace_config_raw());
234 std::unique_ptr<FtraceDataSource> data_source(new FtraceDataSource(
235 ftrace_->GetWeakPtr(), session_id, std::move(ftrace_config),
236 endpoint_->CreateTraceWriter(buffer_id)));
237 if (!ftrace_->AddDataSource(data_source.get())) {
238 PERFETTO_ELOG("Failed to setup ftrace");
239 return nullptr;
240 }
241 return std::unique_ptr<ProbesDataSource>(std::move(data_source));
242 }
243
CreateInodeFileDataSource(TracingSessionID session_id,DataSourceConfig source_config)244 std::unique_ptr<ProbesDataSource> ProbesProducer::CreateInodeFileDataSource(
245 TracingSessionID session_id,
246 DataSourceConfig source_config) {
247 PERFETTO_LOG("Inode file map setup (target_buf=%" PRIu32 ")",
248 source_config.target_buffer());
249 auto buffer_id = static_cast<BufferID>(source_config.target_buffer());
250 if (system_inodes_.empty())
251 CreateStaticDeviceToInodeMap("/system", &system_inodes_);
252 return std::unique_ptr<InodeFileDataSource>(new InodeFileDataSource(
253 std::move(source_config), task_runner_, session_id, &system_inodes_,
254 &cache_, endpoint_->CreateTraceWriter(buffer_id)));
255 }
256
CreateProcessStatsDataSource(TracingSessionID session_id,const DataSourceConfig & config)257 std::unique_ptr<ProbesDataSource> ProbesProducer::CreateProcessStatsDataSource(
258 TracingSessionID session_id,
259 const DataSourceConfig& config) {
260 auto buffer_id = static_cast<BufferID>(config.target_buffer());
261 return std::unique_ptr<ProcessStatsDataSource>(new ProcessStatsDataSource(
262 task_runner_, session_id, endpoint_->CreateTraceWriter(buffer_id), config,
263 std::unique_ptr<CpuFreqInfo>(new CpuFreqInfo())));
264 }
265
CreateAndroidPowerDataSource(TracingSessionID session_id,const DataSourceConfig & config)266 std::unique_ptr<ProbesDataSource> ProbesProducer::CreateAndroidPowerDataSource(
267 TracingSessionID session_id,
268 const DataSourceConfig& config) {
269 auto buffer_id = static_cast<BufferID>(config.target_buffer());
270 return std::unique_ptr<ProbesDataSource>(
271 new AndroidPowerDataSource(config, task_runner_, session_id,
272 endpoint_->CreateTraceWriter(buffer_id)));
273 }
274
CreateAndroidLogDataSource(TracingSessionID session_id,const DataSourceConfig & config)275 std::unique_ptr<ProbesDataSource> ProbesProducer::CreateAndroidLogDataSource(
276 TracingSessionID session_id,
277 const DataSourceConfig& config) {
278 auto buffer_id = static_cast<BufferID>(config.target_buffer());
279 return std::unique_ptr<ProbesDataSource>(
280 new AndroidLogDataSource(config, task_runner_, session_id,
281 endpoint_->CreateTraceWriter(buffer_id)));
282 }
283
CreatePackagesListDataSource(TracingSessionID session_id,const DataSourceConfig & config)284 std::unique_ptr<ProbesDataSource> ProbesProducer::CreatePackagesListDataSource(
285 TracingSessionID session_id,
286 const DataSourceConfig& config) {
287 auto buffer_id = static_cast<BufferID>(config.target_buffer());
288 return std::unique_ptr<ProbesDataSource>(new PackagesListDataSource(
289 config, session_id, endpoint_->CreateTraceWriter(buffer_id)));
290 }
291
CreateSysStatsDataSource(TracingSessionID session_id,const DataSourceConfig & config)292 std::unique_ptr<ProbesDataSource> ProbesProducer::CreateSysStatsDataSource(
293 TracingSessionID session_id,
294 const DataSourceConfig& config) {
295 auto buffer_id = static_cast<BufferID>(config.target_buffer());
296 return std::unique_ptr<SysStatsDataSource>(
297 new SysStatsDataSource(task_runner_, session_id,
298 endpoint_->CreateTraceWriter(buffer_id), config));
299 }
300
CreateMetatraceDataSource(TracingSessionID session_id,const DataSourceConfig & config)301 std::unique_ptr<ProbesDataSource> ProbesProducer::CreateMetatraceDataSource(
302 TracingSessionID session_id,
303 const DataSourceConfig& config) {
304 auto buffer_id = static_cast<BufferID>(config.target_buffer());
305 return std::unique_ptr<ProbesDataSource>(new MetatraceDataSource(
306 task_runner_, session_id, endpoint_->CreateTraceWriter(buffer_id)));
307 }
308
CreateSystemInfoDataSource(TracingSessionID session_id,const DataSourceConfig & config)309 std::unique_ptr<ProbesDataSource> ProbesProducer::CreateSystemInfoDataSource(
310 TracingSessionID session_id,
311 const DataSourceConfig& config) {
312 auto buffer_id = static_cast<BufferID>(config.target_buffer());
313 return std::unique_ptr<ProbesDataSource>(new SystemInfoDataSource(
314 session_id, endpoint_->CreateTraceWriter(buffer_id),
315 std::unique_ptr<CpuFreqInfo>(new CpuFreqInfo())));
316 }
317
318 std::unique_ptr<ProbesDataSource>
CreateInitialDisplayStateDataSource(TracingSessionID session_id,const DataSourceConfig & config)319 ProbesProducer::CreateInitialDisplayStateDataSource(
320 TracingSessionID session_id,
321 const DataSourceConfig& config) {
322 auto buffer_id = static_cast<BufferID>(config.target_buffer());
323 return std::unique_ptr<ProbesDataSource>(new InitialDisplayStateDataSource(
324 task_runner_, config, session_id,
325 endpoint_->CreateTraceWriter(buffer_id)));
326 }
327
StopDataSource(DataSourceInstanceID id)328 void ProbesProducer::StopDataSource(DataSourceInstanceID id) {
329 PERFETTO_LOG("Producer stop (id=%" PRIu64 ")", id);
330 auto it = data_sources_.find(id);
331 if (it == data_sources_.end()) {
332 // Can happen if SetupDataSource() failed (e.g. ftrace was busy).
333 PERFETTO_ELOG("Cannot stop data source id=%" PRIu64 ", not found", id);
334 return;
335 }
336 ProbesDataSource* data_source = it->second.get();
337
338 // MetatraceDataSource special case: re-flush and ack the stop (to record the
339 // flushes of other data sources).
340 if (data_source->descriptor == &MetatraceDataSource::descriptor)
341 data_source->Flush(FlushRequestID{0}, [] {});
342
343 endpoint_->NotifyDataSourceStopped(id);
344
345 TracingSessionID session_id = data_source->tracing_session_id;
346 auto range = session_data_sources_.equal_range(session_id);
347 for (auto kv = range.first; kv != range.second; kv++) {
348 if (kv->second != data_source)
349 continue;
350 session_data_sources_.erase(kv);
351 break;
352 }
353 data_sources_.erase(it);
354 watchdogs_.erase(id);
355 }
356
OnTracingSetup()357 void ProbesProducer::OnTracingSetup() {
358 // shared_memory() can be null in test environments when running in-process.
359 if (endpoint_->shared_memory()) {
360 base::Watchdog::GetInstance()->SetMemoryLimit(
361 endpoint_->shared_memory()->size() + base::kWatchdogDefaultMemorySlack,
362 base::kWatchdogDefaultMemoryWindow);
363 }
364 }
365
Flush(FlushRequestID flush_request_id,const DataSourceInstanceID * data_source_ids,size_t num_data_sources)366 void ProbesProducer::Flush(FlushRequestID flush_request_id,
367 const DataSourceInstanceID* data_source_ids,
368 size_t num_data_sources) {
369 PERFETTO_DCHECK(flush_request_id);
370 auto weak_this = weak_factory_.GetWeakPtr();
371
372 // Issue a Flush() to all started data sources.
373 bool flush_queued = false;
374 for (size_t i = 0; i < num_data_sources; i++) {
375 DataSourceInstanceID ds_id = data_source_ids[i];
376 auto it = data_sources_.find(ds_id);
377 if (it == data_sources_.end() || !it->second->started)
378 continue;
379 pending_flushes_.emplace(flush_request_id, ds_id);
380 flush_queued = true;
381 auto flush_callback = [weak_this, flush_request_id, ds_id] {
382 if (weak_this)
383 weak_this->OnDataSourceFlushComplete(flush_request_id, ds_id);
384 };
385 it->second->Flush(flush_request_id, flush_callback);
386 }
387
388 // If there is nothing to flush, ack immediately.
389 if (!flush_queued) {
390 endpoint_->NotifyFlushComplete(flush_request_id);
391 return;
392 }
393
394 // Otherwise, post the timeout task.
395 task_runner_->PostDelayedTask(
396 [weak_this, flush_request_id] {
397 if (weak_this)
398 weak_this->OnFlushTimeout(flush_request_id);
399 },
400 kFlushTimeoutMs);
401 }
402
OnDataSourceFlushComplete(FlushRequestID flush_request_id,DataSourceInstanceID ds_id)403 void ProbesProducer::OnDataSourceFlushComplete(FlushRequestID flush_request_id,
404 DataSourceInstanceID ds_id) {
405 PERFETTO_DLOG("Flush %" PRIu64 " acked by data source %" PRIu64,
406 flush_request_id, ds_id);
407 auto range = pending_flushes_.equal_range(flush_request_id);
408 for (auto it = range.first; it != range.second; it++) {
409 if (it->second == ds_id) {
410 pending_flushes_.erase(it);
411 break;
412 }
413 }
414
415 if (pending_flushes_.count(flush_request_id))
416 return; // Still waiting for other data sources to ack.
417
418 PERFETTO_DLOG("All data sources acked to flush %" PRIu64, flush_request_id);
419 endpoint_->NotifyFlushComplete(flush_request_id);
420 }
421
OnFlushTimeout(FlushRequestID flush_request_id)422 void ProbesProducer::OnFlushTimeout(FlushRequestID flush_request_id) {
423 if (pending_flushes_.count(flush_request_id) == 0)
424 return; // All acked.
425 PERFETTO_ELOG("Flush(%" PRIu64 ") timed out", flush_request_id);
426 pending_flushes_.erase(flush_request_id);
427 endpoint_->NotifyFlushComplete(flush_request_id);
428 }
429
ClearIncrementalState(const DataSourceInstanceID * data_source_ids,size_t num_data_sources)430 void ProbesProducer::ClearIncrementalState(
431 const DataSourceInstanceID* data_source_ids,
432 size_t num_data_sources) {
433 for (size_t i = 0; i < num_data_sources; i++) {
434 DataSourceInstanceID ds_id = data_source_ids[i];
435 auto it = data_sources_.find(ds_id);
436 if (it == data_sources_.end() || !it->second->started)
437 continue;
438
439 it->second->ClearIncrementalState();
440 }
441 }
442
443 // This function is called by the FtraceController in batches, whenever it has
444 // read one or more pages from one or more cpus and written that into the
445 // userspace tracing buffer. If more than one ftrace data sources are active,
446 // this call typically happens after writing for all session has been handled.
OnFtraceDataWrittenIntoDataSourceBuffers()447 void ProbesProducer::OnFtraceDataWrittenIntoDataSourceBuffers() {
448 TracingSessionID last_session_id = 0;
449 FtraceMetadata* metadata = nullptr;
450 InodeFileDataSource* inode_data_source = nullptr;
451 ProcessStatsDataSource* ps_data_source = nullptr;
452
453 // unordered_multimap guarantees that entries with the same key are contiguous
454 // in the iteration.
455 for (auto it = session_data_sources_.begin(); /* check below*/; it++) {
456 // If this is the last iteration or the session id has changed,
457 // dispatch the metadata update to the linked data sources, if any.
458 if (it == session_data_sources_.end() || it->first != last_session_id) {
459 bool has_inodes = metadata && !metadata->inode_and_device.empty();
460 bool has_pids = metadata && !metadata->pids.empty();
461 bool has_rename_pids = metadata && !metadata->rename_pids.empty();
462 if (has_inodes && inode_data_source)
463 inode_data_source->OnInodes(metadata->inode_and_device);
464 // Ordering the rename pids before the seen pids is important so that any
465 // renamed processes get scraped in the OnPids call.
466 if (has_rename_pids && ps_data_source)
467 ps_data_source->OnRenamePids(metadata->rename_pids);
468 if (has_pids && ps_data_source)
469 ps_data_source->OnPids(metadata->pids);
470 if (metadata)
471 metadata->Clear();
472 metadata = nullptr;
473 inode_data_source = nullptr;
474 ps_data_source = nullptr;
475 if (it == session_data_sources_.end())
476 break;
477 last_session_id = it->first;
478 }
479 ProbesDataSource* ds = it->second;
480 if (!ds->started)
481 continue;
482
483 if (ds->descriptor == &FtraceDataSource::descriptor) {
484 metadata = static_cast<FtraceDataSource*>(ds)->mutable_metadata();
485 } else if (ds->descriptor == &InodeFileDataSource::descriptor) {
486 inode_data_source = static_cast<InodeFileDataSource*>(ds);
487 } else if (ds->descriptor == &ProcessStatsDataSource::descriptor) {
488 // A trace session might have declared more than one ps data source.
489 // In those cases we often use one for a full dump on startup (
490 // targeting a dedicated buffer) and another one for on-demand dumps
491 // targeting the main buffer.
492 // Only use the one that has on-demand dumps enabled, if any.
493 auto ps = static_cast<ProcessStatsDataSource*>(ds);
494 if (ps->on_demand_dumps_enabled())
495 ps_data_source = ps;
496 }
497 } // for (session_data_sources_)
498 }
499
ConnectWithRetries(const char * socket_name,base::TaskRunner * task_runner)500 void ProbesProducer::ConnectWithRetries(const char* socket_name,
501 base::TaskRunner* task_runner) {
502 PERFETTO_DCHECK(state_ == kNotStarted);
503 state_ = kNotConnected;
504
505 ResetConnectionBackoff();
506 socket_name_ = socket_name;
507 task_runner_ = task_runner;
508 Connect();
509 }
510
Connect()511 void ProbesProducer::Connect() {
512 PERFETTO_DCHECK(state_ == kNotConnected);
513 state_ = kConnecting;
514 endpoint_ = ProducerIPCClient::Connect(
515 socket_name_, this, "perfetto.traced_probes", task_runner_,
516 TracingService::ProducerSMBScrapingMode::kDisabled,
517 kTracingSharedMemSizeHintBytes, kTracingSharedMemPageSizeHintBytes);
518 }
519
IncreaseConnectionBackoff()520 void ProbesProducer::IncreaseConnectionBackoff() {
521 connection_backoff_ms_ *= 2;
522 if (connection_backoff_ms_ > kMaxConnectionBackoffMs)
523 connection_backoff_ms_ = kMaxConnectionBackoffMs;
524 }
525
ResetConnectionBackoff()526 void ProbesProducer::ResetConnectionBackoff() {
527 connection_backoff_ms_ = kInitialConnectionBackoffMs;
528 }
529
530 } // namespace perfetto
531