blob: 90c374cd5623d27a474c97e26c7a5a145e02fcb9 [file] [log] [blame]
Alexey Ivanovcc01a9c2019-01-16 09:50:46 -08001#!/usr/bin/python
Alexei Starovoitovb6e43a22015-06-18 14:41:17 -07002# Copyright (c) PLUMgrid, Inc.
3# Licensed under the Apache License, Version 2.0 (the "License")
4
Brenden Blancoc35989d2015-09-02 18:04:07 -07005from bcc import BPF
Alexei Starovoitovb6e43a22015-06-18 14:41:17 -07006from time import sleep
7
Adam Drescher84ce85b2019-05-28 17:29:46 -04008b = BPF(src_file="task_switch.c")
Guodong Xu00b72fd2021-03-13 02:23:47 +00009b.attach_kprobe(event_re="^finish_task_switch$|^finish_task_switch\.isra\.\d$",
10 fn_name="count_sched")
Alexei Starovoitovb6e43a22015-06-18 14:41:17 -070011
12# generate many schedule events
13for i in range(0, 100): sleep(0.01)
14
Brenden Blancoc8b66982015-08-28 23:15:19 -070015for k, v in b["stats"].items():
Alexei Starovoitovb6e43a22015-06-18 14:41:17 -070016 print("task_switch[%5d->%5d]=%u" % (k.prev_pid, k.curr_pid, v.value))