• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 #include <string>
16 #include <iostream>
17 #include "collect_item_result.h"
18 
19 using namespace std;
20 namespace OHOS {
21 namespace HiviewDFX {
CollectItemResult()22 CollectItemResult::CollectItemResult()
23 {}
24 
~CollectItemResult()25 CollectItemResult::~CollectItemResult()
26 {
27     itemValues_.clear();
28 }
29 
SetCollectItemValue(const std::string & item,std::string & value)30 void CollectItemResult::SetCollectItemValue(const std::string& item, std::string &value)
31 {
32     if (item.rfind("/hitrace/") != 0) {
33         return;
34     }
35     CollectItemValue ciValue = CollectItemValue();
36     ciValue.strValue_ = value;
37     itemValues_.emplace(item, ciValue);
38 }
39 
GetCollectItemValue(const std::string & item,std::string & value)40 void CollectItemResult::GetCollectItemValue(const std::string& item, std::string &value)
41 {
42     auto it = itemValues_.find(item);
43     if (it == itemValues_.end()) {
44         value.clear();
45         return;
46     }
47 
48     value = it->second.strValue_;
49 }
50 
GetCollectItemValue(const std::string & item,std::string & value,std::string & unit)51 void CollectItemResult::GetCollectItemValue(const std::string& item, std::string &value, std::string &unit)
52 {
53     auto it = itemValues_.find(item);
54     if (it == itemValues_.end()) {
55         value.clear();
56         unit.clear();
57         return;
58     }
59 
60     value = it->second.strValue_;
61     unit = it->second.unit_;
62 }
63 
GetCollectItemValue(const std::string & item,int32_t & value)64 void CollectItemResult::GetCollectItemValue(const std::string& item, int32_t &value)
65 {
66     auto it = itemValues_.find(item);
67     if (it == itemValues_.end()) {
68         value = 0;
69         return;
70     }
71 
72     value = it->second.intValue_;
73 }
74 
GetCollectItemValue(const std::string & item,int32_t & value,std::string & unit)75 void CollectItemResult::GetCollectItemValue(const std::string& item, int32_t &value, std::string &unit)
76 {
77     auto it = itemValues_.find(item);
78     if (it == itemValues_.end()) {
79         value = 0;
80         unit.clear();
81         return;
82     }
83 
84     value = it->second.intValue_;
85     unit = it->second.unit_;
86 }
87 } // namespace HiviewDFX
88 } // namespace OHOS
89