mirror of
https://gitee.com/openharmony/hiviewdfx_hiview
synced 2024-11-27 03:00:34 +00:00
添加analysis_faultlog测试二进制
Signed-off-by: zhouquan <zhouquan63@huawei.com>
This commit is contained in:
parent
fe1f0720f2
commit
7d0755df6b
1
BUILD.gn
1
BUILD.gn
@ -126,6 +126,7 @@ group("hiview_package") {
|
||||
"$hiview_plugin/performance:xperformance",
|
||||
"$hiview_plugin/plugin_build:adft",
|
||||
"$hiview_plugin/plugin_build:bdfr",
|
||||
"$hiview_root/utility/analysis_faultlog:analysis_faultlog",
|
||||
]
|
||||
|
||||
if (enable_hiview_usage_event_report_build) {
|
||||
|
40
utility/analysis_faultlog/BUILD.gn
Normal file
40
utility/analysis_faultlog/BUILD.gn
Normal file
@ -0,0 +1,40 @@
|
||||
# Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//base/hiviewdfx/hiview/hiview.gni")
|
||||
import("//build/ohos.gni")
|
||||
|
||||
ohos_executable("analysis_faultlog") {
|
||||
sanitize = {
|
||||
cfi = true
|
||||
cfi_cross_dso = true
|
||||
cfi_vcall_icall_only = true
|
||||
debug = false
|
||||
}
|
||||
|
||||
install_enable = false
|
||||
|
||||
sources = [ "analysis_faultlog.cpp" ]
|
||||
|
||||
configs = [ "$hiview_root/utility/smart_parser:smart_parser_config" ]
|
||||
|
||||
deps = [
|
||||
"$hiview_root/utility/common_utils:hiview_reliability_common_utils",
|
||||
"$hiview_root/utility/smart_parser:smart_parser",
|
||||
]
|
||||
|
||||
external_deps = [ "hilog:libhilog" ]
|
||||
|
||||
part_name = "hiview"
|
||||
subsystem_name = "hiviewdfx"
|
||||
}
|
101
utility/analysis_faultlog/analysis_faultlog.cpp
Normal file
101
utility/analysis_faultlog/analysis_faultlog.cpp
Normal file
@ -0,0 +1,101 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include "feature_analysis.h"
|
||||
#include "file_util.h"
|
||||
#include "hiview_logger.h"
|
||||
#include "rule.h"
|
||||
#include "smart_parser.h"
|
||||
#include "tbox.h"
|
||||
|
||||
DEFINE_LOG_TAG("SmartParser");
|
||||
|
||||
static const char* const SMART_PARSER_PATH = "/system/etc/hiview/";
|
||||
|
||||
static void PrintEventInfo(std::map<std::string, std::string> eventInfo, std::string msg)
|
||||
{
|
||||
HIVIEW_LOGI("%{public}s >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", msg.c_str());
|
||||
HIVIEW_LOGI("eventInfo size : %{public}s", std::to_string(eventInfo.size()).c_str());
|
||||
for (auto &[key, val] : eventInfo) {
|
||||
std::istringstream iss(val);
|
||||
std::string line;
|
||||
|
||||
while (std::getline(iss, line)) {
|
||||
HIVIEW_LOGI("[%{public}s] : %{public}s", key.c_str(), line.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static std::map<std::string, std::string> SmartParser(const std::string& eventPath, const std::string& eventType)
|
||||
{
|
||||
auto startTime = std::chrono::high_resolution_clock::now();
|
||||
auto eventInfos = OHOS::HiviewDFX::SmartParser::Analysis(eventPath, SMART_PARSER_PATH, eventType);
|
||||
auto endTime = std::chrono::high_resolution_clock::now();
|
||||
auto diffTime = std::chrono::duration_cast<std::chrono::milliseconds>(endTime - startTime).count();
|
||||
std::cout << "SmartParser::Analysis running time : " << diffTime << " ms" << std::endl;
|
||||
|
||||
PrintEventInfo(eventInfos, "SmartParser::Analysis result:");
|
||||
|
||||
return eventInfos;
|
||||
}
|
||||
|
||||
static void Tbox(std::map<std::string, std::string>& eventInfo, std::string& eventType)
|
||||
{
|
||||
auto startTime = std::chrono::high_resolution_clock::now();
|
||||
OHOS::HiviewDFX::Tbox::FilterTrace(eventInfo, eventType);
|
||||
auto endTime = std::chrono::high_resolution_clock::now();
|
||||
auto diffTime = std::chrono::duration_cast<std::chrono::milliseconds>(endTime - startTime).count();
|
||||
std::cout << "Tbox::FilterTrace running time : " << diffTime << " ms" << std::endl;
|
||||
|
||||
PrintEventInfo(eventInfo, "Tbox::FilterTrace result:");
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
std::string eventType;
|
||||
std::string logPath;
|
||||
for (int i = 1; i < argc; i++) {
|
||||
if (std::string(argv[i]) == "-t") {
|
||||
if (i + 1 < argc) {
|
||||
eventType = argv[i + 1];
|
||||
}
|
||||
} else if (std::string(argv[i]) == "-f") {
|
||||
if (i + 1 < argc) {
|
||||
logPath = argv[i + 1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (eventType.empty() || logPath.empty()) {
|
||||
std::cout << "Usage:" << std::endl;
|
||||
std::cout << "\t" << argv[0] << "-t eventType -f filePath" << std::endl;
|
||||
std::cout << "\teventType\t" <<
|
||||
"The event name must match the event name configured in the configuration file." << std::endl;
|
||||
std::cout << "\tfilePath\t" <<
|
||||
"The parsed file path must match the path matching rule configured in the configuration file." << std::endl;
|
||||
return -1;
|
||||
}
|
||||
std::cout << ">>>>> eventType : " << eventType << std::endl;
|
||||
std::cout << ">>>>> logPath : " << logPath << std::endl;
|
||||
std::cout << std::endl;
|
||||
|
||||
auto eventInfos = SmartParser(logPath, eventType);
|
||||
Tbox(eventInfos, eventType);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user