kernelio.stp
author Taras Glek <tglek@mozilla.com>
Mon, 05 Apr 2010 16:46:47 -0700
changeset 7 6453ad2a7906
parent 4 37148962ffe3
child 9 d2bc55d45345
permissions -rw-r--r--
Don't read in symbols when operating on sections alone
// < 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_readdir"),
  kernel.function("__do_page_cache_readahead")
{
  if (targetpid == pid()) {
    if (!recursion_guard++);
        start = gettimeofday_us();
  }
}

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


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

}

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

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 kernel.function("generic_file_open").return {
  if (targetpid == -1 && isinstr(execname(), "firefox")) {
    targetpid = pid()
  }
}


// blockio_read will read the block......callback


// blocktrace...blktrace...map blacks back to filesystem