Skip to content

Handle edge cases in trace defintion if frames held less than frames_per_toc_entry frames #28

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,42 @@
make
make install
```

## Trace format

The trace consists of three parts: the header,
a table of contents (TOC) holding the frames, and an index into the TOC.

A fixed number of frames are considered _one entry_ in the TOC.
Frames in each entry starts with the size of the frame, followed by the actual frame data.
Then the next frame size followed by the frame data and so forth.

The TOC index is stored at the end.

[!IMPORTANT]
The last TOC entry might holds less than `m` frames.

For specifics about the frame contents, please check the definitions in the [piqi](piqi/) directory.

**Format**

| Offset | Type | Field | Note |
|--------|------|-------|------|
| 0x0 | uint64_t | magic number (7456879624156307493LL) | Header begin |
| 0x8 | uint64_t | trace version number | |
| 0x10 | uint64_t | frame_architecture | |
| 0x18 | uint64_t | frame_machine, 0 for unspecified. | |
| 0x20 | uint64_t | n = total number of frames in trace. | |
| 0x28 | uint64_t | T = offset to TOC index. | |
| 0x30 | uint64_t | sizeof(frame_0) | TOC begin |
| 0x38 | meta_frame | frame_0 | |
| 0x40 | uint64_t | sizeof(frame_1) | |
| 0x48 | type(frame_1) | frame_1 | |
| ... | ... | ... | |
| T-0x10 | uint64_t | sizeof(frame_n-1) | |
| T-0x8 | type(frame_n-1) | frame_n-1 | |
| T+0 | uint64_t | m = maximum number of frames per TOC entry | TOC index begin |
| T+0x8 | uint64_t | offset toc_entry(0) | |
| T+0x10 | uint64_t | offset toc_entry(1) | |
| ... | ... | ... | |
| T+0x8+(0x8*ceil(n/m)) | uint64_t | offset toc_entry(ceil(n/m)) | |
2 changes: 2 additions & 0 deletions libtrace/src/frame_arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -435,4 +435,6 @@ enum frame_architecture
#define FRAME_MODE_PPC32 "ppc:ppc"
#define FRAME_MODE_PPC64 "ppc:ppc64"

#define FRAME_MODE_NONE NULL

#endif
3 changes: 2 additions & 1 deletion libtrace/src/trace.container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,9 @@ namespace SerializedTrace {
/* Read number of frames per toc entry. */
READ(frames_per_toc_entry);

size_t add = (num_frames % frames_per_toc_entry != 0) ? 1 : 0;
/* Read each toc entry. */
for (int i = 0; i < ((num_frames - 1) / frames_per_toc_entry); i++) {
for (int i = 0; i < (num_frames / frames_per_toc_entry) + add; i++) {
uint64_t offset;
READ(offset);
toc.push_back(offset);
Expand Down