xref: /aosp_15_r20/frameworks/av/services/audioflinger/fastpath/FastThreadDumpState.cpp (revision ec779b8e0859a360c3d303172224686826e6e0e1)
1*ec779b8eSAndroid Build Coastguard Worker /*
2*ec779b8eSAndroid Build Coastguard Worker  * Copyright (C) 2014 The Android Open Source Project
3*ec779b8eSAndroid Build Coastguard Worker  *
4*ec779b8eSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*ec779b8eSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*ec779b8eSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*ec779b8eSAndroid Build Coastguard Worker  *
8*ec779b8eSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*ec779b8eSAndroid Build Coastguard Worker  *
10*ec779b8eSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*ec779b8eSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*ec779b8eSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*ec779b8eSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*ec779b8eSAndroid Build Coastguard Worker  * limitations under the License.
15*ec779b8eSAndroid Build Coastguard Worker  */
16*ec779b8eSAndroid Build Coastguard Worker 
17*ec779b8eSAndroid Build Coastguard Worker #include <audio_utils/roundup.h>
18*ec779b8eSAndroid Build Coastguard Worker #include "FastThreadDumpState.h"
19*ec779b8eSAndroid Build Coastguard Worker 
20*ec779b8eSAndroid Build Coastguard Worker namespace android {
21*ec779b8eSAndroid Build Coastguard Worker 
FastThreadDumpState()22*ec779b8eSAndroid Build Coastguard Worker FastThreadDumpState::FastThreadDumpState()
23*ec779b8eSAndroid Build Coastguard Worker {
24*ec779b8eSAndroid Build Coastguard Worker #ifdef FAST_THREAD_STATISTICS
25*ec779b8eSAndroid Build Coastguard Worker     increaseSamplingN(1);
26*ec779b8eSAndroid Build Coastguard Worker #endif
27*ec779b8eSAndroid Build Coastguard Worker }
28*ec779b8eSAndroid Build Coastguard Worker 
29*ec779b8eSAndroid Build Coastguard Worker #ifdef FAST_THREAD_STATISTICS
increaseSamplingN(uint32_t samplingN)30*ec779b8eSAndroid Build Coastguard Worker void FastThreadDumpState::increaseSamplingN(uint32_t samplingN)
31*ec779b8eSAndroid Build Coastguard Worker {
32*ec779b8eSAndroid Build Coastguard Worker     if (samplingN <= mSamplingN || samplingN > kSamplingN || roundup(samplingN) != samplingN) {
33*ec779b8eSAndroid Build Coastguard Worker         return;
34*ec779b8eSAndroid Build Coastguard Worker     }
35*ec779b8eSAndroid Build Coastguard Worker     const uint32_t additional = samplingN - mSamplingN;
36*ec779b8eSAndroid Build Coastguard Worker     // sample arrays aren't accessed atomically with respect to the bounds,
37*ec779b8eSAndroid Build Coastguard Worker     // so clearing reduces chance for dumpsys to read random uninitialized samples
38*ec779b8eSAndroid Build Coastguard Worker     memset(&mMonotonicNs[mSamplingN], 0, sizeof(mMonotonicNs[0]) * additional);
39*ec779b8eSAndroid Build Coastguard Worker     memset(&mLoadNs[mSamplingN], 0, sizeof(mLoadNs[0]) * additional);
40*ec779b8eSAndroid Build Coastguard Worker #ifdef CPU_FREQUENCY_STATISTICS
41*ec779b8eSAndroid Build Coastguard Worker     memset(&mCpukHz[mSamplingN], 0, sizeof(mCpukHz[0]) * additional);
42*ec779b8eSAndroid Build Coastguard Worker #endif
43*ec779b8eSAndroid Build Coastguard Worker     mSamplingN = samplingN;
44*ec779b8eSAndroid Build Coastguard Worker }
45*ec779b8eSAndroid Build Coastguard Worker #endif
46*ec779b8eSAndroid Build Coastguard Worker 
47*ec779b8eSAndroid Build Coastguard Worker }  // namespace android
48