Pistos (owner)

Revisions

gist: 31826 Download_button fork
public
Public Clone URL: git://gist.github.com/31826.git
Embed All Files: show embed
jaykul-parse.rb #
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
60
61
62
63
64
65
#!/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