1 // Copyright 2018 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 
5 #include "tracing.h"
6 
7 #include <lib/async-loop/loop.h>
8 #include <trace-provider/provider.h>
9 
10 #include "../shared/log.h"
11 
12 namespace devmgr {
13 
devhost_start_trace_provider()14 zx_status_t devhost_start_trace_provider() {
15     async_loop_t* loop;
16     zx_status_t status = async_loop_create(&kAsyncLoopConfigNoAttachToThread, &loop);
17     if (status != ZX_OK) {
18         log(ERROR, "devhost: error creating async loop: %d\n", status);
19         return status;
20     }
21 
22     status = async_loop_start_thread(loop, "devhost-tracer", nullptr);
23     if (status != ZX_OK) {
24         async_loop_destroy(loop);
25         log(ERROR, "devhost: error starting async loop thread: %d\n", status);
26         return status;
27     }
28 
29     async_dispatcher_t* dispatcher = async_loop_get_dispatcher(loop);
30     trace_provider_t* trace_provider = trace_provider_create(dispatcher);
31     if (!trace_provider) {
32         async_loop_destroy(loop);
33         log(ERROR, "devhost: error registering provider\n");
34         return ZX_ERR_INTERNAL;
35     }
36 
37     // N.B. The registry has begun, but these things are async. TraceManager
38     // may not even be running yet (and likely isn't).
39     log(INFO, "devhost: trace provider registry begun\n");
40     return ZX_OK;
41 }
42 
43 } // namespace devmgr
44