Monitoring for std container resizing

Viewed 51

I am working on a high performance code base that is suffering from some performance problems due to container resizing. Inspecting throughput or latency over time shows a pattern in which exponentially increasing latency spikes are separated by exponentially increasing periods of time, suggestive of the doubling in size of containers as capacity increases.

I am having a difficult time tracking down which container is growing by manually searching through the code, and was hoping to track the container reservation with gdb.

Is there a breakpoint (or multiple breakpoints) I can set so that gdb will stop execution if a container reserves more space? I am unsure if the container is a vector, map, or set, so if all three rely on the same underlying call to resize, that might be best. Otherwise, I am happy to set multiple breakpoints.

1 Answers

Is there a breakpoint (or multiple breakpoints) I can set so that gdb will stop execution if a container reserves more space?

No: vector, map and set do not share a common resize (except that all eventually get into ::operator new).

You could set a conditional ::operator new breakpoint for reasonably large size, and see where that's getting called from.

suggestive of the doubling in size of containers as capacity increases.

Note that only vector does that, so setting a breakpoint on std::vector...::_M_allocate (for libstdc++) is probably a good starting point.

Related