blob: d6698624f511c9103f2b32253fb34ef23d977791 [file] [log] [blame]
Brendan Greggebdb2422015-08-18 16:53:41 -07001#!/usr/bin/python
Brendan Gregg48fbc3e2015-08-18 14:56:14 -07002#
Brendan Gregg4cbdef72015-08-29 14:53:22 +10003# vfscount Count VFS calls ("vfs_*").
Brendan Gregg48fbc3e2015-08-18 14:56:14 -07004# For Linux, uses BCC, eBPF. See .c file.
5#
6# Written as a basic example of counting functions.
7#
8# Copyright (c) 2015 Brendan Gregg.
9# Licensed under the Apache License, Version 2.0 (the "License")
10#
11# 14-Aug-2015 Brendan Gregg Created this.
12
Brendan Gregg762b1b42015-08-18 16:49:48 -070013from __future__ import print_function
Brenden Blancoc35989d2015-09-02 18:04:07 -070014from bcc import BPF
Brendan Greggd21af642015-09-04 17:42:51 -070015from time import sleep
Brendan Gregg48fbc3e2015-08-18 14:56:14 -070016
Brendan Gregg48fbc3e2015-08-18 14:56:14 -070017# load BPF program
18b = BPF(src_file = "vfscount.c")
Brendan Gregg4cbdef72015-08-29 14:53:22 +100019b.attach_kprobe(event_re="^vfs_.*", fn_name="do_count")
Brendan Gregg48fbc3e2015-08-18 14:56:14 -070020
21# header
Brendan Gregg762b1b42015-08-18 16:49:48 -070022print("Tracing... Ctrl-C to end.")
Brendan Gregg48fbc3e2015-08-18 14:56:14 -070023
24# output
25try:
26 sleep(99999999)
27except KeyboardInterrupt:
28 pass
29
Brendan Gregg4cbdef72015-08-29 14:53:22 +100030print("\n%-16s %-26s %8s" % ("ADDR", "FUNC", "COUNT"))
Brendan Gregg057b0782015-08-20 12:40:37 -070031counts = b.get_table("counts")
Brendan Gregg48fbc3e2015-08-18 14:56:14 -070032for k, v in sorted(counts.items(), key=lambda counts: counts[1].value):
Brendan Gregg921008e2015-08-29 15:14:07 +100033 print("%-16x %-26s %8d" % (k.ip, b.ksym(k.ip), v.value))