05.08.2013 Views

Solaris Application Programming, 1/e - Chapter 4 - Parent Directory

Solaris Application Programming, 1/e - Chapter 4 - Parent Directory

Solaris Application Programming, 1/e - Chapter 4 - Parent Directory

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

4.4 PROCESS- AND PROCESSOR-SPECIFIC TOOLS 83<br />

Example 4.47 Number and Size of Calls to malloc by ls (continued )<br />

256 |@@@@@ 2<br />

512 | 0<br />

1024 | 0<br />

2048 | 0<br />

4096 | 0<br />

8192 | 0<br />

16384 | 0<br />

32768 |@@@ 1<br />

65536 | 0<br />

Once the sizes of the memory requests have been determined, it may also be<br />

interesting to find out where the memory requests are being made. The script<br />

shown in Example 4.48 captures the call stack for the calls to malloc.<br />

Example 4.48 Capturing the User Call Stack for Calls to malloc<br />

#!/usr/sbin/dtrace -s<br />

pid$target:libc.so:malloc:entry<br />

{<br />

@stack[ustack(5)]=count();<br />

@array[probefunc]=quantize(arg0);<br />

}<br />

END<br />

{<br />

printa(@stack);<br />

printa(@array);<br />

}<br />

An example of running the script to capture the call stack of calls to malloc is<br />

shown in Example 4.49.<br />

Example 4.49 Call Stack for malloc Requests Made by the Compiler<br />

# ./malloc_stack.d -c "cc -O an.c"<br />

dtrace: script './malloc_stack.d' matched 2 probes<br />

dtrace: pid 4063 has exited<br />

CPU ID FUNCTION:NAME<br />

6 2 :END<br />

...<br />

cc`malloc<br />

libc.so.1`calloc+0x58<br />

cc`stralloc+0x8<br />

cc`str_newcopy+0xc<br />

cc`addopt+0x88<br />

154<br />

continues

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!