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