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