-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
llvm-kompile --profile-matching (#1095)
We add a new flag to `llvm-kompile` which, when enabled, instruments the `k_step` function and the optimized `step_<ordinal>` functions with calls to a new translation unit, clock.cpp, which contains some very basic use of `clock_gettime` in order to determine how much time is being spent doing pattern matching in order to try to apply each rewrite step. The resulting file contains data about the ordinal of the rule that applied and the time it took to determine that that rule should apply. It emits this data on stderr in a tabular format that can be read easily by a computer. This information is useful in determining how to optimize pattern matching in cases where it is still not clear where time is being spent even after `kompile -O3 --iterated-threshold 1` is passed. When the flag is not passed to the code generator, no instrumentation is emitted, meaning this is zero-overhead unless it is enabled.
- Loading branch information
Dwight Guth
authored
Jun 20, 2024
1 parent
f419535
commit ffb7b10
Showing
9 changed files
with
87 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ add_library(util STATIC | |
match_log.cpp | ||
search.cpp | ||
util.cpp | ||
clock.cpp | ||
) | ||
|
||
install( | ||
|
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,22 @@ | ||
#include <cstdint> | ||
#include <ctime> | ||
#include <iostream> | ||
|
||
static struct timespec start { }; | ||
|
||
extern "C" { | ||
void start_clock() { | ||
clock_gettime(CLOCK_MONOTONIC, &start); | ||
} | ||
|
||
void stop_clock(uint64_t ordinal) { | ||
struct timespec stop { }; | ||
clock_gettime(CLOCK_MONOTONIC, &stop); | ||
int64_t diff_s = stop.tv_sec - start.tv_sec; | ||
int64_t diff_ns = stop.tv_nsec - start.tv_nsec; | ||
|
||
uint64_t diff_ns_total = diff_s * 1000000000 + diff_ns; | ||
|
||
std::cerr << ordinal << " " << diff_ns_total << std::endl; | ||
} | ||
} |
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,6 @@ | ||
#!/bin/bash | ||
# Converts a table of ordinals and seconds to a table of source/location and seconds. Strips directory from file paths. | ||
while read -r ordinal time; do | ||
loc=$(llvm-kompile-compute-loc "$2" $ordinal) | ||
echo "${loc##*/} $time" | ||
done < "$1" |
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,4 @@ | ||
#!/bin/bash | ||
# Sorts table of locations and seconds in reverse order and displays it with individual and cumulative percentages. | ||
sum=$(cat "$1" | awk '{sum += $2} END { print sum }') | ||
tac "$1" | awk '{perc_local=$2 / '"$sum"' * 100; perc += perc_local; print $1 " " $2 " " perc_local " " perc}' |
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,3 @@ | ||
#!/bin/bash | ||
# Aggregates data from --profile-matching and sums together identical ordinals, yielding table with ordinals and seconds. | ||
cat "$1" | awk '{sum[$1] += $2} END { for (i in sum) print i, sum[i]}' | sort -n -k2 | awk '{ print $1, $2 / 1000000000}' |
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