#! /usr/bin/env stap global ind global creat global start global wait global stat_nr global stat_us global filter function string_make(n) { for (i=1; i 0 %? filter = @1 printf("\nTracing \"%s\" and all of its children...\n\n", filter) %: filter = "" print("\nTracing all processes...\n\n") %) } probe kprocess.create { if (filter == "" || pid() in ind || execname() == filter) { ind[new_pid] = ind[pid()] + 2 creat[new_pid] = pid() } } probe kprocess.exec { # check that it is our child if (pid() in creat) { printf("%s%s %d (parent %s %d)\n", string_make(ind[pid()]), filename, pid(), execname(), creat[pid()]) } } probe kprocess.start { if (pid() in creat) { start[pid()] = gettimeofday_us() } } # from wait4time.stp probe syscall.wait4 { } probe syscall.wait4.return { if (pid() in creat) { // tid(), what about threads? elapsed_time = gettimeofday_us() - @entry(gettimeofday_us()) wait[execname()] += elapsed_time } } # probe kprocess.exit { if (pid() in creat) { us = gettimeofday_us() - start[pid()] printf("%s%s %d exit (%s sec)\n", string_make(ind[pid()]), execname(), pid(), show_us(us)) stat_nr[execname()]++ stat_us[execname()]+=us delete ind[pid()] delete start[pid()] delete creat[pid()] } } probe end { print("\n") foreach (name in stat_us-) { printf("%20s : %3d times for %6s sec (%s self + %s wait)\n",name,stat_nr[name],show_us(stat_us[name]),show_us(stat_us[name] - wait[name]),show_us(wait[name])) } }