-
Notifications
You must be signed in to change notification settings - Fork 14.5k
[MemProf] Change histogram storage from uint64_t to uint8_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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// 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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -166,6 +166,68 @@ readMemInfoBlocksV4(const char *Ptr) { | |
return Items; | ||
} | ||
|
||
llvm::SmallVector<std::pair<uint64_t, MemInfoBlock>> | ||
readMemInfoBlocksV5(const char *Ptr) { | ||
using namespace support; | ||
|
||
const uint64_t NumItemsToRead = | ||
endian::readNext<uint64_t, llvm::endianness::little, unaligned>(Ptr); | ||
|
||
llvm::SmallVector<std::pair<uint64_t, MemInfoBlock>> Items; | ||
for (uint64_t I = 0; I < NumItemsToRead; I++) { | ||
const uint64_t Id = | ||
endian::readNext<uint64_t, llvm::endianness::little, unaligned>(Ptr); | ||
|
||
MemInfoBlock MIB; | ||
#define READ_MIB_FIELD(FIELD) \ | ||
MIB.FIELD = endian::readNext<decltype(MIB.FIELD), llvm::endianness::little, \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this a functional change from what we were doing before? Is it required for the new version? If not, should we read things the same way in v4? |
||
unaligned>(Ptr) | ||
|
||
READ_MIB_FIELD(AllocCount); | ||
READ_MIB_FIELD(TotalAccessCount); | ||
READ_MIB_FIELD(MinAccessCount); | ||
READ_MIB_FIELD(MaxAccessCount); | ||
READ_MIB_FIELD(TotalSize); | ||
READ_MIB_FIELD(MinSize); | ||
READ_MIB_FIELD(MaxSize); | ||
READ_MIB_FIELD(AllocTimestamp); | ||
READ_MIB_FIELD(DeallocTimestamp); | ||
READ_MIB_FIELD(TotalLifetime); | ||
READ_MIB_FIELD(MinLifetime); | ||
READ_MIB_FIELD(MaxLifetime); | ||
READ_MIB_FIELD(AllocCpuId); | ||
READ_MIB_FIELD(DeallocCpuId); | ||
READ_MIB_FIELD(NumMigratedCpu); | ||
READ_MIB_FIELD(NumLifetimeOverlaps); | ||
READ_MIB_FIELD(NumSameAllocCpu); | ||
READ_MIB_FIELD(NumSameDeallocCpu); | ||
READ_MIB_FIELD(DataTypeId); | ||
READ_MIB_FIELD(TotalAccessDensity); | ||
READ_MIB_FIELD(MinAccessDensity); | ||
READ_MIB_FIELD(MaxAccessDensity); | ||
READ_MIB_FIELD(TotalLifetimeAccessDensity); | ||
READ_MIB_FIELD(MinLifetimeAccessDensity); | ||
READ_MIB_FIELD(MaxLifetimeAccessDensity); | ||
READ_MIB_FIELD(AccessHistogramSize); | ||
READ_MIB_FIELD(AccessHistogram); | ||
#undef READ_MIB_FIELD | ||
|
||
if (MIB.AccessHistogramSize > 0) { | ||
// The in-memory representation uses uint64_t for histogram entries. | ||
MIB.AccessHistogram = | ||
(uintptr_t)malloc(MIB.AccessHistogramSize * sizeof(uint64_t)); | ||
for (uint64_t J = 0; J < MIB.AccessHistogramSize; J++) { | ||
// The on-disk format for V5 uses uint8_t. | ||
const uint8_t Val = | ||
endian::readNext<uint8_t, llvm::endianness::little, unaligned>(Ptr); | ||
((uint64_t *)MIB.AccessHistogram)[J] = Val; | ||
} | ||
} | ||
Items.push_back({Id, MIB}); | ||
} | ||
return Items; | ||
} | ||
|
||
CallStackMap readStackInfo(const char *Ptr) { | ||
using namespace support; | ||
|
||
|
@@ -658,6 +720,8 @@ RawMemProfReader::readMemInfoBlocks(const char *Ptr) { | |
return readMemInfoBlocksV3(Ptr); | ||
if (MemprofRawVersion == 4ULL) | ||
return readMemInfoBlocksV4(Ptr); | ||
if (MemprofRawVersion == 5ULL) | ||
return readMemInfoBlocksV5(Ptr); | ||
llvm_unreachable( | ||
"Panic: Unsupported version number when reading MemInfoBlocks"); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ We expect 5 MIBs, each with different AccessHistogramValues. | |
|
||
CHECK: MemprofProfile: | ||
CHECK-NEXT: Summary: | ||
CHECK-NEXT: Version: 4 | ||
CHECK-NEXT: Version: 5 | ||
CHECK-NEXT: NumSegments: {{[0-9]+}} | ||
CHECK-NEXT: NumMibInfo: 5 | ||
CHECK-NEXT: NumAllocFunctions: 3 | ||
|
@@ -241,4 +241,4 @@ CHECK-NEXT: MinLifetimeAccessDensity: 56000 | |
CHECK-NEXT: MaxLifetimeAccessDensity: 56000 | ||
CHECK-NEXT: AccessHistogramSize: 8 | ||
CHECK-NEXT: AccessHistogram: {{[0-9]+}} | ||
CHECK-NEXT: AccessHistogramValues: 168 147 126 105 84 63 42 21 | ||
CHECK-NEXT: AccessHistogramValues: 168 147 126 105 84 63 42 21 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Spurious difference here and at the end of some of the other changed tests due to different line ending at EOF? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should/can this use HISTOGRAM_MAX_COUNTER?
Does this mean that we were getting histogram values >255 before in the profile, and if so, do we know how much this matters in practice?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And if a change in behavior do we need a test for that?