How to get the memory a function consumes - memory

Our application consumes lots of memory and we need to identify which function cause the maximum usage of the memory. Is their any way or even any existing tool to do this(Windows, Native)?
Here is the environment:
Windows Xp
VS2008
Native C++ (MFC Based)
Thanks so much.

If you have Visual Studio 2008 Team System you can use the built-in memory allocation profiler. Here's a good MSDN article, Find Application Bottlenecks with Visual Studio Profiler using VS2008. There is also a profiler blog.
RedGate's ANTS
MemProfiler
ValGrind (free)
EDIT: since you updated to indicate C++, please also see this SO answer.
See Also:
.NET Memory Profiling Tools
Does anyone here have a favorite memory profiling/memory leak tool they like to use for their java webapps?
Best .NET memory and performance profiler?

Use a profiler. such as Automated QA's AQTime - http://www.automatedqa.com/products/aqtime/index.asp.

Most tools/profilers operate only on .NET apps which in your case is n/a
I've used Boundschecker and Purify to check for memory leaks/memory profiling for native applications (they got trial versions AFAIK) but you can also use the built in functions for this purpose if you are just interested in a one-shot analysis
look for _crtCheckMemory in your online help for a starting location.

Related

Free memory detection tools for Delphi for QA

I have found some tools that can help the developers to find out the memory leaks like FastMM4. But can a QA person use it to determine memory leaks after we take a build? or is there any tool available that can aid a QA person to find out memory leaks then it would be great.
currently what we follow is like run the application note down the memory usage and perform some tasks and then check out the memory usage and if we find out a huge difference then we star narrowing down. Is there any tool which will do it automatically
Lots of functionality in FastMM4 can be enabled or disabled depending on a presence of FastMM_FullDebugMode.dll in system. This way you can have only one build, where leak detection will be enabled by copying FastMM_FullDebugMode.dll to program folder. Similar functionality you can achieve by using ShareMem unit together with different versions of BorlndMM.dll. In this case you can compile FastMM4 to BorlndMM.dll with any options you want.
Your QA testers can equally use FastMM to detect memory leaks. You just need to give them a build which enables memory leak detection.
SouceGuard is a lite and effective leakproof and bug reporting tool in Delphi.
It was formerly known as UMLD.

How best to debug Delphi using the IDE and/or FOSS?

