aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/ProfileData
AgeCommit message (Collapse)AuthorFilesLines
2025-09-11[LLVM][Coverage][Unittest] Fix dangling reference in unittest (#147118)Tomohiro Kashiwada1-9/+9
In loop of `writeAndReadCoverageRegions`, `OutputFunctions[I].Filenames` references to contents of `Filenames` after returning from `readCoverageRegions` but `Filenames` will be cleared in next call of `readCoverageRegions`, causes dangling reference. The lifetime of the contents of `Filenames` must be equal or longer than `OutputFunctions[I]`, thus it has been moved into `OutputFunctions[I]` (typed `OutputFunctionCoverageData`).
2025-09-04[memprof] Add RecordSerializationRoundTripVersion4HotColdSchema (#156783)Kazu Hirata1-0/+69
I'm planning to remove the V2 support. Now, HotColdSchema is one feature that's tested in V2 but not in V4. This patch derives: RecordSerializationRoundTripVersion4HotColdSchema from: RecordSerializationRoundTripVersion2HotColdSchema and then adds DummyMap, a V4-speicifc item.
2025-09-02[memprof] Rename "v2" functions and tests (NFC) (#156247)Kazu Hirata1-11/+11
I'm planning to remove the V2 support. Now, some functions and tests should not be removed just because they have "v2" in their names. This patch renames them. - makeRecordV2: Renamed to makeRecord. This has "V2" in the name because the concept of call stack ID came out as part of V2. It is still useful for use with V3 and V4. - test_memprof_v4_{partial,full}_schema: Upgraded to use V4. These tests perform serialization/deserialization roundtrip tests of a MemProfRecord with {partial,full} schema.
2025-06-24[InstrProf] Factor out getRecord() and use NamedInstrProfRecord (#145417)Ellis Hoag1-11/+9
Factor out code in `populateCounters()` and `populateCoverage()` used to grab the record into `PGOUseFunc::getRecord()` to reduce code duplication. And return `NamedInstrProfRecord` in `getInstrProfRecord()` to avoid an unnecessary cast. No functional change is intented.
2025-06-13[memprof] Use testing::IsEmpty (NFC) (#144096)Kazu Hirata1-10/+9
This patch replaces testing::IsEmpty with IsEmpty because we already have: using ::testing::IsEmpty; near the beginning of the file.
2025-06-13Reland "[llvm-cov] Add support for baseline coverage" (#144130)Fabian Meumertzheim1-1/+3
When no profile is provided, but the new --empty-profile option is specified, the export/report/show commands now emit coverage data equivalent to that obtained from a profile with all zero counters ("baseline coverage"). This is useful for build systems (e.g. Bazel) that can track coverage information for each build target, even those that are never linked into tests and thus don't have runtime coverage data recorded. By merging in baseline coverage, lines in files that aren't linked into tests are correctly reported as uncovered. Reland with fixes to `CoverageMappingTest.cpp`. Reverts llvm/llvm-project#144121
2025-06-13Revert "[llvm-cov] Add support for baseline coverage" (#144121)Keith Smiley1-3/+1
Reverts llvm/llvm-project#117910 ``` /home/buildbots/llvm-external-buildbots/workers/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/llvm-project/llvm/unittests/ProfileData/CoverageMappingTest.cpp /home/buildbots/llvm-external-buildbots/workers/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/llvm-project/llvm/unittests/ProfileData/CoverageMappingTest.cpp:281:28: error: 'std::reference_wrapper' may not intend to support class template argument deduction [-Werror,-Wctad-maybe-unsupported] 281 | std::make_optional(std::reference_wrapper(*ProfileReader)); | ^ /usr/lib/gcc/ppc64le-redhat-linux/8/../../../../include/c++/8/bits/refwrap.h:289:11: note: add a deduction guide to suppress this warning 289 | class reference_wrapper | ^ ```
2025-06-13[llvm-cov] Add support for baseline coverage (#117910)Fabian Meumertzheim1-1/+3
When no profile is provided, but the new --empty-profile option is specifed, the export/report/show commands now emit coverage data equivalent to that obtained from a profile with all zero counters ("baseline coverage"). This is useful for build systems (e.g. Bazel) that can track coverage information for each build target, even those that are never linked into tests and thus don't have runtime coverage data recorded. By merging in baseline coverage, lines in files that aren't linked into tests are correctly reported as uncovered.
2025-06-10[llvm] annotate interfaces in llvm/ProfileData for DLL export (#142861)Andrew Rogers1-4/+6
## Purpose This patch is one in a series of code-mods that annotate LLVM’s public interface for export. This patch annotates the `llvm/ProfileData` library. These annotations currently have no meaningful impact on the LLVM build; however, they are a prerequisite to support an LLVM Windows DLL (shared library) build. ## Background This effort is tracked in #109483. Additional context is provided in [this discourse](https://discourse.llvm.org/t/psa-annotating-llvm-public-interface/85307), and documentation for `LLVM_ABI` and related annotations is found in the LLVM repo [here](https://github.com/llvm/llvm-project/blob/main/llvm/docs/InterfaceExportAnnotations.rst). The bulk of these changes were generated automatically using the [Interface Definition Scanner (IDS)](https://github.com/compnerd/ids) tool, followed formatting with `git clang-format`. The following manual adjustments were also applied after running IDS on Linux: - Manually annotate the file `llvm/include/llvm/ProfileData/InstrProfData.inc` because it is skipped by IDS - Add `LLVM_TEMPLATE_ABI` and `LLVM_EXPORT_TEMPLATE` to exported instantiated templates. - Add `LLVM_ABI_FRIEND` to friend member functions declared with `LLVM_ABI` - Add `LLVM_ABI` to a small number of symbols that require export but are not declared in headers ## Validation Local builds and tests to validate cross-platform compatibility. This included llvm, clang, and lldb on the following configurations: - Windows with MSVC - Windows with Clang - Linux with GCC - Linux with Clang - Darwin with Clang
2025-05-29[MemProf] Summary section cleanup (NFC) (#142003)Teresa Johnson1-7/+5
Address post-commit review comments from PR141805. Misc cleanup but the biggest changes are moving some common utilities to new MemProfCommon files to reduce unnecessary includes.
2025-05-28[MemProf] Add basic summary section support (#141805)Teresa Johnson1-0/+77
This patch adds support for a basic MemProf summary section, which is built along with the indexed MemProf profile (e.g. when reading the raw or YAML profiles), and serialized through the indexed profile just after the header. Currently only 6 fields are written, specifically the number of contexts (total, cold, hot), and the max context size (cold, warm, hot). To support forwards and backwards compatibility for added fields in the indexed profile, the number of fields serialized first. The code is written to support forwards compatibility (reading newer profiles with additional summary fields), and comments indicate how to implement backwards compatibility (reading older profiles with fewer summary fields) as needed. Support is added to print the summary as YAML comments when displaying both the raw and indexed profiles via `llvm-profdata show`. Because they are YAML comments, the YAML reader ignores these (the summary is always recomputed when building the indexed profile as described above). This necessitated moving some options and a couple of interfaces out of Analysis/MemoryProfileInfo.cpp and into the new ProfileData/MemProfSummary.cpp file, as we need to classify context hotness earlier and also compute context ids to build the summary from older indexed profiles.
2025-05-24Re-apply "[StaticDataLayout][PGO]Implement reader and writer change for data ↵Mingming Liu1-2/+2
access profiles" (#141275) Re-apply https://github.com/llvm/llvm-project/pull/139997 after fixing the use-of-uninitialized-memory error (https://lab.llvm.org/buildbot/#/builders/94/builds/7373). Tested: The error is reproduced with https://github.com/llvm/llvm-zorg/blob/main/zorg/buildbot/builders/sanitizers/buildbot_bootstrap_msan.sh without the fix, and test pass with the fix. **Original commit message:** https://github.com/llvm/llvm-project/pull/138170 introduces classes to operate on data access profiles. This change supports the read and write of `DataAccessProfData` in indexed format of MemProf (v4) as well as its the text (yaml) format. For indexed format: * InstrProfWriter owns (by `std::unique_ptr<DataAccessProfData>`) the data access profiles, and gives a non-owned copy when it calls `writeMemProf`. * MemProf v4 header has a new `uint64_t` to record the byte offset of data access profiles. This `uint64_t` field is zero if data access profile is not set (nullptr). * MemProfReader reads the offset from v4 header and de-serializes in-memory bytes into class `DataAccessProfData`. For textual format: * MemProfYAML.h adds the mapping for DAP class, and make DAP optional for both read and write. 099a0fa (by @snehasish) introduces v4 which contains CalleeGuids in CallSiteInfo, and this change changes the v4 format in place with data access profiles. The current plan is to bump the version and enable v4 profiles with both features, assuming waiting for this change won't delay the callsite change too long. --------- Co-authored-by: Kazu Hirata <kazu@google.com>
2025-05-22Revert "[StaticDataLayout][PGO]Implement reader and writer change for data ↵Mingming Liu1-2/+2
access profiles" (#141157) Reverts llvm/llvm-project#139997 Sanitizer failures (https://lab.llvm.org/buildbot/#/builders/94/builds/7373) Will fix forward later.
2025-05-22[StaticDataLayout][PGO]Implement reader and writer change for data access ↵Mingming Liu1-2/+2
profiles (#139997) https://github.com/llvm/llvm-project/pull/138170 introduces classes to operate on data access profiles. This change supports the read and write of `DataAccessProfData` in indexed format of MemProf (v4) as well as its the text (yaml) format. For indexed format: * InstrProfWriter owns (by `std::unique_ptr<DataAccessProfData>`) the data access profiles, and gives a non-owned copy when it calls `writeMemProf`. * MemProf v4 header has a new `uint64_t` to record the byte offset of data access profiles. This `uint64_t` field is zero if data access profile is not set (nullptr). * MemProfReader reads the offset from v4 header and de-serializes in-memory bytes into class `DataAccessProfData`. For textual format: * MemProfYAML.h adds the mapping for DAP class, and make DAP optional for both read and write. 099a0fa (by @snehasish) introduces v4 which contains CalleeGuids in CallSiteInfo, and this change changes the v4 format in place with data access profiles. The current plan is to bump the version and enable v4 profiles with both features, assuming waiting for this change won't delay the callsite change too long. --------- Co-authored-by: Kazu Hirata <kazu@google.com>
2025-05-19[NFC][MemProf] Move IndexedMemProfData to its own header. (#140503)Snehasish Kumar2-1/+2
Part of a larger refactoring with the following goals 1. Reduce the size of MemProf.h 2. Avoid including ModuleSummaryIndex just for a couple of types
2025-05-19[NFC][MemProf] Move getGUID out of IndexedMemProfRecord (#140502)Snehasish Kumar1-10/+10
Part of a larger refactoring with the following goals 1. Reduce the size of MemProf.h 2. Avoid including ModuleSummaryIndex just for a couple of types
2025-05-19[NFC][MemProf] Move Radix tree methods to their own header and cpp. (#140501)Snehasish Kumar2-0/+2
Part of a larger refactoring with the following goals 1. Reduce the size of MemProf.h 2. Avoid including ModuleSummaryIndex just for a couple of types
2025-05-19[NFC][MemProf] Fix typo in type name (#140500)Snehasish Kumar2-8/+8
2025-05-16[StaticDataLayout][PGO] Remove inclusion of private gmock headerBenjamin Kramer1-1/+0
This one is supposed to be included via gmock.h
2025-05-15[StaticDataLayout][PGO] Add profile format for static data layout, and the ↵Mingming Liu2-0/+183
classes to operate on the profiles. (#138170) Context: For https://discourse.llvm.org/t/rfc-profile-guided-static-data-partitioning/83744#p-336543-background-3, we propose to profile memory loads and stores via hardware events, symbolize the addresses of binary static data sections and feed the profile back into compiler for data partitioning. This change adds the profile format for static data layout, and the classes to operate on it. The profile and its format 1. Conceptually, a piece of data (call it a symbol) is represented by its symbol name or its content hash. The former applies to majority of data whose mangled name remains relatively stable over binary releases, and the latter applies to string literals (with name patterns like `.str.<N>[.llvm.<hash>]`. - The symbols with samples are hot data. The number of hot symbols is small relative to all symbols. The profile tracks its sampled counts and locations. Sampled counts come from hardware events, and locations come from debug information in the profiled binary. The symbols without samples are cold data. The number of such cold symbols is large. The profile tracks its representation (the name or content hash). - Based on a preliminary study, debug information coverage for data symbols is partial and best-effort. In the LLVM IR, global variables with source code correspondence may or may not have debug information. Therefore the location information is optional in the profiles. 2. The profile-and-compile cycle is similar to SamplePGO. Profiles are sampled from production binaries, and used in next binary releases. Known cold symbols and new hot symbols can both have zero sampled counts, so the profile records known cold symbols to tell the two for next compile. In the profile's serialization format, strings are concatenated together and compressed. Individual records stores the index. A separate PR will connect this class to InstrProfReader/Writer via MemProfReader/Writer. --------- Co-authored-by: Kazu Hirata <kazu@google.com>
2025-05-01[MemProf] Add v4 which contains CalleeGuids to CallSiteInfo. (#137394)Snehasish Kumar1-1/+46
This patch adds CalleeGuids to the serialized format and increments the version number to 4. The unit tests are updated to include a new test for v4 and the YAML format is also updated to be able to roundtrip the v4 format.
2025-03-19[ctxprof] Track unhandled call targets (#131417)Mircea Trofin1-7/+7
Collect profiles for functions we encounter when collecting a contextual profile, that are not associated with a call site. This is expected to happen for signal handlers, but it also - problematically - currently happens for mem{memset|copy|move|set}, which are currently inserted after profile instrumentation. Collecting a "regular" flat profile in these cases would hide the problem - that we loose better profile opportunities.
2025-03-14[ctxprof] Capture sampling info for context roots (#131201)Mircea Trofin1-7/+7
When we collect a contextual profile, we sample the threads entering its root and only collect on one at a time (see `ContextRoot::Taken`). If we want to compare profiles between contextual profiles, and/or flat profiles, we have a problem: we don't know how to compare the counter values relative to each other. To that end, we add `ContextRoot::TotalEntries`, which is incremented every time a root is entered and serves as multiplier for the counter values collected under that root. We expose this in the profile and leave the normalization to the user of the profile, for a few reasons: * it's only needed if reasoning about all profiles in aggregate. * the goal, in compiler_rt, is to flush out the profile as quickly as possible, and performing multiplications adds an overhead that may not even be necessary if the consumer of the profile doesn't care about combining profiles * the information itself may be interesting as an indication of relative sampling of various contexts.
2025-03-12[MemProf] Extend CallSite information to include potential callees. (#130441)Snehasish Kumar2-20/+41
* Added YAML traits for `CallSiteInfo` * Updated the `MemProfReader` to pass `Frames` instead of the entire `CallSiteInfo` * Updated test cases to use `testing::Field` * Add YAML sequence traits for CallSiteInfo in MemProfYAML * Also extend IndexedMemProfRecord * XFAIL the MemProfYaml round trip test until we update the profile format For now we only read and write the additional information from the YAML format. The YAML round trip test will be enabled when the serialized format is updated.
2025-03-05[ctxprof] Prepare profile format for flat profiles (#129626)Mircea Trofin1-6/+72
The profile format has now a separate section called "Contexts" - there will be a corresponding one for flat profiles. The root has a separate tag because, in addition to not having a callsite ID as all the other context nodes have under it, it will have additional fields in subsequent patches. The rest of this patch amounts to a bit of refactorings in the reader/writer (for better reuse later) and tests fixups.
2025-03-04[ctxprof][nfc] Prepare CtxProfAnalysis for flat profiles (#129623)Mircea Trofin1-10/+10
Mostly remove the equivalence "no contexts == no CtxProfAnalysis result", and instead check explicitly there are no contextual profiles.
2025-01-09Introduce CounterExpressionBuilder::subst(C, Map) (#112698)NAKAMURA Takumi1-0/+39
This return a counter for each term in the expression replaced by ReplaceMap. At the moment, this doesn't update the Map, so Map is marked as `const`.
2024-12-19[memprof] Introduce IndexedCallstackIdConveter (NFC) (#120540)Kazu Hirata2-48/+24
This patch introduces IndexedCallstackIdConveter as a convenience wrapper around FrameIdConverter and CallStackIdConverter just for tests. With the new wrapper, we get to replace idioms like: FrameIdConverter<decltype(MemProfData.Frames)> FrameIdConv( MemProfData.Frames); CallStackIdConverter<decltype(MemProfData.CallStacks)> CSIdConv( MemProfData.CallStacks, FrameIdConv); with: IndexedCallstackIdConveter CSIdConv(MemProfData); Unfortunately, this exact pattern occurs in tests only; the combinations of the frame ID converter and call stack ID converter are diverse in production code.
2024-12-17[memprof] Don't use Frame::hash or hashCallStacks in unit test (#119984)Kazu Hirata1-47/+30
This patch checks the result of YAML parsing at the level of MemProfRecord instead of IndexedMemProfRecord, thereby avoiding use of Frame::hash and hashCallStacks. This makes sense because we ultimately care about consumers like MemProfiler.cpp obtaining MemProfRecord correctly; IndexedMemProfData and hash values are just intermediaries. Once this patch lands, we call Frame::hash and hashCallStacks only when adding Frames or call stacks to their respective data structures. In other words, the hash functions are pretty much business internal to IndexedMemProfRecord.
2024-12-13[memprof] Don't use Frame::hash() (NFC) (#119828)Kazu Hirata1-2/+2
In these tests, we just want to add one instance of IndexedMemProfRecord to MemProfData.Records and retrieve it from MemProfReader. There is no particular reason to associate F1.hash() with the IndexedMemProfRecord instance. A fake value suffices. While I am at it, I'm switching to try_emplace so that I can move FakeRecord.
2024-12-12[memprof] Use return values from addFrame and addCallStack (NFC) (#119676)Kazu Hirata1-41/+37
Migrating away from Frame::hash and hashCallStack further encapsulates how the IDs are calculated. Note that unit tests are the only places where Frame::hash and hashCallStack are used. The code proper (i.e. llvm/lib) uses IndexedMemProfData::{addFrame,addCallStack}; they do not directly use Frame::hash or hashCallStack.
2024-12-12[memprof] Use addCallStack in a unit test (NFC) (#119651)Kazu Hirata1-6/+4
Here IndexedMemProfRecord just needs to reference a CallStackID, so we can use addCallStack for a real hash-based CallStackId instead of a fake value like 0x222.
2024-12-11[memprof] Use IndexedMemProfData in unit tests (NFC) (#119648)Kazu Hirata1-19/+19
This patch uses IndexedMemProfData in unit tests even when we only need CallStacks. This way, we get to use addCallStack. Also, the look is more consistent with other unit tests, where we typically do: IndexMemProfData MemProfData; MemProfData.addFrame(...); MemProfData.addCallStack(...); // Run some tests
2024-12-11[memprof] Drop testing:: in a unit test (NFC) (#119636)Kazu Hirata1-2/+2
Note that we already have: using ::testing::IsEmpty;
2024-12-11[memprof] Improve the way we express Frames in YAML (#119629)Kazu Hirata1-2/+2
This patch does two things: - During deserialization, we accept a function name for Frame as an alternative to the usual GUID expressed as a hexadecimal number. - During serialization, we print a GUID of Frame as a 16-digit hexadecimal number prefixed with 0x in the usual way. (Without this patch, we print a decimal number, which is not customary.) The patch uses a machinery called "normalization" in YAML I/O, which lets us serialize and deserialize into an alternative data structure. For our use case, we have an alternative Frame data structure, which is identical to "struct Frame" except that Function is of type GUIDHex64 instead of GlobalValue::GUID. This alternative type supports the two bullet points above without modifying "struct Frame" at all.
2024-12-11[memprof] Move YAML support to MemProfYAML.h (NFC) (#119515)Kazu Hirata1-0/+1
The YAML support is increasing in size, so this patch moves it to a separate file.
2024-12-11[memprof] Drop curly braces on small for loops (NFC) (#119516)Kazu Hirata1-8/+4
2024-12-11[memprof] Use front instead of begin in a unit test (NFC) (#119501)Kazu Hirata1-1/+1
"front" allows us to drop a dereference.
2024-12-10[memprof] Accept a function name in YAML (#119453)Kazu Hirata1-0/+38
This patch does two things: - During deserialization, we accept a function name as an alternative to the usual GUID represented as a hexadecimal number. - During serialization, we print a GUID as a 16-digit hexadecimal number prefixed with 0x in the usual way. (Without this patch, we print a decimal number, which is not customary.) In YAML, the MemProf profile is a vector of pairs of GUID and MemProfRecord. This patch accepts a function name for the GUID, but it does not accept a function name for the GUID used in Frames yet. That will be addressed in a subsequent patch.
2024-12-09[memprof] Use std::make_unique in unit tests (NFC) (#119175)Kazu Hirata1-2/+2
2024-12-08[memprof] Use namespaces in a unit test (#119144)Kazu Hirata1-58/+42
MemProfTest.cpp is about MemProf, so mentioning llvm::memprof everywhere is quite verbose.
2024-12-08[memprof] Drop memprof:: in unit tests (NFC) (#119113)Kazu Hirata2-32/+28
This patch replaces memprof::Foo with Foo if we have corresponding: using llvm::memprof::Foo;
2024-12-08[memprof] Compare Frames instead of FrameIds in a unit test (#119111)Kazu Hirata1-13/+4
When we call IndexedMemProfRecord::toMemProfRecord, we care about getting the original (that is, non-indexed) MemProfRecord back, so we should just verify that, not the hash values, which are intermediaries. There is a remote possibility of hash collisions where call stack {F1, F2} might come back as {F1, F1} if F1.hash() == F2.hash() for example. However, since FrameId uses BLAKE, the hash values should be consistent across architectures. That is, if this test case works on one architecture, it should work on others as well.
2024-12-07[memprof] Use IndexedMemProfData in a unit test (NFC) (#119062)Kazu Hirata1-20/+12
IndexedMemProfData eliminates the need for the "using" directives. Also, we do not need to declare maps for individual components of the MemProf profile.
2024-12-07[memprof] Add getMemProfDataForTest for unit tests (#119061)Kazu Hirata1-31/+19
We always call getFrameMapping and getCallStackMapping together in InstrProfTest.cpp. This patch combines the two functions into new function getMemProfDataForTest.
2024-12-07[memprof] Remove a stale comment in a unit test (#119060)Kazu Hirata1-2/+0
We've removed IndexedAllocationInfo::CallStack, so we don't need to mention it.
2024-12-06[memprof] Use gtest matchers at more places (#119050)Kazu Hirata2-32/+22
These gtest matchers reduce the number of times we mention the variables under examined.
2024-12-06[memprof] Use IndexedMemProfData in tests (NFC) (#119049)Kazu Hirata1-13/+14
This patch replaces FrameIdMap and CallStackIdMap with IndexedMemProfData, which comes with recently introduced methods like addFrame and addCallStack.
2024-12-06[memprof] Add IndexedMemProfData::addCallStack (#118920)Kazu Hirata1-4/+2
This patch adds a helper function to replace an idiom like: CallStackId CSId = hashCallStack(CallStack) MemProfData.CallStacks.try_emplace(CSId, CallStack); // Do something with CSId.
2024-12-05[memprof] Rename Inline to IsInlineFrame in YAML (#118901)Kazu Hirata1-9/+9
This patch makes the YAML field name match the struct field name.