• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 "option_debug.h"
17 #include "debug_logger.h"
18 #include "option.h"
19 namespace OHOS {
20 namespace Developtools {
21 namespace HiPerf {
OnVerboseLevel(const std::vector<std::string> & debugLevel)22 static bool OnVerboseLevel(const std::vector<std::string> &debugLevel)
23 {
24 #if defined(is_ohos) && is_ohos
25     if (IsRoot()) {
26         if (debugLevel.size() == 0) {
27             return false;
28         }
29         DebugLogger::GetInstance()->SetLogLevel(LEVEL_VERBOSE);
30         DebugLogger::GetInstance()->Disable(false);
31     }
32 #endif
33     return true;
34 }
35 
OnMuchLevel(const std::vector<std::string> & debugLevel)36 static bool OnMuchLevel(const std::vector<std::string> &debugLevel)
37 {
38 #if defined(is_ohos) && is_ohos
39     if (IsRoot()) {
40         if (debugLevel.size() == 0) {
41             return false;
42         }
43         DebugLogger::GetInstance()->SetLogLevel(LEVEL_MUCH);
44         DebugLogger::GetInstance()->Disable(false);
45     }
46 #endif
47     return true;
48 }
49 
OnDebugLevel(const std::vector<std::string> & debugLevel)50 static bool OnDebugLevel(const std::vector<std::string> &debugLevel)
51 {
52 #if defined(is_ohos) && is_ohos
53     if (IsRoot()) {
54         if (debugLevel.size() == 0) {
55             return false;
56         }
57         DebugLogger::GetInstance()->SetLogLevel(LEVEL_DEBUG);
58         DebugLogger::GetInstance()->Disable(false);
59     }
60 #endif
61     return true;
62 }
63 
OnNoDebug(const std::vector<std::string> & debugLevel)64 static bool OnNoDebug(const std::vector<std::string> &debugLevel)
65 {
66 #if defined(is_ohos) && is_ohos
67     if (IsRoot()) {
68         if (debugLevel.size() == 0) {
69             return false;
70         }
71         DebugLogger::GetInstance()->Disable();
72     }
73 #endif
74     return true;
75 }
76 
OnMixLogOutput(const std::vector<std::string> & debugLevel)77 static bool OnMixLogOutput(const std::vector<std::string> &debugLevel)
78 {
79 #if defined(is_ohos) && is_ohos
80     if (IsRoot()) {
81         if (debugLevel.size() == 0) {
82             return false;
83         }
84         DebugLogger::GetInstance()->SetMixLogOutput(true);
85     }
86 #endif
87     return true;
88 }
89 
OnLogPath(std::vector<std::string> & args)90 static bool OnLogPath(std::vector<std::string> &args)
91 {
92 #if defined(is_ohos) && is_ohos
93     if (IsRoot()) {
94         if (args.size() > 0) {
95             DebugLogger::GetInstance()->SetLogPath(args[0]);
96             args.erase(args.begin());
97         } else {
98             return false;
99         }
100     }
101 #endif
102     return true;
103 }
104 
OnLogTag(std::vector<std::string> & args)105 static bool OnLogTag(std::vector<std::string> &args)
106 {
107 #if defined(is_ohos) && is_ohos
108     if (IsRoot()) {
109         if (args.size() > 0) {
110             DebugLogger::GetInstance()->SetLogTags(args[0]);
111             args.erase(args.begin());
112         } else {
113             return false;
114         }
115     }
116 #endif
117     return true;
118 }
119 #if is_ohos && !is_double_framework
OnHiLog(const std::vector<std::string> & args)120 static bool OnHiLog(const std::vector<std::string> &args)
121 {
122     DebugLogger::GetInstance()->EnableHiLog();
123     return true;
124 }
125 #endif
RegisterMainCommandDebug()126 void RegisterMainCommandDebug()
127 {
128     Option::RegisterMainOption("--nodebug", "disable debug log, usage format: --nodebug [command] [args]",
129                                OnNoDebug);
130     Option::RegisterMainOption("--debug", "show debug log, usage format: --debug [command] [args]",
131                                OnDebugLevel);
132     Option::RegisterMainOption("--verbose", "show debug log, usage format: --verbose [command] [args]",
133                                OnVerboseLevel);
134     Option::RegisterMainOption("--much", "show extremely much debug log, usage format: --much [command] [args]",
135                                OnMuchLevel);
136     Option::RegisterMainOption("--mixlog", "mix the log in output, usage format: --much [command] [args]",
137                                OnMixLogOutput);
138     Option::RegisterMainOption("--logpath",
139                                "log file name full path, usage format: --logpath [filepath] [command] [args]",
140                                OnLogPath);
141     std::string tagUsage = StringPrintf("%s\t%-20s\t%s\t%-20s\t%s",
142         "enable log level for HILOG_TAG, usage format: --logtag <tag>[:level][,<tag>[:level]] [command] [args]\n", " ",
143         "tag: Dump, Report, Record, Stat... level: D, V, M...\n", " ",
144         "example: hiperf --verbose --logtag Record:D [command] [args]");
145     Option::RegisterMainOption("--logtag", tagUsage.c_str(), OnLogTag);
146 #if is_ohos && !is_double_framework
147     Option::RegisterMainOption("--hilog", "use hilog not file to record log", OnHiLog);
148 #endif
149 }
150 } // namespace HiPerf
151 } // namespace Developtools
152 } // namespace OHOS
153