• 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 <algorithm>
16 #include "collect_parameter.h"
17 
18 namespace OHOS {
19 namespace HiviewDFX {
CollectParameter(const std::string & caller)20 CollectParameter::CollectParameter(const std::string &caller): caller_(caller)
21 {}
22 
~CollectParameter()23 CollectParameter::~CollectParameter()
24 {
25     items_.clear();
26     itemIntConfigs_.clear();
27     itemStrConfigs_.clear();
28 }
29 
SetRuntime(const std::string & second,const std::string & minute,const std::string & hour)30 void CollectParameter::SetRuntime(const std::string &second, const std::string &minute, const std::string &hour)
31 {
32     second_ = second;
33     minute_ = minute;
34     hour_ = hour;
35 }
36 
SetExecTimes(uint32_t times)37 void CollectParameter::SetExecTimes(uint32_t times)
38 {
39     times_ = times;
40 }
41 
SetCollectItems(const std::vector<std::string> & items)42 void CollectParameter::SetCollectItems(const std::vector<std::string> &items)
43 {
44     for (auto it = items.begin(); it != items.end(); it++) {
45         auto itFinded = std::find(items_.begin(), items_.end(), *it);
46         if (itFinded != items_.end()) {
47             continue;
48         }
49 
50         items_.emplace_back(*it);
51     }
52 }
53 
SetConfig(const std::string & collectModule,const std::string & config,const std::string value)54 void CollectParameter::SetConfig(const std::string &collectModule, const std::string &config, const std::string value)
55 {
56     auto moduleConfig = itemStrConfigs_.find(collectModule);
57     if (moduleConfig == itemStrConfigs_.end()) {
58         itemStrConfigs_.insert(std::make_pair(collectModule, std::map<std::string, std::string>()));
59         moduleConfig = itemStrConfigs_.find(collectModule);
60     }
61     moduleConfig->second.insert(std::make_pair(config, value));
62 }
63 
SetConfig(const std::string & collectModule,const std::string & config,uint32_t value)64 void CollectParameter::SetConfig(const std::string &collectModule, const std::string &config, uint32_t value)
65 {
66     auto moduleConfig = itemIntConfigs_.find(collectModule);
67     if (moduleConfig == itemIntConfigs_.end()) {
68         itemIntConfigs_.insert(std::make_pair(collectModule, std::map<std::string, uint32_t>()));
69         moduleConfig = itemIntConfigs_.find(collectModule);
70     }
71     moduleConfig->second.insert(std::make_pair(config, value));
72 }
73 } // namespace HiviewDFX
74 } // namespace OHOS
75