Skip to content

Commit

Permalink
use bitset operator[] to reduce overhead
Browse files Browse the repository at this point in the history
  • Loading branch information
Leonardo Parente committed Feb 11, 2022
1 parent b354c61 commit a6b8b83
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/AbstractMetricsManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ class AbstractMetricsManager
std::unique_ptr<MetricsBucketClass> expiring_bucket;
// this changes the live bucket
_metric_buckets.emplace_front(std::make_unique<MetricsBucketClass>());
_metric_buckets[0]->configure_groups(_groups);
_metric_buckets[0]->set_start_tstamp(stamp);
if (_recorded_stream) {
_metric_buckets[0]->set_recorded_stream();
Expand Down
1 change: 1 addition & 0 deletions src/Policies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ std::vector<Policy *> PolicyManager::load(const YAML::Node &policy_yaml)
if (!module.IsMap()) {
throw PolicyException("expecting Handler configuration map");
}

if (!module["type"] || !module["type"].IsScalar()) {
throw PolicyException("missing or invalid stream handler type at key 'type'");
}
Expand Down
12 changes: 6 additions & 6 deletions src/handlers/dns/DnsStreamHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
namespace visor::handler::dns {

DnsStreamHandler::DnsStreamHandler(const std::string &name, InputStream *stream, const Configurable *window_config, StreamHandler *handler)
: StreamMetricsHandler(name, window_config)
: visor::StreamMetricsHandler<DnsMetricsManager>(name, window_config)
{
if (handler) {
throw StreamHandlerException(fmt::format("DnsStreamHandler: unsupported upstream chained stream handler {}", handler->name()));
Expand Down Expand Up @@ -282,12 +282,12 @@ static inline bool endsWith(std::string_view str, std::string_view suffix)
}
bool DnsStreamHandler::_filtering(DnsLayer &payload, [[maybe_unused]] PacketDirection dir, [[maybe_unused]] pcpp::ProtocolType l3, [[maybe_unused]] pcpp::ProtocolType l4, [[maybe_unused]] uint16_t port, timespec stamp)
{
if (_f_enabled.test(Filters::ExcludingRCode) && payload.getDnsHeader()->responseCode == _f_rcode) {
if (_f_enabled[Filters::ExcludingRCode] && payload.getDnsHeader()->responseCode == _f_rcode) {
goto will_filter;
} else if (_f_enabled.test(Filters::OnlyRCode) && payload.getDnsHeader()->responseCode != _f_rcode) {
} else if (_f_enabled[Filters::OnlyRCode] && payload.getDnsHeader()->responseCode != _f_rcode) {
goto will_filter;
}
if (_f_enabled.test(Filters::OnlyQNameSuffix)) {
if (_f_enabled[Filters::OnlyQNameSuffix]) {
if (!payload.parseResources(true) || payload.getFirstQuery() == nullptr) {
goto will_filter;
}
Expand Down Expand Up @@ -591,7 +591,7 @@ void DnsMetricsBucket::process_dns_layer(bool deep, DnsLayer &payload, bool dnst
_dns_qnameCard.update(name);
_dns_topQType.update(query->getDnsType());

if (_groups->test(group::DnsMetrics::TopQnames)) {
if ((*_groups)[group::DnsMetrics::TopQnames]) {
if (payload.getDnsHeader()->queryOrResponse == response) {
switch (payload.getDnsHeader()->responseCode) {
case SrvFail:
Expand Down Expand Up @@ -725,7 +725,7 @@ void DnsMetricsManager::process_dns_layer(DnsLayer &payload, PacketDirection dir
// process in the "live" bucket. this will parse the resources if we are deep sampling
live_bucket()->process_dns_layer(_deep_sampling_now, payload, false, l3, l4, port);

if (_groups->test(group::DnsMetrics::DnsTransactions)) {
if ((*_groups)[group::DnsMetrics::DnsTransactions]) {
// handle dns transactions (query/response pairs)
if (payload.getDnsHeader()->queryOrResponse == QR::response) {
auto xact = _qr_pair_manager.maybe_end_transaction(flowkey, payload.getDnsHeader()->transactionID, stamp);
Expand Down
3 changes: 0 additions & 3 deletions src/tests/test_metrics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ using namespace visor;
class TestMetricsBucket : public AbstractMetricsBucket
{
public:
TestMetricsBucket()
{
}
void specialized_merge([[maybe_unused]] const AbstractMetricsBucket &other)
{
}
Expand Down

0 comments on commit a6b8b83

Please sign in to comment.