Stack Trace And Profiler Log Processing
Asked of: Software Engineer
Last updated

What's being tested
This tests stack simulation over ordered execution logs: reconstruct active calls, compute inclusive and exclusive time, and emit derived trace events. Interviewers are probing careful interval reasoning, edge-case handling, and clean O(n) stream-processing code.
Patterns & templates
-
Call-stack simulation — maintain
stack[(fn, start_ts, child_time)]; onend, exclusive time isend - start - child_time. -
Previous-timestamp accounting — for LeetCode-style
start/endlogs, chargets - prev_tstostack[-1]; updateprev_tsafter each event. -
Stack sample diffing — compare old and new frame arrays by longest common prefix; emit
endevents deepest-first,startevents shallowest-first. -
Call tree reconstruction — parse indentation, frame depth, or parent IDs; attach nodes via a stack of current ancestors in
O(n)time. -
Streaming validation — detect missing
end, impossibleendorder, negative durations, equal timestamp ambiguity, and recursion by tracking frame identity. -
Complexity target — aim for
O(n)time andO(d)space, wheredis max stack depth; aggregate per-function maps separately.
Common pitfalls
Pitfall: Confusing inclusive time with exclusive time; parent time must subtract completed child intervals or only receive gaps while active.
Pitfall: Handling equal timestamps inconsistently; declare whether intervals are half-open
[start, end)or inclusive, then apply it everywhere.
Pitfall: Treating function name as unique identity during recursion; recursive calls need separate stack frames even when
fnis identical.
Practice these
The practice cards below cover the canonical variants — solve all of them and time yourself.
Featured in interview prep guides
Practice questions
- Compute exclusive times and call stack from logsAnthropic · Software Engineer · Technical Screen · Medium
- Simulate stack traces from logsAnthropic · Software Engineer · Onsite · Medium
- Parse and Reconstruct Stack TraceAnthropic · Software Engineer · Technical Screen · Medium
- Convert stack samples to trace eventsAnthropic · Software Engineer · Technical Screen · Medium
- Find the Slowest Function from Profiler EventsAnthropic · Software Engineer · Onsite · medium
Related concepts
- SQL Event Log AnalyticsData Manipulation (SQL/Python)
- Stateful Stream Processing And Time SchedulingCoding & Algorithms
- High-Throughput Streams, Jobs, And ObservabilitySystem Design
- Low-Level Performance EngineeringSystem Design
- Production Debugging And Error HandlingSoftware Engineering Fundamentals
- Streaming, Large Inputs, And External MemorySoftware Engineering Fundamentals