• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "graphic_memory_decorator.h"
17 #include "decorator_util.h"
18 
19 namespace OHOS {
20 namespace HiviewDFX {
21 namespace UCollectUtil {
22 constexpr char GRAPHIC_MEM_COLLECTOR_NAME[] = "GraphicMemoryCollector";
23 StatInfoWrapper GraphicMemoryDecorator::statInfoWrapper_;
24 
GetGraphicUsage(int32_t pid,GraphicType type,bool isLowLatencyMode)25 CollectResult<int32_t> GraphicMemoryDecorator::GetGraphicUsage(int32_t pid, GraphicType type, bool isLowLatencyMode)
26 {
27     auto task = [this, pid, type, isLowLatencyMode] {
28         return graphicMemoryCollector_->GetGraphicUsage(pid, type, isLowLatencyMode);
29     };
30     return Invoke(task, statInfoWrapper_, std::string(GRAPHIC_MEM_COLLECTOR_NAME) + UC_SEPARATOR + __func__);
31 }
32 
SaveStatCommonInfo()33 void GraphicMemoryDecorator::SaveStatCommonInfo()
34 {
35     std::map<std::string, StatInfo> statInfo = statInfoWrapper_.GetStatInfo();
36     std::list<std::string> formattedStatInfo;
37     for (const auto& record : statInfo) {
38         formattedStatInfo.push_back(record.second.ToString());
39     }
40     WriteLinesToFile(formattedStatInfo, false, UC_STAT_LOG_PATH);
41 }
42 
ResetStatInfo()43 void GraphicMemoryDecorator::ResetStatInfo()
44 {
45     statInfoWrapper_.ResetStatInfo();
46 }
47 } // namespace UCollectUtil
48 } // namespace HiviewDFX
49 } // namespace OHOS
50