1
0
mirror of https://git.decapod.one/brethil/dotfiles synced 2024-11-27 13:41:32 +01:00
dotfiles/extras/sort_timings.zsh

Failed to ignore revisions in .git-blame-ignore-revs.

51 lines
1.3 KiB
Bash
Raw Normal View History

#!/usr/bin/env zsh
# Reads output from zprof.
# Usage:
# 1. add the following to the beginning of your zshrc
# if [[ -n $profiling ]]; then
# zmodload zsh/zprof
# zmodload zsh/datetime
# setopt PROMPT_SUBST
# PS4='+$EPOCHREALTIME %N:%i> '
#
# logfile=$(mktemp zsh_profile.XXXXXXXX)
# echo "Logging to $logfile"
# exec 3>&2 2>$logfile
#
# setopt XTRACE
# fi
# 2. add this to the end of your zshrc
# if [[ -n $profiling ]]; then
# unsetopt XTRACE
# exec 2>&3 3>&-
# zprof
# fi
# 3. zsh -i -c exit
# 4. sort_timings.zsh zsh_profile.* # or use the newly-created file
typeset -a lines
typeset -i prev_time=0
typeset prev_command
while read line; do
if [[ $line =~ '^.*\+([0-9]{10})\.([0-9]{6})[0-9]* (.+)' ]]; then
integer this_time=$match[1]$match[2]
if [[ $prev_time -gt 0 ]]; then
time_difference=$(( $this_time - $prev_time ))
lines+="$time_difference $prev_command"
fi
prev_time=$this_time
local this_command=$match[3]
if [[ ${#this_command} -le 80 ]]; then
prev_command=$this_command
else
prev_command="${this_command}..."
fi
fi
done < ${1:-/dev/stdin}
print -l ${(@On)lines} # | sort -h | vim -