Skip to contentSkip to conversation

perf clang-format: Prioritize Python.h and expand other categories

PATCH Superseded Ian Rogers 3 participants 6 messages May 26 – Jul 12 perf events

lore
Share & tools
lore

Ian Rogers

author reviewer
#0 lore raw

PATCH 1/1 perf clang-format: Prioritize Python.h and expand other categories

- Prioritize Python.h by sorting it first (Priority 0).
- Shift other header priorities down to accommodate Python.h.
- Sanity check and complete "C Standard Library Headers" up to C23 (added stdbit.h, stdckdint.h).
- Sanity check and complete "OS/System-Specific Headers" based on actual usage in tools/perf (added asm-generic, uapi, and various flat POSIX/system headers).

Assisted-by Antigravity:gemini-3.5-flash
---
 tools/perf/.clang-format | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)
tools/perf/.clang-format +11 -8
index 902b2f7456f6..68b1c073d070 100644
@@ -2,19 +2,22 @@ BasedOnStyle: InheritParentConfig
 SortIncludes: true
 IncludeBlocks: Regroup
 IncludeCategories:
+  # Python.h must be first
+  - Regex:           '^<Python\.h>'
+    Priority:        0
   # Implicitly the corresponding header for the C file has Priority 0
   # C Standard Library Headers
-  - Regex:           '^<(assert|complex|ctype|errno|fenv|float|inttypes|iso646|limits|locale|math|setjmp|signal|stdalign|stdarg|stdatomic|stdbool|stddef|stdint|stdio|stdlib|stdnoreturn|string|tgmath|threads|time|uchar|wchar|wctype)\.h>'
-    Priority:        1
-  # OS/System-Specific Headers (directories)
-  - Regex:           '^<(sys|linux|asm|arpa|net|netinet|x86_64|machine)/.*>'
+  - Regex:           '^<(assert|complex|ctype|errno|fenv|float|inttypes|iso646|limits|locale|math|setjmp|signal|stdalign|stdarg|stdatomic|stdbit|stdbool|stdckdint|stddef|stdint|stdio|stdlib|stdnoreturn|string|tgmath|threads|time|uchar|wchar|wctype)\.h>'
     Priority:        2
+  # OS/System-Specific Headers (directories)
+  - Regex:           '^<(arpa|asm|asm-generic|linux|machine|net|netinet|sys|uapi|x86_64)/.*>'
+    Priority:        3
   # OS/System-Specific Headers (POSIX/System flat headers)
-  - Regex:           '^<(unistd|pthread|fcntl|dirent|dlfcn|poll|sched|semaphore|spawn|syslog|termios|pwd|grp|netdb|sysexits|err|paths|pty|utmp|resolv|ifaddrs|elf|libelf|gelf)\.h>'
-    Priority:        2
+  - Regex:           '^<(aio|byteswap|dirent|dlfcn|elf|endian|err|execinfo|fcntl|features|fnmatch|ftw|gelf|getopt|grp|ifaddrs|libelf|libgen|malloc|memory|mntent|netdb|numa|numaif|paths|poll|pthread|pty|pwd|regex|resolv|sched|semaphore|spawn|strings|syscall|sysexits|syslog|termios|unistd|utmp|x86intrin)\.h>'
+    Priority:        3
   # Third-Party Library Headers
   - Regex:           '^<.*>'
-    Priority:        3
+    Priority:        4
   # Your Project's Other Headers
   - Regex:           '^".*"'
-    Priority:        4
+    Priority:        5
Signature · 1 line
2.54.0.823.g6e5bcc1fc9-goog
#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] Python.h shares Priority 0 with the implicit main header, failing to guarantee it is strictly…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] Python.h shares Priority 0 with the implicit main header, failing to guarantee it is strictly sorted first. --

commit 68559f2bb53c7691fdfd5703129afea21a0050da
Author: Ian Rogers <[email protected]>

perf clang-format: Prioritize Python.h and expand other categories

This commit adds Python.h to the clang-format configuration with priority 0 to ensure it is sorted first. It also expands the standard and system header categories, shifting their priorities down to accommodate the changes.

tools/perf/.clang-format BasedOnStyle: InheritParentConfig · line 8

Quoted 12 lines
tools/perf/.clang-format +3 -0
index 902b2f7456f61..68b1c073d070b 100644
@@ -2,19 +2,22 @@ BasedOnStyle: InheritParentConfig
 SortIncludes: true
 IncludeBlocks: Regroup
 IncludeCategories:
+  # Python.h must be first
+  - Regex:           '^<Python\.h>'
+    Priority:        0
   # Implicitly the corresponding header for the C file has Priority 0

