global var, varerr
probe $1 {
- t=tid() # or t=0 for thread-agnostic checking
if (@defined($2)) {
try {
newvar = $2;
- if (var[t] != newvar) {
- printf("%s[%d] %s %s:\n", execname(), t, pp(), @2);
+ if (var[tid()] != newvar) {
+ printf("%s[%d] %s %s:\n", execname(), tid(), pp(), @2);
println(newvar);
- var[t] = newvar;
+ var[tid()] = newvar;
}
} catch { varerr ++ } # error during $2 resolution or perhaps var[] assignment
}
probe vfs.read.return {
count = $return
if ( count >= 0 ) {
- e=execname();
- reads[e,dev] <<< count # statistics array
- totals[e,dev] += count
+ reads[execname(),dev] <<< count # statistics array
+ totals[execname(),dev] += count
}
}
probe vfs.write.return {
count = $return
if (count >= 0 ) {
- e=execname();
- writes[e,dev] <<< count # statistics array
- totals[e,dev] += count
+ writes[execname(),dev] <<< count # statistics array
+ totals[execname(),dev] += count
}
}
probe begin { printf("starting probe\n") }
probe syscall.open {
- e=execname();
- opens[e] <<< 1 # statistics array
+ opens[execname()] <<< 1 # statistics array
}
probe syscall.read.return {
count = $return
if ( count >= 0 ) {
- e=execname();
- reads[e] <<< count # statistics array
- totals[e] += count
+ reads[execname()] <<< count # statistics array
+ totals[execname()] += count
}
}
probe syscall.write.return {
count = $return
if (count >= 0 ) {
- e=execname();
- writes[e] <<< count # statistics array
- totals[e] += count
+ writes[execname()] <<< count # statistics array
+ totals[execname()] += count
}
}
probe begin {
printf("Starting data collection\n")
- traced_pid = target()
- if (traced_pid)
- printf("mode Specific Pid, traced pid: %d\n\n", traced_pid)
+ if (target())
+ printf("mode Specific Pid, traced pid: %d\n\n", target())
else
printf("mode - All Pids\n\n")
}
probe begin {
printf("Starting data collection\n")
- traced_pid = target()
- if (traced_pid)
- printf("mode Specific Pid, traced pid: %d\n\n", traced_pid)
+ if (target())
+ printf("mode Specific Pid, traced pid: %d\n\n", target())
else
printf("mode - All Pids\n\n")
}
probe begin {
printf("Starting data collection\n")
- traced_pid = target()
- if (traced_pid)
- printf("mode Specific Pid, traced pid: %d\n\n", traced_pid)
+ if (target())
+ printf("mode Specific Pid, traced pid: %d\n\n", target())
else
printf("mode - All Pids\n\n")
}
probe begin {
printf("Starting data collection\n")
- traced_pid = target()
- if (traced_pid)
- printf("mode Specific Pid, traced pid: %d\n\n", traced_pid)
+ if (target())
+ printf("mode Specific Pid, traced pid: %d\n\n", target())
else
printf("mode - All Pids\n\n")
}
global execnames, page_faults, node_faults, nodes
probe vm.pagefault {
- p = pid();
- execnames[p] = execname()
- page_faults[p, write_access ? 1 : 0] <<< 1
+ execnames[pid()] = execname()
+ page_faults[pid(), write_access ? 1 : 0] <<< 1
try {
n=addr_to_node(address)
- node_faults[p, n] <<< 1
+ node_faults[pid(), n] <<< 1
nodes[n] <<< 1
} catch { }
}
probe vm.pagefault {
t = gettimeofday_us()
- id = tid()
- fault_entry_time[id] = t
- fault_address[id] = address
- fault_access[id] = write_access ? "w" : "r"
+ fault_entry_time[tid()] = t
+ fault_address[tid()] = address
+ fault_access[tid()] = write_access ? "w" : "r"
}
probe vm.pagefault.return {
t=gettimeofday_us()
- id = tid()
- if (!(id in fault_entry_time)) next
+ if (!(tid() in fault_entry_time)) next
e = t - fault_entry_time[id]
if (vm_fault_contains(fault_type,VM_FAULT_MINOR)) {
ftype="minor"
}
printf("%d:%d:%id:%s:%s:%d\n",
- t - time_offset, id, fault_address[id], fault_access[id], ftype, e)
+ t - time_offset, tid(), fault_address[tid()], fault_access[tid()], ftype, e)
#free up memory
- delete fault_entry_time[id]
- delete fault_address[id]
- delete fault_access[id]
+ delete fault_entry_time[tid()]
+ delete fault_address[tid()]
+ delete fault_access[tid()]
}
{
if (!success) next
- pid = pid()
- uid = uid()
- ename = execname()
-
# Check filters
if ('$FILTER') {
if ('$F_PROT' && !(protocol in f_prot)) next
if ('$F_FAM' && !(family in f_fam)) next
- if ('$F_PID' && !(pid in f_pid)) next
- if ('$F_NAME' && !(ename in f_name)) next
- if ('$F_UID' && !(uid in f_uid)) next
+ if ('$F_PID' && !(pid() in f_pid)) next
+ if ('$F_NAME' && !(execname() in f_name)) next
+ if ('$F_UID' && !(uid() in f_uid)) next
if ('$F_TYPE' && !(type in f_type)) next
}
- execname[pid] = ename
- user[pid] = uid
- sk_tx[pid, protocol, family] <<< size
- sk_pid[pid, protocol, family] += size
+ execname[pid()] = execname()
+ user[pid()] = uid()
+ sk_tx[pid(), protocol, family] <<< size
+ sk_pid[pid(), protocol, family] += size
}
probe socket.receive
{
if (!success) next
- pid = pid()
- uid = uid()
- ename = execname()
-
# Check filters
if ('$FILTER') {
if ('$F_PROT' && !(protocol in f_prot)) next
if ('$F_FAM' && !(family in f_fam)) next
- if ('$F_PID' && !(pid in f_pid)) next
- if ('$F_NAME' && !(ename in f_name)) next
- if ('$F_UID' && !(uid in f_uid)) next
+ if ('$F_PID' && !(pid() in f_pid)) next
+ if ('$F_NAME' && !(execname() in f_name)) next
+ if ('$F_UID' && !(uid() in f_uid)) next
if ('$F_TYPE' && !(type in f_type)) next
}
- execname[pid] = ename
- user[pid] = uid
- sk_rx[pid, protocol, family] <<< size
- sk_pid[pid, protocol, family] += size
+ execname[pid()] = execname()
+ user[pid()] = uid()
+ sk_rx[pid(), protocol, family] <<< size
+ sk_pid[pid(), protocol, family] += size
}
function print_activity()
probe syscall.*.return {
errno = errno_p(returnval())
if (errno != 0) {
- t = tid()
- argstr = trace[t]
- delete trace[t]
+ argstr = trace[tid()]
+ delete trace[tid()]
errstr = sprintf("%3d/%s", errno, errno_str(errno))
error[sprintf("%-13s %17s %15s %5d %s", errstr, name, execname(), pid(), argstr)] <<< 1
}
}
probe syscall.futex.return {
- t = tid()
- if (!(t in wait_keys)) next
- key = wait_keys[t]
- delete wait_keys[t]
+ if (!(tid() in wait_keys)) next
+ key = wait_keys[tid()]
+ delete wait_keys[tid()]
cmd = $op & ~(FUTEX_PRIVATE_FLAG|FUTEX_CLOCK_REALTIME);
if (cmd != FUTEX_WAIT) next
probe signal.send
{
- snd_pid = pid()
rcv_pid = sig_pid
- sigcnt[snd_pid, rcv_pid, sig]++
+ sigcnt[pid(), rcv_pid, sig]++
- if (!(snd_pid in pid2name)) pid2name[snd_pid] = execname()
+ if (!(pid() in pid2name)) pid2name[pid()] = execname()
if (!(rcv_pid in pid2name)) pid2name[rcv_pid] = pid_name
if (!(sig in sig2name)) sig2name[sig] = sig_name
}
probe kernel.function("wait_for_completion").return
{
- t=tid()
-
- if ([t] in bored) {
- patience = time() - backtime[t]
+ if ([tid()] in bored) {
+ patience = time() - backtime[tid()]
printf ("thread %d (%s) bored for %d %s\n",
- t, name[t], patience, time_name)
+ tid(), name[tid()], patience, time_name)
}
- delete bored[t]
- delete back[t]
- delete name[t]
- delete backtime[t]
+ delete bored[tid()]
+ delete back[tid()]
+ delete name[tid()]
+ delete backtime[tid()]
}
probe kernel.function("wait_for_completion").call
{
- t=tid()
- back[t]=backtrace()
- name[t]=execname()
- backtime[t]=time()
- delete bored[t]
+ back[tid()]=backtrace()
+ name[tid()]=execname()
+ backtime[tid()]=time()
+ delete bored[tid()]
}
if (filter_p()) next;
- t=tid()
- thread_argstr[t]=argstr
+ thread_argstr[tid()]=argstr
if (timestamp || elapsed_time)
- thread_time[t]=gettimeofday_us()
+ thread_time[tid()]=gettimeofday_us()
if (name in syscalls_nonreturn)
report(name,argstr,"")
function report(syscall_name, syscall_argstr, syscall_retstr)
{
- t=tid()
-
if (timestamp || elapsed_time)
{
now = gettimeofday_us()
- then = thread_time[t]
+ then = thread_time[tid()]
if (timestamp)
prefix=sprintf("%s.%06d ", ctime(then/1000000), then%1000000)
suffix=sprintf(" <%d.%06d>", diff/1000000, diff%1000000)
}
- delete thread_time[t]
+ delete thread_time[tid()]
}
/* add a thread-id string in lots of cases, except if
stap strace.stp -c SINGLE_THREADED_CMD */
if (tid() != target()) {
- prefix .= sprintf("%s[%d] ", execname(), t)
+ prefix .= sprintf("%s[%d] ", execname(), tid())
}
printf("%s%s(%s) = %s%s\n",
syscall_name, syscall_argstr, syscall_retstr,
suffix)
- delete thread_argstr[t]
+ delete thread_argstr[tid()]
}
}
probe syscall.wait4.return {
- t = tid()
elapsed_time = gettimeofday_us() - @entry(gettimeofday_us())
printf("%d %s wait4: %d %d\n", timestamp(), proc(), elapsed_time,
- wait4_pid[t])
- delete wait4_pid[t]
+ wait4_pid[tid()])
+ delete wait4_pid[tid()]
}
function check(t) # t: elapsed time
{
- pf=ppfunc()
- if (@count(times[pf]) >= mincount
- && t >= @max(times[pf]) * note_percent / 100) { # also consider @avg()
+ if (@count(times[ppfunc()]) >= mincount
+ && t >= @max(times[ppfunc()]) * note_percent / 100) { # also consider @avg()
printf("function %s well over %s time (%d vs %d)\n",
- pf, "maximum", t, @max(times[pf]))
+ ppfunc(), "maximum", t, @max(times[ppfunc()]))
# also consider: print_backtrace()
}
- times[pf] <<< t # (increments @count, updates @max)
+ times[ppfunc()] <<< t # (increments @count, updates @max)
}
probe $1.return { check(time()-@entry(time())) }
probe $1.function(@2).call { calls <<< 1 }
probe $1.function(@2).return {
t = gettimeofday_us()
- p = tid()
- s = times[p]
+ s = times[tid()]
if (s) {
e = t - s
- region[last_pp[p]] <<< e
- cfg[last_pp[p], pp()] <<< 1
+ region[last_pp[tid()]] <<< e
+ cfg[last_pp[tid()], pp()] <<< 1
}
- delete times[p]
- delete last_pp[p]
+ delete times[tid()]
+ delete last_pp[tid()]
}
probe $1.statement(@2 "@*:*") {
t = gettimeofday_us()
- p = tid()
- s = times[p]
+ s = times[tid()]
if (s) {
e = t - s
- region[last_pp[p]] <<< e
- cfg[last_pp[p], pp()] <<< 1
+ region[last_pp[tid()]] <<< e
+ cfg[last_pp[tid()], pp()] <<< 1
}
- times[p] = t
- last_pp[p] = pp()
+ times[tid()] = t
+ last_pp[tid()] = pp()
}
probe end {
}
probe syscall.poll.return {
- p = pid()
- if ($return == 0 && to[p] > 0 ) {
- poll_timeout[p]++
- timeout_count[p]++
- process[p] = execname()
- delete to[p]
+ if ($return == 0 && to[pid()] > 0 ) {
+ poll_timeout[pid()]++
+ timeout_count[pid()]++
+ process[pid()] = execname()
+ delete to[pid()]
}
}
probe syscall.epoll_wait.return {
- p = pid()
- if ($return == 0 && to[p] > 0 ) {
- epoll_timeout[p]++
- timeout_count[p]++
+ if ($return == 0 && to[pid()] > 0 ) {
+ epoll_timeout[pid()]++
+ timeout_count[pid()]++
process[p] = execname()
- delete to[p]
+ delete to[pid()]
}
}
probe syscall.select.return {
if ($return == 0) {
- p = pid()
- select_timeout[p]++
- timeout_count[p]++
- process[p] = execname()
+ select_timeout[pid()]++
+ timeout_count[pid()]++
+ process[pid()] = execname()
}
}
probe syscall.futex.return {
if (errno_str($return) == "ETIMEDOUT") {
- p = pid()
- futex_timeout[p]++
- timeout_count[p]++
- process[p] = execname()
+ futex_timeout[pid()]++
+ timeout_count[pid()]++
+ process[pid()] = execname()
}
}
probe syscall.nanosleep.return {
if ($return == 0) {
- p = pid()
- nanosleep_timeout[p]++
- timeout_count[p]++
- process[p] = execname()
+ nanosleep_timeout[pid()]++
+ timeout_count[pid()]++
+ process[pid()] = execname()
}
}
probe kernel.function("it_real_fn") {
- p = pid()
- itimer_timeout[p]++
- timeout_count[p]++
- process[p] = execname()
+ itimer_timeout[pid()]++
+ timeout_count[pid()]++
+ process[pid()] = execname()
}
probe syscall.rt_sigtimedwait.return {
if (errno_str($return) == "EAGAIN") {
- p = pid()
- signal_timeout[p]++
- timeout_count[p]++
- process[p] = execname()
+ signal_timeout[pid()]++
+ timeout_count[pid()]++
+ process[pid()] = execname()
}
}
probe syscall.exit {
- p = pid()
- if (p in process) {
- delete process[p]
- delete timeout_count[p]
- delete poll_timeout[p]
- delete epoll_timeout[p]
- delete select_timeout[p]
- delete itimer_timeout[p]
- delete futex_timeout[p]
- delete nanosleep_timeout[p]
- delete signal_timeout[p]
+ if (pid() in process) {
+ delete process[pid()]
+ delete timeout_count[pid()]
+ delete poll_timeout[pid()]
+ delete epoll_timeout[pid()]
+ delete select_timeout[pid()]
+ delete itimer_timeout[pid()]
+ delete futex_timeout[pid()]
+ delete nanosleep_timeout[pid()]
+ delete signal_timeout[pid()]
}
}
# leaving the guest vm for some reason
probe kernel.trace("kvm_exit")
{
- p = tid()
- e_time[p] = gettimeofday_us()
- reason[p] = $exit_reason;
+ e_time[tid()] = gettimeofday_us()
+ reason[tid()] = $exit_reason;
kvm_isa = @defined($isa) ? $isa : 0
}
probe kernel.trace("kvm_entry")
{
new_t = gettimeofday_us();
- p = tid()
- if ( [p] in e_time) {
- elapsed = new_t - e_time[p]
- stats[reason[p]] <<< elapsed
- delete e_time[p]
- delete reason[p]
+ if ( [tid()] in e_time) {
+ elapsed = new_t - e_time[tid()]
+ stats[reason[tid()]] <<< elapsed
+ delete e_time[tid()]
+ delete reason[tid()]
}
}