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 <cstdio> 17 #include <iostream> 18 19 #include "command.h" 20 #include "debug_logger.h" 21 #include "option_debug.h" 22 #include "subcommand.h" 23 #include "subcommand_help.h" 24 #include "utilities.h" 25 #if SUPPORT_PERF_EVENT 26 #include "subcommand_list.h" 27 #include "subcommand_record.h" 28 #include "subcommand_stat.h" 29 #endif 30 #include "subcommand_dump.h" 31 #include "subcommand_report.h" 32 33 using namespace std; 34 using namespace OHOS::Developtools::HiPerf; 35 36 #ifdef FUZZER_TEST 37 #define main hiperf_fuzzer_main 38 #endif 39 main(const int argc,const char * argv[])40int main(const int argc, const char *argv[]) 41 { 42 std::ios::sync_with_stdio(false); 43 cin.tie(nullptr); 44 45 // pass the argv to next 46 vector<string> args; 47 for (int i = 1; i < argc; i++) { 48 args.push_back(argv[i]); 49 } 50 51 if (args.empty()) { 52 printf("no command input.\n"); 53 args.push_back("help"); // no cmd like help cmd 54 } 55 56 // register all the main command 57 #ifdef HIPERF_DEBUG 58 RegisterMainCommandDebug(); 59 #endif 60 61 // register all the sub command 62 SubCommandHelp::RegisterSubCommandHelp(); 63 64 #if SUPPORT_PERF_EVENT 65 RegisterSubCommandStat(); 66 SubCommandList::RegisterSubCommandList(); 67 SubCommandRecord::RegisterSubCommandRecord(); 68 #endif 69 70 SubCommandDump::RegisterSubCommandDump(); 71 SubCommandReport::RegisterSubCommandReport(); 72 #ifdef FUZZER_TEST 73 bool isRecordCmd = false; 74 if (args[0] == "record") { 75 isRecordCmd = true; 76 } 77 #endif 78 // tell sub cmd to do the process 79 Command::DispatchCommands(args); 80 81 #ifdef FUZZER_TEST 82 SubCommand::ClearSubCommands(); 83 Option::ClearMainOptions(); 84 85 if (isRecordCmd) { 86 const uint64_t msWaitSysReleaseThread = 100; 87 std::this_thread::sleep_for(std::chrono::milliseconds(msWaitSysReleaseThread)); 88 } 89 #endif 90 91 HLOGD("normal exit."); 92 return 0; 93 } 94