Boot Time Profiler

Medium Python Optimization Asked at Rivian
Solve this problem

Turn a boot log with millisecond timestamps into a profile that shows how long each stage took and which stage dominates.

Constraints

  • Lines look like '[00123] stage name'.
  • A stage's duration is the gap to the next timestamp.
  • The last stage has no duration and is reported as 0.
  • Return stages sorted by duration, longest first.
  • Non-conforming lines are ignored.
  • Timestamps that go backwards must raise ValueError.
Starter codePython
1def profile_boot(lines):2    # TODO3    return []