• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/python
2# @lint-avoid-python-3-compatibility-imports
3#
4# syncsnoop Trace sync() syscall.
5#           For Linux, uses BCC, eBPF. Embedded C.
6#
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#
13# 13-Aug-2015   Brendan Gregg   Created this.
14
15from __future__ import print_function
16from bcc import BPF
17
18# load BPF program
19b = BPF(text="""
20void kprobe__sys_sync(void *ctx) {
21    bpf_trace_printk("sync()\\n");
22};
23""")
24
25# header
26print("%-18s %s" % ("TIME(s)", "CALL"))
27
28# format output
29while 1:
30    (task, pid, cpu, flags, ts, msg) = b.trace_fields()
31    print("%-18.9f %s" % (ts, msg))
32