summaryrefslogtreecommitdiff
path: root/tools/perf/scripts/python/futex-contention.py
blob: 7e884d46f92066fcfd29f5a3222f90bbdd0640e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# futex contention
# (c) 2010, Arnaldo Carvalho de Melo <acme@redhat.com>
# Licensed under the terms of the GNU GPL License version 2
#
# Translation of:
#
# http://sourceware.org/systemtap/wiki/WSFutexContention
#
# to perf python scripting.
#
# Measures futex contention

from __future__ import print_function

import os
import sys
sys.path.append(os.environ['PERF_EXEC_PATH'] +
                '/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
from Util import *

process_names = {}
thread_thislock = {}
thread_blocktime = {}

lock_waits = {}  # long-lived stats on (tid,lock) blockage elapsed time
process_names = {}  # long-lived pid-to-execname mapping


def syscalls__sys_enter_futex(event, ctxt, cpu, s, ns, tid, comm, callchain,
                              nr, uaddr, op, val, utime, uaddr2, val3):
    cmd = op & FUTEX_CMD_MASK
    if cmd != FUTEX_WAIT:
        return  # we don't care about originators of WAKE events

    process_names[tid] = comm
    thread_thislock[tid] = uaddr
    thread_blocktime[tid] = nsecs(s, ns)


def syscalls__sys_exit_futex(event, ctxt, cpu, s, ns, tid, comm, callchain,
                             nr, ret):
    if tid in thread_blocktime:
        elapsed = nsecs(s, ns) - thread_blocktime[tid]
        add_stats(lock_waits, (tid, thread_thislock[tid]), elapsed)
        del thread_blocktime[tid]
        del thread_thislock[tid]


def trace_begin():
    print("Press control+C to stop and show the summary")


def trace_end():
    for (tid, lock) in lock_waits:
        min, max, avg, count = lock_waits[tid, lock]
        print("%s[%d] lock %x contended %d times, %d avg ns [max: %d ns, min %d ns]" %
              (process_names[tid], tid, lock, count, avg, max, min))
r>2021-02-08block: factor out a bvec_alloc_gfp helperChristoph Hellwig 2021-02-08block: move struct biovec_slab to bio.cChristoph Hellwig 2021-02-08block: reuse BIO_INLINE_VECS for integrity bvecsChristoph Hellwig 2021-02-02block: fix memory leak of bvecMing Lei 2021-01-27block: split bio_kmalloc from bio_alloc_biosetChristoph Hellwig 2021-01-26block: inherit BIO_REMAPPED when cloning biosChristoph Hellwig 2021-01-25bio: don't copy bvec for direct IOPavel Begunkov 2021-01-25block/psi: remove PSI annotations from direct IOPavel Begunkov 2021-01-24block: set .bi_max_vecs as actual allocated vector numberMing Lei 2021-01-24block: don't allocate inline bvecs if this bioset needn't bvecsMing Lei 2021-01-24block: manage bio slab cache by xarrayMing Lei 2021-01-24block: store a block_device pointer in struct bioChristoph Hellwig 2020-12-02bio: optimise bvec iterationPavel Begunkov 2020-12-01block: switch partition lookup to use struct block_deviceChristoph Hellwig 2020-12-01block: remove the nr_sects field in struct hd_structChristoph Hellwig 2020-10-28block: advance iov_iter on bio_add_hw_page failureNaohiro Aota 2020-10-15docs: bio: fix a kerneldoc markupMauro Carvalho Chehab 2020-10-15block: bio: fix a warning at the kernel-doc markupsMauro Carvalho Chehab 2020-10-13Merge tag 'block-5.10-2020-10-12' of git://git.kernel.dk/linux-blockLinus Torvalds 2020-10-05block: make bio_crypt_clone() able to failEric Biggers 2020-09-09block: Set same_page to false in __bio_try_merge_page if ret is falseRitesh Harjani 2020-08-17block: Fix page_is_mergeable() for compound pagesMatthew Wilcox (Oracle) 2020-07-31block: bio: delete duplicated wordsRandy Dunlap 2020-07-01block: rename generic_make_request to submit_bio_noacctChristoph Hellwig 2020-06-29block: move the bio cgroup associatation helpers to blk-cgroup.cChristoph Hellwig 2020-06-29block: move bio_associate_blkg_from_page to mm/page_io.cChristoph Hellwig 2020-06-29block: merge __bio_associate_blkg into bio_associate_blkg_from_cssChristoph Hellwig 2020-06-29block: really clone the block cgroup in bio_clone_blkg_associationChristoph Hellwig 2020-06-29block: remove bio_disassociate_blkgChristoph Hellwig 2020-06-24block: bio: Use struct_size() in kmalloc()Gustavo A. R. Silva