xref: /aosp_15_r20/external/perfetto/src/android_internal/statsd.cc (revision 6dbdd20afdafa5e3ca9b8809fa73465d530080dc)
1*6dbdd20aSAndroid Build Coastguard Worker /*
2*6dbdd20aSAndroid Build Coastguard Worker  * Copyright (C) 2023 The Android Open Source Project
3*6dbdd20aSAndroid Build Coastguard Worker  *
4*6dbdd20aSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*6dbdd20aSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*6dbdd20aSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*6dbdd20aSAndroid Build Coastguard Worker  *
8*6dbdd20aSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*6dbdd20aSAndroid Build Coastguard Worker  *
10*6dbdd20aSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*6dbdd20aSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*6dbdd20aSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*6dbdd20aSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*6dbdd20aSAndroid Build Coastguard Worker  * limitations under the License.
15*6dbdd20aSAndroid Build Coastguard Worker  */
16*6dbdd20aSAndroid Build Coastguard Worker 
17*6dbdd20aSAndroid Build Coastguard Worker #include "statsd.h"
18*6dbdd20aSAndroid Build Coastguard Worker 
19*6dbdd20aSAndroid Build Coastguard Worker #include <binder/ProcessState.h>
20*6dbdd20aSAndroid Build Coastguard Worker #include <stats_subscription.h>
21*6dbdd20aSAndroid Build Coastguard Worker 
22*6dbdd20aSAndroid Build Coastguard Worker namespace perfetto {
23*6dbdd20aSAndroid Build Coastguard Worker namespace android_internal {
24*6dbdd20aSAndroid Build Coastguard Worker 
AddAtomSubscription(const uint8_t * subscription_config,size_t num_bytes,const AtomCallback callback,void * cookie)25*6dbdd20aSAndroid Build Coastguard Worker int32_t AddAtomSubscription(const uint8_t* subscription_config,
26*6dbdd20aSAndroid Build Coastguard Worker                             size_t num_bytes,
27*6dbdd20aSAndroid Build Coastguard Worker                             const AtomCallback callback,
28*6dbdd20aSAndroid Build Coastguard Worker                             void* cookie) {
29*6dbdd20aSAndroid Build Coastguard Worker   // Although the binder messages we use are one-way we pass an interface that
30*6dbdd20aSAndroid Build Coastguard Worker   // statsd uses to talk back to us. For this to work we need the some binder
31*6dbdd20aSAndroid Build Coastguard Worker   // threads listening to the for these messages. To handle this we start a
32*6dbdd20aSAndroid Build Coastguard Worker   // thread pool if it hasn't been started already:
33*6dbdd20aSAndroid Build Coastguard Worker   android::ProcessState::self()->startThreadPool();
34*6dbdd20aSAndroid Build Coastguard Worker 
35*6dbdd20aSAndroid Build Coastguard Worker   auto c = reinterpret_cast<AStatsManager_SubscriptionCallback>(callback);
36*6dbdd20aSAndroid Build Coastguard Worker   return AStatsManager_addSubscription(subscription_config, num_bytes, c,
37*6dbdd20aSAndroid Build Coastguard Worker                                        cookie);
38*6dbdd20aSAndroid Build Coastguard Worker }
39*6dbdd20aSAndroid Build Coastguard Worker 
RemoveAtomSubscription(int32_t subscription_id)40*6dbdd20aSAndroid Build Coastguard Worker void RemoveAtomSubscription(int32_t subscription_id) {
41*6dbdd20aSAndroid Build Coastguard Worker   AStatsManager_removeSubscription(subscription_id);
42*6dbdd20aSAndroid Build Coastguard Worker }
43*6dbdd20aSAndroid Build Coastguard Worker 
FlushAtomSubscription(int32_t subscription_id)44*6dbdd20aSAndroid Build Coastguard Worker void FlushAtomSubscription(int32_t subscription_id) {
45*6dbdd20aSAndroid Build Coastguard Worker   AStatsManager_flushSubscription(subscription_id);
46*6dbdd20aSAndroid Build Coastguard Worker }
47*6dbdd20aSAndroid Build Coastguard Worker 
48*6dbdd20aSAndroid Build Coastguard Worker }  // namespace android_internal
49*6dbdd20aSAndroid Build Coastguard Worker }  // namespace perfetto
50