• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 "subcommand_list.h"
17 
18 using namespace std;
19 namespace OHOS {
20 namespace Developtools {
21 namespace HiPerf {
OnSubCommand(vector<string> & args)22 bool SubCommandList::OnSubCommand(vector<string> &args)
23 {
24     HLOGV("enter");
25     vector<perf_type_id> requestEventTypes;
26 
27     if (args.empty()) {
28         // all the list
29         for (auto it : PERF_TYPES) {
30             requestEventTypes.push_back(it.first);
31         }
32     } else {
33         string requestEventType = args.front().c_str();
34         auto it = SUPPORT_NAME_OPTIONS.find(requestEventType);
35         if (it == SUPPORT_NAME_OPTIONS.end()) {
36             printf("not support option: '%s'\n", requestEventType.c_str());
37             return false;
38         } else {
39             requestEventTypes.push_back(it->second);
40         }
41     }
42     ShowSupportEventsTypes(requestEventTypes);
43     return true;
44 }
ShowSupportEventsTypes(vector<perf_type_id> requestEventTypes)45 bool SubCommandList::ShowSupportEventsTypes(vector<perf_type_id> requestEventTypes)
46 {
47     // each type
48     for (perf_type_id id : requestEventTypes) {
49         // each config
50         auto configs = perfEvents_.GetSupportEvents(id);
51         printf("\nSupported events for %s:\n", PERF_TYPES.at(id).c_str());
52         for (auto config : configs) {
53             printf("\t%s\n", config.second.c_str());
54         }
55         if (configs.size() == 0) {
56             return false; // support nothing
57         }
58     }
59     std::cout << std::endl;
60     return true;
61 };
62 
RegisterSubCommandList()63 void SubCommandList::RegisterSubCommandList()
64 {
65     HLOGV("enter");
66     SubCommand::RegisterSubCommand("list", make_unique<SubCommandList>());
67 }
68 } // namespace HiPerf
69 } // namespace Developtools
70 } // namespace OHOS