title: Calling C function from DTrace scripts
body: <p><a href="https://wikis.oracle.com/display/DTrace/DTrace" rel="nofollow noreferrer">DTrace</a> is impressive, powerful tracing system originally from Solaris, but it is ported to FreeBSD and Mac OSX.</p>
  
  <p>DTrace uses a high-level language called D not unlike AWK or C. Here is an example:</p>
  
  <pre><code>io:::start
  /pid == $1/
  {
      printf("file %s offset %d size %d block %llu\n", args[2]-&gt;fi_pathname, 
          args[2]-&gt;fi_offset, args[0]-&gt;b_bcount, args[0]-&gt;b_blkno);
  }
  </code></pre>
  
  <p>Using the command line <code>sudo dtrace -q -s &lt;name&gt;.d &lt;pid&gt;</code> all IOs originated from that process are logged.</p>
  
  <p>My question is if and how it is possible to call custom C functions from a DTrace script to do advanced operations with that tracing data during the tracing itself.</p>