Exclusive CPU Time per Function From a Single-Threaded Profiler Trace

Last updated: November 29, 2026

Quick Overview

Given n functions and a profiler trace of entries "id:start:timestamp" and "id:end:timestamp" from a single-threaded program (end timestamps are inclusive), compute each function's exclusive time, excluding time spent in the functions it called.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Medium

0

0

0 solved


Given n functions and a profiler trace of entries "id:start:timestamp" and "id:end:timestamp" from a single-threaded program (end timestamps are inclusive), compute each function's exclusive time, excluding time spent in the functions it called.

Google engineers read flame graphs and profiles constantly, and this phone screen question asks for the core of a profiler aggregator. The interviewer checks log parsing, a call stack, and getting the inclusive-end off-by-one exactly right, including recursion.

What the Interviewer Expects
  • Parses each entry into id, kind, and timestamp
  • Uses a stack to track the currently running function
  • Charges elapsed time to the function on top of the stack at every event
  • Handles the inclusive end timestamp with a plus one
  • Works for recursion and validates mismatched ends
Key Topics to Cover
Stack
Log Parsing
Interval Accounting
Off-by-One Errors
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • Report inclusive time as well as exclusive time.
  • The program is multi-threaded and each entry has a thread id; what changes?
  • Build the aggregated call tree (caller to callee time) like a flame graph.
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements
  • Input: n and a list of entries like 0:start:0, sorted by time.
  • start at t means the function begins at the start of time unit t; end at t means it finishes at the end of unit t.
  • ...
High-Level Design

Keep a stack of running function ids and a pointer prev, the first time unit not yet charged to anyone. On start at t, the function on top of the stack (if any) ran from prev to t - 1, so ch...


Submit Your Answer
Markdown supported