Firefox/Goals/2010Q1/IO Reduction Criteria/sdwilsh-io.d

From MozillaWiki
Jump to: navigation, search
#pragma D option quiet
#prag#pragma D option quiet
#pragma D option destructive

/* Version 1.2 */

id_t mainThread; /* stores the main thread id */

/* Cheating a bit here.  We read early on, so get the main thread's id here. */
BEGIN
{
  mainThread = 0;
}

/* Track open calls to get the filename */
syscall::open*:entry
/execname == "firefox-bin"/
{
  self->path = arg0;
  mainThread == 0 ? mainThread = tid : tid;
}
syscall::open*:return
/execname == "firefox-bin" && self->path != 0/
{
  fdpaths[arg1] = copyinstr(self->path);
}

/* Track close calls to clear out the filename.  Otherwise, file descriptors get
 * reused, and we report things to the wrong filename. */
syscall::close*:entry
/execname == "firefox-bin"/
{
  fdpaths[arg1] = 0;
}

/* Track writes, reads, and fsyncs */
syscall::write*:entry
/execname == "firefox-bin" && mainThread == tid && fdpaths[arg0] != 0/{  self->fname = fdpaths[arg0];
  @write_stacks[ustack(12)] = count();}
syscall::write*:return
/execname == "firefox-bin" && mainThread == tid && self->fname != 0/{  @write_counts = count();  printf("operation:write (%s)", self->fname);
  ustack(12);
}
syscall::read*:entry
/execname == "firefox-bin" && mainThread == tid && fdpaths[arg0] != 0/
{
  self->fname = fdpaths[arg0];
  @read_stacks[ustack(12)] = count();
}
syscall::read*:return
/execname == "firefox-bin" && mainThread == tid && self->fname != 0/
{
  @read_counts = count();
  printf("operation:read (%s)", self->fname);
  ustack(12);
}
syscall::fsync*:entry
/execname == "firefox-bin" && mainThread == tid && fdpaths[arg0] != 0/
{
  self->fname = fdpaths[arg0];
  @fsync_stacks[ustack(12)] = count();
}
syscall::fsync*:return
/execname == "firefox-bin" && mainThread == tid && self->fname != 0/
{
  @fsync_counts = count();
  printf("operation:fsync (%s)", self->fname);
  ustack(12);
}
syscall::fstat*:entry
/execname == "firefox-bin" && mainThread == tid && fdpaths[arg0] != 0/
{
  self->fname = fdpaths[arg0];
  @fstat_stacks[ustack(12)] = count();
}
syscall::fstat*:return
/execname == "firefox-bin" && mainThread == tid && self->fname != 0/
{
  @fstat_counts = count();
  printf("operation:fstat (%s)", self->fname);
  ustack(12);
}

/*
syscall::exit:entry
/execname == "firefox-bin"/
*/
END
{
  printf("\nwrite_stacks:");
  printa(@write_stacks);
  printf("read_stacks:");
  printa(@read_stacks);
  printf("fsync_stacks:");
  printa(@fsync_stacks);
  printf("fstat_stacks:");
  printa(@fstat_stacks);
  printf("write_counts:");
  printa(@write_counts);
  printf("read_counts:");
  printa(@read_counts);
  printf("fsync_counts:");
  printa(@fsync_counts);
  printf("fstat_counts:");
  printa(@fstat_counts);
}