fork/fish-shell
git clone https://git.julia.blue/fork/fish-shell
f0a54510c
master
1#!/usr/bin/env fish 2# 3# Compares the output of two fish profile runs and emits the time difference between 4# the first and second set of results. 5# 6# Usage: ./diff_profiles.fish profile1.log profile2.log > profile_diff.log 7 8if test ( count $argv ) -ne 2 9 10echo "Incorrect number of arguments." 11echo "Usage: " ( status filename) " profile1.log profile2.log" 12exit 1 13end 14 15set -l profile1( cat $argv [ 1 ]) 16set -l profile2( cat $argv [ 2 ]) 17 18set -l line_no0 19while set -l next_line_no( math $line_no +1 ) && set -q profile1[ $next_line_no ] && set -q profile2[ $next_line_no ] 20set line_no$next_line_no 21 22set -l line1$profile1 [ $line_no ] 23set -l line2$profile2 [ $line_no ] 24 25if not string match -qr'^\s*\d+\s+\d+' $line1 26echo $line1 27continue 28end 29 30set -l results1( string match -r'^\s*(\d+)\s+(\d+)\s+(.*)' $line1 ) 31set -l results2( string match -r'^\s*(\d+)\s+(\d+)\s+(.*)' $line2 ) 32 33# times from both files 34set -l time1$results1 [ 2 .. 3 ] 35set -l time2$results2 [ 2 .. 3 ] 36 37# leftover from both files 38set -l remainder1$results1 [ 4 ] 39set -l remainder2$results2 [ 4 ] 40 41if not string match -q --$remainder1 $remainder2 42echo Mismatch on line$line_no : 43echo -$remainder1 44echo +$remainder2 45exit 1 46end 47 48set -l diff 49set diff[ 1 ] ( math $time1 [ 1 ] -$time2 [ 1 ]) 50set diff[ 2 ] ( math $time1 [ 2 ] -$time2 [ 2 ]) 51 52printf '%10d %10d %s\n' $diff [ 1 ] $diff [ 2 ] $remainder1 53end