Skip to content

example: add task_perf example #1188

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 12, 2025

Conversation

Phoenix500526
Copy link
Contributor

Cover the BCC python binding to Rust and libbpf-rs.

The BCC python binding output:

$ sudo python3 bcc-example.py
...
python3[65497] ran_for=326.51ms bt_seq=17

  scheduler_tick
  tick_sched_handle
  tick_nohz_highres_handler
  __hrtimer_run_queues
  hrtimer_interrupt
  __sysvec_apic_timer_interrupt
  sysvec_apic_timer_interrupt
  asm_sysvec_apic_timer_interrupt

  scheduler_tick
  tick_sched_handle
  tick_nohz_highres_handler
  __hrtimer_run_queues
  hrtimer_interrupt
  __sysvec_apic_timer_interrupt
  sysvec_apic_timer_interrupt
  asm_sysvec_apic_timer_interrupt

  scheduler_tick
  tick_sched_handle
  tick_nohz_highres_handler
  __hrtimer_run_queues
  hrtimer_interrupt
  __sysvec_apic_timer_interrupt
  sysvec_apic_timer_interrupt
  asm_sysvec_apic_timer_interrupt
  widen_string
  vsnprintf
  seq_printf
  s_show
  seq_read_iter
  seq_read
  proc_reg_read
  vfs_read
  ksys_read
  __x64_sys_read
  x64_sys_call
  do_syscall_64
  entry_SYSCALL_64_after_hwframe

  scheduler_tick
  tick_sched_handle
  tick_nohz_highres_handler
  __hrtimer_run_queues
  hrtimer_interrupt
  __sysvec_apic_timer_interrupt
  sysvec_apic_timer_interrupt
  asm_sysvec_apic_timer_interrupt
  number
  pointer
  vsnprintf
  seq_printf
  s_show
  seq_read_iter
  seq_read
  proc_reg_read
  vfs_read
  ksys_read
  __x64_sys_read
  x64_sys_call
  do_syscall_64
  entry_SYSCALL_64_after_hwframe

  scheduler_tick
  tick_sched_handle
  tick_nohz_highres_handler
  __hrtimer_run_queues
  hrtimer_interrupt
  __sysvec_apic_timer_interrupt
  sysvec_apic_timer_interrupt
  asm_sysvec_apic_timer_interrupt
  number
  pointer
  vsnprintf
  seq_printf
  s_show
  seq_read_iter
  seq_read
  proc_reg_read
  vfs_read
  ksys_read
  __x64_sys_read
  x64_sys_call
  do_syscall_64
  entry_SYSCALL_64_after_hwframe

  scheduler_tick
  tick_sched_handle
  tick_nohz_highres_handler
  __hrtimer_run_queues
  hrtimer_interrupt
  __sysvec_apic_timer_interrupt
  sysvec_apic_timer_interrupt
  asm_sysvec_apic_timer_interrupt
  number
  pointer
  vsnprintf
  seq_printf
  s_show
  seq_read_iter
  seq_read
  proc_reg_read
  vfs_read
  ksys_read
  __x64_sys_read
  x64_sys_call
  do_syscall_64
  entry_SYSCALL_64_after_hwframe

  scheduler_tick
  tick_sched_handle
  tick_nohz_highres_handler
  __hrtimer_run_queues
  hrtimer_interrupt
  __sysvec_apic_timer_interrupt
  sysvec_apic_timer_interrupt
  asm_sysvec_apic_timer_interrupt

  scheduler_tick
  tick_sched_handle
  tick_nohz_highres_handler
  __hrtimer_run_queues
  hrtimer_interrupt
  __sysvec_apic_timer_interrupt
  sysvec_apic_timer_interrupt
  asm_sysvec_apic_timer_interrupt
  __lruvec_stat_mod_folio
  do_anonymous_page
  handle_pte_fault
  __handle_mm_fault
  handle_mm_fault
  do_user_addr_fault
  exc_page_fault
  asm_exc_page_fault

  scheduler_tick
  tick_sched_handle
  tick_nohz_highres_handler
  __hrtimer_run_queues
  hrtimer_interrupt
  __sysvec_apic_timer_interrupt
  sysvec_apic_timer_interrupt
  asm_sysvec_apic_timer_interrupt
  bsearch
  module_get_kallsym
  update_iter_mod
  update_iter
  s_start
  seq_read_iter
  seq_read
  proc_reg_read
  vfs_read
  ksys_read
  __x64_sys_read
  x64_sys_call
  do_syscall_64
  entry_SYSCALL_64_after_hwframe

  scheduler_tick
  tick_sched_handle
  tick_nohz_highres_handler
  __hrtimer_run_queues
  hrtimer_interrupt
  __sysvec_apic_timer_interrupt
  sysvec_apic_timer_interrupt
  asm_sysvec_apic_timer_interrupt

  scheduler_tick
  tick_sched_handle
  tick_nohz_highres_handler
  __hrtimer_run_queues
  hrtimer_interrupt
  __sysvec_apic_timer_interrupt
  sysvec_apic_timer_interrupt
  asm_sysvec_apic_timer_interrupt

  scheduler_tick
  tick_sched_handle
  tick_nohz_highres_handler
  __hrtimer_run_queues
  hrtimer_interrupt
  __sysvec_apic_timer_interrupt
  sysvec_apic_timer_interrupt
  asm_sysvec_apic_timer_interrupt
  clear_page_erms
  get_page_from_freelist
  __alloc_pages
  alloc_pages_mpol
  vma_alloc_folio
  alloc_anon_folio
  do_anonymous_page
  handle_pte_fault
  __handle_mm_fault
  handle_mm_fault
  do_user_addr_fault
  exc_page_fault
  asm_exc_page_fault

  scheduler_tick
  tick_sched_handle
  tick_nohz_highres_handler
  __hrtimer_run_queues
  hrtimer_interrupt
  __sysvec_apic_timer_interrupt
  sysvec_apic_timer_interrupt
  asm_sysvec_apic_timer_interrupt
  number
  pointer
  vsnprintf
  seq_printf
  s_show
  seq_read_iter
  seq_read
  proc_reg_read
  vfs_read
  ksys_read
  __x64_sys_read
  x64_sys_call
  do_syscall_64
  entry_SYSCALL_64_after_hwframe

  scheduler_tick
  tick_sched_handle
  tick_nohz_highres_handler
  __hrtimer_run_queues
  hrtimer_interrupt
  __sysvec_apic_timer_interrupt
  sysvec_apic_timer_interrupt
  asm_sysvec_apic_timer_interrupt
  number
  pointer
  vsnprintf
  seq_printf
  s_show
  seq_read_iter
  seq_read
  proc_reg_read
  vfs_read
  ksys_read
  __x64_sys_read
  x64_sys_call
  do_syscall_64
  entry_SYSCALL_64_after_hwframe

  scheduler_tick
  tick_sched_handle
  tick_nohz_highres_handler
  __hrtimer_run_queues
  hrtimer_interrupt
  __sysvec_apic_timer_interrupt
  sysvec_apic_timer_interrupt
  asm_sysvec_apic_timer_interrupt

  scheduler_tick
  tick_sched_handle
  tick_nohz_highres_handler
  __hrtimer_run_queues
  hrtimer_interrupt
  __sysvec_apic_timer_interrupt
  sysvec_apic_timer_interrupt
  asm_sysvec_apic_timer_interrupt
  vsnprintf
  seq_printf
  s_show
  seq_read_iter
  seq_read
  proc_reg_read
  vfs_read
  ksys_read
  __x64_sys_read
  x64_sys_call
  do_syscall_64
  entry_SYSCALL_64_after_hwframe

  scheduler_tick
  tick_sched_handle
  tick_nohz_highres_handler
  __hrtimer_run_queues
  hrtimer_interrupt
  __sysvec_apic_timer_interrupt
  sysvec_apic_timer_interrupt
  asm_sysvec_apic_timer_interrupt
  do_user_addr_fault
  exc_page_fault
  asm_exc_page_fault
