diff --git a/lib/base/configobject.cpp b/lib/base/configobject.cpp index 144afa4a9..6f5973570 100644 --- a/lib/base/configobject.cpp +++ b/lib/base/configobject.cpp @@ -421,7 +421,7 @@ void ConfigObject::OnAllConfigLoaded() m_Zone = ctype->GetObject(zoneName); } -void ConfigObject::CreateChildObjects(const Type::Ptr& childType) +void ConfigObject::CreateChildObjects(const Type::Ptr& childType, TotalTimeSpentOnApplyMismatches& totalTimeSpentOnApplyMismatches) { /* Nothing to do here. */ } diff --git a/lib/base/configobject.hpp b/lib/base/configobject.hpp index 559636370..59628de4f 100644 --- a/lib/base/configobject.hpp +++ b/lib/base/configobject.hpp @@ -14,6 +14,7 @@ namespace icinga { class ConfigType; +class TotalTimeSpentOnApplyMismatches; /** * A dynamic object that can be instantiated from the configuration file. @@ -55,7 +56,7 @@ public: virtual void Resume(); virtual void OnConfigLoaded(); - virtual void CreateChildObjects(const Type::Ptr& childType); + virtual void CreateChildObjects(const Type::Ptr& childType, TotalTimeSpentOnApplyMismatches& totalTimeSpentOnApplyMismatches); virtual void OnAllConfigLoaded(); virtual void OnStateLoaded(); diff --git a/lib/config/applyrule.cpp b/lib/config/applyrule.cpp index 308321e60..2693b6fcc 100644 --- a/lib/config/applyrule.cpp +++ b/lib/config/applyrule.cpp @@ -197,3 +197,10 @@ void ApplyRule::CheckMatches(const ApplyRule::Ptr& rule, Type* sourceType, bool << sourceType->GetName() << "' does not match anywhere!"; } } + +double TotalTimeSpentOnApplyMismatches::AsSeconds() const +{ + using namespace std::chrono; + + return duration(steady_clock::duration(m_MonotonicTicks.load())).count(); +} diff --git a/lib/config/applyrule.hpp b/lib/config/applyrule.hpp index cbc79e34f..4b4d8f515 100644 --- a/lib/config/applyrule.hpp +++ b/lib/config/applyrule.hpp @@ -5,9 +5,11 @@ #include "config/i2-config.hpp" #include "config/expression.hpp" +#include "base/atomic.hpp" #include "base/debuginfo.hpp" #include "base/shared-object.hpp" #include "base/type.hpp" +#include #include namespace icinga @@ -110,6 +112,53 @@ private: bool ignoreOnError, DebugInfo di, Dictionary::Ptr scope); }; +class BenchmarkApplyRuleEvaluation; + +class TotalTimeSpentOnApplyMismatches +{ + friend BenchmarkApplyRuleEvaluation; + +public: + TotalTimeSpentOnApplyMismatches() = default; + TotalTimeSpentOnApplyMismatches(const TotalTimeSpentOnApplyMismatches&) = delete; + TotalTimeSpentOnApplyMismatches(TotalTimeSpentOnApplyMismatches&&) = delete; + TotalTimeSpentOnApplyMismatches& operator=(const TotalTimeSpentOnApplyMismatches&) = delete; + TotalTimeSpentOnApplyMismatches& operator=(TotalTimeSpentOnApplyMismatches&&) = delete; + + double AsSeconds() const; + +private: + Atomic m_MonotonicTicks {0}; +}; + +class BenchmarkApplyRuleEvaluation +{ +public: + inline BenchmarkApplyRuleEvaluation(TotalTimeSpentOnApplyMismatches& totalTimeSpentOnMismatches, const bool& ruleMatched) + : m_TotalTimeSpentOnMismatches(totalTimeSpentOnMismatches), + m_RuleMatched(ruleMatched), m_Start(std::chrono::steady_clock::now()) + { } + + BenchmarkApplyRuleEvaluation(const BenchmarkApplyRuleEvaluation&) = delete; + BenchmarkApplyRuleEvaluation(BenchmarkApplyRuleEvaluation&&) = delete; + BenchmarkApplyRuleEvaluation& operator=(const BenchmarkApplyRuleEvaluation&) = delete; + BenchmarkApplyRuleEvaluation& operator=(BenchmarkApplyRuleEvaluation&&) = delete; + + inline ~BenchmarkApplyRuleEvaluation() + { + if (!m_RuleMatched) { + m_TotalTimeSpentOnMismatches.m_MonotonicTicks.fetch_add( + (std::chrono::steady_clock::now() - m_Start).count() + ); + } + } + +private: + TotalTimeSpentOnApplyMismatches& m_TotalTimeSpentOnMismatches; + const bool& m_RuleMatched; + std::chrono::steady_clock::time_point m_Start; +}; + } #endif /* APPLYRULE_H */ diff --git a/lib/config/configitem.cpp b/lib/config/configitem.cpp index 488ab04d7..b1ce51f23 100644 --- a/lib/config/configitem.cpp +++ b/lib/config/configitem.cpp @@ -385,7 +385,10 @@ ConfigItem::Ptr ConfigItem::GetByTypeAndName(const Type::Ptr& type, const String return it2->second; } -bool ConfigItem::CommitNewItems(const ActivationContext::Ptr& context, WorkQueue& upq, std::vector& newItems) +bool ConfigItem::CommitNewItems( + const ActivationContext::Ptr& context, WorkQueue& upq, std::vector& newItems, + TotalTimeSpentOnApplyMismatches& totalTimeSpentOnApplyMismatches +) { typedef std::pair ItemPair; std::unordered_map> itemsByType; @@ -595,14 +598,14 @@ bool ConfigItem::CommitNewItems(const ActivationContext::Ptr& context, WorkQueue auto items (itemsByType.find(loadDep)); if (items != itemsByType.end()) { - upq.ParallelFor(items->second, [&type, ¬ified_items](const ItemPair& ip) { + upq.ParallelFor(items->second, [&type, ¬ified_items, &totalTimeSpentOnApplyMismatches](const ItemPair& ip) { const ConfigItem::Ptr& item = ip.first; if (!item->m_Object) return; ActivationScope ascope(item->m_ActivationContext); - item->m_Object->CreateChildObjects(type); + item->m_Object->CreateChildObjects(type, totalTimeSpentOnApplyMismatches); notified_items++; }); } @@ -620,7 +623,7 @@ bool ConfigItem::CommitNewItems(const ActivationContext::Ptr& context, WorkQueue return false; // Make sure to activate any additionally generated items - if (!CommitNewItems(context, upq, newItems)) + if (!CommitNewItems(context, upq, newItems, totalTimeSpentOnApplyMismatches)) return false; } } @@ -633,7 +636,9 @@ bool ConfigItem::CommitItems(const ActivationContext::Ptr& context, WorkQueue& u if (!silent) Log(LogInformation, "ConfigItem", "Committing config item(s)."); - if (!CommitNewItems(context, upq, newItems)) { + TotalTimeSpentOnApplyMismatches totalTimeSpentOnApplyMismatches; + + if (!CommitNewItems(context, upq, newItems, totalTimeSpentOnApplyMismatches)) { upq.ReportExceptions("config"); for (const ConfigItem::Ptr& item : newItems) { @@ -646,6 +651,10 @@ bool ConfigItem::CommitItems(const ActivationContext::Ptr& context, WorkQueue& u ApplyRule::CheckMatches(silent); if (!silent) { + Log(LogNotice, "ConfigItem") + << "Spent " << totalTimeSpentOnApplyMismatches.AsSeconds() + << " seconds on evaluating mismatching apply rules and parent objects."; + /* log stats for external parsers */ typedef std::map ItemCountMap; ItemCountMap itemCounts; diff --git a/lib/config/configitem.hpp b/lib/config/configitem.hpp index b99cd08e5..bdb464165 100644 --- a/lib/config/configitem.hpp +++ b/lib/config/configitem.hpp @@ -6,6 +6,7 @@ #include "config/i2-config.hpp" #include "config/expression.hpp" #include "config/activationcontext.hpp" +#include "config/applyrule.hpp" #include "base/configobject.hpp" #include "base/workqueue.hpp" @@ -98,7 +99,10 @@ private: ConfigObject::Ptr Commit(bool discard = true); - static bool CommitNewItems(const ActivationContext::Ptr& context, WorkQueue& upq, std::vector& newItems); + static bool CommitNewItems( + const ActivationContext::Ptr& context, WorkQueue& upq, std::vector& newItems, + TotalTimeSpentOnApplyMismatches& totalTimeSpentOnApplyMismatches + ); }; } diff --git a/lib/icinga/dependency-apply.cpp b/lib/icinga/dependency-apply.cpp index 6b063f1a9..88a6d56fb 100644 --- a/lib/icinga/dependency-apply.cpp +++ b/lib/icinga/dependency-apply.cpp @@ -62,8 +62,11 @@ bool Dependency::EvaluateApplyRuleInstance(const Checkable::Ptr& checkable, cons return true; } -bool Dependency::EvaluateApplyRule(const Checkable::Ptr& checkable, const ApplyRule& rule, bool skipFilter) +bool Dependency::EvaluateApplyRule(const Checkable::Ptr& checkable, const ApplyRule& rule, TotalTimeSpentOnApplyMismatches& totalTimeSpentOnApplyMismatches, bool skipFilter) { + bool match = false; + BenchmarkApplyRuleEvaluation bare (totalTimeSpentOnApplyMismatches, match); + auto& di (rule.GetDebugInfo()); std::ostringstream msgbuf; @@ -85,8 +88,6 @@ bool Dependency::EvaluateApplyRule(const Checkable::Ptr& checkable, const ApplyR frame.Locals = checkable->GetFrozenLocalsForApply(); } - bool match = false; - if (rule.GetFTerm()) { Value vinstances; @@ -135,32 +136,32 @@ bool Dependency::EvaluateApplyRule(const Checkable::Ptr& checkable, const ApplyR return match; } -void Dependency::EvaluateApplyRules(const Host::Ptr& host) +void Dependency::EvaluateApplyRules(const Host::Ptr& host, TotalTimeSpentOnApplyMismatches& totalTimeSpentOnApplyMismatches) { CONTEXT("Evaluating 'apply' rules for host '" + host->GetName() + "'"); for (auto& rule : ApplyRule::GetRules(Dependency::TypeInstance, Host::TypeInstance)) { - if (EvaluateApplyRule(host, *rule)) + if (EvaluateApplyRule(host, *rule, totalTimeSpentOnApplyMismatches)) rule->AddMatch(); } for (auto& rule : ApplyRule::GetTargetedHostRules(Dependency::TypeInstance, host->GetName())) { - if (EvaluateApplyRule(host, *rule, true)) + if (EvaluateApplyRule(host, *rule, totalTimeSpentOnApplyMismatches, true)) rule->AddMatch(); } } -void Dependency::EvaluateApplyRules(const Service::Ptr& service) +void Dependency::EvaluateApplyRules(const Service::Ptr& service, TotalTimeSpentOnApplyMismatches& totalTimeSpentOnApplyMismatches) { CONTEXT("Evaluating 'apply' rules for service '" + service->GetName() + "'"); for (auto& rule : ApplyRule::GetRules(Dependency::TypeInstance, Service::TypeInstance)) { - if (EvaluateApplyRule(service, *rule)) + if (EvaluateApplyRule(service, *rule, totalTimeSpentOnApplyMismatches)) rule->AddMatch(); } for (auto& rule : ApplyRule::GetTargetedServiceRules(Dependency::TypeInstance, service->GetHost()->GetName(), service->GetShortName())) { - if (EvaluateApplyRule(service, *rule, true)) + if (EvaluateApplyRule(service, *rule, totalTimeSpentOnApplyMismatches, true)) rule->AddMatch(); } } diff --git a/lib/icinga/dependency.hpp b/lib/icinga/dependency.hpp index 75424cb89..d61ec574e 100644 --- a/lib/icinga/dependency.hpp +++ b/lib/icinga/dependency.hpp @@ -34,8 +34,8 @@ public: void ValidateStates(const Lazy& lvalue, const ValidationUtils& utils) override; - static void EvaluateApplyRules(const intrusive_ptr& host); - static void EvaluateApplyRules(const intrusive_ptr& service); + static void EvaluateApplyRules(const intrusive_ptr& host, TotalTimeSpentOnApplyMismatches& totalTimeSpentOnApplyMismatches); + static void EvaluateApplyRules(const intrusive_ptr& service, TotalTimeSpentOnApplyMismatches& totalTimeSpentOnApplyMismatches); /* Note: Only use them for unit test mocks. Prefer OnConfigLoaded(). */ void SetParent(intrusive_ptr parent); @@ -51,7 +51,11 @@ private: Checkable::Ptr m_Child; static bool EvaluateApplyRuleInstance(const Checkable::Ptr& checkable, const String& name, ScriptFrame& frame, const ApplyRule& rule, bool skipFilter); - static bool EvaluateApplyRule(const Checkable::Ptr& checkable, const ApplyRule& rule, bool skipFilter = false); + + static bool EvaluateApplyRule( + const Checkable::Ptr& checkable, const ApplyRule& rule, + TotalTimeSpentOnApplyMismatches& totalTimeSpentOnApplyMismatches, bool skipFilter = false + ); }; } diff --git a/lib/icinga/host.cpp b/lib/icinga/host.cpp index 2d251fbb0..6199eda61 100644 --- a/lib/icinga/host.cpp +++ b/lib/icinga/host.cpp @@ -47,19 +47,19 @@ void Host::OnAllConfigLoaded() } } -void Host::CreateChildObjects(const Type::Ptr& childType) +void Host::CreateChildObjects(const Type::Ptr& childType, TotalTimeSpentOnApplyMismatches& totalTimeSpentOnApplyMismatches) { if (childType == ScheduledDowntime::TypeInstance) - ScheduledDowntime::EvaluateApplyRules(this); + ScheduledDowntime::EvaluateApplyRules(this, totalTimeSpentOnApplyMismatches); if (childType == Notification::TypeInstance) - Notification::EvaluateApplyRules(this); + Notification::EvaluateApplyRules(this, totalTimeSpentOnApplyMismatches); if (childType == Dependency::TypeInstance) - Dependency::EvaluateApplyRules(this); + Dependency::EvaluateApplyRules(this, totalTimeSpentOnApplyMismatches); if (childType == Service::TypeInstance) - Service::EvaluateApplyRules(this); + Service::EvaluateApplyRules(this, totalTimeSpentOnApplyMismatches); } void Host::Stop(bool runtimeRemoved) diff --git a/lib/icinga/host.hpp b/lib/icinga/host.hpp index 16eed5470..efc2ef0c6 100644 --- a/lib/icinga/host.hpp +++ b/lib/icinga/host.hpp @@ -55,7 +55,7 @@ public: protected: void Stop(bool runtimeRemoved) override; - void CreateChildObjects(const Type::Ptr& childType) override; + void CreateChildObjects(const Type::Ptr& childType, TotalTimeSpentOnApplyMismatches& totalTimeSpentOnApplyMismatches) override; Dictionary::Ptr MakeLocalsForApply() override; diff --git a/lib/icinga/notification-apply.cpp b/lib/icinga/notification-apply.cpp index 54e162dc4..af38e3570 100644 --- a/lib/icinga/notification-apply.cpp +++ b/lib/icinga/notification-apply.cpp @@ -61,8 +61,14 @@ bool Notification::EvaluateApplyRuleInstance(const Checkable::Ptr& checkable, co return true; } -bool Notification::EvaluateApplyRule(const Checkable::Ptr& checkable, const ApplyRule& rule, bool skipFilter) +bool Notification::EvaluateApplyRule( + const Checkable::Ptr& checkable, const ApplyRule& rule, + TotalTimeSpentOnApplyMismatches& totalTimeSpentOnApplyMismatches, bool skipFilter +) { + bool match = false; + BenchmarkApplyRuleEvaluation bare (totalTimeSpentOnApplyMismatches, match); + auto& di (rule.GetDebugInfo()); std::ostringstream msgbuf; @@ -84,8 +90,6 @@ bool Notification::EvaluateApplyRule(const Checkable::Ptr& checkable, const Appl frame.Locals = checkable->GetFrozenLocalsForApply(); } - bool match = false; - if (rule.GetFTerm()) { Value vinstances; @@ -134,33 +138,33 @@ bool Notification::EvaluateApplyRule(const Checkable::Ptr& checkable, const Appl return match; } -void Notification::EvaluateApplyRules(const Host::Ptr& host) +void Notification::EvaluateApplyRules(const Host::Ptr& host, TotalTimeSpentOnApplyMismatches& totalTimeSpentOnApplyMismatches) { CONTEXT("Evaluating 'apply' rules for host '" + host->GetName() + "'"); for (auto& rule : ApplyRule::GetRules(Notification::TypeInstance, Host::TypeInstance)) { - if (EvaluateApplyRule(host, *rule)) + if (EvaluateApplyRule(host, *rule, totalTimeSpentOnApplyMismatches)) rule->AddMatch(); } for (auto& rule : ApplyRule::GetTargetedHostRules(Notification::TypeInstance, host->GetName())) { - if (EvaluateApplyRule(host, *rule, true)) + if (EvaluateApplyRule(host, *rule, totalTimeSpentOnApplyMismatches, true)) rule->AddMatch(); } } -void Notification::EvaluateApplyRules(const Service::Ptr& service) +void Notification::EvaluateApplyRules(const Service::Ptr& service, TotalTimeSpentOnApplyMismatches& totalTimeSpentOnApplyMismatches) { CONTEXT("Evaluating 'apply' rules for service '" + service->GetName() + "'"); for (auto& rule : ApplyRule::GetRules(Notification::TypeInstance, Service::TypeInstance)) { - if (EvaluateApplyRule(service, *rule)) + if (EvaluateApplyRule(service, *rule, totalTimeSpentOnApplyMismatches)) rule->AddMatch(); } for (auto& rule : ApplyRule::GetTargetedServiceRules(Notification::TypeInstance, service->GetHost()->GetName(), service->GetShortName())) { - if (EvaluateApplyRule(service, *rule, true)) + if (EvaluateApplyRule(service, *rule, totalTimeSpentOnApplyMismatches, true)) rule->AddMatch(); } } diff --git a/lib/icinga/notification.hpp b/lib/icinga/notification.hpp index ec9164f19..7702311af 100644 --- a/lib/icinga/notification.hpp +++ b/lib/icinga/notification.hpp @@ -99,8 +99,8 @@ public: void ValidateTypes(const Lazy& lvalue, const ValidationUtils& utils) override; void ValidateTimes(const Lazy& lvalue, const ValidationUtils& utils) override; - static void EvaluateApplyRules(const intrusive_ptr& host); - static void EvaluateApplyRules(const intrusive_ptr& service); + static void EvaluateApplyRules(const intrusive_ptr& host, TotalTimeSpentOnApplyMismatches& totalTimeSpentOnApplyMismatches); + static void EvaluateApplyRules(const intrusive_ptr& service, TotalTimeSpentOnApplyMismatches& totalTimeSpentOnApplyMismatches); static const std::map& GetStateFilterMap(); static const std::map& GetTypeFilterMap(); @@ -119,7 +119,11 @@ private: void ExecuteNotificationHelper(NotificationType type, const User::Ptr& user, const CheckResult::Ptr& cr, bool force, const String& author = "", const String& text = ""); static bool EvaluateApplyRuleInstance(const intrusive_ptr& checkable, const String& name, ScriptFrame& frame, const ApplyRule& rule, bool skipFilter); - static bool EvaluateApplyRule(const intrusive_ptr& checkable, const ApplyRule& rule, bool skipFilter = false); + + static bool EvaluateApplyRule( + const intrusive_ptr& checkable, const ApplyRule& rule, + TotalTimeSpentOnApplyMismatches& totalTimeSpentOnApplyMismatches, bool skipFilter = false + ); static std::map m_StateFilterMap; static std::map m_TypeFilterMap; diff --git a/lib/icinga/scheduleddowntime-apply.cpp b/lib/icinga/scheduleddowntime-apply.cpp index 4a3256988..5f4c07d60 100644 --- a/lib/icinga/scheduleddowntime-apply.cpp +++ b/lib/icinga/scheduleddowntime-apply.cpp @@ -60,8 +60,14 @@ bool ScheduledDowntime::EvaluateApplyRuleInstance(const Checkable::Ptr& checkabl return true; } -bool ScheduledDowntime::EvaluateApplyRule(const Checkable::Ptr& checkable, const ApplyRule& rule, bool skipFilter) +bool ScheduledDowntime::EvaluateApplyRule( + const Checkable::Ptr& checkable, const ApplyRule& rule, + TotalTimeSpentOnApplyMismatches& totalTimeSpentOnApplyMismatches, bool skipFilter +) { + bool match = false; + BenchmarkApplyRuleEvaluation bare (totalTimeSpentOnApplyMismatches, match); + auto& di (rule.GetDebugInfo()); std::ostringstream msgbuf; @@ -83,8 +89,6 @@ bool ScheduledDowntime::EvaluateApplyRule(const Checkable::Ptr& checkable, const frame.Locals = checkable->GetFrozenLocalsForApply(); } - bool match = false; - if (rule.GetFTerm()) { Value vinstances; @@ -133,32 +137,32 @@ bool ScheduledDowntime::EvaluateApplyRule(const Checkable::Ptr& checkable, const return match; } -void ScheduledDowntime::EvaluateApplyRules(const Host::Ptr& host) +void ScheduledDowntime::EvaluateApplyRules(const Host::Ptr& host, TotalTimeSpentOnApplyMismatches& totalTimeSpentOnApplyMismatches) { CONTEXT("Evaluating 'apply' rules for host '" + host->GetName() + "'"); for (auto& rule : ApplyRule::GetRules(ScheduledDowntime::TypeInstance, Host::TypeInstance)) { - if (EvaluateApplyRule(host, *rule)) + if (EvaluateApplyRule(host, *rule, totalTimeSpentOnApplyMismatches)) rule->AddMatch(); } for (auto& rule : ApplyRule::GetTargetedHostRules(ScheduledDowntime::TypeInstance, host->GetName())) { - if (EvaluateApplyRule(host, *rule, true)) + if (EvaluateApplyRule(host, *rule, totalTimeSpentOnApplyMismatches, true)) rule->AddMatch(); } } -void ScheduledDowntime::EvaluateApplyRules(const Service::Ptr& service) +void ScheduledDowntime::EvaluateApplyRules(const Service::Ptr& service, TotalTimeSpentOnApplyMismatches& totalTimeSpentOnApplyMismatches) { CONTEXT("Evaluating 'apply' rules for service '" + service->GetName() + "'"); for (auto& rule : ApplyRule::GetRules(ScheduledDowntime::TypeInstance, Service::TypeInstance)) { - if (EvaluateApplyRule(service, *rule)) + if (EvaluateApplyRule(service, *rule, totalTimeSpentOnApplyMismatches)) rule->AddMatch(); } for (auto& rule : ApplyRule::GetTargetedServiceRules(ScheduledDowntime::TypeInstance, service->GetHost()->GetName(), service->GetShortName())) { - if (EvaluateApplyRule(service, *rule, true)) + if (EvaluateApplyRule(service, *rule, totalTimeSpentOnApplyMismatches, true)) rule->AddMatch(); } } diff --git a/lib/icinga/scheduleddowntime.hpp b/lib/icinga/scheduleddowntime.hpp index e70123616..d86a45b54 100644 --- a/lib/icinga/scheduleddowntime.hpp +++ b/lib/icinga/scheduleddowntime.hpp @@ -29,8 +29,8 @@ public: Checkable::Ptr GetCheckable() const; - static void EvaluateApplyRules(const intrusive_ptr& host); - static void EvaluateApplyRules(const intrusive_ptr& service); + static void EvaluateApplyRules(const intrusive_ptr& host, TotalTimeSpentOnApplyMismatches& totalTimeSpentOnApplyMismatches); + static void EvaluateApplyRules(const intrusive_ptr& service, TotalTimeSpentOnApplyMismatches& totalTimeSpentOnApplyMismatches); static bool AllConfigIsLoaded(); void ValidateRanges(const Lazy& lvalue, const ValidationUtils& utils) override; @@ -52,7 +52,11 @@ private: static std::atomic m_AllConfigLoaded; static bool EvaluateApplyRuleInstance(const Checkable::Ptr& checkable, const String& name, ScriptFrame& frame, const ApplyRule& rule, bool skipFilter); - static bool EvaluateApplyRule(const Checkable::Ptr& checkable, const ApplyRule& rule, bool skipFilter = false); + + static bool EvaluateApplyRule( + const Checkable::Ptr& checkable, const ApplyRule& rule, + TotalTimeSpentOnApplyMismatches& totalTimeSpentOnApplyMismatches, bool skipFilter = false + ); }; } diff --git a/lib/icinga/service-apply.cpp b/lib/icinga/service-apply.cpp index 06d88f1d3..ec400e69f 100644 --- a/lib/icinga/service-apply.cpp +++ b/lib/icinga/service-apply.cpp @@ -55,8 +55,14 @@ bool Service::EvaluateApplyRuleInstance(const Host::Ptr& host, const String& nam return true; } -bool Service::EvaluateApplyRule(const Host::Ptr& host, const ApplyRule& rule, bool skipFilter) +bool Service::EvaluateApplyRule( + const Host::Ptr& host, const ApplyRule& rule, + TotalTimeSpentOnApplyMismatches& totalTimeSpentOnApplyMismatches, bool skipFilter +) { + bool match = false; + BenchmarkApplyRuleEvaluation bare (totalTimeSpentOnApplyMismatches, match); + auto& di (rule.GetDebugInfo()); std::ostringstream msgbuf; @@ -78,8 +84,6 @@ bool Service::EvaluateApplyRule(const Host::Ptr& host, const ApplyRule& rule, bo frame.Locals = host->GetFrozenLocalsForApply(); } - bool match = false; - if (rule.GetFTerm()) { Value vinstances; @@ -130,17 +134,17 @@ bool Service::EvaluateApplyRule(const Host::Ptr& host, const ApplyRule& rule, bo return match; } -void Service::EvaluateApplyRules(const Host::Ptr& host) +void Service::EvaluateApplyRules(const Host::Ptr& host, TotalTimeSpentOnApplyMismatches& totalTimeSpentOnApplyMismatches) { CONTEXT("Evaluating 'apply' rules for host '" + host->GetName() + "'"); for (auto& rule : ApplyRule::GetRules(Service::TypeInstance, Host::TypeInstance)) { - if (EvaluateApplyRule(host, *rule)) + if (EvaluateApplyRule(host, *rule, totalTimeSpentOnApplyMismatches)) rule->AddMatch(); } for (auto& rule : ApplyRule::GetTargetedHostRules(Service::TypeInstance, host->GetName())) { - if (EvaluateApplyRule(host, *rule, true)) + if (EvaluateApplyRule(host, *rule, totalTimeSpentOnApplyMismatches, true)) rule->AddMatch(); } } diff --git a/lib/icinga/service.cpp b/lib/icinga/service.cpp index edea88597..42a7fbb91 100644 --- a/lib/icinga/service.cpp +++ b/lib/icinga/service.cpp @@ -74,16 +74,16 @@ void Service::OnAllConfigLoaded() } } -void Service::CreateChildObjects(const Type::Ptr& childType) +void Service::CreateChildObjects(const Type::Ptr& childType, TotalTimeSpentOnApplyMismatches& totalTimeSpentOnApplyMismatches) { if (childType == ScheduledDowntime::TypeInstance) - ScheduledDowntime::EvaluateApplyRules(this); + ScheduledDowntime::EvaluateApplyRules(this, totalTimeSpentOnApplyMismatches); if (childType == Notification::TypeInstance) - Notification::EvaluateApplyRules(this); + Notification::EvaluateApplyRules(this, totalTimeSpentOnApplyMismatches); if (childType == Dependency::TypeInstance) - Dependency::EvaluateApplyRules(this); + Dependency::EvaluateApplyRules(this, totalTimeSpentOnApplyMismatches); } Service::Ptr Service::GetByNamePair(const String& hostName, const String& serviceName) diff --git a/lib/icinga/service.hpp b/lib/icinga/service.hpp index 9e430985f..3a18dbf70 100644 --- a/lib/icinga/service.hpp +++ b/lib/icinga/service.hpp @@ -42,14 +42,14 @@ public: static StateType StateTypeFromString(const String& state); static String StateTypeToString(StateType state); - static void EvaluateApplyRules(const Host::Ptr& host); + static void EvaluateApplyRules(const Host::Ptr& host, TotalTimeSpentOnApplyMismatches& totalTimeSpentOnApplyMismatches); void OnAllConfigLoaded() override; static boost::signals2::signal OnHostProblemChanged; protected: - void CreateChildObjects(const Type::Ptr& childType) override; + void CreateChildObjects(const Type::Ptr& childType, TotalTimeSpentOnApplyMismatches& totalTimeSpentOnApplyMismatches) override; Dictionary::Ptr MakeLocalsForApply() override; @@ -57,7 +57,11 @@ private: Host::Ptr m_Host; static bool EvaluateApplyRuleInstance(const Host::Ptr& host, const String& name, ScriptFrame& frame, const ApplyRule& rule, bool skipFilter); - static bool EvaluateApplyRule(const Host::Ptr& host, const ApplyRule& rule, bool skipFilter = false); + + static bool EvaluateApplyRule( + const Host::Ptr& host, const ApplyRule& rule, + TotalTimeSpentOnApplyMismatches& totalTimeSpentOnApplyMismatches, bool skipFilter = false + ); }; std::pair GetHostService(const Checkable::Ptr& checkable);