Created
May 13, 2015 15:30
-
-
Save johnl/e7f586489c4a6e0a8fd0 to your computer and use it in GitHub Desktop.
script to parse Linux scsi command logs
This file contains hidden or 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
#!/usr/bin/ruby | |
# Parses linux scsi command logs | |
# http://www.seagate.com/staticfiles/support/disc/manuals/scsi/100293068a.pdf | |
# give this program itself as input to test | |
# DE AD BE EF == 3735928559 | |
# CA FE == 51966 | |
# CDB: Write(10): 2a 08 DE AD BE EF 00 CA FE 00 | |
block_size = 512 | |
STDIN.readlines.each do |line| | |
m = line.scan(/CDB: (.*)\(([0-9]+)\): (.*)/) | |
next if m.empty? | |
m.flatten! | |
opname = m[0] | |
opnum = m[1].to_i | |
bytes = m[2].split.collect { |b| b.to_i(16) }.pack('C*') | |
if (opname == 'Read' || opname == 'Write') && opnum == 10 | |
fields = bytes.unpack('CCNCnC') | |
flags = fields[1] | |
dpo = flags[4] | |
fua = flags[3] | |
fua_nv = flags[1] | |
offset = fields[2] * block_size | |
length = fields[4] * block_size | |
group = [fields[5][4], fields[5][3],fields[5][2],fields[5][1],fields[5][0]].join | |
puts "#{opname} (#{opnum}) offset:#{offset} length:#{length} dpo:#{dpo} fua:#{fua} fua_nv:#{fua_nv} group:#{group}" | |
elsif (opname == 'Synchronize Cache' && opnum == 10) | |
fields = bytes.unpack('CCNCnC') | |
flags = fields[1] | |
sync_nv = flags[2] | |
immed = flags[1] | |
offset = fields[2] * block_size | |
length = fields[4] * block_size | |
group = [fields[5][4], fields[5][3],fields[5][2],fields[5][1],fields[5][0]].join | |
# sync_nv: 0:sync to medium. 1: sync to non-volatile cache, or medium if no cache | |
# length: if 0, sync whole device | |
puts "#{opname} (#{opnum}) offset:#{offset} length:#{length} sync_nv:#{sync_nv} immed:#{immed} group:#{group}" | |
else | |
puts "Unknown op: #{line}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you for the great parser! It helped me to analyze SCSI commands.
And I added some lines to see Write(16) and Read(16).
By the way, what kind of license is applied for the code? Thanks!