-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[MemProf] Change histogram storage from uint64_t to uint16_t #147854
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
snehasish
merged 7 commits into
main
from
users/snehasish/07-08-draft_changes_to_trim_the_histogram_raw_profile_format
Jul 30, 2025
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
536c808
Draft changes to trim the histogram raw profile format.
5841232
Add reader support.
43ebff1
First draft of f16 library
df55d9e
Addres comments
bba96c1
Keep basic v4 test
4bd721f
Actually update the .inc files
2805780
Fix formatting for .inc files
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,35 @@ | ||
| #include <cstdint> | ||
| #include <vector> | ||
|
|
||
| #include "profile/MemProfData.inc" | ||
| #include "gtest/gtest.h" | ||
|
|
||
| namespace llvm { | ||
| namespace memprof { | ||
| namespace { | ||
| TEST(MemProf, F16EncodeDecode) { | ||
| const std::vector<uint64_t> TestCases = { | ||
| 0, 100, 4095, 4096, 5000, 8191, 65535, 1000000, 134213640, 200000000, | ||
| }; | ||
|
|
||
| for (const uint64_t TestCase : TestCases) { | ||
| const uint16_t Encoded = encodeHistogramCount(TestCase); | ||
| const uint64_t Decoded = decodeHistogramCount(Encoded); | ||
|
|
||
| const uint64_t MaxRepresentable = static_cast<uint64_t>(MaxMantissa) | ||
| << MaxExponent; | ||
|
|
||
| if (TestCase >= MaxRepresentable) { | ||
| EXPECT_EQ(Decoded, MaxRepresentable); | ||
| } else if (TestCase <= MaxMantissa) { | ||
| EXPECT_EQ(Decoded, TestCase); | ||
| } else { | ||
| // The decoded value should be close to the original value. | ||
| // The error should be less than 1/1024 for larger numbers. | ||
| EXPECT_NEAR(Decoded, TestCase, static_cast<double>(TestCase) / 1024.0); | ||
| } | ||
| } | ||
| } | ||
| } // namespace | ||
| } // namespace memprof | ||
| } // namespace llvm |
37 changes: 37 additions & 0 deletions
37
compiler-rt/test/memprof/TestCases/memprof_histogram_uint8.cpp
This file contains hidden or 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,37 @@ | ||
| // Test the histogram support in memprof using the text format output. | ||
| // Shadow memory counters per object are limited to 8b. In memory counters | ||
| // aggregating counts across multiple objects are 64b. | ||
|
|
||
| // RUN: %clangxx_memprof -O0 -mllvm -memprof-histogram -mllvm -memprof-use-callbacks=true %s -o %t && %env_memprof_opts=print_text=1:histogram=1:log_path=stdout %run %t 2>&1 | FileCheck %s | ||
|
|
||
| #include <stdio.h> | ||
| #include <stdlib.h> | ||
|
|
||
| int main() { | ||
| // Allocate memory that will create a histogram | ||
| char *buffer = (char *)malloc(1024); | ||
| if (!buffer) | ||
| return 1; | ||
|
|
||
| for (int i = 0; i < 10; ++i) { | ||
| // Access every 8th byte (since shadow granularity is 8b. | ||
| buffer[i * 8] = 'A'; | ||
| } | ||
|
|
||
| for (int j = 0; j < 200; ++j) { | ||
| buffer[8] = 'B'; // Count = previous count + 200 | ||
| } | ||
|
|
||
| for (int j = 0; j < 400; ++j) { | ||
| buffer[16] = 'B'; // Count is saturated at 255 | ||
| } | ||
|
|
||
| // Free the memory to trigger MIB creation with histogram | ||
| free(buffer); | ||
|
|
||
| printf("Test completed successfully\n"); | ||
| return 0; | ||
| } | ||
|
|
||
| // CHECK: AccessCountHistogram[128]: 1 201 255 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 | ||
| // CHECK: Test completed successfully |
This file contains hidden or 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 hidden or 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
Binary file modified
BIN
+54.1 KB
(100%)
llvm/test/tools/llvm-profdata/Inputs/basic-histogram.memprofexe
Binary file not shown.
Binary file modified
BIN
-54.2 KB
(27%)
llvm/test/tools/llvm-profdata/Inputs/basic-histogram.memprofraw
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified
BIN
+54.1 KB
(100%)
llvm/test/tools/llvm-profdata/Inputs/padding-histogram.memprofexe
Binary file not shown.
Binary file modified
BIN
-54 KB
(26%)
llvm/test/tools/llvm-profdata/Inputs/padding-histogram.memprofraw
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.