fuchsia_trace_provider/lib.rs
1// Copyright 2019 The Fuchsia 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
5use zx::sys::zx_handle_t;
6
7/// Creates a trace provider service that enables traces created by a process
8/// to be collected by the system trace manager.
9///
10/// Typically applications would call this method once, early in their main
11/// function to enable them to be eligible to produce traces.
12///
13/// It is safe but unnecessary to call this function more than once.
14pub fn trace_provider_create_with_fdio() {
15 unsafe {
16 sys::trace_provider_create_with_fdio_rust();
17 }
18}
19
20pub fn trace_provider_create_with_service(to_service_h: zx_handle_t) {
21 unsafe {
22 sys::trace_provider_create_with_service_rust(to_service_h);
23 }
24}
25
26/// Wait for trace provider initialization to acknowledge already-running traces before returning.
27///
28/// If the current thread is expected to initialize the provider then this should only be called
29/// after doing so to avoid a deadlock.
30pub fn trace_provider_wait_for_init() {
31 unsafe {
32 sys::trace_provider_wait_for_init();
33 }
34}
35
36mod sys {
37 // From librust-trace-provider.so
38 extern "C" {
39 // See the C++ documentation for these functions in trace_provider.cc
40 pub(super) fn trace_provider_create_with_fdio_rust();
41 pub(super) fn trace_provider_create_with_service_rust(to_service_h: zx::sys::zx_handle_t);
42 pub(super) fn trace_provider_wait_for_init();
43 }
44}