Show HN: Timep – a next-gen profiler and flamegraph-generator for bash code
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
No comments yet