Is it possible to profile memory usage of unit tests?
Asked Answered
C

4

18

I'm looking at building some unit tests to ascertain if resources are leaking (or not) using the unit testing framework that comes with Visual Studio.

At present, I'm evaluating the latest version of ANTS Profiler, but I can't quite work out if it allows me to force a snapshot from code (so that I can take a snapshot, run a unit test a few hundred times, force a garbage collection, and take another snapshot, and save the results out for later analysis).

Is this possible to do with ANTS/Visual Studio or should I be exploring options with other profilers?

Coyle answered 28/5, 2010 at 15:11 Comment(0)
G
2

JetBrains dotTrace/dotMemory and ReSharper have better integration on unit testing and profiling.

http://www.jetbrains.com/profiler/index.html

Not sure if ANTS has such integration, but you can consult Red Gate presales, right?

http://www.red-gate.com/about/all_testimonials.htm

They do expect you to call them for more information.

Garvy answered 29/5, 2010 at 2:23 Comment(7)
Turns out it's due to be supported in "a future version"Coyle
@RowlandShaw Do you know if this is supported now?Doornail
@SimonFischer not that I'm aware ofCoyle
I'm looking for command line parameters for version 7. I've tried the docs I could find online for version 4 but they don;t work in version 7.Konrad
dotTrace is a performance profiler. dotMemory is a memory profiler and dotMemory Unit is a framework specially designed to check your code for all kinds of memory issues with unit or integration tests.Buhler
@Ed.ward, dotMemory was part of dotTrace a few years ago, so not surprising to see my original answer only mentioned dotTrace. Just edited.Garvy
@LexLi It was dotTrace Memory, not dotMemory, but it is confusing I know :) Another important part of my comment was about dotMemory Unit framework, it is just released on the previous week, so it is not much knowledge about it in the web. dotMemory itself does not have an integration with R# unit test runner, as dotTrace has. So link should be jetbrains.com/dotmemory/unit link provided by you leads to the page of performance profiler. Hope TS was not confused.Buhler
M
6

Have you seen dotmemory from JetBrains?

dotMemory Unit is a unit testing framework which allows you to write tests that check your code for all kinds of memory issues.

For example:

When you need to simply evaluate the amount of memory allocated in a test, you can use the AssertTraffic attribute. This flexible attribute allows you to filter traffic data by object type, interface, or namespace.

Mcilroy answered 16/4, 2015 at 13:26 Comment(0)
G
2

JetBrains dotTrace/dotMemory and ReSharper have better integration on unit testing and profiling.

http://www.jetbrains.com/profiler/index.html

Not sure if ANTS has such integration, but you can consult Red Gate presales, right?

http://www.red-gate.com/about/all_testimonials.htm

They do expect you to call them for more information.

Garvy answered 29/5, 2010 at 2:23 Comment(7)
Turns out it's due to be supported in "a future version"Coyle
@RowlandShaw Do you know if this is supported now?Doornail
@SimonFischer not that I'm aware ofCoyle
I'm looking for command line parameters for version 7. I've tried the docs I could find online for version 4 but they don;t work in version 7.Konrad
dotTrace is a performance profiler. dotMemory is a memory profiler and dotMemory Unit is a framework specially designed to check your code for all kinds of memory issues with unit or integration tests.Buhler
@Ed.ward, dotMemory was part of dotTrace a few years ago, so not surprising to see my original answer only mentioned dotTrace. Just edited.Garvy
@LexLi It was dotTrace Memory, not dotMemory, but it is confusing I know :) Another important part of my comment was about dotMemory Unit framework, it is just released on the previous week, so it is not much knowledge about it in the web. dotMemory itself does not have an integration with R# unit test runner, as dotTrace has. So link should be jetbrains.com/dotmemory/unit link provided by you leads to the page of performance profiler. Hope TS was not confused.Buhler
O
1

I use ANTS profiler, and what I find most convenient is to attach the profiler to the running test process, that may be different depending on what testing framework you are using. For example, I use Resharper and the process image name is called something like:

JetBrains.ReSharper.TaskRunner.CLR...

Oreste answered 3/10, 2016 at 17:3 Comment(0)
S
0

For future readers, worth mentioning that you can force snapshots from within your code with ANTS Memory Profiler. You need to reference

RedGate.MemoryProfiler.Snapshot.dll

which is included in the ANTS install directory. You can then take a snapshot by calling

RedGate.MemoryProfiler.Snapshot.TakeSnapshot("Optional snapshot name")

Full details here.

Snob answered 12/8, 2013 at 12:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.