blob: cae57ea8ad33d59fc49033bac9970b976c55344c [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# syncsnoop Trace sync() syscall.
5# For Linux, uses BCC, eBPF. Embedded C.
Brendan Gregg48fbc3e2015-08-18 14:56:14 -07006#
7# Written as a basic example of BCC trace & reformat. See
8# examples/hello_world.py for a BCC trace with default output example.
9#
10# Copyright (c) 2015 Brendan Gregg.
11# Licensed under the Apache License, Version 2.0 (the "License")
12#
Alexei Starovoitovbdf07732016-01-14 10:09:20 -080013# 13-Aug-2015 Brendan Gregg Created this.
Brendan Gregg48fbc3e2015-08-18 14:56:14 -070014
Brendan Gregg762b1b42015-08-18 16:49:48 -070015from __future__ import print_function
Brenden Blancoc35989d2015-09-02 18:04:07 -070016from bcc import BPF
Brendan Gregg48fbc3e2015-08-18 14:56:14 -070017
18# load BPF program
Alexei Starovoitovbdf07732016-01-14 10:09:20 -080019b = BPF(text="""
Brendan Gregg61c7ff12015-09-10 13:43:34 -070020void kprobe__sys_sync(void *ctx) {
Alexei Starovoitovbdf07732016-01-14 10:09:20 -080021 bpf_trace_printk("sync()\\n");
Brendan Gregg48fbc3e2015-08-18 14:56:14 -070022};
23""")
Brendan Gregg48fbc3e2015-08-18 14:56:14 -070024
25# header
Brendan Gregg762b1b42015-08-18 16:49:48 -070026print("%-18s %s" % ("TIME(s)", "CALL"))
Brendan Gregg48fbc3e2015-08-18 14:56:14 -070027
Brendan Gregg48fbc3e2015-08-18 14:56:14 -070028# format output
29while 1:
Alexei Starovoitovbdf07732016-01-14 10:09:20 -080030 (task, pid, cpu, flags, ts, msg) = b.trace_fields()
31 print("%-18.9f %s" % (ts, msg))