[HN Gopher] Show HN: Timep - a next-gen profiler and flamegraph-...
___________________________________________________________________
Show HN: Timep - a next-gen profiler and flamegraph-generator for
bash code
timep is a TIME Profiler for bash code that will give you an
accurate per-command execution time breakdown of any bash script or
function. Unlike other profilers, timep also recovers and
hierarchally records metadata on subshell and function nesting,
allowing it to recreate the full call-stack tree for the bash code
being profiled. If you call timep with the `--flame` flag, it will
automatically generate a flamegraph .svg image where each block
represents the wall-clock time spent on a particular command (top
level) or its parent subshells/functions (all the other levels).
Using timep is simple - just source the timep.bash file then add
timep before whatever you want to profile. You do not need to
change in the code being profiled - timep handles everything for
you. Example usage: . ./timep.bash timep
someFunc timep -flame someScript <inputFile timep will
generate 2 profiles for you: one showing each individual command
(with full subshell/function nesting chains), and one that combines
repeated loops commands into a count + total runtime line with
minimal "extra" metadata. See the github README for more info on
the available flags and output profile specifics. timep works by
cramming all the timing instrumentation logic into a DEBUG trap
that roughly does the following: 1. record end timestamp for
previous command 2. compare current state to state saved in
variables last DEBUG trap to determine what sort of command is
happening. e.g., if BASH_SUBSHELL increased then we know we just
entered a subshell or background fork. 3. once we know what type of
command is happening, generate a log line for the previous command
(now that we have its end time 4. save current state in various
variables (for use next debug trap) 5. record start time for the
next command then after the profiled code is done running, timep
post-processes the logs to produce the final profile
Author : jkool702
Score : 17 points
Date : 2025-07-15 06:44 UTC (1 days ago)
(HTM) web link (github.com)
(TXT) w3m dump (github.com)
| jkool702 wrote:
| Im currently working on adding the ability to record user/sys cpu
| time (in addition to wall-clock time) to timep. This will be
| coupled with a new modification to the timep_flamegraph.pl script
| that will control the flamegraph coloring saturation based on cpu
| time (sys+usr) - lower cpu time will be more faded and higher cpu
| time will be more vivid/saturated.
|
| those interested can see the current progress in the
| "timep_testing" branch of the github repo. The trap timing
| instrumentation and the new flamegraph script are both done, but
| post-processing the new cpu times is a work-in-progress. The new
| flamegraph script is backwards-compatible with the current timep,
| so you can tryout that part now if you want.
___________________________________________________________________
(page generated 2025-07-16 23:01 UTC)