bcc/python: extend perf_event_attr ctype
authorDave Marchevsky <davemarchevsky@fb.com>
Sat, 14 Aug 2021 03:17:27 +0000 (20:17 -0700)
committeryonghong-song <ys114321@gmail.com>
Thu, 19 Aug 2021 17:24:22 +0000 (10:24 -0700)
commitbb691fb8164721ac3a85b29d62883c19a55d4d48
tree065e01fa11be39988a22ce2b0d628451a45a8adf
parent0120770f3cdcd0540861e2f92c4f796fe09c3ff6
bcc/python: extend perf_event_attr ctype

This commit brings the Perf.perf_event_attr ctype in line with version 6
of struct perf_event_attr (see uapi/linux/perf_event.h kernel header).
Specifically:
  * All named fields are added, including field names within anonymous
  unions and bitfields
  * Perf.perf_event_attr now complains when a field which isn't part of
  the ctype struct is set.
    * Goal here is to prevent users from setting a
    recently-added field - which we haven't updated the ctype _fields_ to
    include - and getting confused when it doesn't propagate to the
    perf_event_open syscall. This bit me in #3571 and I am pretty
    familiar with bcc internals so I'd like to prevent this from
    confusing others down the line.
  * Perf.perf_event_attr's 'flags' field is removed as it was a standin
  for the bitfields. The _old_ profile.py was the only script in bcc
  tools that I could find using this.

The last bullet is a breaking change. Although `tools/old/profile.py`
has been migrated to use the bitfield it was flipping using `flags`,
there could be some scripts out in the wild which break. I don't think
this is likely: this stuff hasn't been significantly touched since 2016
and I suspect if users of the python interface were writing lots of
perf_event programs we would've seen more python tools or activity here.

Regardless, there is probably a way to keep `flags` field working while
also exposing named bitfields, but I suspect it'll be ugly and wanted to
see if anyone thought it was necessary.
src/python/bcc/perf.py