Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 6 additions & 15 deletions src/cc/api/BPF.cc
Original file line number Diff line number Diff line change
Expand Up @@ -856,27 +856,18 @@ bool BPF::add_module(std::string module)

namespace {

std::string random_alnum_string(int len) {
static constexpr char kDict[] = "0123456789abcdefghijklmnopqrstuvwxyz";
static std::random_device rd;
std::uniform_int_distribution<size_t> dist(0, sizeof(kDict)-1);
std::string res;
res.reserve(len);
for (int i = 0; i < len; ++i) {
res.push_back(kDict[dist(rd)]);
}
return res;
}

constexpr size_t kEventNameSizeLimit = 224;

std::string shorten_event_name(const std::string& name) {
constexpr size_t kRandomSuffixLen = 16;
constexpr size_t kHashSuffixLen = 16;
std::string res;
size_t hash = std::hash<std::string>{}(name);
res.reserve(kEventNameSizeLimit);
res.assign(name);
res.resize(kEventNameSizeLimit - kRandomSuffixLen);
res.append(random_alnum_string(kRandomSuffixLen));
res.resize(kEventNameSizeLimit - kHashSuffixLen);
std::stringstream stream;
stream << std::hex << hash;
res.append(stream.str());
return res;
}

Expand Down