tcp.d

#!/usr/sbin/dtrace -s
#pragma D option quiet
#pragma D option defaultargs
#pragma D option dynvarsize=64m

inline int TICKS=$1;
inline string ADDR=$$2;

dtrace:::BEGIN
{
       TIMER = ( TICKS != NULL ) ?  TICKS : 1 ;
       ticks = TIMER;
       TITLE = 10;
       title = 0;
       walltime=timestamp;
       printf("starting up ...\n");
}

tcp:::send,
tcp:::receive
/   title == 0
/
{
      printf("%9s %8s %6s %8s %8s %8s \n",
        "delta"    ,
        "cid"    ,
        "pid"    ,
        "send" ,
        "recd"  ,
        "flags"
      );
        title=TITLE;
}

/*
    && curpsinfo->pr_psargs == "/usr/lib/nfs/nfsd"
*/
tcp:::send
/     ( args[2]->ip_daddr == ADDR || ADDR == NULL )
/
{
    nfs[args[1]->cs_cid]=1; /* this is an NFS thread */
    delta= timestamp-walltime;
    walltime=timestamp;
    flags="";
    flags= strjoin((( args[4]->tcp_flags & TH_FIN ) ? "FIN|" : ""),flags);
    flags= strjoin((( args[4]->tcp_flags & TH_SYN ) ? "SYN|" : ""),flags);
    flags= strjoin((( args[4]->tcp_flags & TH_RST ) ? "RST|" : ""),flags);
    flags= strjoin((( args[4]->tcp_flags & TH_PUSH ) ? "PUSH|" : ""),flags);
    flags= strjoin((( args[4]->tcp_flags & TH_ACK ) ? "ACK|" : ""),flags);
    flags= strjoin((( args[4]->tcp_flags & TH_URG ) ? "URG|" : ""),flags);
    flags= strjoin((( args[4]->tcp_flags & TH_ECE ) ? "ECE|" : ""),flags);
    flags= strjoin((( args[4]->tcp_flags & TH_CWR ) ? "CWR|" : ""),flags);
    flags= strjoin((( args[4]->tcp_flags == 0 ) ? "null " : ""),flags);

    printf("%9d %8d %6d %8d --> %8s %8d %8d %12s %12s > %s \n",
        delta/1000,
        args[1]->cs_cid  % 100000,
        args[1]->cs_pid ,
        args[2]->ip_plength - args[4]->tcp_offset,
        "",
        args[4]->tcp_seq % 10000,
        args[4]->tcp_ack % 10000,
        args[2]->ip_daddr,
        flags,
        curpsinfo->pr_psargs
      );
    flag=0;
    title--;
}

tcp:::receive
/ ( args[2]->ip_saddr == ADDR || ADDR == NULL )
    && nfs[args[1]->cs_cid]
/
{
      delta=timestamp-walltime;
      walltime=timestamp;
      flags="";
      flags= strjoin((( args[4]->tcp_flags & TH_FIN ) ? "FIN|" : ""),flags);
      flags= strjoin((( args[4]->tcp_flags & TH_SYN ) ? "SYN|" : ""),flags);
      flags= strjoin((( args[4]->tcp_flags & TH_RST ) ? "RST|" : ""),flags);
      flags= strjoin((( args[4]->tcp_flags & TH_PUSH ) ? "PUSH|" : ""),flags);
      flags= strjoin((( args[4]->tcp_flags & TH_ACK ) ? "ACK|" : ""),flags);
      flags= strjoin((( args[4]->tcp_flags & TH_URG ) ? "URG|" : ""),flags);
      flags= strjoin((( args[4]->tcp_flags & TH_ECE ) ? "ECE|" : ""),flags);
      flags= strjoin((( args[4]->tcp_flags & TH_CWR ) ? "CWR|" : ""),flags);
      flags= strjoin((( args[4]->tcp_flags == 0 ) ? "null " : ""),flags);
      printf("%9d %8d %6d %8s <-- %-8d %8d %8d %12s %12s < %s \n",
        delta/1000,
        args[1]->cs_cid  % 100000,
        args[1]->cs_pid ,
        "",
        args[2]->ip_plength - args[4]->tcp_offset,
        args[4]->tcp_seq % 10000,
        args[4]->tcp_ack % 10000,
        args[2]->ip_saddr,
        flags,
        curpsinfo->pr_psargs
      );
    flag=0;
    title--;
}
Comments