| 1 |
#! /usr/bin/env stap |
| 2 |
|
| 3 |
/* |
| 4 |
* Copyright (C) 2009 Red Hat Inc. |
| 5 |
* |
| 6 |
* This copyrighted material is made available to anyone wishing to use, |
| 7 |
* modify, copy, or redistribute it subject to the terms and conditions |
| 8 |
* of the GNU General Public License v.2. |
| 9 |
* |
| 10 |
* You should have received a copy of the GNU General Public License |
| 11 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 12 |
* |
| 13 |
* Description: displays statistics for waiting and holding big kernel lock (BKL) |
| 14 |
* |
| 15 |
* Run: stap bkl_stats.stap |
| 16 |
* |
| 17 |
* Author: William Cohen <[email protected]> |
| 18 |
*/ |
| 19 |
|
| 20 |
global holder_time |
| 21 |
global holder_stats, wait_stats |
| 22 |
global names |
| 23 |
|
| 24 |
probe begin { printf("biglock_stats running\n"); } |
| 25 |
|
| 26 |
probe end, timer.s(5) { |
| 27 |
print_stats() |
| 28 |
} |
| 29 |
|
| 30 |
function print_stats() { |
| 31 |
# print out time waiting and time lock held |
| 32 |
printf("big kernel lock waiting statistics\n"); |
| 33 |
printf("%-16s %6s %6s %6s %6s %6s\n", |
| 34 |
"name", "tid", "count", "min", "avg", "max"); |
| 35 |
foreach (p+ in names) { |
| 36 |
if (@count(wait_stats[p])) |
| 37 |
printf("%16s %6d %6d %6d %6d %6d\n", names[p], p, |
| 38 |
@count(wait_stats[p]), @min(wait_stats[p]), |
| 39 |
@avg(wait_stats[p]), @max(wait_stats[p])); |
| 40 |
} |
| 41 |
|
| 42 |
printf("\n\nbig kernel lock holder statistics\n"); |
| 43 |
printf("%-16s %6s %6s %6s %6s %6s\n", |
| 44 |
"name", "tid", "count", "min", "avg", "max"); |
| 45 |
foreach (p+ in names) { |
| 46 |
if (@count(holder_stats[p])) |
| 47 |
printf("%16s %6d %6d %6d %6d %6d\n", names[p], p, |
| 48 |
@count(holder_stats[p]), @min(holder_stats[p]), |
| 49 |
@avg(holder_stats[p]), @max(holder_stats[p])); |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
probe kernel.function("_lock_kernel").return!, |
| 54 |
kernel.function("lock_kernel").return |
| 55 |
{ |
| 56 |
t = gettimeofday_us() |
| 57 |
s = @entry(gettimeofday_us()) |
| 58 |
holder_time[tid()] = t |
| 59 |
# record the amount of time waiting for the lock |
| 60 |
if (s) { |
| 61 |
wait_stats[tid()] <<< t - s |
| 62 |
names[tid()] = execname() |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
probe kernel.function("_unlock_kernel")!, |
| 67 |
kernel.function("unlock_kernel") |
| 68 |
{ |
| 69 |
t = gettimeofday_us() |
| 70 |
s = holder_time[tid()] |
| 71 |
holder_time[tid()] = t |
| 72 |
# record the amount of time the process held the lock |
| 73 |
if (s) { |
| 74 |
holder_stats[tid()] <<< t - s |
| 75 |
names[tid()] = execname() |
| 76 |
} |
| 77 |
} |