I see the following means of debugging and wonder if there are others or which FOSS tools a small company can use (we don't do much Windows programming).
1 Debug in the IDE, by setting breakpoints, using watches, etc
2 Debug in the IDE, by using the Event Log
I got some good info from this page and tweaked it to add timestamps and indent/outdent on procedure call/return, so that I can see nested calls more quickly. Does anyone know of anything better ?
3 Using a profiler
4 Any others?
Such as MadExcept, etc?
(I am currently using Delphi 7)
The Delphi integrated debugger is powerful enough, even in Delphi 7, to handle most debugging tasks. It can also debug an application remotely. Anyway, there are situations where you may need to track different kind of issue:
To check for memory leaks, you can switch to a memory manager like FastMM4 which has good memory leak reporting. Profilers like AQTime have also memory allocation profilers to identify such kind of issues.
To investigate performance problems, you need a performance profiler. There are sampling profilers (less invasive, although may be less precise) and standard profilers (AQTime again, not cheap but very good, and others).
To trace exception, especially on deployed applications, you may need tools like JCL/JVCL (free), MadExcept or EurekaLog or SmartInspect
To obtain a log of what the application does, you can use OutputDebugString() and the IDE event viewer, or the DebugView standalone application. There are also dedicated tools like SmartInspect.
You can also convert Delphi 7 .map files to .dbg files and use an external debugger as the WinSDK WinDbg, and look at application calls in tools like ProcessExplorer
Some debugging tools may also offer features like code coverage checks (which code was actually executed, and which was never), platform compliance (check API calls are supported by a given platform), resources use and so on, but may be useful for larger developments.
Delphi 7's IDE is pretty good to start with, only look at 3rd party tools if you run into something you can't fix with what you've got:
It's error messages are informative and not excessively verbose.
The debugger is pretty good, you've got lots of options for inspecting variables, brakepoints, conditional brakepoints, data brakepoints, address brakepoint, module load brakepoint. It's call-stack view is good, it has some support for multi-threaded debugging.
Good step-by-step execution, step into, step over, run until return, etc.
3rd party tools help when you need to diagnose a problem on the client's computer (you have no Delphi IDE on the client's computer). If you can get the problem to manifest on your computer you get away with the IDE alone, no need for any addition, free or payed for.
Profiler: That's not a debugging tool. You use an profiler when you need to find bottlenecks in your application, or you need to do some speed optimizations.
Logging 3rd party frameworks: The good ones are not cheap, and you can do minimal logging without a tool (even ShowMessage works some times).
MadExcept, other tools that log exceptions: They usually require debugging information to be present in the EXE, and that's not a good idea because it makes the program slower AND it easier to hack. Again, if you can get the exception on your machine, you don't need the logger.
I'm not saying 3rd party debugging aids are not useful: they are, but I'd wait until I can clearly see the benefit of any tool before I commit to it. And in my opinion there's no such thing as free software: Even the software you don't pay for requires time to learn how to use it and requires changes to your programs and workflow.
For the bigger work, there is AQTime.
A cheaper solution for selected code is running it through Free Pascal (with the "randomize local variables option") and run it through valgrind. I've validated most my streaming code (which heavily has backwards compat constructs) that way.
Another such interesting switch is -CR, verify object method call. It basically turns every
TXXX(something).callsomething
into
if something is txx then
TXXX(something).callsomething
else
raise some exception;
Specially in code with complex trees this can give some precious information.
Normal Pascal language checking (Range, I/O, Overflow, sTack aka -Criot) can be useful too, and is also available in Delphi.
Some range check errors (often loop bounderies) that can be detected statically, will result in compile errors in (beta) FPC 3.0.x+.
You can try the "Process Stack Viewer" of my (open source) sampling profiler:
http://code.google.com/p/asmprofiler/wiki/ProcessStackViewer
(you need some debug info: a .map or .jdbg file)
You can watch the stack (also the raw stack, with "false positives" but useful when normal stack walking is not possible) of all threads, and do some simple sampling profiling.
Note: My (older) instrumenting profiler does exact profiling, is on the same site.
Not sure why you would want to upgrade to debug a problem. Yes the newer IDE's provide more features to help you debug something, but taking into consideration your previous question on how to debug your program when it hangs, I'd sooner suggest a good logging solution like CodeSite or SmartInspect. They provide way more flexibility and features than any home-grown solution based around the event log and do not require you to step through the code, like the IDE does (which affects timings in multi-threadeded problems).
Update
Sorry, didn't get that FOSS stands for Free and Open Source Software. CodeSite and SmartInspect are neither. For a free solution, you could have a look though at the logging features within the Jedi family of tools.
Rad Studio XE includes a light version of CodeSite, and AQTime, which together are both compelling improvements.
You could do a lot with JCL Debug, MadExcept, and other profiling and logging tools, but CodeSite and AQTime are the two best for their respective tasks.

What are the options in open source world for application lifecycle, fault and performance monitoring for .Net applications?

What are my options in open source world for application lifecycle, fault and performance monitoring for .Net applications? A good commercial benchmark for my need is Avicode (http://www.avicode.com)
So, is there an equivalent for Avicode?
Not an equivalent... however Microsoft recently acquired AVIcode.
More information along with a trial version is available here
http://www.microsoft.com/systemcenter/en/us/avicode.aspx
Thanks,
Aaron
Have a look at dynatrace.
http://www.dynatrace.com/en/

How to find "fat" procedure memory usage?

While working on my code lately, I've noticed that some of the memory usage is going up significantly, and I can't see many reasons for it in my code. So I'm wondering if there are any programs, techniques, or other types of tools that can scan my code (Delphi) and estimate for me what procedures, functions, and functions will be the heaviest memory users. Ideally, I' think I'd be looking at the code as it is run in debug mode, but if something can scan the source files and tell me, that would be even better. Thanks.
The type of tool you are looking for is a Profiler. There are lots of good profilers out there for most languages. I'm less familiar with Delphi though so I used google and it turned the following options
http://www.prodelphi.de/
http://delphitools.info/
But the best information seems to be on this question from StackOverflow
Delphi Profiling tools
See my answer to a similar question:
Memory profiling tool for Delphi?
Without knowing how you are currently measuring "memory use" it's difficult to say what might be the best tools to use.
We have used AQTime in the past it found a load of memory leaks.
http://www.automatedqa.com/products/aqtime/
another good Delphi tool is Eurekalog

Simple code analyzer

Need a simple code analyzer to see if I am forgetting to free objects and classes, or to see if I am releasing them to many times.
This is built into Delphi's memory manager (FastMM). Set ReportMemoryLeaksOnShutdown true. You can also use the "full debug" version of the memory manager for more detailed checks and information.
The Pascal Analyzer from Peganza does a static analysis of your code.
AQTime from Automated QA is pretty much the defacto standard tool in the Delphi World for profiling for memory leaks (and perf of course)
Another option is a static analysys tool, the only one I know of that supports Delphi is Understand from SciTools it's pretty expensive though.
Simplest tool I've ever used for memory leak checking is MemCheck.
http://v.mahon.free.fr/pro/freeware/memcheck/

Resources