Skip to content

Instantly share code, notes, and snippets.

@serpent213
Last active April 5, 2021 08:20
Show Gist options
  • Save serpent213/8518393e521f1a0dd6f7f1c3544590a2 to your computer and use it in GitHub Desktop.
Save serpent213/8518393e521f1a0dd6f7f1c3544590a2 to your computer and use it in GitHub Desktop.
Chia log analyser
#!/usr/bin/env ruby
# Scans Chia logfiles for gaps in challenge processing and gathers some stats.
# Resolution is 1 minute, log level needs to be set to INFO at least.
require 'date'
LOGDIR = '~/.chia/mainnet/log'
Dir.chdir(File.expand_path(LOGDIR))
logfiles = Dir.glob('debug.log.[0-9]').sort.reverse.append('debug.log')
start_time = nil
lines = 0
oldest_mtime = File.stat(logfiles[0]).mtime
timestamp = logfiles.length >= 2 ?
oldest_mtime - (File.stat(logfiles[1]).mtime - oldest_mtime) : # estimate
oldest_mtime - 12 * 60 * 60 # guess
last_good = nil
found_start = false
total_gap = 0
eligible_plots = proofs = challenges = 0
total_duration = max_duration = 0.0
min_duration = 99999.0
logfiles.each do |logfile|
warn "reading #{logfile}"
File.readlines(logfile).each do |line|
lines += 1
warn "processed #{lines} lines" if lines % 20000 == 0
parseline = line.match(
/^\d\d:\d\d.* (?<plots>\d+) plots were eligible for farming [0-9a-f]+... Found (?<proofs>\d+) proofs. Time: (?<duration>[0-9,.]+) s/
)
next unless parseline
eligible_plots += Integer(parseline[:plots])
proofs += Integer(parseline[:proofs])
dur = Float(parseline[:duration])
total_duration += dur
min_duration = dur if dur < min_duration
max_duration = dur if dur > max_duration
challenges += 1
while not line.start_with?(timestamp.strftime('%H:%M'))
timestamp += 60
end
if found_start
gap = timestamp - last_good - 60
total_gap += gap if gap > 1
puts "found gap of #{(gap / 60).round()} minutes (starting #{last_good + 60})" if gap >= 300
last_good = timestamp
else
start_time = timestamp
last_good = timestamp
found_start = true
end
end
end
timespan = timestamp - start_time
percentage = (total_gap / timespan * 100).round(2)
puts "scanned from #{start_time} to #{timestamp} " +
"(#{(timespan / 60).round()} minutes, #{(timespan / 60 / 60 / 24).round(2)} days)"
puts "#{challenges} challenges, #{eligible_plots} eligible plots, #{proofs} proofs, " +
"response time: min #{min_duration.round(3)} s, avg #{(total_duration / challenges).round(3)} s, max #{max_duration.round(3)} s"
puts "not farming for #{total_gap.round() / 60} minutes total (#{percentage}%) " +
(percentage > 1 ? '🤬' : '😎')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment