szaydel
6/28/2015 - 2:37 PM

Dtrace scripts for interaction with filesystem events

Dtrace scripts for interaction with filesystem events

#!/usr/sbin/dtrace -s
#pragma D option quiet
/*
  Copyright 2009-2015 RackTop Systems Inc. and/or its affiliates.
  http:www.racktopsystems.com

  The methods and techniques utilized herein are considered TRADE SECRETS
  and/or CONFIDENTIAL unless otherwise noted. REPRODUCTION or DISTRIBUTION
  is FORBIDDEN, in whole and/or in part, except by express written permission
  of RackTop Systems.

  @@DESCRIPTION@@  Generate detailed CSV output of all reads and writes.
  @@NAME@@         fsiocsv.d
  @@STABILITY@@    unstable
  @@VERSION@@      1.0.1

  This script produces a CSV-like output for all reads and writes
  occuring on the system, without limiting scope to any particular path,
  filesystem, etc.
  ---
  Output looks something like this:
  2015 Jun 28 07:30:23,/storage/p01/test/01/benchmark.1.1,W,425984
  2015 Jun 28 07:30:18,/storage/p01/test/01/benchmark.0.1,W,9043968
  2015 Jun 28 07:30:18,/storage/p01/test/01/benchmark.2.3,W,9404416
  ---
  Redirect output of this script to log, and send stderr to /dev/null,
  to avoid annoying periodic null-pointer issues, which the script fails
  handling periodically, likely due to timing issues.
  Something like this should do: /path/to/fsiocsv.d >/path/to/log 2>/dev/null

  We cannot guarrantee that all file IO is captured by this script, but we
  are confident that the number missed is not significant enough to consider
  this script invalid.
 */

BEGIN {
    /* Extend comment to next line to disable header. */
    printf("timestamp,path,op,source,bytes\n");
}
tick-10sec {
    ts = walltimestamp;
}
fsinfo::fop_read:read /ts/ {
    fpathR = args[0]->fi_pathname;
}

::fop_read:entry /args[0]->v_path != NULL &&
                  stringof(args[0]->v_path) == fpathR/
{
    this->src = execname == "" ? "nocmd" : execname;
    @[ts, fpathR, "R", this->src] = sum(args[1]->uio_resid);
    fpathR = 0;
}

fsinfo::fop_write:write /ts/ {
    fpathW = args[0]->fi_pathname;
}

::fop_write:entry /args[0]->v_path != NULL &&
                   stringof(args[0]->v_path) == fpathW /
{
    this->src = execname == "" ? "nocmd" : execname;
    @[ts, fpathW, "W", this->src] = sum(args[1]->uio_resid);
    fpathW = 0;

}
tick-10sec {
    printa("%Y,%s,%s,%s,%@d\n", @);
    trunc(@);
}