The above example defines a covergroup named "cg". This covergroup will be automatically sampled each time there is a posedge on "clk" signal.
covergroup cg;
...
...
...
endgroup
cg cg_inst = new;
initial // or task or function or always block
begin ...
...
cg_inst.sample();
...
...
end
Sampling can also be done by calling explicitly calling .sample() method in procedural code. This is used when coverage sampling is required based on some calculations rather than events.