Heart Beat Monitor

In reply to SANJAIKUMAR:

Hello, SANJAIKUMAR.
It does not work as you expect and honestly not as I expected.
Heartbeat monitor could watch for certain objection that raised (or dropped) from one and the only uvm_component. Components that could be passed through methods set_heartbeat() or add() do not play any role.
In your code example watched uvm_component is uvm_test_top with the objection that raised (or dropped) in run_phase. This set has determined by the choice of arguments for uvm_heartbeat`s constructor.

One of the ways to make uvm_heartbeat useful for your example is to raise (or drop) key objections on behalf of one special uvm_component. And set this uvm_component as context for uvm_heartbeat.
For example:


class my_env extends uvm_env;
  // .....................................
  task run_phase(uvm_phase phase);
    for(int i = 0; i < 20; i++) begin
      phase.raise_objection(this);
      #10;
      phase.drop_objection(this);
    end
  endtask
  // .....................................
endclass
class my_test extends uvm_test;
  // .....................................
  task run_phase(uvm_phase phase);
    phase.raise_objection(env);
    #200;
    phase.drop_objection(env);
  endtask
  function void heartbeat(uvm_phase phase);
    uvm_callbacks_objection cbs_objection;
    uvm_phase got_phase = phase.find_by_name("run", 0);
    // .....................................
    if(!$cast(cbs_objection, got_run_phase.get_objection()))
      `uvm_fatal(get_full_name(), "Cast failed.")
    heartbeat = new(.name("activity_heartbeat"), .cntxt(env), .objection(cbs_objection));
    // .....................................
  endfunction
endclass

Best regards, Maksim.