Skip to content

Commit

Permalink
Added healthUpdateIntervalInSec in ModuleProps, To make HealtCallback…
Browse files Browse the repository at this point in the history
… Frequency configurable
  • Loading branch information
yashrajsapra committed Aug 1, 2024
1 parent 8635a48 commit 683c4af
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
9 changes: 7 additions & 2 deletions base/include/Module.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class ModuleProps
fIndexStrategyType = FIndexStrategy::FIndexStrategyType::AUTO_INCREMENT;
frameFetchStrategy = FrameFetchStrategy::PUSH;
enableHealthCallBack = false;
healthUpdateIntervalInSec = 5;
}

ModuleProps(float _fps)
Expand All @@ -59,6 +60,7 @@ class ModuleProps
fIndexStrategyType = FIndexStrategy::FIndexStrategyType::AUTO_INCREMENT;
frameFetchStrategy = FrameFetchStrategy::PUSH;
enableHealthCallBack = false;
healthUpdateIntervalInSec = 5;
}

ModuleProps(float _fps, size_t _qlen, bool _logHealth)
Expand All @@ -72,6 +74,7 @@ class ModuleProps
fIndexStrategyType = FIndexStrategy::FIndexStrategyType::AUTO_INCREMENT;
frameFetchStrategy = FrameFetchStrategy::PUSH;
enableHealthCallBack = false;
healthUpdateIntervalInSec = 5;
}

ModuleProps(FrameFetchStrategy _frameFetchStrategy)
Expand All @@ -85,6 +88,7 @@ class ModuleProps
fIndexStrategyType = FIndexStrategy::FIndexStrategyType::AUTO_INCREMENT;
frameFetchStrategy = _frameFetchStrategy;
enableHealthCallBack = false;
healthUpdateIntervalInSec = 5;
}

size_t getQLen()
Expand Down Expand Up @@ -125,8 +129,9 @@ class ModuleProps
FrameFetchStrategy frameFetchStrategy;
QuePushStrategy::QuePushStrategyType quePushStrategyType;
FIndexStrategy::FIndexStrategyType fIndexStrategyType;
bool enableHealthCallBack;

bool enableHealthCallBack; // ToEnable HealthCallback we need to set ModuleProps as true, Will get Callbacks only if ControlModule is there
int healthUpdateIntervalInSec; // Health Callback Interval Defined in Sec, if Value is
// set to 5, then it means after every 5 sec Control Module will receive health callback
private:
friend class Module;

Expand Down
8 changes: 5 additions & 3 deletions base/src/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@ class Module::Profiler
using sys_clock = std::chrono::system_clock;

public:
Profiler(string &id, bool _shouldLog, int _printFrequency,
Profiler(string &id, bool _shouldLog, int _printFrequency, int _healthUpdateIntervalInSec,
std::function<string()> _getPoolHealthRecord,
APHealthCallback _healthCallback)
: moduleId(id), shouldLog(_shouldLog), mPipelineFps(0),
printFrequency(_printFrequency), healthCallback(_healthCallback)
{
getPoolHealthRecord = _getPoolHealthRecord;
lastHealthCallbackTime = sys_clock::now();
mHealthUpdateIntervalInSec = _healthUpdateIntervalInSec;
}

void setShouldLog(bool _shouldLog) { shouldLog = _shouldLog; }
Expand Down Expand Up @@ -100,7 +101,7 @@ class Module::Profiler
auto elapsed = std::chrono::duration_cast<std::chrono::seconds>(
now - lastHealthCallbackTime)
.count();
if (elapsed >= 1)
if (elapsed >= mHealthUpdateIntervalInSec)
{
if (healthCallback)
{
Expand Down Expand Up @@ -137,6 +138,7 @@ class Module::Profiler

double mPipelineFps;
APHealthCallback healthCallback;
int mHealthUpdateIntervalInSec;
};

Module::Module(Kind nature, string name, ModuleProps _props)
Expand All @@ -156,7 +158,7 @@ Module::Module(Kind nature, string name, ModuleProps _props)
pacer = boost::shared_ptr<PaceMaker>(new PaceMaker(_props.fps));
auto tempId = getId();
mProfiler.reset(new Profiler(
tempId, _props.logHealth, _props.logHealthFrequency,
tempId, _props.logHealth, _props.logHealthFrequency, _props.healthUpdateIntervalInSec,
[&]() -> std::string
{
if (!mpFrameFactory.get())
Expand Down
7 changes: 4 additions & 3 deletions base/test/ImageEncodeCV_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ BOOST_AUTO_TEST_CASE(MONO_profile, *boost::unit_test::disabled())
BOOST_AUTO_TEST_CASE(RGB_profile, *boost::unit_test::disabled())
{
LoggerProps logprops;
logprops.logLevel = boost::log::trivial::severity_level::info;
logprops.logLevel = boost::log::trivial::severity_level::error;
Logger::initLogger(logprops);


Expand All @@ -162,6 +162,7 @@ BOOST_AUTO_TEST_CASE(RGB_profile, *boost::unit_test::disabled())

ImageEncoderCVProps encoderProps;
encoderProps.enableHealthCallBack = true;
encoderProps.healthUpdateIntervalInSec = 10;
auto m2 = boost::shared_ptr<ImageEncoderCV>(new ImageEncoderCV(encoderProps));
fileReader->setNext(m2);

Expand All @@ -172,8 +173,8 @@ BOOST_AUTO_TEST_CASE(RGB_profile, *boost::unit_test::disabled())
boost::shared_ptr<SimpleControlModule> mControl = boost::shared_ptr<SimpleControlModule>(new SimpleControlModule(controlProps));

StatSinkProps statSinkProps;
statSinkProps.logHealth = true;
statSinkProps.logHealthFrequency = 10;
// statSinkProps.logHealth = true;
// statSinkProps.logHealthFrequency = 10;
auto statSink = boost::shared_ptr<Module>(new StatSink(statSinkProps));
m2->setNext(statSink);

Expand Down

0 comments on commit 683c4af

Please sign in to comment.