-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
With the loop supported added in the 5.0 kernel we're now able to implement C-style while and for loops. Allowing us to write code like: ``` i:s:1 { $i = 0; while ($i < 100) { if ( ($i/10) * 10 == $i ) { printf("\n"); } if ( ($i/6)*6 == $i ){ printf("XX "); $i+=1; continue; } printf("%2d ", $i); $i+=1; if ($i >= 50) { break; } } } ``` To generate: ``` Attaching 1 probe... XX 1 2 3 4 5 XX 7 8 9 10 11 XX 13 14 15 16 17 XX 19 20 21 22 23 XX 25 26 27 28 29 XX 31 32 33 34 35 XX 37 38 39 40 41 XX 43 44 45 46 47 XX 49 ``` Using only a few instructions: ``` 203: perf_event name 1 tag 4881cacfe5abad41 gpl loaded_at 2020-03-26T18:17:17+0000 uid 0 xlated 448B jited 340B memlock 4096B map_ids 85 ``` Note that LLVM tries to unroll quite aggressively causing a loop the following be fully unrolled: ``` i:s:1 { $i = 0; while ($i < 30) { @=$i; $i++ } } ```
- Loading branch information
Showing
18 changed files
with
490 additions
and
74 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include "common.h" | ||
|
||
namespace bpftrace { | ||
namespace test { | ||
namespace codegen { | ||
|
||
TEST(codegen, basic_while_loop) | ||
{ | ||
test("i:s:1 { $a = 1; while ($a <= 150) { @=$a++; }}", NAME); | ||
} | ||
|
||
} // namespace codegen | ||
} // namespace test | ||
} // namespace bpftrace |
Oops, something went wrong.