mudgangster

Tiny, scriptable MUD client
Log | Files | Refs | README

ninja_timeline.lua (1256B)


      1 local graph_width = 85
      2 local filename_length = 16
      3 
      4 local log = io.open( "build/.ninja_log", "r" ):read( "*all" )
      5 
      6 local edges = { }
      7 
      8 for line in log:gmatch( "([^\n]+)" ) do
      9 	local start, finish, target = line:match( "^(%d+)%s+(%d+)%s+%d+%s+(%S+)" )
     10 	if start then
     11 		table.insert( edges, {
     12 			start = tonumber( start ),
     13 			dt = tonumber( finish ) - tonumber( start ),
     14 			target = target:match( "[^/]+$" ),
     15 		} )
     16 	end
     17 end
     18 
     19 table.sort( edges, function( a, b )
     20 	return a.start < b.start
     21 end )
     22 
     23 local function truncate( str, len )
     24 	str = str:gsub( "%.pic", "" ):gsub( "%.obj", "" ):gsub( "%.o", "" )
     25 	return str:sub( 1, len ) .. string.rep( " ", len - str:len() )
     26 end
     27 
     28 local total_duration = edges[ #edges ].start + edges[ #edges ].dt
     29 
     30 for i, e in ipairs( edges ) do
     31 	local pre = math.floor( graph_width * e.start / total_duration )
     32 	local width = math.max( 0, math.floor( graph_width * e.dt / total_duration - 2 ) )
     33 
     34 	local target = truncate( e.target, filename_length )
     35 	local spacing = string.rep( " ", pre )
     36 
     37 	if i % 2 == 0 then
     38 		spacing = spacing:gsub( "   ", " - " )
     39 	end
     40 
     41 	print( ( "%s %s[%s] %.2fs" ):format( target, spacing, string.rep( ">", width ), e.dt / 1000 ) )
     42 end
     43 
     44 print()
     45 print( ( "Total build time: %.2fs" ):format( total_duration / 1000 ) )