#! /usr/bin/env stap # This script displays the top 10 most shared locks, i.e. locks which are # accessed by multiple different threads. # Example output: # Tracing pid 8874 # ^Clock #threads acquisitions # 0x0000000002531d90 8 8 # 0x0000000002652650 5 120 # 0x000000000259d2c8 5 5396 # 0x000000000259cb20 5 2588 # 0x000000000259ca00 5 6 # 0x000000000263a7f0 3 26 # 0x0000000002637ba8 3 219 # 0x0000000002637aa0 3 106 # 0x0000000002637700 3 135 # 0x00000000025b7af0 3 1005 global lock_thread_dist # map[lock, thread] = count global top10 probe begin { if (target() == 0) { println("Target pid or process needed.") exit() } printf("Tracing pid %d\n", target()) } probe end { count=0 sum=0 lock=0 foreach ([l-, t] in lock_thread_dist) { if (lock != l) { if (lock != 0) top10[lock, count] = sum lock = l count = 0 sum = 0 } count++ sum += @count(lock_thread_dist[l,t]) } println("lock\t#threads\tacquisitions") foreach ([l, c-] in top10 limit 10) printf("%p\t%d\t%d\n", l, c, top10[l,c]) } probe process("/lib64/libpthread.so.0").mark("mutex_acquire") { lock_thread_dist[$arg1, tid()] <<< 1 }