...

The task_longrun output:

$ sudo ./task_longrun -t 10
...
sh[95413] ran_for=11.79ms bt_samples=1
  scheduler_tick
  tick_sched_handle
  tick_nohz_highres_handler
  __hrtimer_run_queues
  hrtimer_interrupt
  __sysvec_apic_timer_interrupt
  sysvec_apic_timer_interrupt
  asm_sysvec_apic_timer_interrupt
  up_write
  __mmap_region
  mmap_region
  do_mmap
  vm_mmap_pgoff
  ksys_mmap_pgoff
  __x64_sys_mmap
  x64_sys_call
  do_syscall_64
  entry_SYSCALL_64_after_hwframe


sed[95415] ran_for=21.59ms bt_samples=2
  scheduler_tick
  tick_sched_handle
  tick_nohz_highres_handler
  __hrtimer_run_queues
  hrtimer_interrupt
  __sysvec_apic_timer_interrupt
  sysvec_apic_timer_interrupt
  asm_sysvec_apic_timer_interrupt
  __mmap_region
  mmap_region
  do_mmap
  vm_mmap_pgoff
  ksys_mmap_pgoff
  __x64_sys_mmap
  x64_sys_call
  do_syscall_64
  entry_SYSCALL_64_after_hwframe

  scheduler_tick
  tick_sched_handle
  tick_nohz_highres_handler
  __hrtimer_run_queues
  hrtimer_interrupt
  __sysvec_apic_timer_interrupt
  sysvec_apic_timer_interrupt
  asm_sysvec_apic_timer_interrupt
  cgroup_exit
  do_exit
  do_group_exit
  __x64_sys_exit_group
  x64_sys_call
  do_syscall_64
  entry_SYSCALL_64_after_hwframe
...

Closes: #1125

Thank you for considering a contribution!

In order to streamline review experience for contributors and reviewers, please
be sure to read and follow the Contributor's Guide. It
lays out basic best practices, which, if followed will reduce unnecessary back
and forth and, ultimately, minimize the time it takes to get your change into
the library.

@Phoenix500526 Phoenix500526 force-pushed the example/task_longrun branch 5 times, most recently from e8cab9b to 258ecbf Compare June 11, 2025 01:24
@danielocfb danielocfb requested a review from d-e-s-o June 11, 2025 16:55
Copy link
Collaborator

@d-e-s-o d-e-s-o left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this example looks great and didn't spot any issues (though I am no expert on the BPF C code). Thanks for taking this on!

Will give others a day or two to take a look as well.

@Phoenix500526 Phoenix500526 force-pushed the example/task_longrun branch from 258ecbf to 3e8e9ba Compare June 12, 2025 01:05
Closes: libbpf#1125
Signed-off-by: Jiawei Zhao <Phoenix500526@163.com>
@Phoenix500526 Phoenix500526 force-pushed the example/task_longrun branch from 3e8e9ba to 0bef90c Compare June 12, 2025 01:07
@d-e-s-o d-e-s-o merged commit d5906f9 into libbpf:master Jun 12, 2025
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add more comprehensive examples
2 participants