kernelio.stp
author Taras Glek <tglek@mozilla.com>
Tue, 29 Jun 2010 16:30:26 -0700
changeset 18 782c42e1d6a4
parent 12 74e2f62fe64c
permissions -rw-r--r--
checkpoint
// < fche> -p2 will just expand the alias for you to the actual low level probes
// kernel.function("wait_for_completion") [.return]  sleepingBeauties.stp
// a: print_backtrace() et al., should work, as long as all needed shared libraries are either probed or named with '-d /path/to/libfoo.so -d /path/to/libbar.so'
// make -C /usr/share/systemtap/runtime/uprobes ; insmod /usr/share/systemtap/runtime/uprobes/uprobes.ko

global block_start;
global block_total;
global start;
global recursion_guard;
global targetpid;
// TODO: make a table of files read..then see if there are any non-firefox accesses to them
probe begin {
  start = 0;
  block_total = 0;
  recursion_guard = 0;
  targetpid = -1;
  printf("BEGIN;\nDELETE FROM startup;\n");
}

probe end {
  printf("END\;");
  printf("-- %dus of ext4 reads unaccounted for\n", block_total);
  if (recursion_guard)
    printf("-- Oh noes, recursion_guard(%d) got out of control!\n", recursion_guard);
}

probe kernel.function("vfs_read"),
  kernel.function("vfs_write"),
  kernel.function("vfs_readdir"),
  kernel.function("__do_page_cache_readahead")
{
  if (targetpid == pid()) {
    if (!recursion_guard++);
        start = gettimeofday_us();
  }
}

function report(path, pos, size, write) {
    fname = d_path(path);
    if (fname != "//") {
      printf("-- p/a %d\n", uaddr());
      printf("INSERT INTO startup VALUES('%s', '%s', %d, %d, %d);%s\n", 
             execname(), fname, pos, size, gettimeofday_us() - start, write ? " -- write":""); 
    }
    start = 0;
}


probe kernel.function("vfs_read").return {
  if (targetpid == pid()) {
    if (!--recursion_guard)
      if ($return > 0)
        report(&$file->f_path, $pos[0], $return, 0);
  }

}

probe kernel.function("vfs_write").return {
  if (targetpid == pid()) {
    if (!--recursion_guard)
      if ($return > 0) {
        report(&$file->f_path, $pos[0], $return, 1);
      }
  }

}


probe kernel.function("vfs_readdir").return
{
  if (targetpid == pid()) {
    if (!--recursion_guard)
      if ($return > 0)
        report(&$file->f_path, 0, 0, 0);
  }
}

probe kernel.function("__do_page_cache_readahead").return {
  if (targetpid == pid()) {
    if (!--recursion_guard)
      report(&$filp->f_path, $offset*4096, $nr_to_read*4096, 0);
  }
}

probe kernel.function("ext4_get_block") {
  if (!start)
    block_start = gettimeofday_us();
}

probe kernel.function("ext4_get_block").return {
  if(!start)
    block_total += gettimeofday_us() - block_start;
}

probe process(@1).begin {
  targetpid = pid();
  printf("-- %d %s\n", targetpid, @1);
}

////////////////////////////////////////////////////
/*
function lookup_lib(addr) {
  foreach (e in mmap_len) {
    if (addr > e && addr < mmap_len[e]) {
      addr = addr - e + mmap_offset[e];
      return sprintf("%s, %x", mmap_files[e], addr);
    }
  }
  return ""
}

global mmap_len;
global mmap_files;
global mmap_offset;
global filenames;

probe syscall.open.return {
  if (targetpid == pid() && $return > -1)
    filenames[$return] = kernel_string($filename);
}

probe syscall.mmap2.return 
{
  //printf("%s %s\n", probefunc(), $$parms);
  if (targetpid == pid()) {
    if ($fd in filenames) {
      end = $return + $len;
      mmap_len[$return] = end;
      mmap_files[$return] = filenames[$fd];
      mmap_offset[$return] = $pgoff * 4096;
      //printf("%x:%x %s\n", $return,end, filenames[$fd])
    }
  }
}

probe syscall.munmap {
  mmap_len[$addr] = 0;
}
*/