Last active
July 21, 2023 19:50
-
-
Save ZenGround0/fe929e2c22cccf77b9514a81ff523c8a to your computer and use it in GitHub Desktop.
Commands for analyzing miner cron
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Use a trailing slash in directory if not provided | |
[[ "$2" != */ ]] && dir="$2"/ || dir="$2" | |
./lotus state --tipset=@$1 compute-state --json | jq --argjson height "$1" '. + {Height: $height}' > "${dir}"gas-trace-"$1".json | |
cat "${dir}"gas-trace-$1.json | jq -c '.Trace | .[] | select( .Msg | .To== "f03") | .ExecutionTrace | .Subcalls | .[] | select( .Msg | .To == "f04") | .Subcalls | .[] | select( .Msg | .Method == 12) | {"To":( .Msg | .To) , "Gas": (reduce (.. | .GasCharges? | select(.) | .[]) as $gas ({tg: 0}; {tg: ($gas.tg + .tg)}))} ' | jq --argjson height "$1" -s '[.[] | . + {Height: $height}]' > "${dir}"crongas-"$1".json | |
cat "${dir}"gas-trace-$1.json | jq -c '.Trace | .[] | select( .Msg | .To== "f03") | .ExecutionTrace | .Subcalls | .[] | select( .Msg | .To == "f04") | .Subcalls | .[] | select( .Msg | .Method == 12) | {"To":( .Msg | .To) , "Gas": (reduce (.. | .GasCharges? | select(.) | .[] | select(.Name == "wasm_exec") ) as $gas ({tt: 0}; {tt: ($gas.tt + .tt)}))} ' | jq --argjson height "$1" -s '[.[] | . + {Height: $height}]' > "${dir}"crontime-"$1".json | |
jq -s ' | |
(.[0] + .[1]) | | |
group_by(.To) | | |
map(reduce .[] as $item ({}; .To = $item.To | .Height = $item.Height | .Gas += $item.Gas)) | |
' "${dir}"crongas-"$1".json "${dir}"crontime-"$1".json > "${dir}"cronsummary-"$1".json | |
(cat "${dir}"cronsummary-"$1".json | ./lotus-shed cron-wc deadline-summary; cat "${dir}"cronsummary-"$1".json) | jq -s '.' | jq 'transpose | .[] | .[0] + .[1]' > "${dir}"output-"$1".json | |
# remove intermediates | |
rm "${dir}"/crongas-"$1".json | |
rm "${dir}"/crontime-"$1".json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is a summary script, not yet something you should run | |
# Grab gas trace | |
./lotus state --tipset=@3020500 compute-state --json | jq '. + {Height: 3020500}' > gas-trace-3020500.json | |
# Read the gas trace | |
# Parse out subtrace for miner deadline cron | |
# Combine all gas charges made by this method call and all subcalls | |
# Simplify gas charge to just keep total time and total gas | |
cat gas-trace-3020500.json | jq -c '.Trace | .[] | select( .Msg | .To== "f03") | .ExecutionTrace | .Subcalls | .[] | select( .Msg | .To == "f04") | .Subcalls | .[] | select( .Msg | .Method == 12) | {"To":( .Msg | .To) , "Gas": (reduce (.. | .GasCharges? | select(.) | .[]) as $gas ({tt: 0, tg: 0}; {tt: ($gas.tt + .tt), tg: ($gas.tg + .tg)}))} ' | jq -s '[.[] | . + {Height: 3020500}]' > crongas-3020500.json | |
# Add partition metadata to the gas trace by calling shed tool | |
begin; cat crongas-3020500.json | ./lotus-shed cron-wc deadline-summary; cat crongas-3020500.json; end | jq -s '.' | jq 'transpose | .[] | .[0] + .[1]' > output3020500.json | |
# Basic processing: i.e. count empty partion cron jobs and gas of these jobs | |
``` | |
root@zen-lotus-dev /m/storage# cat ~/filecoin/lotus/experiment3029280 | jq -s '.[] |select(.Partitions!=null) | .Gas.tt' | jq -s 'add' | |
129258501 | |
root@zen-lotus-dev /m/storage# cat ~/filecoin/lotus/experiment3029280 | jq -s '.[] |select(.Partitions==null) | .Gas.tt' | jq -s 'add' | |
106152018 | |
root@zen-lotus-dev /m/storage# cat ~/filecoin/lotus/experiment3029280 | jq -s '.[] |select(.Partitions==null) | .Gas.tt' | jq -s 'length' | |
30 | |
root@zen-lotus-dev /m/storage# cat ~/filecoin/lotus/experiment3029280 | jq -s '.[] |select(.Partitions!=null) | .Gas.tt' | jq -s 'length' | |
29 | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment