fork/fish-shell

git clone https://git.julia.blue/fork/fish-shell

Daniel RainerFormat files using `build_tools/style.fish`f0a54510c

master
1.4 KiB53 linesraw
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
10    echo "Incorrect number of arguments."
11    echo "Usage: "(status filename)" profile1.log profile2.log"
12    exit 1
13end
14
15set -l profile1 (cat $argv[1])
16set -l profile2 (cat $argv[2])
17
18set -l line_no 0
19while set -l next_line_no (math $line_no + 1) && set -q profile1[$next_line_no] && set -q profile2[$next_line_no]
20    set line_no $next_line_no
21
22    set -l line1 $profile1[$line_no]
23    set -l line2 $profile2[$line_no]
24
25    if not string match -qr '^\s*\d+\s+\d+' $line1
26        echo $line1
27        continue
28    end
29
30    set -l results1 (string match -r '^\s*(\d+)\s+(\d+)\s+(.*)' $line1)
31    set -l results2 (string match -r '^\s*(\d+)\s+(\d+)\s+(.*)' $line2)
32
33    # times from both files
34    set -l time1 $results1[2..3]
35    set -l time2 $results2[2..3]
36
37    # leftover from both files
38    set -l remainder1 $results1[4]
39    set -l remainder2 $results2[4]
40
41    if not string match -q -- $remainder1 $remainder2
42        echo Mismatch on line $line_no:
43        echo - $remainder1
44        echo + $remainder2
45        exit 1
46    end
47
48    set -l diff
49    set diff[1] (math $time1[1] - $time2[1])
50    set diff[2] (math $time1[2] - $time2[2])
51
52    printf '%10d %10d %s\n' $diff[1] $diff[2] $remainder1
53end