Complex Cases. Traffic Class
In dotMemory Unit, memory traffic is represented with the Traffic type. The object of the Traffic type is returned as a result of the Memory.GetTrafficFrom* method.
To slice and dice traffic data, you should use a lambda expression passed to the Where method of the Traffic type. The Where method also returns an instance of the Traffic type allowing you to build chains of Where methods.
The Traffic type allows you to get data about allocated and collected memory using two properties: AllocatedMemory and CollectedMemory. These properties, in turn, have the ObjectsCount and SizeInBytes properties that you can use in test assertions.
Example
For example, to make the assertion that the bar.Foo() method allocates no more than 1000 objects of the string type, write the following:
dotMemory Unit also provides alternative syntax for traffic queries. You can use the ==, &, and | logic operators to combine a number of queries. For example:
Another benefit of using the Traffic class is the ability to group traffic by objects type:
Traffic class
Traffic methods
Name | Description |
|---|---|
| Gets memory traffic data by a specific condition. The condition is defined by a Returns an instance of the |
| Gets memory traffic data by a specific condition. The condition is defined by a reusable query - an instance of the TrafficPredicateQuery type. For more information, refer to QueryBuilder. Returns an instance of the |
| Returns a collection of objects of the TypeTrafficInfo type. Each object represents traffic of objects of a particular type and carries info about the allocated and collected objects of that type. |
Traffic properties
Name | Type | Description |
|---|---|---|
|
| Data on allocated objects: object count and total size. |
|
| Data on collected objects: object count and total size. |
MemoryInfo struct
The MemoryInfo struct is used to get data about number of objects and their size.
MemoryInfo properties
Name | Type | Description |
|---|---|---|
|
| Total number of objects in the set. |
|
| Total size of objects in the set. |
TrafficProperty class
Filters traffic by a specific condition: type, interface, and other.
TrafficProperty properties
Name | Type | Description |
|---|---|---|
| Allows filtering traffic by object type. | |
| Allows filtering traffic by interface. | |
| Allows filtering traffic by namespace. | |
| Allows filtering traffic by assemblies. |
TypeTrafficInfo class
TypeTrafficInfo carries info about traffic of objects of the same type: allocated and collected objects. Instances of the TypeTrafficInfo class are a result of grouping the traffic via the GroupByType() method.
TypeTrafficInfo properties
Name | Type | Description |
|---|---|---|
|
| Data on allocated objects of the |
|
| Data on collected objects of the |
|
| Fully qualified name of the |
|
| Type of objects represented by this instance of the Can be |