1 /*
2 * Copyright (C) 2023 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 "statsd.h"
18
19 #include <binder/ProcessState.h>
20 #include <stats_subscription.h>
21
22 namespace perfetto {
23 namespace android_internal {
24
AddAtomSubscription(const uint8_t * subscription_config,size_t num_bytes,const AtomCallback callback,void * cookie)25 int32_t AddAtomSubscription(const uint8_t* subscription_config,
26 size_t num_bytes,
27 const AtomCallback callback,
28 void* cookie) {
29 // Although the binder messages we use are one-way we pass an interface that
30 // statsd uses to talk back to us. For this to work we need the some binder
31 // threads listening to the for these messages. To handle this we start a
32 // thread pool if it hasn't been started already:
33 android::ProcessState::self()->startThreadPool();
34
35 auto c = reinterpret_cast<AStatsManager_SubscriptionCallback>(callback);
36 return AStatsManager_addSubscription(subscription_config, num_bytes, c,
37 cookie);
38 }
39
RemoveAtomSubscription(int32_t subscription_id)40 void RemoveAtomSubscription(int32_t subscription_id) {
41 AStatsManager_removeSubscription(subscription_id);
42 }
43
FlushAtomSubscription(int32_t subscription_id)44 void FlushAtomSubscription(int32_t subscription_id) {
45 AStatsManager_flushSubscription(subscription_id);
46 }
47
48 } // namespace android_internal
49 } // namespace perfetto
50