mirror of
https://gitee.com/openharmony/developtools_profiler
synced 2024-11-23 06:50:12 +00:00
告警清理
Signed-off-by:wenlong12 <wenlong12@huawei.com> Signed-off-by: wenlong12 <wenlong12@huawei.com>
This commit is contained in:
parent
0a4c2dcb83
commit
68cc71c523
@ -22,7 +22,7 @@
|
||||
|
||||
namespace COMMON {
|
||||
bool IsProcessRunning(); // add file lock, only one process can run
|
||||
bool IsProcessExist(std::string& processName, int& pid); // Check if the process exists and get PID
|
||||
bool IsProcessExist(const std::string& processName, int& pid); // Check if the process exists and get PID
|
||||
int StartProcess(const std::string& processBin, std::vector<char*>& argv);
|
||||
int KillProcess(int pid);
|
||||
void PrintMallinfoLog(const std::string& mallInfoPrefix);
|
||||
|
@ -52,9 +52,10 @@ inline long getsystid()
|
||||
return GetCurrentThreadId();
|
||||
}
|
||||
#endif
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <ctime>
|
||||
#include <vector>
|
||||
#include <unistd.h>
|
||||
|
||||
static inline long GetTid(void)
|
||||
{
|
||||
|
@ -87,7 +87,7 @@ bool IsProcessRunning()
|
||||
return false;
|
||||
}
|
||||
|
||||
bool IsProcessExist(std::string& processName, int& pid)
|
||||
bool IsProcessExist(const std::string& processName, int& pid)
|
||||
{
|
||||
DIR* dir = opendir("/proc");
|
||||
if (dir == nullptr) {
|
||||
|
@ -69,13 +69,13 @@ protected:
|
||||
*/
|
||||
HWTEST_F(CommonTest, IsProcessExist, TestSize.Level1)
|
||||
{
|
||||
std::string procName = "hiprofiler_base_ut";
|
||||
const std::string procName = "hiprofiler_base_ut";
|
||||
int pid = 0;
|
||||
EXPECT_TRUE(COMMON::IsProcessExist(procName, pid));
|
||||
EXPECT_NE(pid, 0);
|
||||
procName = "ls";
|
||||
const std::string noProcName = "ls";
|
||||
pid = 0;
|
||||
EXPECT_FALSE(COMMON::IsProcessExist(procName, pid));
|
||||
EXPECT_FALSE(COMMON::IsProcessExist(noProcName, pid));
|
||||
EXPECT_EQ(pid, 0);
|
||||
}
|
||||
|
||||
|
@ -45,9 +45,9 @@ constexpr int KEEP_SESSION_TIMEOUT_MS = 5 * 1000;
|
||||
constexpr int KEEP_SESSION_SLEEP_SECOND = 3;
|
||||
constexpr int DEFAULT_SESSION_TIME_S = 10;
|
||||
const std::string DEFAULT_OUTPUT_FILE = "/data/local/tmp/hiprofiler_data.htrace";
|
||||
std::string HIPROFILERD_NAME("hiprofilerd");
|
||||
std::string HIPROFILER_PLUGINS_NAME("hiprofiler_plugins");
|
||||
std::string NATIVE_DAEMON_NAME("native_daemon");
|
||||
const std::string HIPROFILERD_NAME("hiprofilerd");
|
||||
const std::string HIPROFILER_PLUGINS_NAME("hiprofiler_plugins");
|
||||
const std::string NATIVE_DAEMON_NAME("native_daemon");
|
||||
|
||||
uint32_t g_sampleDuration = 0;
|
||||
int g_hiprofilerdPid = -1;
|
||||
|
@ -67,9 +67,9 @@ public:
|
||||
}
|
||||
_exit(1);
|
||||
} else if (DEFAULT_HIPROFILERD_PATH == name) {
|
||||
g_hiprofilerdPid = processNum;
|
||||
hiprofilerdPid = processNum;
|
||||
} else if (DEFAULT_HIPROFILER_PLUGINS_PATH == name) {
|
||||
g_hiprofilerPluginsPid = processNum;
|
||||
hiprofilerPluginsPid = processNum;
|
||||
}
|
||||
}
|
||||
|
||||
@ -272,8 +272,8 @@ public:
|
||||
}
|
||||
}
|
||||
private:
|
||||
int g_hiprofilerdPid = -1;
|
||||
int g_hiprofilerPluginsPid = -1;
|
||||
int hiprofilerdPid = -1;
|
||||
int hiprofilerPluginsPid = -1;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -304,7 +304,7 @@ HWTEST_F(HiprofilerCmdTest, DFX_DFR_Hiprofiler_0110, Function | MediumTest | Lev
|
||||
EXPECT_TRUE(RunCommand(cmd, content));
|
||||
destStr = "OK";
|
||||
EXPECT_EQ(strncmp(content.c_str(), destStr.c_str(), strlen(destStr.c_str())), 0);
|
||||
StopProcessStub(g_hiprofilerdPid);
|
||||
StopProcessStub(hiprofilerdPid);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -350,8 +350,8 @@ HWTEST_F(HiprofilerCmdTest, DFX_DFR_Hiprofiler_0120, Function | MediumTest | Lev
|
||||
// 删除资源文件和生成的trace文件
|
||||
cmd = "rm " + configFile + " " + outFile;
|
||||
system(cmd.c_str());
|
||||
StopProcessStub(g_hiprofilerPluginsPid);
|
||||
StopProcessStub(g_hiprofilerdPid);
|
||||
StopProcessStub(hiprofilerPluginsPid);
|
||||
StopProcessStub(hiprofilerdPid);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -380,7 +380,7 @@ HWTEST_F(HiprofilerCmdTest, DFX_DFR_Hiprofiler_0130, Function | MediumTest | Lev
|
||||
// 删除资源文件和生成的trace文件
|
||||
cmd = "rm " + FTRACE_PLUGIN_PATH + " " + outFile;
|
||||
system(cmd.c_str());
|
||||
StopProcessStub(g_hiprofilerPluginsPid);
|
||||
StopProcessStub(g_hiprofilerdPid);
|
||||
StopProcessStub(hiprofilerPluginsPid);
|
||||
StopProcessStub(hiprofilerdPid);
|
||||
}
|
||||
}
|
||||
|
@ -939,7 +939,7 @@ HWTEST_F(CpuDataPluginTest, TestPid, TestSize.Level1)
|
||||
EXPECT_TRUE(PluginCpuinfoStub(plugin2, cpuData2, static_cast<int>(pid2), false, false));
|
||||
EXPECT_LT(cpuData1.cpu_usage_info().process_cpu_time_ms(), cpuData2.cpu_usage_info().process_cpu_time_ms());
|
||||
|
||||
while (waitpid(-1, NULL, WNOHANG) == 0) {
|
||||
while (waitpid(-1, nullptr, WNOHANG) == 0) {
|
||||
kill(pid1, SIGKILL);
|
||||
kill(pid2, SIGKILL);
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ void IoTest()
|
||||
|
||||
// 一次写100K数据,写10次
|
||||
int count = 0;
|
||||
FILE* writeFp = fopen(writeFile.c_str(),"w");
|
||||
FILE* writeFp = fopen(writeFile.c_str(), "w");
|
||||
if (writeFp == nullptr) {
|
||||
printf("fopen() error");
|
||||
return;
|
||||
|
@ -235,7 +235,7 @@ HWTEST_F(DiskioDataPluginTest, TestSystemFile, TestSize.Level1)
|
||||
EXPECT_TRUE(PluginDiskioInfoStub(plugin2, diskioData2, false));
|
||||
EXPECT_LE(diskioData1.wr_sectors_kb() + WRITE_KB, diskioData2.wr_sectors_kb());
|
||||
|
||||
while (waitpid(-1, NULL, WNOHANG) == 0) {
|
||||
while (waitpid(-1, nullptr, WNOHANG) == 0) {
|
||||
kill(pid, SIGKILL);
|
||||
}
|
||||
|
||||
|
@ -61,7 +61,7 @@ bool PrintkFormatsParser::Parse(const std::string& printkFormats)
|
||||
auto pos = line.find(seperator);
|
||||
if (pos != std::string::npos) {
|
||||
std::string addrStr = StringUtils::Strip(line.substr(0, pos));
|
||||
addr = static_cast<uint64_t>(strtoull(addrStr.c_str(), NULL, HEX_BASE));
|
||||
addr = static_cast<uint64_t>(strtoull(addrStr.c_str(), nullptr, HEX_BASE));
|
||||
|
||||
symbol = StringUtils::Strip(line.substr(pos + 1));
|
||||
if (symbol.back() == '"') {
|
||||
|
@ -211,7 +211,7 @@ HWTEST_F(PrintkFormatsParserTest, PrintkFormatsParserNormalRand, TestSize.Level1
|
||||
std::string line = BuildPrintkLine(addr, symbol);
|
||||
EXPECT_TRUE(PrintkFormatsParser::GetInstance().Parse(line));
|
||||
|
||||
std::string symbolGot = PrintkFormatsParser::GetInstance().GetSymbol(strtoull(addr.c_str(), NULL, HEX_BASE));
|
||||
std::string symbolGot = PrintkFormatsParser::GetInstance().GetSymbol(strtoull(addr.c_str(), nullptr, HEX_BASE));
|
||||
EXPECT_EQ(symbolGot, symbol);
|
||||
}
|
||||
}
|
||||
|
@ -293,7 +293,7 @@ class FtraceEventCodeGenerator(object):
|
||||
targets = list(self.allowed_events & self.available_events)
|
||||
Common.logger.info("target events: %d", len(targets))
|
||||
targets.sort()
|
||||
self.target_event_list = [self.category_to_info[c] for c in targets]
|
||||
self.target_event_list = [self.category_to_info.get(c) for c in targets]
|
||||
Common.logger.info("target_event_list: %d", len(self.target_event_list))
|
||||
|
||||
def _parse_ftrace_formats(self):
|
||||
|
@ -205,7 +205,7 @@ FILE* HidumpPlugin::CustomPopen(const char* command, const char* type)
|
||||
}
|
||||
|
||||
setpgid(pid, pid);
|
||||
execl(BIN_COMMAND.c_str(), BIN_COMMAND.c_str(), "-c", command, NULL);
|
||||
execl(BIN_COMMAND.c_str(), BIN_COMMAND.c_str(), "-c", command, nullptr);
|
||||
exit(0);
|
||||
} else {
|
||||
if (!strncmp(type, "r", strlen(type))) {
|
||||
|
@ -26,7 +26,7 @@
|
||||
|
||||
namespace {
|
||||
constexpr uint32_t MAX_BUFFER_SIZE = 4 * 1024 * 1024;
|
||||
std::mutex taskMutex;
|
||||
std::mutex g_taskMutex;
|
||||
constexpr int32_t RET_OK = 0;
|
||||
constexpr int32_t RET_ERR = -1;
|
||||
bool g_releaseResources = false;
|
||||
@ -50,7 +50,7 @@ void RunCmd(std::string& cmd)
|
||||
|
||||
static int32_t HiebpfSessionStart(const uint8_t* configData, uint32_t configSize)
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(taskMutex);
|
||||
std::lock_guard<std::mutex> guard(g_taskMutex);
|
||||
CHECK_TRUE(!g_releaseResources, 0, "%s: hiebpf released resources, return", __func__);
|
||||
HILOG_DEBUG(LOG_CORE, "enter");
|
||||
if (configData == nullptr || configSize < 0) {
|
||||
@ -82,7 +82,7 @@ static int32_t HiebpfSessionStart(const uint8_t* configData, uint32_t configSize
|
||||
|
||||
static int32_t HiebpfSessionStop()
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(taskMutex);
|
||||
std::lock_guard<std::mutex> guard(g_taskMutex);
|
||||
CHECK_TRUE(!g_releaseResources, 0, "%s: hiebpf released resources, return", __func__);
|
||||
HILOG_DEBUG(LOG_CORE, "enter");
|
||||
std::string stop = "hiebpf --stop true";
|
||||
|
@ -474,9 +474,9 @@ int32_t main(int32_t argc, char* argv[])
|
||||
std::ios::sync_with_stdio(false);
|
||||
std::cin.tie(nullptr);
|
||||
struct option long_options[] = {
|
||||
{"input", required_argument, NULL, 'i'},
|
||||
{"out", required_argument, NULL, 'o'},
|
||||
{"help", no_argument, NULL, 'h'},
|
||||
{"input", required_argument, nullptr, 'i'},
|
||||
{"out", required_argument, nullptr, 'o'},
|
||||
{"help", no_argument, nullptr, 'h'},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
int32_t opt;
|
||||
|
@ -21,8 +21,8 @@
|
||||
#include "logging.h"
|
||||
#include "plugin_module_api.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <atomic>
|
||||
#include <cstdio>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
@ -13,8 +13,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef _BUFFER_SPLITTER_H_
|
||||
#define _BUFFER_SPLITTER_H_
|
||||
#ifndef BUFFER_SPLITTER_H
|
||||
#define BUFFER_SPLITTER_H
|
||||
|
||||
#include <string>
|
||||
|
||||
|
@ -606,13 +606,13 @@ HWTEST_F(MemoryDataPluginTest, TestProcessTreeRunTime, TestSize.Level1)
|
||||
std::vector<uint8_t> dataBuffer(plugin->resultBufferSizeHint);
|
||||
EXPECT_EQ(plugin->callbacks->onPluginSessionStart(configData.data(), configData.size()), 0);
|
||||
clock_t clockstart = clock();
|
||||
gettimeofday(&start, NULL);
|
||||
gettimeofday(&start, nullptr);
|
||||
while (testCount--) {
|
||||
int ret = plugin->callbacks->onPluginReportResult(dataBuffer.data(), dataBuffer.size());
|
||||
ASSERT_GT(ret, 0);
|
||||
OutputData(dataBuffer.data(), (uint32_t)ret);
|
||||
}
|
||||
gettimeofday(&end, NULL);
|
||||
gettimeofday(&end, nullptr);
|
||||
clock_t clockend = clock();
|
||||
int timeuse = US_PER_S * (end.tv_sec - start.tv_sec) + end.tv_usec - start.tv_usec;
|
||||
HILOG_INFO(LOG_CORE, "clock time=%.3fs, timeofday=%.3fs", (double)(clockend - clockstart) / CLOCKS_PER_SEC,
|
||||
@ -713,7 +713,7 @@ HWTEST_F(MemoryDataPluginTest, TestPid, TestSize.Level1)
|
||||
EXPECT_TRUE(PluginStub(plugin, config, memoryData));
|
||||
EXPECT_GT(memoryData.processesinfo(0).vm_size_kb(), memoryData.processesinfo(1).vm_size_kb());
|
||||
|
||||
while (waitpid(-1, NULL, WNOHANG) == 0) {
|
||||
while (waitpid(-1, nullptr, WNOHANG) == 0) {
|
||||
kill(pid1, SIGKILL);
|
||||
kill(pid2, SIGKILL);
|
||||
}
|
||||
|
@ -17,12 +17,12 @@
|
||||
#define HIPERF_DEBUG_H
|
||||
|
||||
#include <chrono>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <sstream>
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
#include <unistd.h>
|
||||
|
||||
|
@ -20,7 +20,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
long get_thread_id(void);
|
||||
long GetThreadId(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -16,7 +16,7 @@
|
||||
#ifndef HOOK_COMMON_H
|
||||
#define HOOK_COMMON_H
|
||||
|
||||
#if HAVE_LIBUNWIND
|
||||
#if defined(HAVE_LIBUNWIND) && HAVE_LIBUNWIND
|
||||
// for libunwind.h empty struct has size 0 in c, size 1 in c++
|
||||
#define UNW_EMPTY_STRUCT uint8_t unused;
|
||||
#include <libunwind.h>
|
||||
|
@ -42,6 +42,8 @@ recorded in the corresponding mmap.
|
||||
*/
|
||||
constexpr static int32_t MIN_STACK_DEPTH = 6;
|
||||
constexpr static size_t FILTER_STACK_DEPTH = 2;
|
||||
static constexpr int SHIFT_2 = 2;
|
||||
static constexpr int SHIFT_6 = 6;
|
||||
|
||||
class VirtualRuntime {
|
||||
public:
|
||||
@ -149,8 +151,8 @@ private:
|
||||
std::hash<uint64_t> hasher;
|
||||
size_t seed = 0;
|
||||
// 6 and 2 is the number of displacements
|
||||
seed ^= hasher(key.ip) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
|
||||
seed ^= hasher(key.filePathId) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
|
||||
seed ^= hasher(key.ip) + 0x9e3779b9 + (seed << SHIFT_6) + (seed >> SHIFT_2);
|
||||
seed ^= hasher(key.filePathId) + 0x9e3779b9 + (seed << SHIFT_6) + (seed >> SHIFT_2);
|
||||
return seed;
|
||||
}
|
||||
};
|
||||
|
@ -22,7 +22,7 @@
|
||||
|
||||
#include "get_thread_id.h"
|
||||
|
||||
long get_thread_id(void)
|
||||
long GetThreadId(void)
|
||||
{
|
||||
#if !is_mingw
|
||||
return syscall(SYS_gettid);
|
||||
|
@ -73,7 +73,7 @@ bool HookManager::CheckProcess()
|
||||
void HookManager::CheckProcessName()
|
||||
{
|
||||
int pidValue = -1;
|
||||
std::string processName = hookConfig_.process_name();
|
||||
const std::string processName = hookConfig_.process_name();
|
||||
bool isExist = COMMON::IsProcessExist(processName, pidValue);
|
||||
if (hookConfig_.startup_mode() || !isExist) {
|
||||
HILOG_INFO(LOG_CORE, "Wait process %s start or restart, set param", hookConfig_.process_name().c_str());
|
||||
|
@ -85,13 +85,13 @@ void ReadShareMemory(uint64_t duration, const std::string& performance_filename)
|
||||
CHECK_NOTNULL(g_shareMemoryBlock, NO_RETVAL, "smb is null!");
|
||||
uint64_t value = g_eventNotifier->Take();
|
||||
|
||||
static bool first_flag = true;
|
||||
static bool end_flag = false;
|
||||
static bool firstFlag = true;
|
||||
static bool endFlag = false;
|
||||
static uint64_t times = 0;
|
||||
|
||||
struct timespec first_time;
|
||||
struct timespec begin_time;
|
||||
struct timespec end_time;
|
||||
struct timespec firstTime;
|
||||
struct timespec beginTime;
|
||||
struct timespec endTime;
|
||||
std::vector<u64> u64regs;
|
||||
std::vector<OHOS::HiviewDFX::CallFrame> callFrames;
|
||||
uint64_t total_time = 0;
|
||||
@ -152,11 +152,11 @@ void ReadShareMemory(uint64_t duration, const std::string& performance_filename)
|
||||
#endif
|
||||
}
|
||||
|
||||
if (!end_flag && duration != 0) {
|
||||
clock_gettime(CLOCK_REALTIME, &begin_time);
|
||||
if (first_flag) {
|
||||
first_flag = false;
|
||||
first_time = begin_time;
|
||||
if (!endFlag && duration != 0) {
|
||||
clock_gettime(CLOCK_REALTIME, &beginTime);
|
||||
if (firstFlag) {
|
||||
firstFlag = false;
|
||||
firstTime = beginTime;
|
||||
}
|
||||
}
|
||||
|
||||
@ -168,20 +168,20 @@ void ReadShareMemory(uint64_t duration, const std::string& performance_filename)
|
||||
HILOG_ERROR(LOG_CORE, "unwind fatal error");
|
||||
return false;
|
||||
}
|
||||
if (!end_flag && duration != 0) {
|
||||
clock_gettime(CLOCK_REALTIME, &end_time);
|
||||
total_time += (end_time.tv_sec - begin_time.tv_sec) * 1000000000LLU +
|
||||
(end_time.tv_nsec - begin_time.tv_nsec);
|
||||
if (!endFlag && duration != 0) {
|
||||
clock_gettime(CLOCK_REALTIME, &endTime);
|
||||
total_time += (endTime.tv_sec - beginTime.tv_sec) * 1000000000LLU +
|
||||
(endTime.tv_nsec - beginTime.tv_nsec);
|
||||
++times;
|
||||
if (end_time.tv_sec - first_time.tv_sec >= static_cast<long>(duration)) {
|
||||
end_flag = true;
|
||||
if (endTime.tv_sec - firstTime.tv_sec >= static_cast<long>(duration)) {
|
||||
endFlag = true;
|
||||
FILE *fp = fopen(performance_filename.c_str(), "a");
|
||||
if (fp) {
|
||||
time_t now = time(NULL);
|
||||
struct tm now_tm;
|
||||
localtime_r(&now, &now_tm);
|
||||
fprintf(fp, "Current time: %04d-%02d-%02d %02d:%02d:%02d\n", now_tm.tm_year + 1900,
|
||||
now_tm.tm_mon + 1, now_tm.tm_mday, now_tm.tm_hour, now_tm.tm_min, now_tm.tm_sec);
|
||||
time_t now = time(nullptr);
|
||||
struct tm nowTime;
|
||||
localtime_r(&now, &nowTime);
|
||||
fprintf(fp, "Current time: %04d-%02d-%02d %02d:%02d:%02d\n", nowTime.tm_year + 1900,
|
||||
nowTime.tm_mon + 1, nowTime.tm_mday, nowTime.tm_hour, nowTime.tm_min, nowTime.tm_sec);
|
||||
fprintf(fp, "Total durations: %" PRIu64 " nanoseconds\n", total_time);
|
||||
fprintf(fp, "Total times: %" PRIu64 "\n", times);
|
||||
fprintf(fp, "Average unwinding stack time: %.2f nanoseconds\n\n",
|
||||
|
@ -138,7 +138,8 @@ void GetHookedProceInfo(HookData& hookData)
|
||||
printf("Please send signal 36 to target process %d\n", hookData.pid);
|
||||
} else if (!hookData.processName.empty()) {
|
||||
int pidValue = -1;
|
||||
bool isExist = COMMON::IsProcessExist(hookData.processName, pidValue);
|
||||
const std::string processName = hookData.processName;
|
||||
bool isExist = COMMON::IsProcessExist(processName, pidValue);
|
||||
if (!isExist) {
|
||||
printf("Please start process %s\n", hookData.processName.c_str());
|
||||
} else {
|
||||
|
@ -360,7 +360,7 @@ protected:
|
||||
}
|
||||
|
||||
private:
|
||||
bool EhFrameHDRValid_ {false};
|
||||
bool ehFrameHDRValid_ {false};
|
||||
uint64_t ehFrameHDRElfOffset_ {0};
|
||||
uint64_t ehFrameHDRFdeCount_ {0};
|
||||
uint64_t ehFrameHDRFdeTableItemSize_ {0};
|
||||
@ -439,13 +439,13 @@ private:
|
||||
bool GetHDRSectionInfo(uint64_t &ehFrameHdrElfOffset, uint64_t &fdeTableElfOffset,
|
||||
uint64_t &fdeTableSize) const override
|
||||
{
|
||||
if (EhFrameHDRValid_) {
|
||||
if (ehFrameHDRValid_) {
|
||||
ehFrameHdrElfOffset = ehFrameHDRElfOffset_;
|
||||
fdeTableElfOffset = ehFrameHDRFdeTableElfOffset_;
|
||||
fdeTableSize = ehFrameHDRFdeCount_ * ehFrameHDRFdeTableItemSize_;
|
||||
return true;
|
||||
} else {
|
||||
HLOGW("!EhFrameHDRValid_");
|
||||
HLOGW("!ehFrameHDRValid_");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -484,7 +484,7 @@ private:
|
||||
HLOGD("eh_frame_hdr version is invalid");
|
||||
return false;
|
||||
}
|
||||
EhFrameHDRValid_ = true;
|
||||
ehFrameHDRValid_ = true;
|
||||
ehFrameHDRElfOffset_ = shdrOffset;
|
||||
ehFrameHDRFdeCount_ = dwFdeCount.GetAppliedValue();
|
||||
ehFrameHDRFdeTableElfOffset_ = dwTable.GetData() - buffer + shdrOffset;
|
||||
|
@ -508,7 +508,7 @@ std::string GetLastErrorString()
|
||||
LPVOID lpMsgBuf;
|
||||
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
|
||||
FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
NULL, GetLastError(), 0, (LPTSTR)&lpMsgBuf, 0, NULL);
|
||||
nullptr, GetLastError(), 0, (LPTSTR)&lpMsgBuf, 0, nullptr);
|
||||
std::string error((LPTSTR)lpMsgBuf);
|
||||
LocalFree(lpMsgBuf);
|
||||
return error;
|
||||
|
@ -109,7 +109,7 @@ HWTEST_F(CallStackTest, UnwindCallStack, TestSize.Level1)
|
||||
// fix the name
|
||||
symbolsFile->filePath_ = TEST_DWARF_MMAP.front().fileName;
|
||||
std::shared_ptr<VirtualRuntime> runtime = std::make_shared<VirtualRuntime>();
|
||||
VirtualThread thread(getpid(), get_thread_id(), symbolsFiles, runtime.get(), false);
|
||||
VirtualThread thread(getpid(), GetThreadId(), symbolsFiles, runtime.get(), false);
|
||||
MakeMaps(thread);
|
||||
std::vector<CallFrame> callFrames;
|
||||
CallStack callStack;
|
||||
|
@ -752,7 +752,7 @@ HWTEST_F(SymbolsFileTest, ReadRoMemory, TestSize.Level1)
|
||||
ASSERT_EQ(symbolsFile->ReadRoMemory(addr++, &readRoByte, 1), 0U);
|
||||
}
|
||||
|
||||
struct sectionInfo {
|
||||
struct SectionInfo {
|
||||
const std::string name;
|
||||
uint64_t addr;
|
||||
uint64_t size;
|
||||
@ -809,7 +809,7 @@ HWTEST_F(SymbolsFileTest, GetSectionInfo, TestSize.Level1)
|
||||
000000000000012c 0000000000000000 0 0 1
|
||||
*/
|
||||
#ifdef __arm__
|
||||
const std::vector<sectionInfo> sectionCheckList = {
|
||||
const std::vector<SectionInfo> sectionCheckList = {
|
||||
{".note.gnu.build-id", 0x000001c8, 0x000024, 0x0001c8},
|
||||
{".text", 0x00001320, 0x000818, 0x001320},
|
||||
{".eh_frame_hdr", 0x00002034, 0x0000dc, 0x002034},
|
||||
@ -819,7 +819,7 @@ HWTEST_F(SymbolsFileTest, GetSectionInfo, TestSize.Level1)
|
||||
{".shstrtab", 0x00000000, 0x00012a, 0x004381},
|
||||
};
|
||||
#else
|
||||
const std::vector<sectionInfo> sectionCheckList = {
|
||||
const std::vector<SectionInfo> sectionCheckList = {
|
||||
{".note.gnu.build-id", 0x0000000000000358, 0x0000000000000024, 0x00000358},
|
||||
{".text", 0x00000000000022f0, 0x00000000000007b5, 0x000022f0},
|
||||
{".eh_frame_hdr", 0x0000000000003034, 0x00000000000000bc, 0x00003034},
|
||||
@ -829,7 +829,7 @@ HWTEST_F(SymbolsFileTest, GetSectionInfo, TestSize.Level1)
|
||||
{".shstrtab", 0x00000000, 0x000000000000012c, 0x000055eb},
|
||||
};
|
||||
#endif
|
||||
for (sectionInfo info : sectionCheckList) {
|
||||
for (SectionInfo info : sectionCheckList) {
|
||||
uint64_t addr;
|
||||
uint64_t size;
|
||||
uint64_t offset;
|
||||
|
@ -114,12 +114,12 @@ HWTEST_F(VirtualRuntimeTest, GetSymbolsFiles, TestSize.Level1)
|
||||
}
|
||||
|
||||
namespace {
|
||||
constexpr const pid_t testTid = 1;
|
||||
constexpr const uint64_t testUserVaddr = 0x1000;
|
||||
constexpr const uint64_t testKernelVaddr = testUserVaddr / 4;
|
||||
constexpr const uint64_t testKernelLen = testUserVaddr / 2;
|
||||
constexpr const uint64_t testUserMapBegin = 0x2000;
|
||||
constexpr const uint64_t testUserMapLen = 0x4000;
|
||||
constexpr const pid_t TEST_TID = 1;
|
||||
constexpr const uint64_t TEST_USET_VADDR = 0x1000;
|
||||
constexpr const uint64_t TEST_KERNEL_VADDR = TEST_USET_VADDR / 4;
|
||||
constexpr const uint64_t TEST_KERNEL_LEN = TEST_USET_VADDR / 2;
|
||||
constexpr const uint64_t TEST_USET_MAP_BEGIN = 0x2000;
|
||||
constexpr const uint64_t TEST_USET_MAP_LEN = 0x4000;
|
||||
} // namespace
|
||||
|
||||
void VirtualRuntimeTest::PrepareKernelSymbol()
|
||||
@ -127,15 +127,15 @@ void VirtualRuntimeTest::PrepareKernelSymbol()
|
||||
std::string kernelSymbol = "kernel_symbol";
|
||||
auto kernel = SymbolsFile::CreateSymbolsFile(SYMBOL_KERNEL_FILE);
|
||||
kernel->filePath_ = kernelSymbol;
|
||||
kernel->symbols_.emplace_back(testKernelVaddr, 1u, "first_kernel_func", kernel->filePath_);
|
||||
kernel->symbols_.emplace_back(testKernelVaddr + 1u, 1u, "second_kernel_func",
|
||||
kernel->symbols_.emplace_back(TEST_KERNEL_VADDR, 1u, "first_kernel_func", kernel->filePath_);
|
||||
kernel->symbols_.emplace_back(TEST_KERNEL_VADDR + 1u, 1u, "second_kernel_func",
|
||||
kernel->filePath_);
|
||||
runtime_->symbolsFiles_[kernel->filePath_] = std::move(kernel);
|
||||
|
||||
auto &kernelMap = runtime_->kernelSpaceMemMaps_.emplace_back();
|
||||
kernelMap.name_ = kernelSymbol;
|
||||
kernelMap.begin_ = 0;
|
||||
kernelMap.end_ = 0 + testKernelLen;
|
||||
kernelMap.end_ = 0 + TEST_KERNEL_LEN;
|
||||
kernelMap.pageoffset_ = 0;
|
||||
}
|
||||
|
||||
@ -144,14 +144,14 @@ void VirtualRuntimeTest::PrepareUserSymbol()
|
||||
std::string userSymbol = "user_symbol";
|
||||
auto user = SymbolsFile::CreateSymbolsFile(SYMBOL_ELF_FILE);
|
||||
user->filePath_ = userSymbol;
|
||||
user->symbols_.emplace_back(testUserVaddr, 1u, "first_user_func", user->filePath_);
|
||||
user->symbols_.emplace_back(testUserVaddr + 1u, 1u, "second_user_func", user->filePath_);
|
||||
user->textExecVaddrFileOffset_ = testUserVaddr;
|
||||
user->textExecVaddr_ = testUserVaddr;
|
||||
user->symbols_.emplace_back(TEST_KERNEL_VADDR, 1u, "first_user_func", user->filePath_);
|
||||
user->symbols_.emplace_back(TEST_KERNEL_VADDR + 1u, 1u, "second_user_func", user->filePath_);
|
||||
user->textExecVaddrFileOffset_ = TEST_KERNEL_VADDR;
|
||||
user->textExecVaddr_ = TEST_KERNEL_VADDR;
|
||||
runtime_->symbolsFiles_[user->filePath_] = std::move(user);
|
||||
|
||||
VirtualThread &thread = runtime_->GetThread(testTid, testTid);
|
||||
thread.CreateMapItem(userSymbol, testUserMapBegin, testUserMapLen, 0);
|
||||
VirtualThread &thread = runtime_->GetThread(TEST_TID, TEST_TID);
|
||||
thread.CreateMapItem(userSymbol, TEST_USET_MAP_BEGIN, TEST_USET_MAP_LEN, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -168,14 +168,14 @@ HWTEST_F(VirtualRuntimeTest, GetSymbol, TestSize.Level1)
|
||||
ScopeDebugLevel tempLogLevel(LEVEL_MUCH);
|
||||
CallFrame callFrame(0);
|
||||
|
||||
symbol = runtime_->GetSymbol(callFrame, testTid, testTid);
|
||||
symbol = runtime_->GetSymbol(callFrame, TEST_TID, TEST_TID);
|
||||
EXPECT_EQ(symbol.isValid(), false);
|
||||
|
||||
callFrame.ip_ = testUserVaddr + testUserMapBegin;
|
||||
symbol = runtime_->GetSymbol(callFrame, testTid, testTid);
|
||||
callFrame.ip_ = TEST_KERNEL_VADDR + TEST_USET_MAP_BEGIN;
|
||||
symbol = runtime_->GetSymbol(callFrame, TEST_TID, TEST_TID);
|
||||
// in user
|
||||
EXPECT_EQ(symbol.isValid(), true);
|
||||
EXPECT_EQ(symbol.funcVaddr_, testUserVaddr);
|
||||
EXPECT_EQ(symbol.funcVaddr_, TEST_KERNEL_VADDR);
|
||||
EXPECT_STREQ(symbol.name_.data(), "first_user_func");
|
||||
}
|
||||
|
||||
|
@ -218,7 +218,7 @@ HWTEST_F(VirtualThreadTest, ParseMap, TestSize.Level1)
|
||||
|
||||
std::shared_ptr<VirtualRuntime> runtime = std::make_shared<VirtualRuntime>();
|
||||
std::shared_ptr<VirtualThread> thread = std::make_shared<VirtualThread>(getpid(),
|
||||
get_thread_id(), files, runtime.get());
|
||||
GetThreadId(), files, runtime.get());
|
||||
|
||||
dl_iterate_phdr(PhdrCallBack, static_cast<void *>(thread.get()));
|
||||
|
||||
@ -238,7 +238,7 @@ HWTEST_F(VirtualThreadTest, CreateMapItem, TestSize.Level1)
|
||||
{
|
||||
std::unordered_map<std::string, std::unique_ptr<SymbolsFile>> files;
|
||||
std::shared_ptr<VirtualRuntime> runtime = std::make_shared<VirtualRuntime>();
|
||||
std::shared_ptr<VirtualThread> thread = std::make_shared<VirtualThread>(getpid(), get_thread_id(),
|
||||
std::shared_ptr<VirtualThread> thread = std::make_shared<VirtualThread>(getpid(), GetThreadId(),
|
||||
files, runtime.get(), false);
|
||||
const std::vector<MemMapItem> &maps = thread->GetMaps();
|
||||
|
||||
@ -277,10 +277,10 @@ HWTEST_F(VirtualThreadTest, InheritMaps, TestSize.Level1)
|
||||
|
||||
std::shared_ptr<VirtualRuntime> runtime = std::make_shared<VirtualRuntime>();
|
||||
std::shared_ptr<VirtualThread> thread = std::make_shared<VirtualThread>(getpid(),
|
||||
get_thread_id(), files, runtime.get());
|
||||
GetThreadId(), files, runtime.get());
|
||||
|
||||
std::shared_ptr<VirtualThread> thread2 = std::make_shared<VirtualThread>(getpid(),
|
||||
get_thread_id() + 1, files, runtime.get());
|
||||
GetThreadId() + 1, files, runtime.get());
|
||||
|
||||
const std::vector<MemMapItem> &maps = thread->GetMaps();
|
||||
const std::vector<MemMapItem> &maps2 = thread2->GetMaps();
|
||||
@ -309,7 +309,7 @@ HWTEST_F(VirtualThreadTest, FindMapByAddr, TestSize.Level1)
|
||||
{
|
||||
std::unordered_map<std::string, std::unique_ptr<SymbolsFile>> files;
|
||||
std::shared_ptr<VirtualRuntime> runtime = std::make_shared<VirtualRuntime>();
|
||||
std::shared_ptr<VirtualThread> thread = std::make_shared<VirtualThread>(getpid(), get_thread_id(),
|
||||
std::shared_ptr<VirtualThread> thread = std::make_shared<VirtualThread>(getpid(), GetThreadId(),
|
||||
files, runtime.get(), false);
|
||||
|
||||
thread->CreateMapItem("0.so", 1000u, 2000u, 3000u);
|
||||
@ -350,7 +350,7 @@ HWTEST_F(VirtualThreadTest, FindMapByFileInfo, TestSize.Level1)
|
||||
{
|
||||
std::unordered_map<std::string, std::unique_ptr<SymbolsFile>> files;
|
||||
std::shared_ptr<VirtualRuntime> runtime = std::make_shared<VirtualRuntime>();
|
||||
std::shared_ptr<VirtualThread> thread = std::make_shared<VirtualThread>(getpid(), get_thread_id(),
|
||||
std::shared_ptr<VirtualThread> thread = std::make_shared<VirtualThread>(getpid(), GetThreadId(),
|
||||
files, runtime.get(), false);
|
||||
|
||||
thread->CreateMapItem("0.so", 1000u, 2000u, 3000u);
|
||||
@ -397,7 +397,7 @@ HWTEST_F(VirtualThreadTest, FindSymbolsFileByMap, TestSize.Level1)
|
||||
files["3.elf"] = std::make_unique<SymbolsFile>(SYMBOL_UNKNOW_FILE, "3.elf");
|
||||
|
||||
std::shared_ptr<VirtualRuntime> runtime = std::make_shared<VirtualRuntime>();
|
||||
std::shared_ptr<VirtualThread> thread = std::make_shared<VirtualThread>(getpid(), get_thread_id(),
|
||||
std::shared_ptr<VirtualThread> thread = std::make_shared<VirtualThread>(getpid(), GetThreadId(),
|
||||
files, runtime.get(), false);
|
||||
|
||||
MemMapItem inMap;
|
||||
@ -430,7 +430,7 @@ HWTEST_F(VirtualThreadTest, ReadRoMemory, TestSize.Level1)
|
||||
{
|
||||
std::unordered_map<std::string, std::unique_ptr<SymbolsFile>> symbolsFiles;
|
||||
std::shared_ptr<VirtualRuntime> runtime = std::make_shared<VirtualRuntime>();
|
||||
std::shared_ptr<VirtualThread> thread = std::make_shared<VirtualThread>(getpid(), get_thread_id(),
|
||||
std::shared_ptr<VirtualThread> thread = std::make_shared<VirtualThread>(getpid(), GetThreadId(),
|
||||
symbolsFiles, runtime.get(), false);
|
||||
std::unique_ptr<FILE, decltype(&fclose)> fp(fopen(TEST_FILE_ELF_FULL_PATH.c_str(), "rb"),
|
||||
fclose);
|
||||
|
@ -16,7 +16,7 @@
|
||||
#ifndef __OHOS_MALLOC_HOOK_CLIENT_H__
|
||||
#define __OHOS_MALLOC_HOOK_CLIENT_H__
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <cstdlib>
|
||||
#include "musl_malloc_dispatch.h"
|
||||
|
||||
#define EXPORT_API __attribute__((visibility("default")))
|
||||
|
@ -116,7 +116,7 @@ pid_t GetRealPid(void)
|
||||
pid_t inline __attribute__((always_inline)) GetCurThreadId()
|
||||
{
|
||||
if (pthread_getspecific(g_hookTid) == nullptr) {
|
||||
pthread_setspecific(g_hookTid, reinterpret_cast<void *>(get_thread_id()));
|
||||
pthread_setspecific(g_hookTid, reinterpret_cast<void *>(GetThreadId()));
|
||||
}
|
||||
return reinterpret_cast<long>((pthread_getspecific(g_hookTid)));
|
||||
}
|
||||
|
@ -131,7 +131,6 @@ static void GetAnUnlimitedLine(FILE* fp, std::string& buf)
|
||||
void GetMainThreadRuntimeStackRange()
|
||||
{
|
||||
std::string line;
|
||||
int buf_size = 0;
|
||||
FILE* fp = fopen("/proc/self/maps", "re");
|
||||
if (fp == nullptr) {
|
||||
return;
|
||||
|
@ -18,11 +18,12 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <sys/types.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#ifdef HOOK_ENABLE
|
||||
#include "memory_trace.h"
|
||||
|
@ -15,13 +15,13 @@
|
||||
#include <chrono>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <dlfcn.h>
|
||||
#include <new>
|
||||
#include <pthread.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <unistd.h>
|
||||
#include <thread>
|
||||
#include <dlfcn.h>
|
||||
#include <pthread.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/prctl.h>
|
||||
#include <sys/syscall.h>
|
||||
|
||||
#pragma clang optimize off
|
||||
|
||||
|
@ -38,7 +38,7 @@ const int WAIT_FLUSH = 2;
|
||||
|
||||
const std::string DEFAULT_NATIVE_DAEMON_PATH("/system/bin/native_daemon");
|
||||
std::string DEFAULT_PATH("/data/local/tmp/");
|
||||
const int g_shareMemorySize = 1000 * 4096;
|
||||
const int SHARE_MEMORY_SIZE = 1000 * 4096;
|
||||
const int BUFFER_SIZE = 100 * 1024;
|
||||
const int DEFAULT_DEPTH = 32;
|
||||
const int CALLOC_DEPTH = 13;
|
||||
@ -64,7 +64,7 @@ public:
|
||||
if (processNum == 0) {
|
||||
// start running native_daemon -o -s -p
|
||||
execl(DEFAULT_NATIVE_DAEMON_PATH.c_str(), DEFAULT_NATIVE_DAEMON_PATH.c_str(), "-o", outFile.c_str(),
|
||||
"-s", std::to_string(g_shareMemorySize).c_str(), "-p", std::to_string(pid).c_str(), nullptr);
|
||||
"-s", std::to_string(SHARE_MEMORY_SIZE).c_str(), "-p", std::to_string(pid).c_str(), nullptr);
|
||||
_exit(1);
|
||||
} else {
|
||||
daemonPid_ = processNum;
|
||||
@ -77,7 +77,7 @@ public:
|
||||
if (processNum == 0) {
|
||||
// start running native_daemon -o -s -p -d
|
||||
execl(DEFAULT_NATIVE_DAEMON_PATH.c_str(), DEFAULT_NATIVE_DAEMON_PATH.c_str(), "-o", outFile.c_str(),
|
||||
"-s", std::to_string(g_shareMemorySize).c_str(), "-p", std::to_string(pid).c_str(),
|
||||
"-s", std::to_string(SHARE_MEMORY_SIZE).c_str(), "-p", std::to_string(pid).c_str(),
|
||||
"-d", std::to_string(setHookDepth).c_str(), nullptr);
|
||||
_exit(1);
|
||||
} else {
|
||||
|
@ -41,7 +41,7 @@ public:
|
||||
*/
|
||||
HWTEST_F(NativeHookTest, NormalMallocHookTest, TestSize.Level1)
|
||||
{
|
||||
EXPECT_TRUE(ohos_malloc_hook_initialize(&__libc_malloc_default_dispatch, NULL, NULL));
|
||||
EXPECT_TRUE(ohos_malloc_hook_initialize(&__libc_malloc_default_dispatch, nullptr, nullptr));
|
||||
EXPECT_TRUE(ohos_malloc_hook_on_start());
|
||||
|
||||
void* mallocBlack = ohos_malloc_hook_malloc(g_size);
|
||||
@ -59,7 +59,7 @@ HWTEST_F(NativeHookTest, NormalMallocHookTest, TestSize.Level1)
|
||||
*/
|
||||
HWTEST_F(NativeHookTest, NormalHookReallocTest, TestSize.Level1)
|
||||
{
|
||||
EXPECT_TRUE(ohos_malloc_hook_initialize(&__libc_malloc_default_dispatch, NULL, NULL));
|
||||
EXPECT_TRUE(ohos_malloc_hook_initialize(&__libc_malloc_default_dispatch, nullptr, nullptr));
|
||||
EXPECT_TRUE(ohos_malloc_hook_on_start());
|
||||
|
||||
void* mallocBlack = ohos_malloc_hook_malloc(g_size);
|
||||
@ -79,7 +79,7 @@ HWTEST_F(NativeHookTest, NormalHookReallocTest, TestSize.Level1)
|
||||
*/
|
||||
HWTEST_F(NativeHookTest, NormalHookCallocTest, TestSize.Level1)
|
||||
{
|
||||
EXPECT_TRUE(ohos_malloc_hook_initialize(&__libc_malloc_default_dispatch, NULL, NULL));
|
||||
EXPECT_TRUE(ohos_malloc_hook_initialize(&__libc_malloc_default_dispatch, nullptr, nullptr));
|
||||
EXPECT_TRUE(ohos_malloc_hook_on_start());
|
||||
|
||||
void* callocBlack = ohos_malloc_hook_calloc(g_size, g_resize);
|
||||
@ -97,7 +97,7 @@ HWTEST_F(NativeHookTest, NormalHookCallocTest, TestSize.Level1)
|
||||
*/
|
||||
HWTEST_F(NativeHookTest, NormalHookVallocTest, TestSize.Level1)
|
||||
{
|
||||
EXPECT_TRUE(ohos_malloc_hook_initialize(&__libc_malloc_default_dispatch, NULL, NULL));
|
||||
EXPECT_TRUE(ohos_malloc_hook_initialize(&__libc_malloc_default_dispatch, nullptr, nullptr));
|
||||
EXPECT_TRUE(ohos_malloc_hook_on_start());
|
||||
|
||||
void* vallocBlack = ohos_malloc_hook_valloc(g_size);
|
||||
@ -115,7 +115,7 @@ HWTEST_F(NativeHookTest, NormalHookVallocTest, TestSize.Level1)
|
||||
*/
|
||||
HWTEST_F(NativeHookTest, NormalHookMemalignTest, TestSize.Level1)
|
||||
{
|
||||
EXPECT_TRUE(ohos_malloc_hook_initialize(&__libc_malloc_default_dispatch, NULL, NULL));
|
||||
EXPECT_TRUE(ohos_malloc_hook_initialize(&__libc_malloc_default_dispatch, nullptr, nullptr));
|
||||
EXPECT_TRUE(ohos_malloc_hook_on_start());
|
||||
|
||||
void* memalignBlack = ohos_malloc_hook_memalign(g_size, g_resize);
|
||||
@ -134,7 +134,7 @@ HWTEST_F(NativeHookTest, NormalHookMemalignTest, TestSize.Level1)
|
||||
*/
|
||||
HWTEST_F(NativeHookTest, NormalTest, TestSize.Level1)
|
||||
{
|
||||
EXPECT_TRUE(ohos_malloc_hook_initialize(&__libc_malloc_default_dispatch, NULL, NULL));
|
||||
EXPECT_TRUE(ohos_malloc_hook_initialize(&__libc_malloc_default_dispatch, nullptr, nullptr));
|
||||
EXPECT_TRUE(ohos_malloc_hook_on_start());
|
||||
|
||||
void* mallocBlack = ohos_malloc_hook_malloc(g_size);
|
||||
@ -164,7 +164,7 @@ HWTEST_F(NativeHookTest, NormalTest, TestSize.Level1)
|
||||
*/
|
||||
HWTEST_F(NativeHookTest, NormalOtherTest, TestSize.Level1)
|
||||
{
|
||||
EXPECT_TRUE(ohos_malloc_hook_initialize(&__libc_malloc_default_dispatch, NULL, NULL));
|
||||
EXPECT_TRUE(ohos_malloc_hook_initialize(&__libc_malloc_default_dispatch, nullptr, nullptr));
|
||||
EXPECT_TRUE(ohos_malloc_hook_on_start());
|
||||
|
||||
ohos_malloc_hook_finalize();
|
||||
@ -179,7 +179,7 @@ HWTEST_F(NativeHookTest, NormalOtherTest, TestSize.Level1)
|
||||
*/
|
||||
HWTEST_F(NativeHookTest, FailureTest, TestSize.Level1)
|
||||
{
|
||||
EXPECT_TRUE(ohos_malloc_hook_initialize(nullptr, NULL, NULL));
|
||||
EXPECT_TRUE(ohos_malloc_hook_initialize(nullptr, nullptr, nullptr));
|
||||
EXPECT_TRUE(ohos_malloc_hook_on_start());
|
||||
EXPECT_TRUE(ohos_malloc_hook_on_end());
|
||||
}
|
||||
|
@ -17,21 +17,20 @@
|
||||
#define NETWORK_PLUGIN_H
|
||||
|
||||
#include <algorithm>
|
||||
#include <ctime>
|
||||
#include <fstream>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <utility>
|
||||
#include <dirent.h>
|
||||
#include <fcntl.h>
|
||||
#include <inttypes.h>
|
||||
#include <iomanip>
|
||||
#include <string>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <unordered_map>
|
||||
#include <utility>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
#include <time.h>
|
||||
|
||||
#include "logging.h"
|
||||
#include "network_plugin_config.pb.h"
|
||||
|
@ -63,13 +63,13 @@ const std::string BASE_SOURCE_STRING = R"(
|
||||
#include "unix_socket_server.h"
|
||||
#include <unistd.h>
|
||||
|
||||
namespace{
|
||||
const uint32_t WAIT_FOR_EVER=24*60*60*1000;
|
||||
namespace {
|
||||
const uint32_t WAIT_FOR_EVER = 24 * 60 * 60 * 1000;
|
||||
}
|
||||
|
||||
#SERVICE_CLASS_NAME#::#SERVICE_CLASS_NAME#()
|
||||
{
|
||||
serviceName_="#SERVICE_NAME#";
|
||||
serviceName_ = "#SERVICE_NAME#";
|
||||
}
|
||||
|
||||
#RESPONSE_IMPLEMENT#
|
||||
@ -85,18 +85,18 @@ bool #SERVICE_CLASS_NAME#::ProtocolProc(SocketContext &context, uint32_t pnum, c
|
||||
|
||||
#CLIENT_CLASS_NAME#::#CLIENT_CLASS_NAME#()
|
||||
{
|
||||
unixSocketClient_=nullptr;
|
||||
serviceName_="#SERVICE_NAME#";
|
||||
unixSocketClient_ = nullptr;
|
||||
serviceName_ = "#SERVICE_NAME#";
|
||||
}
|
||||
bool #CLIENT_CLASS_NAME#::Connect(const std::string addrname)
|
||||
{
|
||||
if (unixSocketClient_!=nullptr) {
|
||||
if (unixSocketClient_ != nullptr) {
|
||||
return false;
|
||||
}
|
||||
unixSocketClient_ = std::make_shared<UnixSocketClient>();
|
||||
if (!unixSocketClient_->Connect(addrname, *this)) {
|
||||
printf("Socket Connect failed\n");
|
||||
unixSocketClient_=nullptr;
|
||||
unixSocketClient_ = nullptr;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -110,8 +110,8 @@ bool #CLIENT_CLASS_NAME#::ProtocolProc(SocketContext &context, uint32_t pnum, co
|
||||
switch (pnum) {
|
||||
#CLIENT_PROTOCOL_PROC#
|
||||
}
|
||||
if (waitingFor==pnum) {
|
||||
waitingFor=-1;
|
||||
if (waitingFor == pnum) {
|
||||
waitingFor = -1;
|
||||
mWait_.unlock();
|
||||
}
|
||||
return false;
|
||||
@ -308,7 +308,7 @@ namespace {
|
||||
const std::string SERVICE_CALL_IMPL_STRING = R"(
|
||||
bool #SERVER_CLASS_NAME#::#METHOD_NAME#(SocketContext &context,
|
||||
#PACKAGE_NAME##REQUEST_NAME# &request,
|
||||
#PACKAGE_NAME##RESPONSE_NAME# &response){
|
||||
#PACKAGE_NAME##RESPONSE_NAME# &response) {
|
||||
return false;
|
||||
}
|
||||
)";
|
||||
|
@ -198,7 +198,7 @@ bool SocketContext::SendHookConfig(const uint8_t* config, size_t len)
|
||||
phead.protoType = PROTOCOL_TYPE_PROTOBUF;
|
||||
phead.protoSize = len + sizeof(struct ProtocolHead);
|
||||
send(socketHandle_, reinterpret_cast<int8_t*>(&phead), sizeof(struct ProtocolHead), 0);
|
||||
send(socketHandle_, config , len, 0);
|
||||
send(socketHandle_, config, len, 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -119,9 +119,9 @@ protected:
|
||||
}
|
||||
_exit(1);
|
||||
} else if (DEFAULT_HIPROFILERD_PATH == name) {
|
||||
g_hiprofilerdPid = processNum;
|
||||
hiprofilerdPid = processNum;
|
||||
} else if (DEFAULT_HIPROFILER_PLUGINS_PATH == name) {
|
||||
g_hiprofilerPluginsPid = processNum;
|
||||
hiprofilerPluginsPid = processNum;
|
||||
}
|
||||
}
|
||||
|
||||
@ -155,7 +155,7 @@ protected:
|
||||
mc.set_report_sysmem_vmem_info(true);
|
||||
mc.add_sys_vmeminfo_counters(SysVMeminfoType::VMEMINFO_NR_FREE_PAGES);
|
||||
mc.add_sys_vmeminfo_counters(SysVMeminfoType::VMEMINFO_NR_ALLOC_BATCH);
|
||||
mc.add_pid(g_idlePid);
|
||||
mc.add_pid(idlePid);
|
||||
if (isFirstConfig) {
|
||||
mc.add_pid(requstMemoryPid);
|
||||
}
|
||||
@ -409,7 +409,7 @@ protected:
|
||||
|
||||
cpuPlugin->callbacks->onPluginSessionStop();
|
||||
} else {
|
||||
cpuActivePid= processNum;
|
||||
cpuActivePid = processNum;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -423,7 +423,7 @@ protected:
|
||||
sleep(1);
|
||||
}
|
||||
} else {
|
||||
g_idlePid = processNum;
|
||||
idlePid = processNum;
|
||||
}
|
||||
}
|
||||
|
||||
@ -504,9 +504,9 @@ protected:
|
||||
private:
|
||||
std::unique_ptr<IProfilerService::Stub> profilerStub_;
|
||||
std::vector<std::string> pluginVec_;
|
||||
int g_hiprofilerdPid = -1;
|
||||
int g_hiprofilerPluginsPid = -1;
|
||||
pid_t g_idlePid = -1;
|
||||
int hiprofilerdPid = -1;
|
||||
int hiprofilerPluginsPid = -1;
|
||||
pid_t idlePid = -1;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -679,7 +679,7 @@ HWTEST_F(ProfilerServicePerformanceTest, DFX_DFR_Hiprofiler_0010, Function | Med
|
||||
|
||||
// 创建不同的memory config
|
||||
uint32_t sessionId2;
|
||||
EXPECT_TRUE(CreatePluginSession(sessionId2, g_idlePid, false));
|
||||
EXPECT_TRUE(CreatePluginSession(sessionId2, idlePid, false));
|
||||
EXPECT_TRUE(KeepPluginSession(ROUND_COUNT, sessionId2));
|
||||
|
||||
// 开启每隔4s发一次心跳的线程,确保seesionid不会失效
|
||||
@ -740,9 +740,9 @@ HWTEST_F(ProfilerServicePerformanceTest, DFX_DFR_Hiprofiler_0010, Function | Med
|
||||
sendHeart2 = false;
|
||||
keepSessionThread2.join();
|
||||
|
||||
StopProcessStub(g_hiprofilerPluginsPid);
|
||||
StopProcessStub(g_hiprofilerdPid);
|
||||
StopProcessStub(g_idlePid);
|
||||
StopProcessStub(hiprofilerPluginsPid);
|
||||
StopProcessStub(hiprofilerdPid);
|
||||
StopProcessStub(idlePid);
|
||||
StopProcessStub(requestMemoryPid);
|
||||
|
||||
pluginVec_.clear();
|
||||
@ -775,7 +775,7 @@ HWTEST_F(ProfilerServicePerformanceTest, DFX_DFR_Hiprofiler_0020, Function | Med
|
||||
|
||||
timer.Reset();
|
||||
uint32_t sessionId1;
|
||||
EXPECT_TRUE(CreatePluginSession(sessionId1, g_idlePid));
|
||||
EXPECT_TRUE(CreatePluginSession(sessionId1, idlePid));
|
||||
timeCost = timer.ElapsedUs();
|
||||
printf("CreateSession cost %ldus.\n", timeCost);
|
||||
EXPECT_LE(timeCost, TIMEOUT_US);
|
||||
@ -978,10 +978,10 @@ HWTEST_F(ProfilerServicePerformanceTest, DFX_DFR_Hiprofiler_0020, Function | Med
|
||||
}
|
||||
}
|
||||
|
||||
StopProcessStub(g_hiprofilerPluginsPid);
|
||||
StopProcessStub(g_hiprofilerdPid);
|
||||
StopProcessStub(hiprofilerPluginsPid);
|
||||
StopProcessStub(hiprofilerdPid);
|
||||
StopProcessStub(cpuActivePid);
|
||||
StopProcessStub(g_idlePid);
|
||||
StopProcessStub(idlePid);
|
||||
|
||||
pluginVec_.clear();
|
||||
}
|
||||
@ -1126,8 +1126,8 @@ HWTEST_F(ProfilerServicePerformanceTest, DFX_DFR_Hiprofiler_0030, Function | Med
|
||||
EXPECT_GT(diskioDataVec2[i].rd_sectors_kb(), 0);
|
||||
}
|
||||
|
||||
StopProcessStub(g_hiprofilerPluginsPid);
|
||||
StopProcessStub(g_hiprofilerdPid);
|
||||
StopProcessStub(hiprofilerPluginsPid);
|
||||
StopProcessStub(hiprofilerdPid);
|
||||
StopProcessStub(diskioPid);
|
||||
|
||||
pluginVec_.clear();
|
||||
@ -1226,9 +1226,9 @@ HWTEST_F(ProfilerServicePerformanceTest, DFX_DFR_Hiprofiler_0040, Function | Med
|
||||
EXPECT_GT(static_cast<int>(processData.processesinfo().size()), 0);
|
||||
for (int j = 0; j < processData.processesinfo().size(); j++) {
|
||||
ProcessInfo info = processData.processesinfo(j);
|
||||
if (info.pid() == g_hiprofilerdPid) {
|
||||
if (info.pid() == hiprofilerdPid) {
|
||||
hiprofilerdPidCount++;
|
||||
} else if (info.pid() == g_hiprofilerPluginsPid) {
|
||||
} else if (info.pid() == hiprofilerPluginsPid) {
|
||||
hiprofilerPluginsPidCount++;
|
||||
}
|
||||
}
|
||||
@ -1261,8 +1261,8 @@ HWTEST_F(ProfilerServicePerformanceTest, DFX_DFR_Hiprofiler_0040, Function | Med
|
||||
sendHeart = false;
|
||||
keepSessionThread.join();
|
||||
|
||||
StopProcessStub(g_hiprofilerPluginsPid);
|
||||
StopProcessStub(g_hiprofilerdPid);
|
||||
StopProcessStub(hiprofilerPluginsPid);
|
||||
StopProcessStub(hiprofilerdPid);
|
||||
|
||||
pluginVec_.clear();
|
||||
}
|
||||
@ -1404,8 +1404,8 @@ HWTEST_F(ProfilerServicePerformanceTest, DFX_DFR_Hiprofiler_0050, Function | Med
|
||||
sendHeart2 = false;
|
||||
keepSessionThread2.join();
|
||||
|
||||
StopProcessStub(g_hiprofilerPluginsPid);
|
||||
StopProcessStub(g_hiprofilerdPid);
|
||||
StopProcessStub(hiprofilerPluginsPid);
|
||||
StopProcessStub(hiprofilerdPid);
|
||||
|
||||
pluginVec_.clear();
|
||||
}
|
||||
@ -1512,8 +1512,8 @@ HWTEST_F(ProfilerServicePerformanceTest, DFX_DFR_Hiprofiler_0060, Function | Med
|
||||
sendHeart = false;
|
||||
keepSessionThread.join();
|
||||
|
||||
StopProcessStub(g_hiprofilerPluginsPid);
|
||||
StopProcessStub(g_hiprofilerdPid);
|
||||
StopProcessStub(hiprofilerPluginsPid);
|
||||
StopProcessStub(hiprofilerdPid);
|
||||
|
||||
pluginVec_.clear();
|
||||
}
|
||||
@ -1668,8 +1668,8 @@ HWTEST_F(ProfilerServicePerformanceTest, DFX_DFR_Hiprofiler_0070, Function | Med
|
||||
sendHeart = false;
|
||||
keepSessionThread1.join();
|
||||
|
||||
StopProcessStub(g_hiprofilerPluginsPid);
|
||||
StopProcessStub(g_hiprofilerdPid);
|
||||
StopProcessStub(hiprofilerPluginsPid);
|
||||
StopProcessStub(hiprofilerdPid);
|
||||
|
||||
pluginVec_.clear();
|
||||
}
|
||||
|
@ -15,15 +15,15 @@
|
||||
|
||||
#include "hidebug_base.h"
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include <errno.h>
|
||||
#include <inttypes.h>
|
||||
#include <limits.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
#include <dlfcn.h>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include "securec.h"
|
||||
|
||||
|
@ -170,7 +170,7 @@ static std::string GetFileNameParam(napi_env env, napi_callback_info info)
|
||||
return DEFAULT_FILENAME;
|
||||
}
|
||||
size_t bufLen = 0;
|
||||
napi_status status = napi_get_value_string_utf8(env, argv[0], NULL, 0, &bufLen);
|
||||
napi_status status = napi_get_value_string_utf8(env, argv[0], nullptr, 0, &bufLen);
|
||||
if (status != napi_ok) {
|
||||
HiLog::Error(LABEL, "Get input filename param length failed.");
|
||||
return DEFAULT_FILENAME;
|
||||
@ -202,7 +202,7 @@ static bool GetFileNameParamThrowErrorVersion(napi_env env, napi_callback_info i
|
||||
return false;
|
||||
}
|
||||
size_t bufLen = 0;
|
||||
napi_status status = napi_get_value_string_utf8(env, argv[0], NULL, 0, &bufLen);
|
||||
napi_status status = napi_get_value_string_utf8(env, argv[0], nullptr, 0, &bufLen);
|
||||
if (status != napi_ok) {
|
||||
HiLog::Error(LABEL, "Get input filename param length failed.");
|
||||
return false;
|
||||
|
@ -16,14 +16,15 @@
|
||||
#ifndef HIEBPF_COMMAND_H
|
||||
#define HIEBPF_COMMAND_H
|
||||
|
||||
#include <csignal>
|
||||
#include <fstream>
|
||||
#include <queue>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <signal.h>
|
||||
#include <queue>
|
||||
#include <fstream>
|
||||
|
||||
#include "bpf_controller.h"
|
||||
#include "maps_info.h"
|
||||
#include "elf_symbol_info.h"
|
||||
#include "maps_info.h"
|
||||
#include "ring_buffer.h"
|
||||
#include "hiebpf_common.h"
|
||||
class Command {
|
||||
|
@ -248,7 +248,7 @@ static int GetNextFlag(
|
||||
if (rm and flags_.count(flagName) != 0) {
|
||||
// remove parsed argument and its value
|
||||
ClearCString((*argv)[argIndex - 1]);
|
||||
ClearCString((*argv)[argIndex - 2]);
|
||||
ClearCString((*argv)[argIndex - 2]); // 2: point of args
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -726,7 +726,7 @@ int ParseFlags(int *argc, char ***argv, bool rm = true)
|
||||
std::string flagName {};
|
||||
std::string flagValue {};
|
||||
int argIndex {1};
|
||||
if (((*argc) % 2) == 0) {
|
||||
if (((*argc) % 2) == 0) { // 2: double
|
||||
std::cout << "CommandLineFlags ERROE: incorrect number of arguments" << std::endl;
|
||||
PrintArgFormat();
|
||||
return -1;
|
||||
|
@ -15,6 +15,9 @@
|
||||
|
||||
/* This line is generated to truncate the original file */
|
||||
/************************** fstrace BPF progs BEGIN *****************************/
|
||||
#ifndef FSTRACE_PROGS_H
|
||||
#define FSTRACE_PROGS_H
|
||||
|
||||
SEC("kprobe/do_sys_openat2")
|
||||
int BPF_KPROBE(do_sys_openat2_entry, int dfd, const char __user* filename, struct open_how* how)
|
||||
{
|
||||
@ -484,3 +487,4 @@ int BPF_KRETPROBE(__close_fd_exit, int64_t retval)
|
||||
return emit_event(ctx, retval, FSTRACE);
|
||||
}
|
||||
/*************************** fstrace BPF progs END ******************************/
|
||||
#endif // FSTRACE_PROGS_H
|
||||
|
@ -16,22 +16,22 @@
|
||||
#ifndef _HHLOG_H
|
||||
#define _HHLOG_H
|
||||
|
||||
#include <atomic>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <ctime>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <strstream>
|
||||
#include <thread>
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <atomic>
|
||||
#include <ctime>
|
||||
#include <cstring>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdarg.h>
|
||||
#include <sys/time.h>
|
||||
#include <securec.h>
|
||||
#include <stdarg.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include "ringbuffer.h"
|
||||
|
||||
|
@ -15,14 +15,14 @@
|
||||
|
||||
#ifndef HIEBPF_DATA_FILE_H
|
||||
#define HIEBPF_DATA_FILE_H
|
||||
#include <sys/mman.h>
|
||||
#include <cerrno>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <mutex>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/mman.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "type_headers.h"
|
||||
#include "ringbuffer.h"
|
||||
|
@ -661,122 +661,122 @@ int BPFController::HandleEvent(void *ctx, void *data, size_t dataSize)
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int DumpOpenat2Args(const struct fstrace_cmplt_event_t &cmplt_event)
|
||||
static int DumpOpenat2Args(const struct fstrace_cmplt_event_t &cmpltEvent)
|
||||
{
|
||||
std::cout << "\nArgs:";
|
||||
std::cout << "\n dfd = " << cmplt_event.start_event.openat2_args.dfd;
|
||||
std::cout << "\n filename = " << cmplt_event.start_event.openat2_args.filename;
|
||||
std::cout << "\n how = " << cmplt_event.start_event.openat2_args.how;
|
||||
std::cout << "\n dfd = " << cmpltEvent.start_event.openat2_args.dfd;
|
||||
std::cout << "\n filename = " << cmpltEvent.start_event.openat2_args.filename;
|
||||
std::cout << "\n how = " << cmpltEvent.start_event.openat2_args.how;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int DumpReadvArgs(const struct fstrace_cmplt_event_t &cmplt_event)
|
||||
static int DumpReadvArgs(const struct fstrace_cmplt_event_t &cmpltEvent)
|
||||
{
|
||||
std::cout << "\nArgs:";
|
||||
std::cout << "\n fd = " << cmplt_event.start_event.readv_args.fd;
|
||||
std::cout << "\n vec = " << cmplt_event.start_event.readv_args.vec;
|
||||
std::cout << "\n vlen = " << cmplt_event.start_event.readv_args.vlen;
|
||||
std::cout << "\n flags = " << cmplt_event.start_event.readv_args.flags;
|
||||
std::cout << "\n fd = " << cmpltEvent.start_event.readv_args.fd;
|
||||
std::cout << "\n vec = " << cmpltEvent.start_event.readv_args.vec;
|
||||
std::cout << "\n vlen = " << cmpltEvent.start_event.readv_args.vlen;
|
||||
std::cout << "\n flags = " << cmpltEvent.start_event.readv_args.flags;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int DumpPreadvArgs(const struct fstrace_cmplt_event_t &cmplt_event)
|
||||
static int DumpPreadvArgs(const struct fstrace_cmplt_event_t &cmpltEvent)
|
||||
{
|
||||
std::cout << "\nArgs:";
|
||||
std::cout << "\n fd = " << cmplt_event.start_event.preadv_args.fd;
|
||||
std::cout << "\n vec = " << cmplt_event.start_event.preadv_args.vec;
|
||||
std::cout << "\n vlen = " << cmplt_event.start_event.preadv_args.vlen;
|
||||
std::cout << "\n pos = " << cmplt_event.start_event.preadv_args.pos;
|
||||
std::cout << "\n flags = " << cmplt_event.start_event.preadv_args.flags;
|
||||
std::cout << "\n fd = " << cmpltEvent.start_event.preadv_args.fd;
|
||||
std::cout << "\n vec = " << cmpltEvent.start_event.preadv_args.vec;
|
||||
std::cout << "\n vlen = " << cmpltEvent.start_event.preadv_args.vlen;
|
||||
std::cout << "\n pos = " << cmpltEvent.start_event.preadv_args.pos;
|
||||
std::cout << "\n flags = " << cmpltEvent.start_event.preadv_args.flags;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int DumpReadArgs(const struct fstrace_cmplt_event_t &cmplt_event)
|
||||
static int DumpReadArgs(const struct fstrace_cmplt_event_t &cmpltEvent)
|
||||
{
|
||||
std::cout << "\nArgs:";
|
||||
std::cout << "\n fd = " << cmplt_event.start_event.read_args.fd;
|
||||
std::cout << "\n buf = " << cmplt_event.start_event.read_args.buf;
|
||||
std::cout << "\n count = " << cmplt_event.start_event.read_args.count;
|
||||
std::cout << "\n fd = " << cmpltEvent.start_event.read_args.fd;
|
||||
std::cout << "\n buf = " << cmpltEvent.start_event.read_args.buf;
|
||||
std::cout << "\n count = " << cmpltEvent.start_event.read_args.count;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int DumpPread64Args(const struct fstrace_cmplt_event_t &cmplt_event)
|
||||
static int DumpPread64Args(const struct fstrace_cmplt_event_t &cmpltEvent)
|
||||
{
|
||||
std::cout << "\nArgs:";
|
||||
std::cout << "\n fd = " << cmplt_event.start_event.pread64_args.fd;
|
||||
std::cout << "\n buf = " << cmplt_event.start_event.pread64_args.buf;
|
||||
std::cout << "\n count = " << cmplt_event.start_event.pread64_args.count;
|
||||
std::cout << "\n pos = " << cmplt_event.start_event.pread64_args.pos;
|
||||
std::cout << "\n fd = " << cmpltEvent.start_event.pread64_args.fd;
|
||||
std::cout << "\n buf = " << cmpltEvent.start_event.pread64_args.buf;
|
||||
std::cout << "\n count = " << cmpltEvent.start_event.pread64_args.count;
|
||||
std::cout << "\n pos = " << cmpltEvent.start_event.pread64_args.pos;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int DumpWritevArgs(const struct fstrace_cmplt_event_t &cmplt_event)
|
||||
static int DumpWritevArgs(const struct fstrace_cmplt_event_t &cmpltEvent)
|
||||
{
|
||||
std::cout << "\nArgs:";
|
||||
std::cout << "\n fd = " << cmplt_event.start_event.writev_args.fd;
|
||||
std::cout << "\n vec = " << cmplt_event.start_event.writev_args.vec;
|
||||
std::cout << "\n vlen = " << cmplt_event.start_event.writev_args.vlen;
|
||||
std::cout << "\n flags = " << cmplt_event.start_event.writev_args.flags;
|
||||
std::cout << "\n fd = " << cmpltEvent.start_event.writev_args.fd;
|
||||
std::cout << "\n vec = " << cmpltEvent.start_event.writev_args.vec;
|
||||
std::cout << "\n vlen = " << cmpltEvent.start_event.writev_args.vlen;
|
||||
std::cout << "\n flags = " << cmpltEvent.start_event.writev_args.flags;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int DumpPwritevArgs(const struct fstrace_cmplt_event_t &cmplt_event)
|
||||
static int DumpPwritevArgs(const struct fstrace_cmplt_event_t &cmpltEvent)
|
||||
{
|
||||
std::cout << "\nArgs:";
|
||||
std::cout << "\n fd = " << cmplt_event.start_event.pwritev_args.fd;
|
||||
std::cout << "\n vec = " << cmplt_event.start_event.pwritev_args.vec;
|
||||
std::cout << "\n vlen = " << cmplt_event.start_event.pwritev_args.vlen;
|
||||
std::cout << "\n pos = " << cmplt_event.start_event.pwritev_args.pos;
|
||||
std::cout << "\n flags = " << cmplt_event.start_event.pwritev_args.flags;
|
||||
std::cout << "\n fd = " << cmpltEvent.start_event.pwritev_args.fd;
|
||||
std::cout << "\n vec = " << cmpltEvent.start_event.pwritev_args.vec;
|
||||
std::cout << "\n vlen = " << cmpltEvent.start_event.pwritev_args.vlen;
|
||||
std::cout << "\n pos = " << cmpltEvent.start_event.pwritev_args.pos;
|
||||
std::cout << "\n flags = " << cmpltEvent.start_event.pwritev_args.flags;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int DumpWriteArgs(const struct fstrace_cmplt_event_t &cmplt_event)
|
||||
static int DumpWriteArgs(const struct fstrace_cmplt_event_t &cmpltEvent)
|
||||
{
|
||||
std::cout << "\nArgs:";
|
||||
std::cout << "\n fd = " << cmplt_event.start_event.write_args.fd;
|
||||
std::cout << "\n buf = " << cmplt_event.start_event.write_args.buf;
|
||||
std::cout << "\n count = " << cmplt_event.start_event.write_args.count;
|
||||
std::cout << "\n fd = " << cmpltEvent.start_event.write_args.fd;
|
||||
std::cout << "\n buf = " << cmpltEvent.start_event.write_args.buf;
|
||||
std::cout << "\n count = " << cmpltEvent.start_event.write_args.count;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int DumpPwrite64Args(const struct fstrace_cmplt_event_t &cmplt_event)
|
||||
static int DumpPwrite64Args(const struct fstrace_cmplt_event_t &cmpltEvent)
|
||||
{
|
||||
std::cout << "\nArgs:";
|
||||
std::cout << "\n fd = " << cmplt_event.start_event.pwrite64_args.fd;
|
||||
std::cout << "\n buf = " << cmplt_event.start_event.pwrite64_args.buf;
|
||||
std::cout << "\n count = " << cmplt_event.start_event.pwrite64_args.count;
|
||||
std::cout << "\n pos = " << cmplt_event.start_event.pwrite64_args.pos;
|
||||
std::cout << "\n fd = " << cmpltEvent.start_event.pwrite64_args.fd;
|
||||
std::cout << "\n buf = " << cmpltEvent.start_event.pwrite64_args.buf;
|
||||
std::cout << "\n count = " << cmpltEvent.start_event.pwrite64_args.count;
|
||||
std::cout << "\n pos = " << cmpltEvent.start_event.pwrite64_args.pos;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int DumpCloseArgs(const struct fstrace_cmplt_event_t &cmplt_event)
|
||||
static int DumpCloseArgs(const struct fstrace_cmplt_event_t &cmpltEvent)
|
||||
{
|
||||
std::cout << "\nArgs:";
|
||||
std::cout << "\n files = " << cmplt_event.start_event.close_args.files;
|
||||
std::cout << "\n fd = " << cmplt_event.start_event.close_args.fd;
|
||||
std::cout << "\n files = " << cmpltEvent.start_event.close_args.files;
|
||||
std::cout << "\n fd = " << cmpltEvent.start_event.close_args.fd;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int DumpTypeAndArgs(const struct fstrace_cmplt_event_t &cmplt_event)
|
||||
static int DumpTypeAndArgs(const struct fstrace_cmplt_event_t &cmpltEvent)
|
||||
{
|
||||
std::cout << "\nevent type: ";
|
||||
switch (cmplt_event.start_event.type) {
|
||||
case SYS_OPENAT2: std::cout << "openat2"; return DumpOpenat2Args(cmplt_event);
|
||||
switch (cmpltEvent.start_event.type) {
|
||||
case SYS_OPENAT2: std::cout << "openat2"; return DumpOpenat2Args(cmpltEvent);
|
||||
|
||||
case SYS_READV: std::cout << "readv"; return DumpReadvArgs(cmplt_event);
|
||||
case SYS_PREADV: std::cout << "preadv"; return DumpPreadvArgs(cmplt_event);
|
||||
case SYS_READ: std::cout << "read"; return DumpReadArgs(cmplt_event);
|
||||
case SYS_PREAD64: std::cout << "pread64"; return DumpPread64Args(cmplt_event);
|
||||
case SYS_READV: std::cout << "readv"; return DumpReadvArgs(cmpltEvent);
|
||||
case SYS_PREADV: std::cout << "preadv"; return DumpPreadvArgs(cmpltEvent);
|
||||
case SYS_READ: std::cout << "read"; return DumpReadArgs(cmpltEvent);
|
||||
case SYS_PREAD64: std::cout << "pread64"; return DumpPread64Args(cmpltEvent);
|
||||
|
||||
case SYS_WRITEV: std::cout << "writev"; return DumpWritevArgs(cmplt_event);
|
||||
case SYS_PWRITEV: std::cout << "pwritev"; return DumpPwritevArgs(cmplt_event);
|
||||
case SYS_WRITE: std::cout << "write"; return DumpWriteArgs(cmplt_event);
|
||||
case SYS_PWRITE64: std::cout << "pwrite64"; return DumpPwrite64Args(cmplt_event);
|
||||
case SYS_WRITEV: std::cout << "writev"; return DumpWritevArgs(cmpltEvent);
|
||||
case SYS_PWRITEV: std::cout << "pwritev"; return DumpPwritevArgs(cmpltEvent);
|
||||
case SYS_WRITE: std::cout << "write"; return DumpWriteArgs(cmpltEvent);
|
||||
case SYS_PWRITE64: std::cout << "pwrite64"; return DumpPwrite64Args(cmpltEvent);
|
||||
|
||||
case SYS_CLOSE: std::cout << "close"; return DumpCloseArgs(cmplt_event);
|
||||
case SYS_CLOSE: std::cout << "close"; return DumpCloseArgs(cmpltEvent);
|
||||
}
|
||||
HHLOGE(true, "unreognized fstrace event type = %d", cmplt_event.start_event.type);
|
||||
HHLOGE(true, "unreognized fstrace event type = %d", cmpltEvent.start_event.type);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -789,25 +789,25 @@ int BPFController::DumpFSTraceEvent(BPFController *bpfctlr, void *data, size_t d
|
||||
<< std::endl;
|
||||
return -1;
|
||||
}
|
||||
struct fstrace_cmplt_event_t cmplt_event {};
|
||||
if (memcpy_s(&cmplt_event, sizeof(fstrace_cmplt_event_t), data, dataSize) != EOK) {
|
||||
struct fstrace_cmplt_event_t cmpltEvent {};
|
||||
if (memcpy_s(&cmpltEvent, sizeof(fstrace_cmplt_event_t), data, dataSize) != EOK) {
|
||||
std::cout << "failed to copy data to fstrace_cmplt_event_t" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
std::cout << "\nFSTrace Event:"
|
||||
<< "\ndata size: " << dataSize;
|
||||
DumpTypeAndArgs(cmplt_event);
|
||||
std::cout << "\nretval: " << cmplt_event.retval
|
||||
<< "\nstart time: " << cmplt_event.start_event.stime
|
||||
<< "\nexit time: " << cmplt_event.ctime
|
||||
<< "\npid: " << cmplt_event.pid
|
||||
<< "\ntgid: " << cmplt_event.tgid
|
||||
<< "\ncomm: " << cmplt_event.comm
|
||||
<< "\nips: " << cmplt_event.nips
|
||||
DumpTypeAndArgs(cmpltEvent);
|
||||
std::cout << "\nretval: " << cmpltEvent.retval
|
||||
<< "\nstart time: " << cmpltEvent.start_event.stime
|
||||
<< "\nexit time: " << cmpltEvent.ctime
|
||||
<< "\npid: " << cmpltEvent.pid
|
||||
<< "\ntgid: " << cmpltEvent.tgid
|
||||
<< "\ncomm: " << cmpltEvent.comm
|
||||
<< "\nips: " << cmpltEvent.nips
|
||||
<< "\nips:"
|
||||
<< std::setw(WIDE_SIXTEEN) << std::hex;
|
||||
for (uint32_t i = 0; i < cmplt_event.nips; ++i) {
|
||||
std::cout << "\n " << cmplt_event.ips[i];
|
||||
for (uint32_t i = 0; i < cmpltEvent.nips; ++i) {
|
||||
std::cout << "\n " << cmpltEvent.ips[i];
|
||||
}
|
||||
std::cout << std::dec << std::endl;
|
||||
return 0;
|
||||
@ -822,15 +822,15 @@ int BPFController::DumpPFTraceEvent(BPFController *bpfctlr, void *data, size_t d
|
||||
<< std::endl;
|
||||
return -1;
|
||||
}
|
||||
struct pftrace_cmplt_event_t cmplt_event {};
|
||||
if (memcpy_s(&cmplt_event, sizeof(pftrace_cmplt_event_t), data, dataSize) != EOK) {
|
||||
struct pftrace_cmplt_event_t cmpltEvent {};
|
||||
if (memcpy_s(&cmpltEvent, sizeof(pftrace_cmplt_event_t), data, dataSize) != EOK) {
|
||||
std::cout << "failed to copy data to pftrace_cmplt_event_t" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
std::cout << "PFTrace Event:"
|
||||
<< "\ndata size: " << dataSize
|
||||
<< "\nevent type: ";
|
||||
switch (cmplt_event.start_event.type) {
|
||||
switch (cmpltEvent.start_event.type) {
|
||||
case PF_COPY_ON_WRITE: std::cout << "Copy On Write"; break;
|
||||
case PF_FAKE_ZERO_PAGE: std::cout << "Zero FAKE Page"; break;
|
||||
case PF_FILE_BACKED_IN: std::cout << "File Backed In"; break;
|
||||
@ -838,19 +838,19 @@ int BPFController::DumpPFTraceEvent(BPFController *bpfctlr, void *data, size_t d
|
||||
case PF_SWAP_FROM_DISK: std::cout << "Swap From Disk"; break;
|
||||
case PF_SWAP_FROM_ZRAM: std::cout << "Swap From Zram"; break;
|
||||
case PF_ZERO_FILL_PAGE: std::cout << "Zero Fill Page"; break;
|
||||
default: std::cout << cmplt_event.start_event.type;
|
||||
default: std::cout << cmpltEvent.start_event.type;
|
||||
}
|
||||
std::cout << "\naddress: " << cmplt_event.start_event.addr
|
||||
<< "\nsize: " << cmplt_event.size
|
||||
<< "\nstart time: " << cmplt_event.start_event.stime
|
||||
<< "\nexit time: " << cmplt_event.ctime
|
||||
<< "\npid: " << cmplt_event.pid
|
||||
<< "\ntgid: " << cmplt_event.tgid
|
||||
<< "\ncomm: " << cmplt_event.comm
|
||||
<< "\nips: " << cmplt_event.nips
|
||||
std::cout << "\naddress: " << cmpltEvent.start_event.addr
|
||||
<< "\nsize: " << cmpltEvent.size
|
||||
<< "\nstart time: " << cmpltEvent.start_event.stime
|
||||
<< "\nexit time: " << cmpltEvent.ctime
|
||||
<< "\npid: " << cmpltEvent.pid
|
||||
<< "\ntgid: " << cmpltEvent.tgid
|
||||
<< "\ncomm: " << cmpltEvent.comm
|
||||
<< "\nips: " << cmpltEvent.nips
|
||||
<< std::setw(WIDE_SIXTEEN) << std::hex;
|
||||
for (uint32_t i = 0; i < cmplt_event.nips; ++i) {
|
||||
std::cout << "\n " << cmplt_event.ips[i];
|
||||
for (uint32_t i = 0; i < cmpltEvent.nips; ++i) {
|
||||
std::cout << "\n " << cmpltEvent.ips[i];
|
||||
}
|
||||
std::cout << std::dec << std::endl;
|
||||
return 0;
|
||||
@ -865,36 +865,36 @@ int BPFController::DumpBIOTraceEvent(BPFController *bpfctlr, void *data, size_t
|
||||
<< std::endl;
|
||||
return -1;
|
||||
}
|
||||
struct biotrace_cmplt_event_t cmplt_event {};
|
||||
if (memcpy_s(&cmplt_event, sizeof(biotrace_cmplt_event_t), data, dataSize) != EOK) {
|
||||
struct biotrace_cmplt_event_t cmpltEvent {};
|
||||
if (memcpy_s(&cmpltEvent, sizeof(biotrace_cmplt_event_t), data, dataSize) != EOK) {
|
||||
std::cout << "failed to copy data to biotrace_cmplt_event_t" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
std::cout << "BIOTrace Event:"
|
||||
<< "\ndata size: " << dataSize
|
||||
<< "\nevent type: ";
|
||||
switch (cmplt_event.start_event.type) {
|
||||
switch (cmpltEvent.start_event.type) {
|
||||
case BIO_DATA_READ: std::cout << "DATA_READ"; break;
|
||||
case BIO_DATA_WRITE: std::cout << "DATA_WRITE"; break;
|
||||
case BIO_METADATA_READ: std::cout << "METADATA_READ"; break;
|
||||
case BIO_METADATA_WRITE: std::cout << "METADATA_WRITE"; break;
|
||||
case BIO_PAGE_IN: std::cout << "PAGE_IN"; break;
|
||||
case BIO_PAGE_OUT: std::cout << "PAGE_OUT"; break;
|
||||
default: std::cout << cmplt_event.start_event.type;
|
||||
default: std::cout << cmpltEvent.start_event.type;
|
||||
}
|
||||
|
||||
std::cout << "\nstart time: " << cmplt_event.start_event.stime
|
||||
<< "\nexit time: " << cmplt_event.ctime
|
||||
<< "\npid: " << cmplt_event.start_event.pid
|
||||
<< "\ntgid: " << cmplt_event.start_event.tgid
|
||||
<< "\ncomm: " << cmplt_event.start_event.comm
|
||||
<< "\nprio: " << cmplt_event.prio
|
||||
<< "\nsize: " << cmplt_event.start_event.size
|
||||
<< "\nblkcnt: " << cmplt_event.blkcnt
|
||||
<< "\nips: " << cmplt_event.nips
|
||||
std::cout << "\nstart time: " << cmpltEvent.start_event.stime
|
||||
<< "\nexit time: " << cmpltEvent.ctime
|
||||
<< "\npid: " << cmpltEvent.start_event.pid
|
||||
<< "\ntgid: " << cmpltEvent.start_event.tgid
|
||||
<< "\ncomm: " << cmpltEvent.start_event.comm
|
||||
<< "\nprio: " << cmpltEvent.prio
|
||||
<< "\nsize: " << cmpltEvent.start_event.size
|
||||
<< "\nblkcnt: " << cmpltEvent.blkcnt
|
||||
<< "\nips: " << cmpltEvent.nips
|
||||
<< std::setw(WIDE_SIXTEEN) << std::hex;
|
||||
for (uint32_t i = 0; i < cmplt_event.nips; ++i) {
|
||||
std::cout << "\n " << cmplt_event.ips[i];
|
||||
for (uint32_t i = 0; i < cmpltEvent.nips; ++i) {
|
||||
std::cout << "\n " << cmpltEvent.ips[i];
|
||||
}
|
||||
std::cout << std::dec << std::endl;
|
||||
return 0;
|
||||
@ -909,21 +909,21 @@ int BPFController::DumpSTRTraceEvent(void *data, size_t dataSize)
|
||||
<< std::endl;
|
||||
return -1;
|
||||
}
|
||||
struct strtrace_cmplt_event_t cmplt_event {};
|
||||
if (memcpy_s(&cmplt_event, sizeof(strtrace_cmplt_event_t), data, dataSize) != EOK) {
|
||||
struct strtrace_cmplt_event_t cmpltEvent {};
|
||||
if (memcpy_s(&cmpltEvent, sizeof(strtrace_cmplt_event_t), data, dataSize) != EOK) {
|
||||
std::cout << "failed to copy data to strtrace_cmplt_event_t" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
std::cout << "STRTrace Event:"
|
||||
<< "\ndata size: " << dataSize
|
||||
<< "\ntracer: " << cmplt_event.start_event.stracer
|
||||
<< "\ntype: " << cmplt_event.start_event.type
|
||||
<< "\naddress: " << cmplt_event.start_event.addr
|
||||
<< "\nstart time: " << cmplt_event.start_event.stime
|
||||
<< "\npid: " << cmplt_event.pid
|
||||
<< "\ntgid: " << cmplt_event.tgid
|
||||
<< "\nfilename len: " << cmplt_event.len
|
||||
<< "\nfilename: " << cmplt_event.filename
|
||||
<< "\ntracer: " << cmpltEvent.start_event.stracer
|
||||
<< "\ntype: " << cmpltEvent.start_event.type
|
||||
<< "\naddress: " << cmpltEvent.start_event.addr
|
||||
<< "\nstart time: " << cmpltEvent.start_event.stime
|
||||
<< "\npid: " << cmpltEvent.pid
|
||||
<< "\ntgid: " << cmpltEvent.tgid
|
||||
<< "\nfilename len: " << cmpltEvent.len
|
||||
<< "\nfilename: " << cmpltEvent.filename
|
||||
<< std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
@ -20,91 +20,91 @@ static constexpr int ARGS_POINT_ONE = 1;
|
||||
static constexpr int ARGS_POINT_TWO = 2;
|
||||
static constexpr int ARGS_POINT_THREE = 3;
|
||||
|
||||
static int Openat2ArgsConverter(__u64* args, const struct fstrace_start_event_t* start_event)
|
||||
static int Openat2ArgsConverter(__u64* args, const struct fstrace_start_event_t* startEvent)
|
||||
{
|
||||
args[ARGS_POINT_ZERO] = (__u64) start_event->openat2_args.dfd;
|
||||
args[ARGS_POINT_ONE] = (__u64) start_event->openat2_args.filename;
|
||||
args[ARGS_POINT_TWO] = (__u64) start_event->openat2_args.how;
|
||||
args[ARGS_POINT_ZERO] = (__u64) startEvent->openat2_args.dfd;
|
||||
args[ARGS_POINT_ONE] = (__u64) startEvent->openat2_args.filename;
|
||||
args[ARGS_POINT_TWO] = (__u64) startEvent->openat2_args.how;
|
||||
args[ARGS_POINT_THREE] = 0xFFFFFFFFFFFFFFFF;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ReadArgsConverter(__u64* args, const struct fstrace_start_event_t* start_event)
|
||||
static int ReadArgsConverter(__u64* args, const struct fstrace_start_event_t* startEvent)
|
||||
{
|
||||
args[ARGS_POINT_ZERO] = (__u64) start_event->read_args.fd;
|
||||
args[ARGS_POINT_ONE] = (__u64) start_event->read_args.buf;
|
||||
args[ARGS_POINT_TWO] = (__u64) start_event->read_args.count;
|
||||
args[ARGS_POINT_ZERO] = (__u64) startEvent->read_args.fd;
|
||||
args[ARGS_POINT_ONE] = (__u64) startEvent->read_args.buf;
|
||||
args[ARGS_POINT_TWO] = (__u64) startEvent->read_args.count;
|
||||
args[ARGS_POINT_THREE] = 0xFFFFFFFFFFFFFFFF;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int WriteArgsConverter(__u64* args, const struct fstrace_start_event_t* start_event)
|
||||
static int WriteArgsConverter(__u64* args, const struct fstrace_start_event_t* startEvent)
|
||||
{
|
||||
args[ARGS_POINT_ZERO] = (__u64) start_event->write_args.fd;
|
||||
args[ARGS_POINT_ONE] = (__u64) start_event->write_args.buf;
|
||||
args[ARGS_POINT_TWO] = (__u64) start_event->write_args.count;
|
||||
args[ARGS_POINT_ZERO] = (__u64) startEvent->write_args.fd;
|
||||
args[ARGS_POINT_ONE] = (__u64) startEvent->write_args.buf;
|
||||
args[ARGS_POINT_TWO] = (__u64) startEvent->write_args.count;
|
||||
args[ARGS_POINT_THREE] = 0xFFFFFFFFFFFFFFFF;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int Pread64ArgsConverter(__u64* args, const struct fstrace_start_event_t* start_event)
|
||||
static int Pread64ArgsConverter(__u64* args, const struct fstrace_start_event_t* startEvent)
|
||||
{
|
||||
args[ARGS_POINT_ZERO] = (__u64) start_event->pread64_args.fd;
|
||||
args[ARGS_POINT_ONE] = (__u64) start_event->pread64_args.buf;
|
||||
args[ARGS_POINT_TWO] = (__u64) start_event->pread64_args.count;
|
||||
args[ARGS_POINT_THREE] = (__u64) start_event->pread64_args.pos;
|
||||
args[ARGS_POINT_ZERO] = (__u64) startEvent->pread64_args.fd;
|
||||
args[ARGS_POINT_ONE] = (__u64) startEvent->pread64_args.buf;
|
||||
args[ARGS_POINT_TWO] = (__u64) startEvent->pread64_args.count;
|
||||
args[ARGS_POINT_THREE] = (__u64) startEvent->pread64_args.pos;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int Pwrite64ArgsConverter(__u64* args, const struct fstrace_start_event_t* start_event)
|
||||
static int Pwrite64ArgsConverter(__u64* args, const struct fstrace_start_event_t* startEvent)
|
||||
{
|
||||
args[ARGS_POINT_ZERO] = (__u64) start_event->pwrite64_args.fd;
|
||||
args[ARGS_POINT_ONE] = (__u64) start_event->pwrite64_args.buf;
|
||||
args[ARGS_POINT_TWO] = (__u64) start_event->pwrite64_args.count;
|
||||
args[ARGS_POINT_THREE] = (__u64) start_event->pwrite64_args.pos;
|
||||
args[ARGS_POINT_ZERO] = (__u64) startEvent->pwrite64_args.fd;
|
||||
args[ARGS_POINT_ONE] = (__u64) startEvent->pwrite64_args.buf;
|
||||
args[ARGS_POINT_TWO] = (__u64) startEvent->pwrite64_args.count;
|
||||
args[ARGS_POINT_THREE] = (__u64) startEvent->pwrite64_args.pos;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ReadvArgsConverter(__u64* args, const struct fstrace_start_event_t* start_event)
|
||||
static int ReadvArgsConverter(__u64* args, const struct fstrace_start_event_t* startEvent)
|
||||
{
|
||||
args[ARGS_POINT_ZERO] = (__u64) start_event->readv_args.fd;
|
||||
args[ARGS_POINT_ONE] = (__u64) start_event->readv_args.vec;
|
||||
args[ARGS_POINT_TWO] = (__u64) start_event->readv_args.vlen;
|
||||
args[ARGS_POINT_THREE] = (__u64) start_event->readv_args.flags;
|
||||
args[ARGS_POINT_ZERO] = (__u64) startEvent->readv_args.fd;
|
||||
args[ARGS_POINT_ONE] = (__u64) startEvent->readv_args.vec;
|
||||
args[ARGS_POINT_TWO] = (__u64) startEvent->readv_args.vlen;
|
||||
args[ARGS_POINT_THREE] = (__u64) startEvent->readv_args.flags;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int WritevArgsConverter(__u64* args, const struct fstrace_start_event_t* start_event)
|
||||
static int WritevArgsConverter(__u64* args, const struct fstrace_start_event_t* startEvent)
|
||||
{
|
||||
args[ARGS_POINT_ZERO] = (__u64) start_event->writev_args.fd;
|
||||
args[ARGS_POINT_ONE] = (__u64) start_event->writev_args.vec;
|
||||
args[ARGS_POINT_TWO] = (__u64) start_event->writev_args.vlen;
|
||||
args[ARGS_POINT_THREE] = (__u64) start_event->writev_args.flags;
|
||||
args[ARGS_POINT_ZERO] = (__u64) startEvent->writev_args.fd;
|
||||
args[ARGS_POINT_ONE] = (__u64) startEvent->writev_args.vec;
|
||||
args[ARGS_POINT_TWO] = (__u64) startEvent->writev_args.vlen;
|
||||
args[ARGS_POINT_THREE] = (__u64) startEvent->writev_args.flags;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int PreadvArgsConverter(__u64* args, const struct fstrace_start_event_t* start_event)
|
||||
static int PreadvArgsConverter(__u64* args, const struct fstrace_start_event_t* startEvent)
|
||||
{
|
||||
args[ARGS_POINT_ZERO] = (__u64) start_event->preadv_args.fd;
|
||||
args[ARGS_POINT_ONE] = (__u64) start_event->preadv_args.vec;
|
||||
args[ARGS_POINT_TWO] = (__u64) start_event->preadv_args.vlen;
|
||||
args[ARGS_POINT_THREE] = (__u64) start_event->preadv_args.pos;
|
||||
args[ARGS_POINT_ZERO] = (__u64) startEvent->preadv_args.fd;
|
||||
args[ARGS_POINT_ONE] = (__u64) startEvent->preadv_args.vec;
|
||||
args[ARGS_POINT_TWO] = (__u64) startEvent->preadv_args.vlen;
|
||||
args[ARGS_POINT_THREE] = (__u64) startEvent->preadv_args.pos;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int PwritevArgsConverter(__u64* args, const struct fstrace_start_event_t* start_event)
|
||||
static int PwritevArgsConverter(__u64* args, const struct fstrace_start_event_t* startEvent)
|
||||
{
|
||||
args[ARGS_POINT_ZERO] = (__u64) start_event->pwritev_args.fd;
|
||||
args[ARGS_POINT_ONE] = (__u64) start_event->pwritev_args.vec;
|
||||
args[ARGS_POINT_TWO] = (__u64) start_event->pwritev_args.vlen;
|
||||
args[ARGS_POINT_THREE] = (__u64) start_event->pwritev_args.pos;
|
||||
args[ARGS_POINT_ZERO] = (__u64) startEvent->pwritev_args.fd;
|
||||
args[ARGS_POINT_ONE] = (__u64) startEvent->pwritev_args.vec;
|
||||
args[ARGS_POINT_TWO] = (__u64) startEvent->pwritev_args.vlen;
|
||||
args[ARGS_POINT_THREE] = (__u64) startEvent->pwritev_args.pos;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int CloseArgsConverter(__u64* args, const struct fstrace_start_event_t* start_event)
|
||||
static int CloseArgsConverter(__u64* args, const struct fstrace_start_event_t* startEvent)
|
||||
{
|
||||
args[ARGS_POINT_ZERO] = (__u64) start_event->close_args.files;
|
||||
args[ARGS_POINT_ONE] = (__u64) start_event->close_args.fd;
|
||||
args[ARGS_POINT_ZERO] = (__u64) startEvent->close_args.files;
|
||||
args[ARGS_POINT_ONE] = (__u64) startEvent->close_args.fd;
|
||||
args[ARGS_POINT_TWO] = 0xFFFFFFFFFFFFFFFF;
|
||||
args[ARGS_POINT_THREE] = 0xFFFFFFFFFFFFFFFF;
|
||||
return 0;
|
||||
|
@ -29,6 +29,7 @@
|
||||
|
||||
extern int LINUX_KERNEL_VERSION __kconfig;
|
||||
const volatile unsigned int g_stack_limit = 0;
|
||||
static constexpr int SHIFT_32 = 32;
|
||||
|
||||
// global configuration data
|
||||
// const volatile int tracer_pid = -1;
|
||||
@ -139,9 +140,9 @@ int emit_fstrace_event(void* ctx, int64_t retval)
|
||||
cmplt_event->ctime = ctime;
|
||||
cmplt_event->tracer = FSTRACE;
|
||||
cmplt_event->pid = (u32) pid_tgid;
|
||||
cmplt_event->tgid = (u32) (pid_tgid >> 32);
|
||||
cmplt_event->tgid = (u32) (pid_tgid >> SHIFT_32);
|
||||
cmplt_event->uid = bpf_get_current_uid_gid();
|
||||
cmplt_event->gid = (bpf_get_current_uid_gid() >> 32);
|
||||
cmplt_event->gid = (bpf_get_current_uid_gid() >> SHIFT_32);
|
||||
cmplt_event->retval = retval;
|
||||
err = bpf_get_current_comm(cmplt_event->comm, MAX_COMM_LEN);
|
||||
if (err) {
|
||||
@ -301,9 +302,9 @@ int emit_pftrace_event(void* ctx, int64_t retval)
|
||||
cmplt_event->tracer = PFTRACE;
|
||||
cmplt_event->ctime = ctime;
|
||||
cmplt_event->pid = (u32) pid_tgid;
|
||||
cmplt_event->tgid = (pid_tgid >> 32);
|
||||
cmplt_event->tgid = (pid_tgid >> SHIFT_32);
|
||||
cmplt_event->uid = bpf_get_current_uid_gid();
|
||||
cmplt_event->gid = (bpf_get_current_uid_gid() >> 32);
|
||||
cmplt_event->gid = (bpf_get_current_uid_gid() >> SHIFT_32);
|
||||
err = bpf_get_current_comm(cmplt_event->comm, MAX_COMM_LEN);
|
||||
if (err < 0) {
|
||||
BPFLOGD(BPF_TRUE, "pftrace event discarded: failed to get process command");
|
||||
@ -381,7 +382,7 @@ int check_current_pid(const int32_t pid, const int32_t tgid)
|
||||
}
|
||||
int32_t curr_tgid = tgid;
|
||||
if (curr_tgid < 0) {
|
||||
curr_tgid = (int32_t)(bpf_get_current_pid_tgid() >> 32);
|
||||
curr_tgid = (int32_t)(bpf_get_current_pid_tgid() >> SHIFT_32);
|
||||
}
|
||||
if (curr_pid == tracer_pid || curr_tgid == tracer_pid) {
|
||||
// currrent process is not a target process
|
||||
@ -579,7 +580,7 @@ int emit_strtrace_event(u64 stime, u32 type, const void *addr, u32 stracer)
|
||||
cmplt_event->start_event.stime = stime;
|
||||
cmplt_event->start_event.addr = addr;
|
||||
cmplt_event->pid = bpf_get_current_pid_tgid();
|
||||
cmplt_event->tgid = (bpf_get_current_pid_tgid() >> 32);
|
||||
cmplt_event->tgid = (bpf_get_current_pid_tgid() >> SHIFT_32);
|
||||
int err = 0;
|
||||
switch (stracer) {
|
||||
case BIOTRACE: {
|
||||
@ -732,7 +733,7 @@ int handle_blk_issue(struct request *rq)
|
||||
emit_strtrace_event(bio_se->stime, bio_se->type, BPF_CORE_READ(rq, bio), BIOTRACE);
|
||||
u64 tgid_pid = bpf_get_current_pid_tgid();
|
||||
bio_se->pid = (u32) tgid_pid;
|
||||
bio_se->tgid = (u32) (tgid_pid >> 32);
|
||||
bio_se->tgid = (u32) (tgid_pid >> SHIFT_32);
|
||||
bpf_get_current_comm(bio_se->comm, MAX_COMM_LEN);
|
||||
bio_se->size = BPF_CORE_READ(rq, bio, bi_iter.bi_size);
|
||||
bpf_map_update_elem(&start_event_map, &start_event_map_key, &start_event, BPF_ANY);
|
||||
@ -809,7 +810,7 @@ int BPF_KRETPROBE(uretprobe_dlopen, void *ret)
|
||||
}
|
||||
start_event->type = DLOPEN_TRACE;
|
||||
u64 tgid_pid = bpf_get_current_pid_tgid();
|
||||
start_event->tgid = (u32)(tgid_pid >> 32);
|
||||
start_event->tgid = (u32)(tgid_pid >> SHIFT_32);
|
||||
bpf_ringbuf_submit(start_event, BPF_RB_FORCE_WAKEUP);
|
||||
return 0;
|
||||
}
|
||||
|
@ -13,22 +13,19 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <chrono>
|
||||
#include <cerrno>
|
||||
#include <csignal>
|
||||
#include <cstdlib>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <linux/perf_event.h>
|
||||
#include <linux/bpf.h>
|
||||
#include <signal.h>
|
||||
#include <errno.h>
|
||||
#include <sys/resource.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "bpf_controller.h"
|
||||
#include "commandline_flags.h"
|
||||
|
@ -13,10 +13,10 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <sstream>
|
||||
#include <cstdio>
|
||||
#include <ctime>
|
||||
#include <sstream>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
|
||||
|
@ -69,7 +69,7 @@ private:
|
||||
static int g_sleepUs = 0;
|
||||
void CallStack1(const char * filename)
|
||||
{
|
||||
int fd = open(filename, O_RDWR|O_CREAT|O_TRUNC, FILE_MODE);
|
||||
int fd = open(filename, O_RDWR | O_CREAT | O_TRUNC, FILE_MODE);
|
||||
if (fd < 0) {
|
||||
printf("NOTE Open file err: %s!\n", filename);
|
||||
return ;
|
||||
@ -78,7 +78,7 @@ void CallStack1(const char * filename)
|
||||
usleep(g_sleepUs);
|
||||
}
|
||||
|
||||
std::vector<char> buf(BUF_SIZE * 2,'a'); // 2: double
|
||||
std::vector<char> buf(BUF_SIZE * 2, 'a'); // 2: double
|
||||
write(fd, buf.data(), buf.size());
|
||||
fsync(fd);
|
||||
if (g_sleepUs) {
|
||||
@ -102,7 +102,7 @@ void CallStack0(const char * filename)
|
||||
CallStack1(filename);
|
||||
}
|
||||
|
||||
void* thread_func_cpp(void* param)
|
||||
void* ThreadFuncCpp(void* param)
|
||||
{
|
||||
unsigned int idx = 0;
|
||||
int threadNo = static_cast<int*>(param)[0];
|
||||
@ -116,8 +116,8 @@ void* thread_func_cpp(void* param)
|
||||
prctl(PR_SET_NAME, name.c_str());
|
||||
name = DEFAULT_PATH + name;
|
||||
const auto startTime = std::chrono::steady_clock::now();
|
||||
std::chrono::seconds timeOut_{time};
|
||||
const auto endTime = startTime + timeOut_;
|
||||
std::chrono::seconds timeOut{time};
|
||||
const auto endTime = startTime + timeOut;
|
||||
|
||||
while (true) {
|
||||
const auto thisTime = std::chrono::steady_clock::now();
|
||||
@ -143,8 +143,8 @@ long ThreadTimeCost(int threadNum, int writeReadTime) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
pthread_t* thr_array = new (std::nothrow) pthread_t[threadNum];
|
||||
if (!thr_array) {
|
||||
pthread_t* thrArray = new (std::nothrow) pthread_t[threadNum];
|
||||
if (!thrArray) {
|
||||
printf("new thread array failed.\n");
|
||||
return 1;
|
||||
}
|
||||
@ -152,15 +152,15 @@ long ThreadTimeCost(int threadNum, int writeReadTime) {
|
||||
for (idx = 0; idx < threadNum; ++idx) {
|
||||
args[idx][0] = idx;
|
||||
args[idx][1] = writeReadTime;
|
||||
if (pthread_create(thr_array + idx, nullptr, thread_func_cpp, static_cast<void*>(args[idx])) != 0) {
|
||||
if (pthread_create(thrArray + idx, nullptr, ThreadFuncCpp, static_cast<void*>(args[idx])) != 0) {
|
||||
printf("Creating thread failed.\n");
|
||||
}
|
||||
}
|
||||
|
||||
for (idx = 0; idx < threadNum; ++idx) {
|
||||
pthread_join(thr_array[idx], nullptr);
|
||||
pthread_join(thrArray[idx], nullptr);
|
||||
}
|
||||
delete []thr_array;
|
||||
delete []thrArray;
|
||||
|
||||
return timer.ElapsedUs();
|
||||
}
|
||||
@ -189,7 +189,7 @@ int main(int argc, char *argv[])
|
||||
auto timeCost = ThreadTimeCost(threadNum, writeReadTime);
|
||||
|
||||
if (timeCost > 0) {
|
||||
printf("Time cost %ld us.\n",timeCost);
|
||||
printf("Time cost %ld us.\n", timeCost);
|
||||
} else {
|
||||
printf("Test failure end!\n");
|
||||
return 0;
|
||||
|
@ -14,7 +14,7 @@
|
||||
*/
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <math.h>
|
||||
#include <cmath>
|
||||
#include <cstdio>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
@ -16,7 +16,6 @@
|
||||
#ifndef PLUGIN_MODULE_API_H
|
||||
#define PLUGIN_MODULE_API_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <climits>
|
||||
|
Loading…
Reference in New Issue
Block a user