mirror of
https://github.com/awesome-lists/awesome-bash.git
synced 2026-07-11 13:52:35 -05:00
[PR #139] [MERGED] Add timep #138
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/awesome-lists/awesome-bash/pull/139
Author: @jkool702
Created: 7/17/2025
Status: ✅ Merged
Merged: 7/25/2025
Merged by: @hyperupcall
Base:
master← Head:master📝 Commits (1)
195c6f6Update README.md📊 Changes
1 file changed (+1 additions, -0 deletions)
View changed files
📝
README.md(+1 -0)📄 Description
New App Submission
NOTE: I officially released
timepwithin the past few days, but I've been working on the code for several months. It began life in this repo, but after 250 commits and 22 differenttimep_testingbranches I figured it was time to give it its own dedicated repo. Hopefully this meets the "at least 90 days old" criteria.Repo or homepage link: https://github.com/jkool702/timep
Description:
timepis an efficient and accurate state-of-the-art trap-based profiler and flamegraph generator for bash code.timepdoes much more than "providing per-command execution times" -- it maps the full call-stack tree for the bash code being profiled, and (optionally) uses that call-stack tree to generate a FlameGraph of the profiled bash commands!timepwill automatically set up timing instrumentation using DEBUG/EXIT/RETURN traps and run your code (redirecting stdin to it if needed). It overloads thetrapbuiltin with atrapfunction that allows the instrumentation to continue to work even if the code being profiled sets its own DEBUG/EXIT/RETURN traps. ZERO changes need to be made to the code - just sourcetimep.bashand addtimepbefore whatever you want to profile.Why I think it's awesome: I think
timepis "awesome" because it is the first of its kind.Sure there are other profilers for bash out there, but (to the best of my knowledge) these all basically just give you per command (or per line) execution time.
timepgives you this as well (of course), buttimepis the first profiler to also map structure as it profiles. For each command it figures out both:Some of this info is readily available...much of it is not. For the ladder the required info is inferred (usually with the help of /proc). For example - from inside the child's debug trap, it is virtually impossible to tell if you are in a subshell or a background fork. Both cases will increment
$BASH_SUBSHELL, and (from the child's perspective) neither will change$!. Sotimepinfers this by reading and keeping track of PGID and TPID (read from /proc/$BASHPID/stat whenever $BASHPID changes). There are a handful of distinct patterns in how the TPID/PGID of parent and child are related that correspond to it being a background fork....if it doesnt match one of them its a subshell.Oh, and the "directly being able to create a flamegraph (where all you need to do is use
timep --flameinstead oftimep) is pretty awesome too. To clarify - this is NOT a flamegraph generated viaperf- this is a flamegraph where each top-level box represents the runtime of a particular bash command, and the different levels represent entering a function or a subshell. it is a bash native flamegraph showing actual shell commands, not the calls made by the bash binary.EXAMPLE OUTPUT:
below is an example of the profile generated for a relatively simple function.
At the bottom is a flamegraph generated from my
forkruncode that computes a bunch of checksums (13 different ones) on a bunch of small files on a ramdisk (620k / 14 gb). twice (once newline-delimited, once null-delimited). Each run has 28 active workers running a functionff, which computes the 13 checksums one at a time for that batch of files.You can clearly see both runs, and within each run you can clearly see the 28 workers running ff (plus a few other things like the main process waiting), and within each ff call you can clearly see the 13 different checksums, with their widths proportional to the relative runtimes.
Like I said...first of its kind ;)
NOTE: the flamegraph should zoom in when you click on a box. if it doesnt, download the .svg image from here and then open that locally-saved .svg file.
TIME PROFILE
gives
FLAMEGRAPH
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.