top | item 44564929

Show HN: Timep – a next-gen time-profiler and flamegraph-generator for bash code

3 points| jkool702 | 7 months ago |github.com

`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 heirarchally 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).

USAGE: To use `timep`, download and source the `timep.bash` file from the github repo, then just add `timep` before whatever you want to profile. `timep` handles everything else, including (when needed) redirecting stdin to whatever is being profiled.

    . timep.bash
    timep someFunc <input_file
    timep --flame /path/to/someScript.bash

OUTPUTS: `timep` will create 2 time profiles for you - one that has every single command + full metadata, and one that combines commands repeated in loops and only shown run count + total runtime for each command.

DEPENDENCIES: bash 5+ and a mounted /proc + common linux tools

See README on github for more info.

See https://github.com/jkool702/timep/blob/main/TESTS/simple_exa... for a simple example of the profiler output.

See https://raw.githubusercontent.com/jkool702/timep/refs/heads/... for an example of the flamegraph generated from a rather complicated multi-threaded code that profiled computing ~16 million file checksums

discuss

order

No comments yet.