[Severity: Low]
Since the corresponding main header for the C file implicitly has Priority 0, does assigning Priority 0 to Python.h guarantee it will always be sorted first?

Because both share the same priority, they are placed in the same include block and sorted alphabetically. While uppercase 'P' alphabetically precedes most lowercase filenames, it might not provide the strict overriding priority intended here.

Would it be safer to assign a negative priority (such as Priority: -1) to Python.h to strictly guarantee it is placed before the main header?

Additionally, I noticed that the C Standard Library headers were shifted to Priority 2, leaving Priority 1 completely unused:

Quoted 5 lines
tools/perf/.clang-format +1 -2
   # C Standard Library Headers
-  - Regex:           '^<(assert|complex|ctype|errno|fenv|float|inttypes|iso646|limits|locale|math|setjmp|signal|stdalign|stdarg|stdatomic|stdbool|stddef|stdint|stdio|stdlib|stdnoreturn|string|tgmath|threads|time|uchar|wchar|wctype)\.h>'
-    Priority:        1
+  - Regex:           '^<(assert|complex|ctype|errno|fenv|float|inttypes|iso646|limits|locale|math|setjmp|signal|stdalign|stdarg|stdatomic|stdbit|stdbool|stdckdint|stddef|stdint|stdio|stdlib|stdnoreturn|string|tgmath|threads|time|uchar|wchar|wctype)\.h>'
     Priority:        2
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
author reviewer
#2 lore raw

PATCH v2 1/1 perf clang-format: Prioritize Python.h and expand other categories

In reply to Ian Rogers

- Prioritize Python.h by sorting it first (Priority 0).
- Shift other header priorities down to accommodate Python.h.
- Sanity check and complete "C Standard Library Headers" up to C23 (added stdbit.h, stdckdint.h).
- Sanity check and complete "OS/System-Specific Headers" based on actual usage in tools/perf (added asm-generic, uapi, and various flat POSIX/system headers).

Assisted-by Antigravity:gemini-3.5-flash
---
 tools/perf/.clang-format | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
tools/perf/.clang-format +6 -3
index 902b2f7456f6..e4cff363a603 100644
@@ -2,15 +2,18 @@ BasedOnStyle: InheritParentConfig
 SortIncludes: true
 IncludeBlocks: Regroup
 IncludeCategories:
+  # Python.h must be first
+  - Regex:           '^<Python\.h>'
+    Priority:        -1
   # Implicitly the corresponding header for the C file has Priority 0
   # C Standard Library Headers
-  - Regex:           '^<(assert|complex|ctype|errno|fenv|float|inttypes|iso646|limits|locale|math|setjmp|signal|stdalign|stdarg|stdatomic|stdbool|stddef|stdint|stdio|stdlib|stdnoreturn|string|tgmath|threads|time|uchar|wchar|wctype)\.h>'
+  - Regex:           '^<(assert|complex|ctype|errno|fenv|float|inttypes|iso646|limits|locale|math|setjmp|signal|stdalign|stdarg|stdatomic|stdbit|stdbool|stdckdint|stddef|stdint|stdio|stdlib|stdnoreturn|string|tgmath|threads|time|uchar|wchar|wctype)\.h>'
     Priority:        1
   # OS/System-Specific Headers (directories)
-  - Regex:           '^<(sys|linux|asm|arpa|net|netinet|x86_64|machine)/.*>'
+  - Regex:           '^<(arpa|asm|asm-generic|linux|machine|net|netinet|sys|uapi|x86_64)/.*>'
     Priority:        2
   # OS/System-Specific Headers (POSIX/System flat headers)
-  - Regex:           '^<(unistd|pthread|fcntl|dirent|dlfcn|poll|sched|semaphore|spawn|syslog|termios|pwd|grp|netdb|sysexits|err|paths|pty|utmp|resolv|ifaddrs|elf|libelf|gelf)\.h>'
+  - Regex:           '^<(aio|byteswap|dirent|dlfcn|elf|endian|err|execinfo|fcntl|features|fnmatch|ftw|gelf|getopt|grp|ifaddrs|libelf|libgen|malloc|memory|mntent|netdb|numa|numaif|paths|poll|pthread|pty|pwd|regex|resolv|sched|semaphore|spawn|strings|syscall|sysexits|syslog|termios|unistd|utmp|x86intrin)\.h>'
     Priority:        2
   # Third-Party Library Headers
   - Regex:           '^<.*>'
Signature · 1 line
2.54.0.823.g6e5bcc1fc9-goog
#3 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] The commit message contradicts the actual patch implementation regarding header sorting…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The commit message contradicts the actual patch implementation regarding header sorting priorities. --

commit 6df1a36d29968fecb941bfb94a7d676143f46552
Author: Ian Rogers <[email protected]>

