remove hookdecoder

Signed-off-by: zyxzyx <zhangyixin19@huawei.com>
This commit is contained in:
zyxzyx 2024-11-13 17:25:37 +08:00
parent 7733456455
commit 5b0f71838f
5 changed files with 0 additions and 248 deletions

View File

@ -28,8 +28,6 @@ group("hiprofiler_targets") {
"plugins/hiperf_plugin:hiperfplugin",
"plugins/hisysevent_plugin:hisyseventplugin",
"plugins/memory_plugin:memdataplugin",
"plugins/native_hook:hookDecoder",
"plugins/native_hook:malloctest",
"plugins/native_hook:malloctest_cpp",
"plugins/native_hook:nativetest_c",
"plugins/native_hook:nativetest_cpp",

View File

@ -126,8 +126,6 @@
<preparer>
<option name="shell" value="remount"/>
<option name="push" value="developtools/hiprofiler/libnativetest_so.z.so -> /data/local/tmp/" src="out"/>
<option name="push" value="developtools/hiprofiler/malloctest -> /data/local/tmp/" src="out"/>
<option name="push" value="developtools/hiprofiler/hookDecoder -> /data/local/tmp/" src="out"/>
</preparer>
</target>
<target name="processplugin_ut">

View File

@ -123,50 +123,6 @@ ohos_executable("nativetest_c") {
part_name = "${OHOS_PROFILER_PART_NAME}"
}
ohos_executable("malloctest") {
output_name = "malloctest"
sources = [ "test/malloctest.cpp" ]
ldflags = [ "-rdynamic" ]
install_enable = false
subsystem_name = "${OHOS_PROFILER_SUBSYS_NAME}"
part_name = "${OHOS_PROFILER_PART_NAME}"
}
ohos_executable("hookDecoder") {
output_name = "hookDecoder"
sources = [ "test/hook_decoder.cpp" ]
if (current_toolchain != host_toolchain) {
defines = [ "HAVE_HILOG" ]
external_deps = [
"abseil-cpp:absl_sync",
"bounds_checking_function:libsec_shared",
"grpc:grpc",
"grpc:grpcxx",
"hilog:libhilog",
"openssl:libcrypto_shared",
"protobuf:protobuf",
"protobuf:protobuf_lite",
]
}
cflags = [
"-Wno-error=inline-asm",
"-O3",
]
deps = [
"${OHOS_PROFILER_DIR}/device/services/profiler_service:profiler_service",
"${OHOS_PROFILER_DIR}/protos/services:plugin_service_proto",
"${OHOS_PROFILER_DIR}/protos/services:profiler_service_all_type_source",
"${OHOS_PROFILER_DIR}/protos/types/plugins/native_hook:native_hook_cpp",
"${OHOS_PROFILER_DIR}/protos/types/plugins/native_hook:native_hook_cpp_standard",
]
ldflags = [ "-rdynamic" ]
install_enable = false
subsystem_name = "${OHOS_PROFILER_SUBSYS_NAME}"
part_name = "${OHOS_PROFILER_PART_NAME}"
}
ohos_executable("nativetest_cpp") {
output_name = "nativetest_cpp"
sources = [ "test/hook_test.cpp" ]

View File

@ -1,97 +0,0 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2024. All rights reserved.
* 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 <sys/file.h>
#include <unistd.h>
#include "common_types.pb.h"
#include "trace_file_reader.h"
#include "trace_file_header.h"
#include "native_hook_result_standard.pb.h"
#include "native_hook_config_standard.pb.h"
#include "google/protobuf/text_format.h"
namespace {
using UsageHandle = std::function<void(void)>;
static std::map<std::string, std::string> params;
int ParseArgs(int argc, char** argv, UsageHandle usage)
{
params.clear();
for (int i = 1; i < argc;) {
std::string key = argv[i];
i++;
if (i >= argc) {
if (usage) usage();
break;
}
std::string val = argv[i];
i++;
params.insert(std::make_pair(key, val));
}
return params.size();
}
int GetStringArg(const char* name, std::string& val, const char* defaultVal)
{
val = params[std::string(name)];
if (val.empty()) {
val = defaultVal;
}
return val.size();
}
void Usage()
{
printf("usage: hookdecoder [-f filepath] \n");
}
} // namespace
int main(int argc, char* argv[])
{
std::string filePath;
int ret = ParseArgs(argc, argv, Usage);
if (ret == 0) {
std::cout << "parse parameters error!" << std::endl;
return 0;
}
GetStringArg("-f", filePath, "/data/local/tmp/hiprofiler_data.htrace");
auto reader = std::make_shared<TraceFileReader>();
if (!reader->Open(filePath)) {
std::cout << "open file :" << filePath << "failed!" << std::endl;
return 0;
}
long bytes = 0;
do {
ProfilerPluginData data{};
bytes = reader->Read(data);
if (data.data().size() <= 0) {
continue;
}
std::cout << "name=" << data.name() << ",status=" << data.status() << ",tv_sec=" << data.tv_sec()
<< ",tv_nsec=" << data.tv_nsec() << ",version=" << data.version() << std::endl;
std::string str;
ForStandard::BatchNativeHookData StandardStackData;
if (!StandardStackData.ParseFromArray(data.data().data(), data.data().size())) {
std::cout << "parse profiler plugin data failed!" << std::endl;
continue;
}
google::protobuf::TextFormat::PrintToString(StandardStackData, &str);
std::cout << str << std::endl;
} while (bytes > 0);
return 0;
}

View File

@ -1,103 +0,0 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2024. All rights reserved.
* 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 <iostream>
#include <thread>
#include <mutex>
#include <chrono>
#include <unistd.h>
#include <cstring>
#pragma clang optimize off
std::recursive_mutex mtx;
constexpr uint64_t S_TO_NS = 1000 * 1000 * 1000;
constexpr uint64_t SLEEP_TIME = 5;
constexpr uint64_t COUNT_INDEX = 3;
constexpr uint64_t SIZE_INDEX = 2;
constexpr int MAX_SIZE = 1024 * 1024 * 1024;
void AllocateMemory(int depth, int size)
{
if (size > MAX_SIZE || (size == 0)) {
return;
}
if (depth == 0) {
char* mem = new char[size];
if (mem == nullptr) {
return;
}
mem[0] = 'a';
delete[] mem;
return;
}
AllocateMemory(depth - 1, size);
}
void ThreadFunc(int depth, int count, int size)
{
for (int i = 0; i < count; ++i) {
AllocateMemory(depth, size);
}
}
int main(int argc, char* argv[])
{
int threadCount = 10;
int depth = 10;
int count = 10000;
int mallocSize = 1;
depth = atoi(argv[1]);
mallocSize = atoi(argv[SIZE_INDEX]);
count = atoi(argv[COUNT_INDEX]);
if (depth <= 0) {
std::cout << "invalid depth" << std::endl;
return 0;
}
if (count <= 0) {
std::cout << "invalid count" << std::endl;
return 0;
}
if (mallocSize < 1 || mallocSize >= MAX_SIZE) {
std::cout << "invalid size" << std::endl;
return 0;
}
std::cout << "starting memory allocation..." << std::endl;
sleep(SLEEP_TIME);
std::cout << "starting hook..." << std::endl;
void* ptr = malloc(1);
free(ptr);
sleep(SLEEP_TIME);
std::thread threads[threadCount];
std::cout << "Running..." << std::endl;
struct timespec start = {};
clock_gettime(CLOCK_REALTIME, &start);
for (int i = 0; i < threadCount; ++i) {
threads[i] = std::thread(ThreadFunc, depth, count, mallocSize);
}
for (int i = 0; i < threadCount; i++) {
threads[i].join();
}
struct timespec end = {};
clock_gettime(CLOCK_REALTIME, &end);
std::cout << "Total cost time: " << (end.tv_sec - start.tv_sec) * S_TO_NS + (end.tv_nsec - start.tv_nsec)
<< " ns" << std::endl;
sleep(SLEEP_TIME);
return 0;
}