From bfbec494a98f6b872b7449c4f641d2a94942d84b Mon Sep 17 00:00:00 2001 From: rfwang07 Date: Tue, 10 Dec 2024 16:06:31 +0800 Subject: [PATCH] filter so address pmudata --- include/records.h | 1 + src/configs.cc | 4 +++- src/oeaware_plugins/tuner_sysboost.cc | 1 + src/records.cc | 1 + src/startup_opt.cc | 28 +++++++++++++++++++++------ 5 files changed, 28 insertions(+), 7 deletions(-) diff --git a/include/records.h b/include/records.h index c86ce62..df7d39d 100644 --- a/include/records.h +++ b/include/records.h @@ -23,6 +23,7 @@ typedef struct { typedef struct { uint64_t processed_samples; std::map pids; + std::map modules; } global_records; extern global_records records; diff --git a/src/configs.cc b/src/configs.cc index 9aa6d36..ab96d2a 100644 --- a/src/configs.cc +++ b/src/configs.cc @@ -128,12 +128,14 @@ std::string get_app_collected_profile_path(AppConfig *app) int parse_app(boost::property_tree::ptree pt, std::string app_name) { std::string full_path; + char rlpath[1024] = {0}; try { full_path = pt.get(app_name + ".FULL_PATH"); - if (!boost::filesystem::exists(full_path)) { + if (!get_real_path(full_path.c_str(), rlpath)) { ERROR("Error: File does not exist: " << full_path); return DFOT_ERROR; } + full_path = std::string(rlpath); } catch (const boost::property_tree::ptree_bad_path &e) { ERROR("FULL_PATH is needed."); return DFOT_ERROR; diff --git a/src/oeaware_plugins/tuner_sysboost.cc b/src/oeaware_plugins/tuner_sysboost.cc index b471ccf..14025fd 100644 --- a/src/oeaware_plugins/tuner_sysboost.cc +++ b/src/oeaware_plugins/tuner_sysboost.cc @@ -81,6 +81,7 @@ void SysboostTuner::UpdateData(const DataList &dataList) processing = true; int64_t start_ts = get_current_timestamp(); + records.modules.clear(); uint64_t total_samples = 0; for (unsigned long long i = 0; i < dataList.len; i++) { PmuSamplingData *data = (PmuSamplingData *)(dataList.data[i]); diff --git a/src/records.cc b/src/records.cc index 1f2cbe3..9b212a6 100644 --- a/src/records.cc +++ b/src/records.cc @@ -8,6 +8,7 @@ void reset_records() { records.processed_samples = 0; records.pids.clear(); + records.modules.clear(); } void debug_print_records() diff --git a/src/startup_opt.cc b/src/startup_opt.cc index 14b4aa4..78cae70 100644 --- a/src/startup_opt.cc +++ b/src/startup_opt.cc @@ -92,9 +92,25 @@ void update_app_profile_data(AppConfig *app, struct PmuData &data) // {函数名func: {内存地址addr: 计数count, ...}, ...} auto &funcs = app->profile.funcs; + // 刷新modules记录,避免直接匹配modules字符串,此处的module是relapath路径 + auto symbol = data.stack->symbol; + if (records.modules.find(symbol->module) == records.modules.end()) { + records.modules[symbol->module] = false; + if (strcmp(symbol->module, app->full_path.c_str()) == 0) { + records.modules[symbol->module] = true; + } else if (strstr(symbol->module, ".rto") != nullptr && + strncmp(symbol->module, app->full_path.c_str(), strlen(app->full_path.c_str())) == 0) { + records.modules[symbol->module] = true; + } + } + + if (!records.modules[symbol->module]) { + return; + } + // symbol->codeMapAddr symbol->offset // 如果是BOLT优化过后的二进制的采样数据则只需记录地址和计数 - unsigned long addr = data.stack->symbol->codeMapAddr; + unsigned long addr = symbol->codeMapAddr; if (records.pids[data.pid]->instance->version > 0) { if (addrs.find(addr) != addrs.end()) { @@ -108,18 +124,18 @@ void update_app_profile_data(AppConfig *app, struct PmuData &data) // 原始二进制的采样数据,读取地址+符号+偏移 if (addrs.find(addr) != addrs.end()) { addrs[addr].count++; - funcs[addrs[addr].name][data.stack->symbol->offset]++; + funcs[addrs[addr].name][symbol->offset]++; } else { addrs[addr] = AddrInfo(); - if (data.stack->symbol->mangleName != nullptr) { - addrs[addr].name = data.stack->symbol->mangleName; + if (symbol->mangleName != nullptr) { + addrs[addr].name = symbol->mangleName; } else { auto sym = SymResolverMapAddr(data.pid, addr); addrs[addr].name = sym->mangleName; } - addrs[addr].offset = data.stack->symbol->offset; + addrs[addr].offset = symbol->offset; addrs[addr].count = 1; - funcs[addrs[addr].name][data.stack->symbol->offset] = 1; + funcs[addrs[addr].name][symbol->offset] = 1; } } -- 2.39.5 (Apple Git-154)