Search code examples
linuxlinux-kernelperfsystemtap

systemtap: how to determine probe events and args


I'm trying to find out the reason for these writes to my flash drive.

deathstar> while true
> do
> dmesg|grep sdc|grep WRITE
> sleep 3
> done
[17967.580179] kworker/u4:2(6863): WRITE block 20971648 on sdc1 (8 sectors)
[17967.580206] kworker/u4:2(6863): WRITE block 20971784 on sdc1 (8 sectors)
[17967.580214] kworker/u4:2(6863): WRITE block 20971832 on sdc1 (8 sectors)
[17967.580222] kworker/u4:2(6863): WRITE block 21037080 on sdc1 (8 sectors)

I ran:

perf record -g -a

and then

perf report -s comm

to get

-    0.10%     0.10%     kworker/u4:2                                                                    ▒
     ext4_bio_write_page                                                                                 ▒
     strnlen                                                                                             ▒
     elv_rqhash_del.isra.5.part.6                                                                        ▒
     find_get_pages                                                                                      ▒
     find_get_pages_tag                                                                                  ▒
     scsi_init_io                                                                                        ◆
     ext4_mb_use_inode_pa                                                                                ▒
     cpuacct_charge                                                                                      ▒
     i915_gem_retire_requests_ring                                                                       ▒
     cfq_insert_request                                                                                  ▒
     i915_gem_free_request                                                                               ▒
     __wake_up_bit                                                                                       ▒
     i915_gem_object_move_to_inactive                                                                    ▒
     bdi_wakeup_thread_delayed                                                                           ▒
     __test_set_page_writeback                                                                           ▒
     scsi_request_fn                                                                                     ▒
     ext4_group_desc_csum                                                                                ▒
     __pagevec_lru_add_fn                                                                                ▒
     clear_page_dirty_for_io                                                                             ▒
     wb_writeback                                                                                        ▒
     cfq_service_tree_add                                                                                ▒
     cache_grow                                                                                          ▒
     __writeback_inodes_wb   

How do i now use: ext4_bio_write_page within systemtap to print various arguments.. how do i even determine what the possible args are? I want to do something like:

 > stap -v -e 'probe ext4.ext4_bio_write_page?? { printf("%s %d", ???

and extract something interesting like maybe buffer_size or file_name - i don't know what specifically (i want to go through those functions one by one and look at their signatures).

[please note i'm totally new to this so i may have made some very stupid mistakes]


Solution

  • See the systemtap tutorial section 2.2 "what to print" and section 3.2 "target variables". A brief excerpt:

    { println($$vars) }
    

    prints all variables in scope. $foo$ pretty-prints the foo object, including one level of struct subfields. $foo$$ pretty-prints deeply (subject to MAXSTRINGLEN limits).

    # stap -L 'kernel.function("foo")' 
    

    will print out the list of variables in scope of function foo.