Skip to content

Commit d0b4780

Browse files
[nfc][docs]Generalize header description and ascii art for indexed profiles (#83507)
- Add pointers to code for source of truth. - Move necessary details from doc to code.
1 parent 5906b1a commit d0b4780

File tree

2 files changed

+43
-39
lines changed

2 files changed

+43
-39
lines changed

llvm/docs/InstrProfileFormat.rst

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,10 @@ profiles generated by older tools or compilers.
360360
General Storage Layout
361361
-----------------------
362362

363+
The ASCII art depicts the general storage layout of indexed profiles.
364+
Specifically, the indexed profile header describes the byte offset of individual
365+
payload sections.
366+
363367
::
364368

365369
+-----------------------+---+
@@ -369,55 +373,49 @@ General Storage Layout
369373
+-----------------------+ |
370374
| HashType | H
371375
+-----------------------+ E
372-
+-------| HashOffset | A
373-
| +-----------------------+ D
374-
+-----------| MemProfOffset | E
375-
| | +-----------------------+ R
376-
| | +--| BinaryIdOffset | |
377-
| | | +-----------------------+ |
378-
+---------------| TemporalProf- | |
379-
| | | | | TracesOffset | |
380-
| | | | +-----------------------+---+
381-
| | | | | Profile Summary | |
382-
| | | | +-----------------------+ P
383-
| | +------>| Function data | A
384-
| | | +-----------------------+ Y
385-
| +---------->| MemProf profile data | L
386-
| | +-----------------------+ O
387-
| +->| Binary Ids | A
376+
| Byte Offset | A
377+
+------ | of section A | D
378+
| +-----------------------+ E
379+
| | Byte Of fset | R
380+
+-----------| of section B | |
381+
| | +-----------------------+ |
382+
| | | ... | |
383+
| | +-----------------------+ |
384+
| | | Byte Offset | |
385+
+---------------| of section Z | |
386+
| | | +-----------------------+---+
387+
| | | | Profile Summary | |
388+
| | | +-----------------------+ P
389+
| | +------>| Section A | A
390+
| | +-----------------------+ Y
391+
| +---------->| Section B | L
392+
| +-----------------------+ O
393+
| | ... | A
388394
| +-----------------------+ D
389-
+-------------->| Temporal profiles | |
395+
+-------------->| Section Z | |
390396
+-----------------------+---+
391397

392-
Header
393-
--------
398+
.. note::
394399

395-
``Magic``
396-
The purpose of the magic number is to be able to tell if the profile is an
397-
indexed profile.
400+
Profile summary section is at the beginning of payload. It's right after the
401+
header so its position is implicitly known after reading the header.
398402

399-
``Version``
400-
Similar to raw profile version, the lower 32 bits specify the version of the
401-
indexed profile and the most significant 32 bits are reserved to specify the
402-
variant types of the profile.
403+
Header
404+
--------
403405

404-
``HashType``
405-
The hashing scheme for on-disk hash table keys. Only MD5 hashing is used as of
406-
writing.
406+
The `Header struct`_ is the source of truth and struct fields should explain
407+
what's in the header. At a high level, `*Offset` fields record section byte
408+
offsets, which are used by readers to locate interesting sections and skip
409+
uninteresting ones.
407410

408-
``HashOffset``
409-
An on-disk hash table stores the per-function profile records. This field records
410-
the offset of this hash table's metadata (i.e., the number of buckets and
411-
entries), which follows right after the payload of the entire hash table.
411+
.. note::
412412

413-
``MemProfOffset``
414-
Records the byte offset of MemProf profiling data.
413+
To maintain backward compatibility of the indexed profiles, existing fields
414+
shouldn't be deleted from struct definition; the field order shouldn't be
415+
modified. New fields should be appended.
415416

416-
``BinaryIdOffset``
417-
Records the byte offset of binary id sections.
417+
.. _`Header struct`: https://github.com/llvm/llvm-project/blob/1a2960bab6381f2b288328e2371829b460ac020c/llvm/include/llvm/ProfileData/InstrProf.h#L1053-L1080
418418

419-
``TemporalProfTracesOffset``
420-
Records the byte offset of temporal profiles.
421419

422420
Payload Sections
423421
------------------

llvm/include/llvm/ProfileData/InstrProf.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,9 +1062,15 @@ inline uint64_t ComputeHash(StringRef K) { return ComputeHash(HashType, K); }
10621062
// as appropriate when updating the indexed profile format.
10631063
struct Header {
10641064
uint64_t Magic;
1065+
// The lower 32 bits specify the version of the indexed profile.
1066+
// The most significant 32 bits are reserved to specify the variant types of
1067+
// the profile.
10651068
uint64_t Version;
10661069
uint64_t Unused; // Becomes unused since version 4
10671070
uint64_t HashType;
1071+
// This field records the offset of this hash table's metadata (i.e., the
1072+
// number of buckets and entries), which follows right after the payload of
1073+
// the entire hash table.
10681074
uint64_t HashOffset;
10691075
uint64_t MemProfOffset;
10701076
uint64_t BinaryIdOffset;

0 commit comments

Comments
 (0)