Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rec: rec_control top* cleanup #14825

Merged
merged 4 commits into from
Nov 8, 2024
Merged
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
89 changes: 43 additions & 46 deletions pdns/recursordist/rec_channel_rec.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1513,37 +1513,35 @@ vector<ComboAddress>* pleaseGetTimeouts()
return ret;
}

static string doGenericTopRemotes(pleaseremotefunc_t func)
static string doGenericTopRemotes(const pleaseremotefunc_t& func)
{
typedef map<ComboAddress, int, ComboAddress::addressOnlyLessThan> counts_t;
counts_t counts;

vector<ComboAddress> remotes = broadcastAccFunction<vector<ComboAddress>>(func);

unsigned int total = 0;
for (const ComboAddress& ca : remotes) {
total++;
counts[ca]++;
auto remotes = broadcastAccFunction<vector<ComboAddress>>(func);
const unsigned int total = remotes.size();
if (total == 0) {
return "No qualifying data available\n";
}

typedef std::multimap<int, ComboAddress> rcounts_t;
rcounts_t rcounts;
std::map<ComboAddress, unsigned int, ComboAddress::addressOnlyLessThan> counts;
for (const auto& address : remotes) {
counts[address]++;
}

for (auto&& c : counts)
rcounts.emplace(-c.second, c.first);
std::multimap<unsigned int, ComboAddress> rcounts;
for (const auto& count : counts) {
rcounts.emplace(count.second, count.first);
}

ostringstream ret;
ret << "Over last " << total << " entries:\n";
boost::format fmt("%.02f%%\t%s\n");
int limit = 0, accounted = 0;
if (total) {
for (rcounts_t::const_iterator i = rcounts.begin(); i != rcounts.end() && limit < 20; ++i, ++limit) {
ret << fmt % (-100.0 * i->first / total) % i->second.toString();
accounted += -i->first;
}
ret << '\n'
<< fmt % (100.0 * (total - accounted) / total) % "rest";
}
unsigned int limit = 0;
unsigned int accounted = 0;
for (auto i = rcounts.rbegin(); i != rcounts.rend() && limit < 20; ++i, ++limit) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm surprised clang-tidy doesn't scream at this i variable name.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ret << fmt % (100.0 * i->first / total) % i->second.toString();
accounted += i->first;
}
ret << '\n'
<< fmt % (100.0 * (total - accounted) / total) % "rest";
return ret.str();
}

Expand Down Expand Up @@ -1584,37 +1582,36 @@ static DNSName nopFilter(const DNSName& name)
return name;
}

static string doGenericTopQueries(pleasequeryfunc_t func, std::function<DNSName(const DNSName&)> filter = nopFilter)
static string doGenericTopQueries(const pleasequeryfunc_t& func, const std::function<DNSName(const DNSName&)>& filter = nopFilter)
{
typedef pair<DNSName, uint16_t> query_t;
typedef map<query_t, int> counts_t;
counts_t counts;
vector<query_t> queries = broadcastAccFunction<vector<query_t>>(func);

unsigned int total = 0;
for (const query_t& q : queries) {
total++;
counts[pair(filter(q.first), q.second)]++;
using query_t = pair<DNSName, uint16_t>;
auto queries = broadcastAccFunction<vector<query_t>>(func);
const unsigned int total = queries.size();
if (total == 0) {
return "No qualifying data available\n";
}

typedef std::multimap<int, query_t> rcounts_t;
rcounts_t rcounts;
map<query_t, unsigned int> counts;
for (const auto& query : queries) {
counts[pair(filter(query.first), query.second)]++;
}

for (auto&& c : counts)
rcounts.emplace(-c.second, c.first);
std::multimap<unsigned int, query_t> rcounts;
for (const auto& count : counts) {
rcounts.emplace(count.second, count.first);
}

ostringstream ret;
ret << "Over last " << total << " entries:\n";
boost::format fmt("%.02f%%\t%s\n");
int limit = 0, accounted = 0;
if (total) {
for (rcounts_t::const_iterator i = rcounts.begin(); i != rcounts.end() && limit < 20; ++i, ++limit) {
ret << fmt % (-100.0 * i->first / total) % (i->second.first.toLogString() + "|" + DNSRecordContent::NumberToType(i->second.second));
accounted += -i->first;
}
ret << '\n'
<< fmt % (100.0 * (total - accounted) / total) % "rest";
}
unsigned int limit = 0;
unsigned int accounted = 0;
for (auto i = rcounts.rbegin(); i != rcounts.rend() && limit < 20; ++i, ++limit) {
omoerbeek marked this conversation as resolved.
Show resolved Hide resolved
ret << fmt % (100.0 * i->first / total) % (i->second.first.toLogString() + "|" + DNSRecordContent::NumberToType(i->second.second));
accounted += i->first;
}
ret << '\n'
<< fmt % (100.0 * (total - accounted) / total) % "rest";

return ret.str();
}
Expand Down
Loading