summaryrefslogtreecommitdiff
path: root/fossil_replay.sh
blob: 282de81dd78928b8a782f753859e58e5aa3ca182 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env bash
# Copyright © 2020 Valve Corporation

# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:

# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

# Usage: fossil_replay.sh fossils/ output.csv <arguments to pass to fossilize-replay>
# Runs each app in a separate fossilize-replay process as recommended and to
# handle separate Vulkan version requirements.
IFS=$'\n'
rm -f "$2" /tmp/fossil_replay.txt
for db in `find -L "$1" -type f -name "*.foz"`; do
    if [ ! $printed_name ]; then
        # Print the device name
        fossilize-replay ${@:3} "$db" --graphics-pipeline-range 0 0 --compute-pipeline-range 0 0 2>&1 | grep "Chose GPU:" -A1
        printed_name=1
    fi

    # Append stdout/stderr to file to reduce spam
    echo -n "Replaying $db"
    echo "Replaying $db" >> "/tmp/fossil_replay.txt"
    rm -f "$2".tmp

    start_time_ns=$(date +%s%N)
    fossilize-replay --enable-pipeline-stats "$2".tmp ${@:3} "$db" 1>&2 2>> "/tmp/fossil_replay.txt"
    end_time_ns=$(date +%s%N)

    # Check for failures
    if [ ! -e "$2".tmp ]; then
        rm -f "$2".tmp.__tmp.foz
        echo " failed"
        grep "pipeline crashed or hung" /tmp/fossil_replay.txt
        exit 1
    else
        duration_ns=$(($end_time_ns-$start_time_ns))
        duration_s=$(($duration_ns/1000000000))
        duration_cs=$(($(($duration_ns/10000000))-$(($duration_s*100))))
        echo " took $duration_s.$(($duration_cs))s"
    fi

    # Append to result CSV
    cat "$2".tmp >> "$2"
done
rm -f "$2".tmp