What makes it superior than others..?
If we go for dbx or any other Debugger in the IDE ,these tools will give larger data collection about memory leaks.But using Collect we can collect same memory leaks with smaller data collection.
Steps we need to do,
- Run the program with debug option
% CC -g -o test test.cc - Run time Data collection
We are concern about memory leaks, so we have to turn the heap tracing on with -H option. By default, heap tracing is off.
/opt/SUNWspro/prod/bin/collect
% collect -H on -o test.er test
Creating experiment database test.er ...
Address of x = 434323322, y = 434343434
New address of x = 434343433, y = 434344444
It creates the test.er experiment and archives the binary files describing each load object referenced in the loadobjects file. - Call the performance analyzer, er_print (command line tool) or analyzer (graphical tool)
% er_print test.er
(er_print) source allocate
Source file: ./test.c
Object file: ./test
Load Object: ./test
%>er_print mem.er
(er_print) source allocate
Source file: ./test.cc
Object file: ./test
Load Object: ./test
Incl. Incl.
Excl. Incl.
Bytes Leaks User CPU User CPU Leaked sec. sec.
Incl. Incl.
Excl. Incl.
Bytes Leaks User CPU User CPU Leaked sec. sec.
……………………………………………………………1. #include
……………………………………………………………2. using namespace std;
……………………………………………………………3. void allocate();
0 0 0. 0. …………………………………………………4. int main() {
## 1012 3 0. 0. ………………………………………....5. allocate();
0 0 0. 0. …………………………………………………6.return (0);
0 0 0. 0…………………………………………………..7. }
……………………………………………………………8.
0 0 0. 0. …………………………………………………9. void allocate() {
……………………………………………………………10. int *a;
……………………………………………………………11. char *b;
………………………………………………..…………..12.
0 0 0. 0……………………………...……………………13. a = (int *) malloc( 512);
512 1 0. 0……………………………………………… .14. b = (char *) malloc ( 512);
………………….………………………………………...15.
0 0 0. 0. ………………………………………….…….. 16. printf("\nAddress of a = %u, b = %u", a, b);
0 0 0. 0. …………………………………………………17. free(a);
250 1 0. 0………………………..…………………….. 18. a = (int *) malloc (250);
250 1 0. 0. ………………..…………………………….19. b = (char *) malloc (250);
0 0 0. 0. …………………………………………………20. printf("\nNew address of a = %u, a = %u\n", a, b);
0 0 0. 0. …………………………………………………21. }
Source:
http://docs.sun.com/source/819-0493/Collector.html#pgfId-1041571
No comments :
Post a Comment