1 /*
2 * Copyright (c) 2025 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 #undef LOG_TAG
16 #define LOG_TAG "AudioCapturerDfxCollector"
17
18 #include <map>
19
20 #include "audio_capturer_dfx_collector.h"
21 #include "media_monitor_manager.h"
22 #include "audio_common_log.h"
23 #include "dfx_msg_manager.h"
24
25 namespace OHOS {
26 namespace AudioStandard {
27
FlushDfxMsg(uint32_t index,int32_t appUid)28 void AudioCapturerDfxCollector::FlushDfxMsg(uint32_t index, int32_t appUid)
29 {
30 if (appUid == DFX_INVALID_APP_UID) {
31 AUDIO_INFO_LOG("flush failed index=%{public}d, appUid=%{public}d", index, appUid);
32 return;
33 }
34
35 for (auto &item : dfxInfos_) {
36 AUDIO_INFO_LOG("FlushDfxMsg..., index=%{public}u, appUid=%{public}d", item.first, appUid);
37 DfxMsgManager::GetInstance().Enqueue({.appUid = appUid, .captureInfo = item.second});
38 }
39 dfxInfos_.clear();
40 }
41
WriteActionMsg(uint32_t dfxIndex,CapturerStage stage)42 CapturerDfxBuilder &CapturerDfxBuilder::WriteActionMsg(uint32_t dfxIndex, CapturerStage stage)
43 {
44 dfxInfo_.capturerAction = {dfxIndex, 0, 0, stage};
45 return *this;
46 }
47
WriteInfoMsg(SourceType sourceType)48 CapturerDfxBuilder &CapturerDfxBuilder::WriteInfoMsg(SourceType sourceType)
49 {
50 dfxInfo_.capturerInfo = {0, 0, sourceType, 0};
51 return *this;
52 }
53
WriteStatMsg(const AudioCapturerInfo & info,const RecordStat & stat)54 CapturerDfxBuilder &CapturerDfxBuilder::WriteStatMsg(const AudioCapturerInfo &info, const RecordStat &stat)
55 {
56 dfxInfo_.capturerStat = {info.samplingRate, stat.recordDuration_};
57 return *this;
58 }
59
GetResult()60 CapturerDfxInfo CapturerDfxBuilder::GetResult()
61 {
62 return dfxInfo_;
63 }
64
65 } // namespace AudioStandard
66 } // namespace OHOS
67