xref: /aosp_15_r20/external/bcc/examples/tracing/task_switch.py (revision 387f9dfdfa2baef462e92476d413c7bc2470293e)
1*387f9dfdSAndroid Build Coastguard Worker#!/usr/bin/python
2*387f9dfdSAndroid Build Coastguard Worker# Copyright (c) PLUMgrid, Inc.
3*387f9dfdSAndroid Build Coastguard Worker# Licensed under the Apache License, Version 2.0 (the "License")
4*387f9dfdSAndroid Build Coastguard Worker
5*387f9dfdSAndroid Build Coastguard Workerfrom bcc import BPF
6*387f9dfdSAndroid Build Coastguard Workerfrom time import sleep
7*387f9dfdSAndroid Build Coastguard Worker
8*387f9dfdSAndroid Build Coastguard Workerb = BPF(src_file="task_switch.c")
9*387f9dfdSAndroid Build Coastguard Workerb.attach_kprobe(event_re="^finish_task_switch$|^finish_task_switch\.isra\.\d$",
10*387f9dfdSAndroid Build Coastguard Worker                fn_name="count_sched")
11*387f9dfdSAndroid Build Coastguard Worker
12*387f9dfdSAndroid Build Coastguard Worker# generate many schedule events
13*387f9dfdSAndroid Build Coastguard Workerfor i in range(0, 100): sleep(0.01)
14*387f9dfdSAndroid Build Coastguard Worker
15*387f9dfdSAndroid Build Coastguard Workerfor k, v in b["stats"].items():
16*387f9dfdSAndroid Build Coastguard Worker    print("task_switch[%5d->%5d]=%u" % (k.prev_pid, k.curr_pid, v.value))
17