Skip to content

Instantly share code, notes, and snippets.

@Pistos
Created December 4, 2008 03:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pistos/31826 to your computer and use it in GitHub Desktop.
Save Pistos/31826 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'time'
#Dir.chdir("/project/prd/Builds/")
Dir.chdir( "/project/prd/Builds/nc/logs" )
class Capture < Regexp
def NamedMatches( string, names )
theMatches = match( string )
hsh = Hash.new
if theMatches
i = 1
names.map { |name|
hsh[ name ] = theMatches[ i ]
i += 1
}
hsh.rehash
end
hsh
end
end
commonMatches = [ "program","platform","component","operation" ]
orderMatches = [ "state","operation","program","platform","component","time","client" ]
re = Capture.new( '^={4,6}\s+(Start|End):\s+(\S+)\s+([^-\s]+)-([^-\s]+)-(\S+)\s+@\s+(.*?)(?:\s+on\s+(\S+)\s+)?\s*={4,8}' )
found = Hash.new
## Dir["{nc,nc2,sorcery}/logs/**/nightlybuild.out"].each {|path|
Dir[ "**/nightlybuild.out" ].each do |path|
found[ path ] = Array.new
File.open( path ) do |file|
file.grep( /^======\s+(?:Start|End)/ ) { |line|
found[ path ] << re.NamedMatches( line, orderMatches )
}
end
end
$, = ", "
puts commonMatches,"start","end","duration(sec)","julian","client"
found.each do |path,matches|
matches.each do |startMatch|
next if startMatch[ "state" ] != "Start"
matches.each do |endMatch|
matched = endMatch[ "state" ] == "End"
next if not matched
commonMatches.each do |k|
matched &= startMatch[ k ] == endMatch[ k ]
end
if matched
startTime = Time.parse( startMatch[ "time" ] )
endTime = Time.parse( endMatch[ "time" ] )
puts commonMatches.map{ |k| startMatch[ k ] }, startTime, endTime, endTime-startTime, path.split( '/' )[ -3 ], startMatch[ "client" ]
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment