tejohnson created this revision. tejohnson added reviewers: snehasish, davidxl. Herald added subscribers: Enna1, wenlei. Herald added a project: All. tejohnson requested review of this revision. Herald added projects: clang, Sanitizers, LLVM. Herald added subscribers: Sanitizers, cfe-commits.
Track min/max/avg access density (accesses per byte and accesses per byte per lifetime second) metrics directly during profiling. This allows more accurate use of these metrics in profile analysis and use, instead of trying to compute them from already aggregated data in the profile. This required regenerating some of the raw profile and executable inputs for a few tests. While here, make the llvm-profdata memprof tests more resilient to differences in things like memory mapping, timestamps and cpu ids to make future test updates easier. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D141558 Files: clang/test/CodeGen/Inputs/memprof.memprofraw compiler-rt/include/profile/MIBEntryDef.inc compiler-rt/include/profile/MemProfData.inc llvm/include/llvm/ProfileData/MIBEntryDef.inc llvm/include/llvm/ProfileData/MemProfData.inc llvm/test/Transforms/PGOProfile/Inputs/memprof.exe llvm/test/Transforms/PGOProfile/Inputs/memprof.memprofraw llvm/test/tools/llvm-profdata/Inputs/basic.memprofexe llvm/test/tools/llvm-profdata/Inputs/basic.memprofraw llvm/test/tools/llvm-profdata/Inputs/inline.memprofexe llvm/test/tools/llvm-profdata/Inputs/inline.memprofraw llvm/test/tools/llvm-profdata/Inputs/multi.memprofexe llvm/test/tools/llvm-profdata/Inputs/multi.memprofraw llvm/test/tools/llvm-profdata/memprof-basic.test llvm/test/tools/llvm-profdata/memprof-inline.test llvm/test/tools/llvm-profdata/memprof-multi.test
Index: llvm/test/tools/llvm-profdata/memprof-multi.test =================================================================== --- llvm/test/tools/llvm-profdata/memprof-multi.test +++ llvm/test/tools/llvm-profdata/memprof-multi.test @@ -41,7 +41,7 @@ CHECK: MemprofProfile: CHECK-NEXT: Summary: CHECK-NEXT: Version: 1 -CHECK-NEXT: NumSegments: 9 +CHECK-NEXT: NumSegments: 7 CHECK-NEXT: NumMibInfo: 2 CHECK-NEXT: NumAllocFunctions: 1 CHECK-NEXT: NumStackOffsets: 2 Index: llvm/test/tools/llvm-profdata/memprof-inline.test =================================================================== --- llvm/test/tools/llvm-profdata/memprof-inline.test +++ llvm/test/tools/llvm-profdata/memprof-inline.test @@ -41,57 +41,19 @@ CHECK: MemprofProfile: CHECK-NEXT: Summary: CHECK-NEXT: Version: 1 -CHECK-NEXT: NumSegments: 9 +CHECK-NEXT: NumSegments: {{[0-9]+}} CHECK-NEXT: NumMibInfo: 2 CHECK-NEXT: NumAllocFunctions: 2 CHECK-NEXT: NumStackOffsets: 1 CHECK-NEXT: Segments: CHECK-NEXT: - CHECK-NEXT: BuildId: <None> -CHECK-NEXT: Start: 0x200000 -CHECK-NEXT: End: 0x29B000 -CHECK-NEXT: Offset: 0x0 +CHECK-NEXT: Start: 0x{{[0-9]+}} +CHECK-NEXT: End: 0x{{[0-9]+}} +CHECK-NEXT: Offset: 0x{{[0-9]+}} CHECK-NEXT: - -CHECK-NEXT: BuildId: <None> -CHECK-NEXT: Start: 0x7F5871485000 -CHECK-NEXT: End: 0x7F58715CD000 -CHECK-NEXT: Offset: 0x26000 -CHECK-NEXT: - -CHECK-NEXT: BuildId: <None> -CHECK-NEXT: Start: 0x7F587162D000 -CHECK-NEXT: End: 0x7F587163F000 -CHECK-NEXT: Offset: 0x3000 -CHECK-NEXT: - -CHECK-NEXT: BuildId: <None> -CHECK-NEXT: Start: 0x7F5871646000 -CHECK-NEXT: End: 0x7F5871648000 -CHECK-NEXT: Offset: 0x2000 -CHECK-NEXT: - -CHECK-NEXT: BuildId: <None> -CHECK-NEXT: Start: 0x7F587165A000 -CHECK-NEXT: End: 0x7F58716F4000 -CHECK-NEXT: Offset: 0xF000 -CHECK-NEXT: - -CHECK-NEXT: BuildId: <None> -CHECK-NEXT: Start: 0x7F5871791000 -CHECK-NEXT: End: 0x7F5871795000 -CHECK-NEXT: Offset: 0x3000 -CHECK-NEXT: - -CHECK-NEXT: BuildId: <None> -CHECK-NEXT: Start: 0x7F58717A0000 -CHECK-NEXT: End: 0x7F58717AF000 -CHECK-NEXT: Offset: 0x7000 -CHECK-NEXT: - -CHECK-NEXT: BuildId: <None> -CHECK-NEXT: Start: 0x7F58717D6000 -CHECK-NEXT: End: 0x7F58717FA000 -CHECK-NEXT: Offset: 0x1000 -CHECK-NEXT: - -CHECK-NEXT: BuildId: <None> -CHECK-NEXT: Start: 0x7FFFC77BD000 -CHECK-NEXT: End: 0x7FFFC77BF000 -CHECK-NEXT: Offset: 0x0 -CHECK-NEXT: Records: + +CHECK: Records: CHECK-NEXT: - CHECK-NEXT: FunctionGUID: 15505678318020221912 CHECK-NEXT: AllocSites: @@ -129,18 +91,24 @@ CHECK-NEXT: TotalSize: 1 CHECK-NEXT: MinSize: 1 CHECK-NEXT: MaxSize: 1 -CHECK-NEXT: AllocTimestamp: 894 -CHECK-NEXT: DeallocTimestamp: 894 +CHECK-NEXT: AllocTimestamp: {{[0-9]+}} +CHECK-NEXT: DeallocTimestamp: {{[0-9]+}} CHECK-NEXT: TotalLifetime: 0 CHECK-NEXT: MinLifetime: 0 CHECK-NEXT: MaxLifetime: 0 -CHECK-NEXT: AllocCpuId: 23 -CHECK-NEXT: DeallocCpuId: 23 +CHECK-NEXT: AllocCpuId: {{[0-9]+}} +CHECK-NEXT: DeallocCpuId: {{[0-9]+}} CHECK-NEXT: NumMigratedCpu: 0 CHECK-NEXT: NumLifetimeOverlaps: 0 CHECK-NEXT: NumSameAllocCpu: 0 CHECK-NEXT: NumSameDeallocCpu: 0 CHECK-NEXT: DataTypeId: {{[0-9]+}} +CHECK-NEXT: TotalAccessDensity: 100 +CHECK-NEXT: MinAccessDensity: 100 +CHECK-NEXT: MaxAccessDensity: 100 +CHECK-NEXT: TotalLifetimeAccessDensity: 100000 +CHECK-NEXT: MinLifetimeAccessDensity: 100000 +CHECK-NEXT: MaxLifetimeAccessDensity: 100000 CHECK-NEXT: - CHECK-NEXT: FunctionGUID: 6699318081062747564 CHECK-NEXT: AllocSites: @@ -178,18 +146,24 @@ CHECK-NEXT: TotalSize: 1 CHECK-NEXT: MinSize: 1 CHECK-NEXT: MaxSize: 1 -CHECK-NEXT: AllocTimestamp: 894 -CHECK-NEXT: DeallocTimestamp: 894 +CHECK-NEXT: AllocTimestamp: {{[0-9]+}} +CHECK-NEXT: DeallocTimestamp: {{[0-9]+}} CHECK-NEXT: TotalLifetime: 0 CHECK-NEXT: MinLifetime: 0 CHECK-NEXT: MaxLifetime: 0 -CHECK-NEXT: AllocCpuId: 23 -CHECK-NEXT: DeallocCpuId: 23 +CHECK-NEXT: AllocCpuId: {{[0-9]+}} +CHECK-NEXT: DeallocCpuId: {{[0-9]+}} CHECK-NEXT: NumMigratedCpu: 0 CHECK-NEXT: NumLifetimeOverlaps: 0 CHECK-NEXT: NumSameAllocCpu: 0 CHECK-NEXT: NumSameDeallocCpu: 0 CHECK-NEXT: DataTypeId: {{[0-9]+}} +CHECK-NEXT: TotalAccessDensity: 100 +CHECK-NEXT: MinAccessDensity: 100 +CHECK-NEXT: MaxAccessDensity: 100 +CHECK-NEXT: TotalLifetimeAccessDensity: 100000 +CHECK-NEXT: MinLifetimeAccessDensity: 100000 +CHECK-NEXT: MaxLifetimeAccessDensity: 100000 CHECK-NEXT: CallSites: CHECK-NEXT: - CHECK-NEXT: - Index: llvm/test/tools/llvm-profdata/memprof-basic.test =================================================================== --- llvm/test/tools/llvm-profdata/memprof-basic.test +++ llvm/test/tools/llvm-profdata/memprof-basic.test @@ -40,57 +40,19 @@ CHECK: MemprofProfile: CHECK-NEXT: Summary: CHECK-NEXT: Version: 1 -CHECK-NEXT: NumSegments: 9 +CHECK-NEXT: NumSegments: {{[0-9]+}} CHECK-NEXT: NumMibInfo: 2 CHECK-NEXT: NumAllocFunctions: 1 CHECK-NEXT: NumStackOffsets: 2 CHECK-NEXT: Segments: CHECK-NEXT: - CHECK-NEXT: BuildId: <None> -CHECK-NEXT: Start: 0x200000 -CHECK-NEXT: End: 0x298000 -CHECK-NEXT: Offset: 0x0 +CHECK-NEXT: Start: 0x{{[0-9]+}} +CHECK-NEXT: End: 0x{{[0-9]+}} +CHECK-NEXT: Offset: 0x{{[0-9]+}} CHECK-NEXT: - -CHECK-NEXT: BuildId: <None> -CHECK-NEXT: Start: 0x7FFFF7C7C000 -CHECK-NEXT: End: 0x7FFFF7DC5000 -CHECK-NEXT: Offset: 0x26000 -CHECK-NEXT: - -CHECK-NEXT: BuildId: <None> -CHECK-NEXT: Start: 0x7FFFF7E1E000 -CHECK-NEXT: End: 0x7FFFF7E30000 -CHECK-NEXT: Offset: 0x3000 -CHECK-NEXT: - -CHECK-NEXT: BuildId: <None> -CHECK-NEXT: Start: 0x7FFFF7E36000 -CHECK-NEXT: End: 0x7FFFF7E38000 -CHECK-NEXT: Offset: 0x1000 -CHECK-NEXT: - -CHECK-NEXT: BuildId: <None> -CHECK-NEXT: Start: 0x7FFFF7E4A000 -CHECK-NEXT: End: 0x7FFFF7EE5000 -CHECK-NEXT: Offset: 0xF000 -CHECK-NEXT: - -CHECK-NEXT: BuildId: <None> -CHECK-NEXT: Start: 0x7FFFF7F83000 -CHECK-NEXT: End: 0x7FFFF7F87000 -CHECK-NEXT: Offset: 0x3000 -CHECK-NEXT: - -CHECK-NEXT: BuildId: <None> -CHECK-NEXT: Start: 0x7FFFF7F92000 -CHECK-NEXT: End: 0x7FFFF7FA1000 -CHECK-NEXT: Offset: 0x7000 -CHECK-NEXT: - -CHECK-NEXT: BuildId: <None> -CHECK-NEXT: Start: 0x7FFFF7FD0000 -CHECK-NEXT: End: 0x7FFFF7FD2000 -CHECK-NEXT: Offset: 0x0 -CHECK-NEXT: - -CHECK-NEXT: BuildId: <None> -CHECK-NEXT: Start: 0x7FFFF7FD3000 -CHECK-NEXT: End: 0x7FFFF7FF3000 -CHECK-NEXT: Offset: 0x1000 -CHECK-NEXT: Records: + +CHECK: Records: CHECK-NEXT: - CHECK-NEXT: FunctionGUID: {{[0-9]+}} CHECK-NEXT: AllocSites: @@ -110,24 +72,30 @@ CHECK-NEXT: TotalSize: 10 CHECK-NEXT: MinSize: 10 CHECK-NEXT: MaxSize: 10 -CHECK-NEXT: AllocTimestamp: 986 -CHECK-NEXT: DeallocTimestamp: 986 +CHECK-NEXT: AllocTimestamp: {{[0-9]+}} +CHECK-NEXT: DeallocTimestamp: {{[0-9]+}} CHECK-NEXT: TotalLifetime: 0 CHECK-NEXT: MinLifetime: 0 CHECK-NEXT: MaxLifetime: 0 -CHECK-NEXT: AllocCpuId: 56 -CHECK-NEXT: DeallocCpuId: 56 +CHECK-NEXT: AllocCpuId: {{[0-9]+}} +CHECK-NEXT: DeallocCpuId: {{[0-9]+}} CHECK-NEXT: NumMigratedCpu: 0 CHECK-NEXT: NumLifetimeOverlaps: 0 CHECK-NEXT: NumSameAllocCpu: 0 CHECK-NEXT: NumSameDeallocCpu: 0 CHECK-NEXT: DataTypeId: {{[0-9]+}} +CHECK-NEXT: TotalAccessDensity: 20 +CHECK-NEXT: MinAccessDensity: 20 +CHECK-NEXT: MaxAccessDensity: 20 +CHECK-NEXT: TotalLifetimeAccessDensity: 20000 +CHECK-NEXT: MinLifetimeAccessDensity: 20000 +CHECK-NEXT: MaxLifetimeAccessDensity: 20000 CHECK-NEXT: - CHECK-NEXT: Callstack: CHECK-NEXT: - CHECK-NEXT: Function: {{[0-9]+}} CHECK-NEXT: SymbolName: main -CHECK-NEXT: LineOffset: 5 +CHECK-NEXT: LineOffset: 4 CHECK-NEXT: Column: 15 CHECK-NEXT: Inline: 0 CHECK-NEXT: MemInfoBlock: @@ -138,15 +106,21 @@ CHECK-NEXT: TotalSize: 10 CHECK-NEXT: MinSize: 10 CHECK-NEXT: MaxSize: 10 -CHECK-NEXT: AllocTimestamp: 987 -CHECK-NEXT: DeallocTimestamp: 987 +CHECK-NEXT: AllocTimestamp: {{[0-9]+}} +CHECK-NEXT: DeallocTimestamp: {{[0-9]+}} CHECK-NEXT: TotalLifetime: 0 CHECK-NEXT: MinLifetime: 0 CHECK-NEXT: MaxLifetime: 0 -CHECK-NEXT: AllocCpuId: 56 -CHECK-NEXT: DeallocCpuId: 56 +CHECK-NEXT: AllocCpuId: {{[0-9]+}} +CHECK-NEXT: DeallocCpuId: {{[0-9]+}} CHECK-NEXT: NumMigratedCpu: 0 CHECK-NEXT: NumLifetimeOverlaps: 0 CHECK-NEXT: NumSameAllocCpu: 0 CHECK-NEXT: NumSameDeallocCpu: 0 CHECK-NEXT: DataTypeId: {{[0-9]+}} +CHECK-NEXT: TotalAccessDensity: 20 +CHECK-NEXT: MinAccessDensity: 20 +CHECK-NEXT: MaxAccessDensity: 20 +CHECK-NEXT: TotalLifetimeAccessDensity: 20000 +CHECK-NEXT: MinLifetimeAccessDensity: 20000 +CHECK-NEXT: MaxLifetimeAccessDensity: 20000 Index: llvm/include/llvm/ProfileData/MemProfData.inc =================================================================== --- llvm/include/llvm/ProfileData/MemProfData.inc +++ llvm/include/llvm/ProfileData/MemProfData.inc @@ -127,6 +127,19 @@ TotalLifetime = DeallocTimestamp - AllocTimestamp; MinLifetime = TotalLifetime; MaxLifetime = TotalLifetime; + // Access density is accesses per byte. Multiply by 100 to include the + // fractional part. + TotalAccessDensity = AccessCount * 100 / Size; + MinAccessDensity = TotalAccessDensity; + MaxAccessDensity = TotalAccessDensity; + // Lifetime access density is the access density per second of lifetime. + // Multiply by 1000 to convert denominator lifetime to seconds (using a + // minimum lifetime of 1ms to avoid divide by 0. Do the multiplication first + // to reduce truncations to 0. + TotalLifetimeAccessDensity = + TotalAccessDensity * 1000 / (TotalLifetime ? TotalLifetime : 1); + MinLifetimeAccessDensity = TotalLifetimeAccessDensity; + MaxLifetimeAccessDensity = TotalLifetimeAccessDensity; AllocCpuId = AllocCpu; DeallocCpuId = DeallocCpu; NumMigratedCpu = AllocCpuId != DeallocCpuId; @@ -147,6 +160,24 @@ MinLifetime = newMIB.MinLifetime < MinLifetime ? newMIB.MinLifetime : MinLifetime; MaxLifetime = newMIB.MaxLifetime > MaxLifetime ? newMIB.MaxLifetime : MaxLifetime; + TotalAccessDensity += newMIB.TotalAccessDensity; + MinAccessDensity = newMIB.MinAccessDensity < MinAccessDensity + ? newMIB.MinAccessDensity + : MinAccessDensity; + MaxAccessDensity = newMIB.MaxAccessDensity > MaxAccessDensity + ? newMIB.MaxAccessDensity + : MaxAccessDensity; + + TotalLifetimeAccessDensity += newMIB.TotalLifetimeAccessDensity; + MinLifetimeAccessDensity = + newMIB.MinLifetimeAccessDensity < MinLifetimeAccessDensity + ? newMIB.MinLifetimeAccessDensity + : MinLifetimeAccessDensity; + MaxLifetimeAccessDensity = + newMIB.MaxLifetimeAccessDensity > MaxLifetimeAccessDensity + ? newMIB.MaxLifetimeAccessDensity + : MaxLifetimeAccessDensity; + // We know newMIB was deallocated later, so just need to check if it was // allocated before last one deallocated. NumLifetimeOverlaps += newMIB.AllocTimestamp < DeallocTimestamp; Index: llvm/include/llvm/ProfileData/MIBEntryDef.inc =================================================================== --- llvm/include/llvm/ProfileData/MIBEntryDef.inc +++ llvm/include/llvm/ProfileData/MIBEntryDef.inc @@ -45,3 +45,9 @@ MIBEntryDef(NumSameAllocCpu = 17, NumSameAllocCpu, uint32_t) MIBEntryDef(NumSameDeallocCpu = 18, NumSameDeallocCpu, uint32_t) MIBEntryDef(DataTypeId = 19, DataTypeId, uint64_t) +MIBEntryDef(TotalAccessDensity = 20, TotalAccessDensity, uint64_t) +MIBEntryDef(MinAccessDensity = 21, MinAccessDensity, uint32_t) +MIBEntryDef(MaxAccessDensity = 22, MaxAccessDensity, uint32_t) +MIBEntryDef(TotalLifetimeAccessDensity = 23, TotalLifetimeAccessDensity, uint64_t) +MIBEntryDef(MinLifetimeAccessDensity = 24, MinLifetimeAccessDensity, uint32_t) +MIBEntryDef(MaxLifetimeAccessDensity = 25, MaxLifetimeAccessDensity, uint32_t) Index: compiler-rt/include/profile/MemProfData.inc =================================================================== --- compiler-rt/include/profile/MemProfData.inc +++ compiler-rt/include/profile/MemProfData.inc @@ -127,6 +127,19 @@ TotalLifetime = DeallocTimestamp - AllocTimestamp; MinLifetime = TotalLifetime; MaxLifetime = TotalLifetime; + // Access density is accesses per byte. Multiply by 100 to include the + // fractional part. + TotalAccessDensity = AccessCount * 100 / Size; + MinAccessDensity = TotalAccessDensity; + MaxAccessDensity = TotalAccessDensity; + // Lifetime access density is the access density per second of lifetime. + // Multiply by 1000 to convert denominator lifetime to seconds (using a + // minimum lifetime of 1ms to avoid divide by 0. Do the multiplication first + // to reduce truncations to 0. + TotalLifetimeAccessDensity = + TotalAccessDensity * 1000 / (TotalLifetime ? TotalLifetime : 1); + MinLifetimeAccessDensity = TotalLifetimeAccessDensity; + MaxLifetimeAccessDensity = TotalLifetimeAccessDensity; AllocCpuId = AllocCpu; DeallocCpuId = DeallocCpu; NumMigratedCpu = AllocCpuId != DeallocCpuId; @@ -147,6 +160,24 @@ MinLifetime = newMIB.MinLifetime < MinLifetime ? newMIB.MinLifetime : MinLifetime; MaxLifetime = newMIB.MaxLifetime > MaxLifetime ? newMIB.MaxLifetime : MaxLifetime; + TotalAccessDensity += newMIB.TotalAccessDensity; + MinAccessDensity = newMIB.MinAccessDensity < MinAccessDensity + ? newMIB.MinAccessDensity + : MinAccessDensity; + MaxAccessDensity = newMIB.MaxAccessDensity > MaxAccessDensity + ? newMIB.MaxAccessDensity + : MaxAccessDensity; + + TotalLifetimeAccessDensity += newMIB.TotalLifetimeAccessDensity; + MinLifetimeAccessDensity = + newMIB.MinLifetimeAccessDensity < MinLifetimeAccessDensity + ? newMIB.MinLifetimeAccessDensity + : MinLifetimeAccessDensity; + MaxLifetimeAccessDensity = + newMIB.MaxLifetimeAccessDensity > MaxLifetimeAccessDensity + ? newMIB.MaxLifetimeAccessDensity + : MaxLifetimeAccessDensity; + // We know newMIB was deallocated later, so just need to check if it was // allocated before last one deallocated. NumLifetimeOverlaps += newMIB.AllocTimestamp < DeallocTimestamp; Index: compiler-rt/include/profile/MIBEntryDef.inc =================================================================== --- compiler-rt/include/profile/MIBEntryDef.inc +++ compiler-rt/include/profile/MIBEntryDef.inc @@ -45,3 +45,9 @@ MIBEntryDef(NumSameAllocCpu = 17, NumSameAllocCpu, uint32_t) MIBEntryDef(NumSameDeallocCpu = 18, NumSameDeallocCpu, uint32_t) MIBEntryDef(DataTypeId = 19, DataTypeId, uint64_t) +MIBEntryDef(TotalAccessDensity = 20, TotalAccessDensity, uint64_t) +MIBEntryDef(MinAccessDensity = 21, MinAccessDensity, uint32_t) +MIBEntryDef(MaxAccessDensity = 22, MaxAccessDensity, uint32_t) +MIBEntryDef(TotalLifetimeAccessDensity = 23, TotalLifetimeAccessDensity, uint64_t) +MIBEntryDef(MinLifetimeAccessDensity = 24, MinLifetimeAccessDensity, uint32_t) +MIBEntryDef(MaxLifetimeAccessDensity = 25, MaxLifetimeAccessDensity, uint32_t)
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits