| 1 |
#! /usr/bin/env stap |
| 2 |
# |
| 3 |
# Copyright (C) 2018 Red Hat, Inc. |
| 4 |
# By William Cohen, Red Hat Inc. |
| 5 |
# [email protected] |
| 6 |
# |
| 7 |
# USAGE: stap syscalllatencybypid.stp --suppress-handler-errors |
| 8 |
# |
| 9 |
# The "--suppress-handler-errors" option allows the script to continue |
| 10 |
# run when probes are skipped. The probe skips make the data less accurate, |
| 11 |
# but are otherwise harmless. |
| 12 |
|
| 13 |
global arr%[20000], sys%[20000], entry_time%[20000] |
| 14 |
|
| 15 |
probe syscall_any { |
| 16 |
entry_time[tid()] = gettimeofday_ns(); |
| 17 |
sys[tid()] = syscall_nr |
| 18 |
} |
| 19 |
probe syscall_any.return { |
| 20 |
et = entry_time[tid()] |
| 21 |
id = sys[tid()] |
| 22 |
delete entry_time[tid()] |
| 23 |
delete sys[tid()] |
| 24 |
if (et) |
| 25 |
arr[pid(), id] += (gettimeofday_ns() - et) |
| 26 |
} |
| 27 |
|
| 28 |
probe scheduler.process_exit { delete arr[pid(),*] } |
| 29 |
|
| 30 |
function ns2sec:string(v:long) { |
| 31 |
return sprintf("%d.%d", v/1000000000, v%1000000000) |
| 32 |
} |
| 33 |
|
| 34 |
probe prometheus { |
| 35 |
@prometheus_dump_array2_map(arr, "syscall_time", "pid", "syscall", |
| 36 |
ns2sec, sprint, syscall_name) |
| 37 |
} |