C function call from DTrace scripts

DTrace is an impressive, powerful tracing system, originally from Solaris, but ported to FreeBSD and Mac OSX.

DTrace uses a high-level D language other than AWK or C. Here is an example:

io:::start
/pid == $1/
{
    printf("file %s offset %d size %d block %llu\n", args[2]->fi_pathname, 
        args[2]->fi_offset, args[0]->b_bcount, args[0]->b_blkno);
}

Using the command line sudo dtrace -q -s <name>.d <pid>, all IOs created from this process are logged.

My question is if and how you can call custom C functions from a DTrace script to perform advanced operations with trace data during the trace itself.

+3
source share
4 answers

DTrace - , D: - , , . D-, KERNEL, . " Linux:"

, . C, , , core dump .

D- D- . =]

+6

dtrace .

sudo dtrace -n 'proc:::exec-success { trace(curpsinfo->pr_psargs); }' | perl myscript.pl

myscript.pl:

#!/usr/bin/perl
while (<>){
print $_;
print "another application launched, do something!";
}
+1

C , @Sniggerfardimungus, ( / /etc ), C ( C ).

libdtrace ( /usr/include/dtrace.h Mac OS X) , node-libdtrace. , DTrace (, dtrace(1m)), script. , , .

+1

, system() DTrace script, , , DTrace. , -w #pragma D option destructive D script. , , , , , . ( , , , .)

You can use a run script system()to invoke arbitrary C code (or send a signal to another process to call it, etc.).

+1
source

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


All Articles