forked from libbpf/libbpf-bootstrap
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
examples/c: add support for clang-format
Add support for clang-format so the code style would be consistent throughout the whole project for C examples. Signed-off-by: Hosein Bakhtiari <[email protected]>
- Loading branch information
1 parent
6ee3b62
commit 500eba1
Showing
18 changed files
with
232 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
# SPDX-License-Identifier: GPL-2.0 | ||
# | ||
# clang-format configuration file. Intended for clang-format >= 11. | ||
# | ||
# For more information, see: | ||
# | ||
# Documentation/process/clang-format.rst | ||
# https://clang.llvm.org/docs/ClangFormat.html | ||
# https://clang.llvm.org/docs/ClangFormatStyleOptions.html | ||
# | ||
--- | ||
AccessModifierOffset: -4 | ||
AlignAfterOpenBracket: Align | ||
AlignConsecutiveAssignments: false | ||
AlignConsecutiveDeclarations: false | ||
AlignEscapedNewlines: Left | ||
AlignOperands: true | ||
AlignTrailingComments: false | ||
AllowAllParametersOfDeclarationOnNextLine: false | ||
AllowShortBlocksOnASingleLine: false | ||
AllowShortCaseLabelsOnASingleLine: false | ||
AllowShortFunctionsOnASingleLine: None | ||
AllowShortIfStatementsOnASingleLine: false | ||
AllowShortLoopsOnASingleLine: false | ||
AlwaysBreakAfterDefinitionReturnType: None | ||
AlwaysBreakAfterReturnType: None | ||
AlwaysBreakBeforeMultilineStrings: false | ||
AlwaysBreakTemplateDeclarations: false | ||
BinPackArguments: true | ||
BinPackParameters: true | ||
BraceWrapping: | ||
AfterClass: false | ||
AfterControlStatement: false | ||
AfterEnum: false | ||
AfterFunction: true | ||
AfterNamespace: true | ||
AfterObjCDeclaration: false | ||
AfterStruct: false | ||
AfterUnion: false | ||
AfterExternBlock: false | ||
BeforeCatch: false | ||
BeforeElse: false | ||
IndentBraces: false | ||
SplitEmptyFunction: true | ||
SplitEmptyRecord: true | ||
SplitEmptyNamespace: true | ||
BreakBeforeBinaryOperators: None | ||
BreakBeforeBraces: Custom | ||
BreakBeforeInheritanceComma: false | ||
BreakBeforeTernaryOperators: false | ||
BreakConstructorInitializersBeforeComma: false | ||
BreakConstructorInitializers: BeforeComma | ||
BreakAfterJavaFieldAnnotations: false | ||
BreakStringLiterals: false | ||
ColumnLimit: 100 | ||
CommentPragmas: '^ IWYU pragma:' | ||
CompactNamespaces: false | ||
ConstructorInitializerAllOnOneLineOrOnePerLine: false | ||
ConstructorInitializerIndentWidth: 8 | ||
ContinuationIndentWidth: 8 | ||
Cpp11BracedListStyle: false | ||
DerivePointerAlignment: false | ||
DisableFormat: false | ||
ExperimentalAutoDetectBinPacking: false | ||
FixNamespaceComments: false | ||
|
||
ForEachMacros: | ||
- 'bpf__perf_for_each_map' | ||
- 'bpf__perf_for_each_map_named' | ||
- 'bpf_for_each_spilled_reg' | ||
- 'bpf_object__for_each_map' | ||
- 'bpf_object__for_each_program' | ||
- 'bpf_object__for_each_safe' | ||
- 'bpf_perf_object__for_each' | ||
- 'for_each_btf_ext_rec' | ||
- 'for_each_btf_ext_sec' | ||
- 'hashmap__for_each_entry' | ||
- 'hashmap__for_each_entry_safe' | ||
- 'hashmap__for_each_key_entry' | ||
- 'hashmap__for_each_key_entry_safe' | ||
- 'list_for_each_entry' | ||
- 'libbpf_nla_for_each_attr' | ||
- 'list_for_each_entry' | ||
- 'list_for_each_entry_continue' | ||
- 'list_for_each_entry_continue_rcu' | ||
- 'list_for_each_entry_continue_reverse' | ||
- 'list_for_each_entry_from' | ||
- 'list_for_each_entry_from_rcu' | ||
- 'list_for_each_entry_from_reverse' | ||
- 'list_for_each_entry_lockless' | ||
- 'list_for_each_entry_rcu' | ||
- 'list_for_each_entry_reverse' | ||
- 'list_for_each_entry_safe' | ||
- 'list_for_each_entry_safe_continue' | ||
- 'list_for_each_entry_safe_from' | ||
- 'list_for_each_entry_safe_reverse' | ||
- 'list_for_each_entry_srcu' | ||
|
||
|
||
IncludeBlocks: Preserve | ||
IncludeCategories: | ||
- Regex: '.*' | ||
Priority: 1 | ||
IncludeIsMainRegex: '(Test)?$' | ||
IndentCaseLabels: false | ||
IndentGotoLabels: false | ||
IndentPPDirectives: None | ||
IndentWidth: 8 | ||
IndentWrappedFunctionNames: false | ||
JavaScriptQuotes: Leave | ||
JavaScriptWrapImports: true | ||
KeepEmptyLinesAtTheStartOfBlocks: false | ||
MacroBlockBegin: '' | ||
MacroBlockEnd: '' | ||
MaxEmptyLinesToKeep: 1 | ||
NamespaceIndentation: None | ||
ObjCBinPackProtocolList: Auto | ||
ObjCBlockIndentWidth: 8 | ||
ObjCSpaceAfterProperty: true | ||
ObjCSpaceBeforeProtocolList: true | ||
|
||
# Taken from git's rules | ||
PenaltyBreakAssignment: 10 | ||
PenaltyBreakBeforeFirstCallParameter: 30 | ||
PenaltyBreakComment: 10 | ||
PenaltyBreakFirstLessLess: 0 | ||
PenaltyBreakString: 10 | ||
PenaltyExcessCharacter: 100 | ||
PenaltyReturnTypeOnItsOwnLine: 60 | ||
|
||
PointerAlignment: Right | ||
ReflowComments: false | ||
SortIncludes: false | ||
SortUsingDeclarations: false | ||
SpaceAfterCStyleCast: false | ||
SpaceAfterTemplateKeyword: true | ||
SpaceBeforeAssignmentOperators: true | ||
SpaceBeforeCtorInitializerColon: true | ||
SpaceBeforeInheritanceColon: true | ||
SpaceBeforeParens: ControlStatementsExceptForEachMacros | ||
SpaceBeforeRangeBasedForLoopColon: true | ||
SpaceInEmptyParentheses: false | ||
SpacesBeforeTrailingComments: 1 | ||
SpacesInAngles: false | ||
SpacesInContainerLiterals: false | ||
SpacesInCStyleCastParentheses: false | ||
SpacesInParentheses: false | ||
SpacesInSquareBrackets: false | ||
Standard: Cpp03 | ||
TabWidth: 8 | ||
UseTab: Always | ||
|
||
AlignConsecutiveMacros: AcrossEmptyLines |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
/build | ||
/examples/c/build | ||
/examples/c/.xmake | ||
/.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,5 @@ | |
/sockfilter | ||
/tc | ||
/ksyscall | ||
/cmake-build-debug/ | ||
/cmake-build-release/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,13 +16,12 @@ static struct env { | |
|
||
const char *argp_program_version = "bootstrap 0.0"; | ||
const char *argp_program_bug_address = "<[email protected]>"; | ||
const char argp_program_doc[] = | ||
"BPF bootstrap demo application.\n" | ||
"\n" | ||
"It traces process start and exits and shows associated \n" | ||
"information (filename, process duration, PID and PPID, etc).\n" | ||
"\n" | ||
"USAGE: ./bootstrap [-d <min-duration-ms>] [-v]\n"; | ||
const char argp_program_doc[] = "BPF bootstrap demo application.\n" | ||
"\n" | ||
"It traces process start and exits and shows associated \n" | ||
"information (filename, process duration, PID and PPID, etc).\n" | ||
"\n" | ||
"USAGE: ./bootstrap [-d <min-duration-ms>] [-v]\n"; | ||
|
||
static const struct argp_option opts[] = { | ||
{ "verbose", 'v', NULL, 0, "Verbose debug output" }, | ||
|
@@ -85,14 +84,14 @@ static int handle_event(void *ctx, void *data, size_t data_sz) | |
strftime(ts, sizeof(ts), "%H:%M:%S", tm); | ||
|
||
if (e->exit_event) { | ||
printf("%-8s %-5s %-16s %-7d %-7d [%u]", | ||
ts, "EXIT", e->comm, e->pid, e->ppid, e->exit_code); | ||
printf("%-8s %-5s %-16s %-7d %-7d [%u]", ts, "EXIT", e->comm, e->pid, e->ppid, | ||
e->exit_code); | ||
if (e->duration_ns) | ||
printf(" (%llums)", e->duration_ns / 1000000); | ||
printf("\n"); | ||
} else { | ||
printf("%-8s %-5s %-16s %-7d %-7d %s\n", | ||
ts, "EXEC", e->comm, e->pid, e->ppid, e->filename); | ||
printf("%-8s %-5s %-16s %-7d %-7d %s\n", ts, "EXEC", e->comm, e->pid, e->ppid, | ||
e->filename); | ||
} | ||
|
||
return 0; | ||
|
@@ -149,8 +148,8 @@ int main(int argc, char **argv) | |
} | ||
|
||
/* Process events */ | ||
printf("%-8s %-5s %-16s %-7s %-7s %s\n", | ||
"TIME", "EVENT", "COMM", "PID", "PPID", "FILENAME/EXIT CODE"); | ||
printf("%-8s %-5s %-16s %-7s %-7s %s\n", "TIME", "EVENT", "COMM", "PID", "PPID", | ||
"FILENAME/EXIT CODE"); | ||
while (!exiting) { | ||
err = ring_buffer__poll(rb, 100 /* timeout, ms */); | ||
/* Ctrl-C will cause -EINTR */ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.