1 /*
2  * Copyright (c) 2023-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 "network_decorator.h"
17 
18 namespace OHOS {
19 namespace HiviewDFX {
20 namespace UCollectUtil {
21 const std::string NET_COLLECTOR_NAME = "NetworkCollector";
22 StatInfoWrapper NetworkDecorator::statInfoWrapper_;
23 
CollectRate()24 CollectResult<NetworkRate> NetworkDecorator::CollectRate()
25 {
26     auto task = [this] { return networkCollector_->CollectRate(); };
27     return Invoke(task, statInfoWrapper_, NET_COLLECTOR_NAME + UC_SEPARATOR + __func__);
28 }
29 
SaveStatCommonInfo()30 void NetworkDecorator::SaveStatCommonInfo()
31 {
32     std::map<std::string, StatInfo> statInfo = statInfoWrapper_.GetStatInfo();
33     std::vector<std::string> formattedStatInfo;
34     for (const auto& record : statInfo) {
35         formattedStatInfo.push_back(record.second.ToString());
36     }
37     WriteLinesToFile(formattedStatInfo, false);
38 }
39 
ResetStatInfo()40 void NetworkDecorator::ResetStatInfo()
41 {
42     statInfoWrapper_.ResetStatInfo();
43 }
44 } // namespace UCollectUtil
45 } // namespace HiviewDFX
46 } // namespace OHOS
47