raw类型事件名允许使用十六进制值

Signed-off-by: yuanye <yuanye64@huawei.com>
This commit is contained in:
yuanye 2024-06-04 11:01:15 +08:00
parent b977d813b5
commit c1e5754fc4
2 changed files with 21 additions and 6 deletions

View File

@ -331,6 +331,7 @@ public:
static constexpr size_t MAX_BUFFER_SIZE_LARGE = 256 * 1024 * 1024;
static constexpr uint64_t DEFAULT_EVENT_MAX_SAMPLE_RATE = 8000;
static constexpr uint64_t MIN_HM_TRACEPOINT_EVENT_ID = 32768;
static constexpr size_t MAX_HEX_EVENT_NAME_LENGTH = 10;
PerfEvents();
~PerfEvents();
@ -463,6 +464,18 @@ public:
return "<not found>";
};
static const std::tuple<bool, perf_type_id, __u64> GetStaticConfigId(const std::string &event_name)
{
for (auto type : TYPE_CONFIGS) {
for (auto config : (type.second)) {
if (config.second == event_name) {
return std::make_tuple(true, type.first, config.first);
}
}
}
return std::make_tuple(false, PERF_TYPE_MAX, 0);
}
const std::string GetTraceConfigName(__u64 config_id)
{
auto config = traceConfigTable.find(config_id);

View File

@ -249,12 +249,14 @@ bool PerfEvents::AddEvent(const std::string &eventString, bool followGroup)
}
}
} else {
for (auto type : TYPE_CONFIGS) {
for (auto config : (type.second)) {
if (config.second == eventName) {
return AddEvent(type.first, config.first, excludeUser, excludeKernel,
followGroup);
}
if (StringStartsWith(eventName, "0x")
&& eventName.length() <= MAX_HEX_EVENT_NAME_LENGTH && IsHexDigits(eventName)) {
return AddEvent(PERF_TYPE_RAW, std::stoull(eventName, nullptr, NUMBER_FORMAT_HEX_BASE),
excludeUser, excludeKernel, followGroup);
} else {
auto [find, typeId, configId] = GetStaticConfigId(eventName);
if (find) {
return AddEvent(typeId, configId, excludeUser, excludeKernel, followGroup);
}
}
}