Repository navigation
Split traces larger than -b instead of dropping them - #170
Merged
Merged
Conversation
Supersedes #167, which in turn superseded #157. Currently phpspy drops traces that are larger than `-b`, which defaults to `PIPE_BUF` (4096 bytes). The idea is to avoid interleaved traces in `-P` mode. The problem is that traces are often larger than 4k in production, so we often bump `-b` and eat the cost of potentially corrupt traces. The fix is to split large traces into smaller chunks. As long as each thread outputs each chunk under `PIPE_BUF` bytes, then readers like `stackcollapse-phpspy.pl` can reassemble the chunks back into the full trace. Differences compared to #167: * Writes happen in a single pass. #167 did one pass to count chunks and another pass to write each chunk as `k/n`. Here we include a sentinel with each chunk that indicates "incomplete" (`~`) or "complete" (`!`). * There's no fixed reserve for `trace_id` records. It's calculated dynamically. * Traces under `-b` are unchanged -- no `trace_id` metadata. * No partial records. If a single record exceeds `-b`, drop it and end the trace with a `# truncated = 1` chunk by itself. * `-1` mode is not a special case. #167 disabled chunking in `-1` mode. * The `-o` fd is `open`-d then `dup`-d by other threads under a mutex. This avoids interleaving/corruption in `-P -o ...` mode. Adds a comment TODO the same for `-O` and `-E`. Could be a separate commit. * Delimiter stripping uses `memchr` -- more efficient than the existing byte loop. Could be a separate commit.
This was referenced Oct 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Supersedes #167, which in turn superseded #157.
Currently phpspy drops traces that are larger than
-b, which defaults toPIPE_BUF(4096 bytes). The idea is to avoid interleaved traces in-Pmode. The problem is that traces are often larger than 4k in production, so we often bump-band eat the cost of potentially corrupt traces.The fix is to split large traces into smaller chunks. As long as each thread outputs each chunk under
PIPE_BUFbytes, then readers likestackcollapse-phpspy.plcan reassemble the chunks back into the full trace.Differences compared to #167:
Writes happen in a single pass. 167 did one pass to count chunks and another pass to write each chunk as
k/n. Here we include a sentinel with each chunk that indicates "incomplete" (~) or "complete" (!).There's no fixed reserve for
trace_idrecords. It's calculated dynamically.Traces under
-bare unchanged -- notrace_idmetadata.No partial records. If a single frame record exceeds
-b, drop it and emit a# truncated = 1metadata record. We could make it a flag to emit partial records.-1mode is not a special case. 167 disabled chunking in-1mode.The
-ofd isopen-d thendup-d by other threads under a mutex. This avoids interleaving/corruption in-P -o ...mode. Adds a comment TODO the same for-Oand-E. Could be a separate commit.Delimiter stripping uses
memchr-- more efficient than the existing byte loop. Could be a separate commit.