How to run this DTrace script to profile my application?

I searched the Internet for something that helped me profile the pipeline. I searched and found something at http://www.webservertalk.com/message897404.html

There are two parts to this problem; finding all the instructions of a certain type (inc, add, shl, etc.) to determine the groupings, and then finding out which are executed and summarized. The first bit is difficult if disassembled enough is enough. To determine which instructions are being executed, Dtrace is of course your friend here (at least in userland).

The most enjoyable way to do this is to use the tool only to start each base unit; finding them now will be a manual process ... however, the toolkit of each instruction is possible for small applications. Here is an example:

First, our rather trivial C program:

main()
{
    int i;

    for (i = 0; i < 100; i++)
    getpid();
}

Now our slightly complicated D script:

#pragma D option quiet

pid$target:a.out::entry
/address[probefunc] == 0/
{
    address[probefunc]=uregs[R_PC];
}

pid$target:a.out::
/address[probefunc] != 0/
{
    @a[probefunc,(uregs[R_PC]-address[probefunc]), uregs[R_PC]]=count();
}

END
{
    printa("%s+%#x:\t%d\t%@d\n", @a);
}
main+0x1:           1
main+0x3:           1
main+0x6:           1
main+0x9:           1
main+0xe:           1
main+0x11:           1
main+0x14:           1
main+0x17:           1
main+0x1a:           1
main+0x1c:           1
main+0x23:         101
main+0x27:         101
main+0x29:         100
main+0x2e:         100
main+0x31:         100
main+0x33:         100
main+0x35:           1
main+0x36:           1
main+0x37:           1

From the above example, this is exactly what I need. However, I have no idea what it does, how to save the DTrace program, how to execute the code that I want to get. So I opened it, hoping that some people with a good DTrace background can help me understand the code, save it, run it, and hopefully get the results.

+3
source share
1 answer

, , DTrace script, .d script , :

sudo dtrace -s dtracescript.d -c [Path to executable]

dtracescript.d script.

, DTrace ( Mac OS X, Leopard).

, , DTrace MacResearch , .

+4

Source: https://habr.com/ru/post/1783853/


All Articles