Heart beats are often required to show that an application is running, or in the case of a distributed/multi-processor application, to show that each processor is running. This can be achieved simply by defining a Heartbeat Thread which is definitive on each node. The thread then simple sleeps for a given time then signals a semaphore.
A more advanced solution is to interrogate the system (Platform dependant) to extract process/processor CPU loading, memory usage etc. This could be done every time the Thread wakes, and the results written to a common (non-definitive) store. In a multicore processor, the information can sometimes be extracted on a per-core basis, which could be reported on either a per-core or per-processor basis.
Uns MyCircuit_HeartbeatThrdElem::Process()
{
// TODO: Add custom process code
Uns count = 0;
while ( TRUE )
{
// wait a while
ClpSleep( HEARTBEAT_INTERVAL_MS );
// open output store
this->Aux1_HeartbeatTst1Cxn().OpenWrite();
this->Aux1_HeartbeatTst1Rec().Construct();
// access store data
ProcLoad& load = this->Aux1_HeartbeatTst1Rec().Data();
// identify where the heartbeat comes from
load.ProcId() = ClpThisSlaveId();
// set the heartbeat counter
load.Count() = ++count;
// get the process cpu/memory load info
Parent().mProcLoadDev.GetProcess( load.ProcessInfo() );
// get the system cpu/memory load info
Parent().mProcLoadDev.GetSystem( load.SystemInfo() );
// close the store
this->Aux1_HeartbeatTst1Cxn().Close();
}
return TRUE;
}
This part of the code can be run on any number of slaves/master (slave id = 0) processors. It is only the Display callback function that needs to worry about how many slaves are actually running, but this is usually a trivial problem for graphics (just add an extra column of output and scale the data to fit the available space). Heartbeats are often shown as alternating colours; when the colours stop changing the process has stopped. Or alternatively, the Masters' heartbeat can be used as a reset to clear the display, if a slave has not reported in for a while.