Interview conceptCoding & Algorithms

Stack Trace And Profiler Log Processing

Asked of: Software Engineer

Last updated

Horizontal 6-step trace infographic that shows stack simulation for profiler logs: at each step a log event, the call-stack (fn, start_ts, child_time), a short caption, timeline ticks, and calculations of exclusive/inclusive times.

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)]; on end, exclusive time is end - start - child_time.

  • Previous-timestamp accounting — for LeetCode-style start/end logs, charge ts - prev_ts to stack[-1]; update prev_ts after each event.

  • Stack sample diffing — compare old and new frame arrays by longest common prefix; emit end events deepest-first, start events 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, impossible end order, negative durations, equal timestamp ambiguity, and recursion by tracking frame identity.

  • Complexity target — aim for O(n) time and O(d) space, where d is 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 fn is 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

Related concepts

Stack Trace And Profiler Log Processing — Tech Interview Concept | PracHub