Code Tracing Troubleshooting

Code Trace buffer overflow

Symptom:

When using code tracing, I am seeing the following warning:

Failed to store FUNCTION_CALL Code Trace checkpoint (buffer size 10485755 bytes, allocated 10485760 bytes) (code_trace_request.cpp:639)
Code Trace buffer overflow at size 10485751 bytes (allocated 10485760 bytes) (code_trace_request.cpp:569)

Reason:

The warning informs you that ZendHQ was not able to store the complete code trace. It does collect what it can and then flags the trace as incomplete.

Solution:

An incomplete trace is still readable up to the point where it ran our of buffer space. In most cases, this is enough to see which path the code took and you do not need to do anything about this warning.

If however you need the full trace, you may need to increase the buffer size. Be careful to not exceed your server memory.

To increase the buffer limit, add the zendhq.codetracing.buffer_size directive to the zendhq.ini file and define your new buffer size.

Default:

zendhq.codetracing.buffer_size=10M

Example:

zendhq.codetracing.buffer_size=90M

A simple script like this requires a buffer size of 90MB, because it needs to store 1 million function calls.

<?php
function hello($name) {
    echo "Hello $name!";
}
for ($i = 0; $i < 1000000; ++$i) {
    hello("World");
}

If you have 10 PHP workers, this means that 900MB of memory is used just for code trace buffers and you may run out of your server memory if you increase the buffer size even more.