Multiple Instances of a Covergroup

Hi,

I’m trying to create multiple instances of a covergroup.But everytime it is throwing some error as invalid type.

//pseudo code
class cov_monitor extends uvm_component;
int a;
int b;
covergroup common_cg with function sample(axi_transaction txn,bit mode);
option.per_instance =1;
CP1 : coverpoint txn.a{ 
       bins ...
       bins...
     }
endgoup

covergroup cov_cg with function sample(int mode);
option.per_instance =1;
CP2: : coverpoint   a{
     bins..
     bins..
       }
endgroup

function new(string name= "cov_monitor",uvm_component parent);
common_cg = new();//Recognized Properly and Bins are hitting
cov_cg cg_rx = new();//Throws Error
cov_cg cg_tx=new();
endfunction

function get_data();
//Sample Here
endfunction

endclass

*Error:
Error-[SE] Syntax error
Following verilog source has syntax error :
Token ‘cov_cg’ not recognized as a type. Please check
whether it is misspelled, not visible/valid in the current context, or not
properly imported/exported. This is occurring in a context where a variable
declaration, a statement, or a sequence expression is expected. Either the
declaration type is not known or this is incorrect syntax.
*

Can anyone help on this:)

In reply to ajithomas003:

SystemVerilog does not allow multiple instances of a class embedded covergroup. You must either declare the covergroup outside the class, or create a separate class with an embedded covergroup, and create multiple instance of that class.

In reply to dave_59:

Hi dave,

I have created covergroup inside the class. Created two instance for that class and samples the covergroup by using these two instance. But on seeing my coverage report I can able to see only one coverage. Can You please explain that exact method to use it

In reply to harimshr:

Are you using
option.per_instance =1;
?

If you already are using that option and only seeing one coverage item, you will have to check with your tool vendor’s documentation or support.

In reply to dave_59:

I have tried with that. In tool I could see instance hits same as score. I’m having doubt, that covergroup will be seen as two instance of it in tool or else only this instance will show it