Check Memory Traffic
Check memory traffic
When you need just to evaluate the amount of memory allocated in a test, you can use the AssertTraffic attribute.
The attribute is quite flexible and allows you to filter traffic data by objects' type, interface, or namespace.
Note that you can add any number of AssertTraffic
attributes in case you want to filter memory traffic by a number of conditions.
Filter memory traffic by complex conditions
In more complex scenarios (e.g. when you need to check traffic on a specific time interval), you should use the Traffic type.
To mark time intervals where memory traffic can be analyzed, you should use checkpoints created by dotMemory.Check (as you probably guessed, this method simply takes memory snapshot).
The checkpoint that defines the starting point of the interval is passed to the
GetTrafficFrom
method.For example, this line asserts that the total size of objects implementing the
IFoo
interface created on the interval betweenmemoryCheckPoint1
andmemoryCheckPoint2
is less than 1000 bytes.You can use any checkpoint created earlier as a base for analysis. Thus, this line gets traffic data between the current
dotMemory.Check
call andmemoryCheckPoint2
.
dotMemory Unit also provides alternative syntax for traffic queries. You can use the ==
, &
, and |
logic operators to combine a number of queries. For example: