blob: bc0f544bf3215e19d11a81b3e842b3ef533d3395 [file] [log] [blame]
Brendan Greggebdb2422015-08-18 16:53:41 -07001#!/usr/bin/python
Alexei Starovoitovbdf07732016-01-14 10:09:20 -08002# @lint-avoid-python-3-compatibility-imports
Brendan Gregg48fbc3e2015-08-18 14:56:14 -07003#
Alexei Starovoitovbdf07732016-01-14 10:09:20 -08004# vfscount Count VFS calls ("vfs_*").
5# For Linux, uses BCC, eBPF. See .c file.
Brendan Gregg48fbc3e2015-08-18 14:56:14 -07006#
7# Written as a basic example of counting functions.
8#
9# Copyright (c) 2015 Brendan Gregg.
10# Licensed under the Apache License, Version 2.0 (the "License")
11#
Alexei Starovoitovbdf07732016-01-14 10:09:20 -080012# 14-Aug-2015 Brendan Gregg Created this.
Brendan Gregg48fbc3e2015-08-18 14:56:14 -070013
Brendan Gregg762b1b42015-08-18 16:49:48 -070014from __future__ import print_function
Brenden Blancoc35989d2015-09-02 18:04:07 -070015from bcc import BPF
Brendan Greggd21af642015-09-04 17:42:51 -070016from time import sleep
Brendan Gregg48fbc3e2015-08-18 14:56:14 -070017
Brendan Gregg48fbc3e2015-08-18 14:56:14 -070018# load BPF program
Alexei Starovoitovbdf07732016-01-14 10:09:20 -080019b = BPF(src_file="vfscount.c")
Brendan Gregg4cbdef72015-08-29 14:53:22 +100020b.attach_kprobe(event_re="^vfs_.*", fn_name="do_count")
Brendan Gregg48fbc3e2015-08-18 14:56:14 -070021
22# header
Brendan Gregg762b1b42015-08-18 16:49:48 -070023print("Tracing... Ctrl-C to end.")
Brendan Gregg48fbc3e2015-08-18 14:56:14 -070024
25# output
26try:
Alexei Starovoitovbdf07732016-01-14 10:09:20 -080027 sleep(99999999)
Brendan Gregg48fbc3e2015-08-18 14:56:14 -070028except KeyboardInterrupt:
Alexei Starovoitovbdf07732016-01-14 10:09:20 -080029 pass
Brendan Gregg48fbc3e2015-08-18 14:56:14 -070030
Brendan Gregg4cbdef72015-08-29 14:53:22 +100031print("\n%-16s %-26s %8s" % ("ADDR", "FUNC", "COUNT"))
Brendan Gregg057b0782015-08-20 12:40:37 -070032counts = b.get_table("counts")
Brendan Gregg48fbc3e2015-08-18 14:56:14 -070033for k, v in sorted(counts.items(), key=lambda counts: counts[1].value):
Alexei Starovoitovbdf07732016-01-14 10:09:20 -080034 print("%-16x %-26s %8d" % (k.ip, b.ksym(k.ip), v.value))