Functions | |
| str | blank_comments_and_strings (str text) |
| Replace comments, string and character literals with spaces, keeping offsets and newlines. | |
| find_functions (str code) | |
| Locate top-level function definitions in comment- and string-blanked C code. | |
| check_function (str code, int body_open, int body_close) | |
| Check one function body against the timer rules. | |
| bool | ends_in_return (str body) |
| Whether a function body's last top-level statement is a return. | |
| int | line_of (str text, int offset) |
| 1-based line number of an offset. | |
| int | main () |
| Run the audit over src/*.c, include/*.h and tests/c, print problems. | |
Variables | |
| REPO_ROOT = Path(__file__).resolve().parents[2] | |
| SOURCES = sorted((REPO_ROOT / "src").glob("*.c")) | |
| dict | EXCLUDED |
| dict | EXCLUDED_FILES |
| BEGIN_RE = re.compile(r"\bPROFILE_(?:FUNCTION|HELPER)_BEGIN\b") | |
| END_TAIL_RE = re.compile(r"PROFILE_(?:FUNCTION|HELPER)_END\s*;\s*$") | |
| RETURN_RE = re.compile(r"\b(?:return\b|PetscFunctionReturn(?:Void)?\s*\()") | |
| FUNCT_RE = re.compile(r"\b__FUNCT__\b") | |
| dict | CONTROL_WORDS = {"if", "for", "while", "switch", "return", "sizeof", "do", "else"} |
Enforce that every eligible C function in src/ is profiled and closes its timer on every return. Rules (docs/pages/09_Monitor_Reference.md, profiling): - every function defined in src/*.c that is not `static inline` and is not on the exclusion list below begins exactly one timer, PROFILE_FUNCTION_BEGIN or PROFILE_HELPER_BEGIN; - every explicit `return` and `PetscFunctionReturn`/`PetscFunctionReturnVoid` after the timer's BEGIN is immediately preceded by PROFILE_FUNCTION_END or PROFILE_HELPER_END, and a function whose body can fall off its end ends with one; error returns inside SETERRQ/PetscCall/CHKERRQ are not explicit returns and are exempt; - no file defines or reads `__FUNCT__`: timers, logging and PETSc's error traces all take the name from `__func__`. A missed END leaves the function's PETSc event open, after which its calls are no longer recorded.
| str audit_profiling_coverage.blank_comments_and_strings | ( | str | text | ) |
Replace comments, string and character literals with spaces, keeping offsets and newlines.
| [in] | text | C source. |
Definition at line 62 of file audit_profiling_coverage.py.
| audit_profiling_coverage.find_functions | ( | str | code | ) |
Locate top-level function definitions in comment- and string-blanked C code.
| [in] | code | Output of blank_comments_and_strings(). |
Definition at line 110 of file audit_profiling_coverage.py.
| audit_profiling_coverage.check_function | ( | str | code, |
| int | body_open, | ||
| int | body_close | ||
| ) |
Check one function body against the timer rules.
| [in] | code | Blanked source. |
| [in] | body_open | Offset of the body's opening brace. |
| [in] | body_close | Offset of the body's closing brace. |
Definition at line 146 of file audit_profiling_coverage.py.
| bool audit_profiling_coverage.ends_in_return | ( | str | body | ) |
Whether a function body's last top-level statement is a return.
A body ending in a block (}) or in any other statement can fall off its end.
| [in] | body | Blanked function body, without its braces. |
Definition at line 172 of file audit_profiling_coverage.py.
| int audit_profiling_coverage.line_of | ( | str | text, |
| int | offset | ||
| ) |
1-based line number of an offset.
| [in] | text | Source text. |
| [in] | offset | Character offset. |
Definition at line 195 of file audit_profiling_coverage.py.
| int audit_profiling_coverage.main | ( | ) |
Run the audit over src/*.c, include/*.h and tests/c, print problems.
Definition at line 205 of file audit_profiling_coverage.py.
| audit_profiling_coverage.REPO_ROOT = Path(__file__).resolve().parents[2] |
Definition at line 23 of file audit_profiling_coverage.py.
| audit_profiling_coverage.SOURCES = sorted((REPO_ROOT / "src").glob("*.c")) |
Definition at line 24 of file audit_profiling_coverage.py.
| dict audit_profiling_coverage.EXCLUDED |
Definition at line 27 of file audit_profiling_coverage.py.
| dict audit_profiling_coverage.EXCLUDED_FILES |
Definition at line 50 of file audit_profiling_coverage.py.
| audit_profiling_coverage.BEGIN_RE = re.compile(r"\bPROFILE_(?:FUNCTION|HELPER)_BEGIN\b") |
Definition at line 55 of file audit_profiling_coverage.py.
| audit_profiling_coverage.END_TAIL_RE = re.compile(r"PROFILE_(?:FUNCTION|HELPER)_END\s*;\s*$") |
Definition at line 56 of file audit_profiling_coverage.py.
| audit_profiling_coverage.RETURN_RE = re.compile(r"\b(?:return\b|PetscFunctionReturn(?:Void)?\s*\()") |
Definition at line 57 of file audit_profiling_coverage.py.
| audit_profiling_coverage.FUNCT_RE = re.compile(r"\b__FUNCT__\b") |
Definition at line 58 of file audit_profiling_coverage.py.
| dict audit_profiling_coverage.CONTROL_WORDS = {"if", "for", "while", "switch", "return", "sizeof", "do", "else"} |
Definition at line 59 of file audit_profiling_coverage.py.