1 /*
2 * Copyright (c) 2024 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
16 #include "wm_decorator.h"
17
18 namespace OHOS {
19 namespace HiviewDFX {
20 namespace UCollectUtil {
21 const std::string WM_COLLECTOR_NAME = "WmCollector";
22 StatInfoWrapper WmDecorator::statInfoWrapper_;
23
ExportWindowsInfo()24 CollectResult<std::string> WmDecorator::ExportWindowsInfo()
25 {
26 auto task = [this] { return wmCollector_->ExportWindowsInfo(); };
27 return Invoke(task, statInfoWrapper_, WM_COLLECTOR_NAME + UC_SEPARATOR + __func__);
28 }
29
ExportWindowsMemory()30 CollectResult<std::string> WmDecorator::ExportWindowsMemory()
31 {
32 auto task = [this] { return wmCollector_->ExportWindowsMemory(); };
33 return Invoke(task, statInfoWrapper_, WM_COLLECTOR_NAME + UC_SEPARATOR + __func__);
34 }
35
ExportGpuMemory()36 CollectResult<std::string> WmDecorator::ExportGpuMemory()
37 {
38 auto task = [this] { return wmCollector_->ExportGpuMemory(); };
39 return Invoke(task, statInfoWrapper_, WM_COLLECTOR_NAME + UC_SEPARATOR + __func__);
40 }
41
SaveStatCommonInfo()42 void WmDecorator::SaveStatCommonInfo()
43 {
44 std::map<std::string, StatInfo> statInfo = statInfoWrapper_.GetStatInfo();
45 std::vector<std::string> formattedStatInfo;
46 for (const auto& record : statInfo) {
47 formattedStatInfo.push_back(record.second.ToString());
48 }
49 WriteLinesToFile(formattedStatInfo, false);
50 }
51
ResetStatInfo()52 void WmDecorator::ResetStatInfo()
53 {
54 statInfoWrapper_.ResetStatInfo();
55 }
56 } // namespace UCollectUtil
57 } // namespace HiviewDFX
58 } // namespace OHOS
59