perf clang-format: Prioritize Python.h and expand other categories

This commit updates the .clang-format rules for the perf tools. It prioritizes Python.h sorting and expands the regex lists for C standard library and OS specific headers.

Quoted 2 lines

- Prioritize Python.h by sorting it first (Priority 0).
- Shift other header priorities down to accommodate Python.h.

[Severity: Medium]
Is this description accurate regarding the patch implementation?

The commit message states Python.h is set to Priority 0 and other priorities are shifted down. However, the patch actually assigns Priority -1 to Python.h and leaves the other categories at their original priorities (1 and 2).

Setting the priority to -1 also means Python.h will be sorted before the C file's main header, which implicitly has Priority 0.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
author reviewer
#4 lore raw

PATCH v3 1/1 perf clang-format: Prioritize Python.h and expand other categories

In reply to Ian Rogers

This commit updates the .clang-format rules for the perf tools. It prioritizes Python.h sorting and expands the regex lists for C standard library and OS specific headers.

- Prioritize Python.h by sorting it first (Priority -1), ensuring it is sorted before even the main header (Priority 0).
- Keep other header priorities (1 and 2) to maintain their relative order.
- Sanity check and complete "C Standard Library Headers" up to C23 (added stdbit.h, stdckdint.h).
- Sanity check and complete "OS/System-Specific Headers" based on actual usage in tools/perf (added asm-generic, uapi, and various flat POSIX/system headers).

---
 tools/perf/.clang-format | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
tools/perf/.clang-format +6 -3
index 902b2f7456f6..e4cff363a603 100644
@@ -2,15 +2,18 @@ BasedOnStyle: InheritParentConfig
 SortIncludes: true
 IncludeBlocks: Regroup
 IncludeCategories:
+  # Python.h must be first
+  - Regex:           '^<Python\.h>'
+    Priority:        -1
   # Implicitly the corresponding header for the C file has Priority 0
   # C Standard Library Headers
-  - Regex:           '^<(assert|complex|ctype|errno|fenv|float|inttypes|iso646|limits|locale|math|setjmp|signal|stdalign|stdarg|stdatomic|stdbool|stddef|stdint|stdio|stdlib|stdnoreturn|string|tgmath|threads|time|uchar|wchar|wctype)\.h>'
+  - Regex:           '^<(assert|complex|ctype|errno|fenv|float|inttypes|iso646|limits|locale|math|setjmp|signal|stdalign|stdarg|stdatomic|stdbit|stdbool|stdckdint|stddef|stdint|stdio|stdlib|stdnoreturn|string|tgmath|threads|time|uchar|wchar|wctype)\.h>'
     Priority:        1
   # OS/System-Specific Headers (directories)
-  - Regex:           '^<(sys|linux|asm|arpa|net|netinet|x86_64|machine)/.*>'
+  - Regex:           '^<(arpa|asm|asm-generic|linux|machine|net|netinet|sys|uapi|x86_64)/.*>'
     Priority:        2
   # OS/System-Specific Headers (POSIX/System flat headers)
-  - Regex:           '^<(unistd|pthread|fcntl|dirent|dlfcn|poll|sched|semaphore|spawn|syslog|termios|pwd|grp|netdb|sysexits|err|paths|pty|utmp|resolv|ifaddrs|elf|libelf|gelf)\.h>'
+  - Regex:           '^<(aio|byteswap|dirent|dlfcn|elf|endian|err|execinfo|fcntl|features|fnmatch|ftw|gelf|getopt|grp|ifaddrs|libelf|libgen|malloc|memory|mntent|netdb|numa|numaif|paths|poll|pthread|pty|pwd|regex|resolv|sched|semaphore|spawn|strings|syscall|sysexits|syslog|termios|unistd|utmp|x86intrin)\.h>'
     Priority:        2
   # Third-Party Library Headers
   - Regex:           '^<.*>'
Signature · 1 line
2.54.0.1032.g2f8565e1d1-goog
maintainer Applied
#5 lore raw
Quoted 14 lines · Ian Rogers

This commit updates the .clang-format rules for the perf tools. It prioritizes Python.h sorting and expands the regex lists for C standard library and OS specific headers.

- Prioritize Python.h by sorting it first (Priority -1), ensuring it is sorted before even the main header (Priority 0).
- Keep other header priorities (1 and 2) to maintain their relative order.
- Sanity check and complete "C Standard Library Headers" up to C23 (added stdbit.h, stdckdint.h).
- Sanity check and complete "OS/System-Specific Headers" based on actual usage in tools/perf (added asm-generic, uapi, and various flat POSIX/system headers).

Quoted 1 line

[...]

Applied to perf-tools-next, thanks!

Best regards,
Namhyung