-- -- adsl log processor - plots the ADSL SHOW CHANNEL output of Solwise EL715 ADSL modem. -- -- Description: This script plots the ADSL SHOW CHANNEL output. -- -- To run: I use lua5.1exe and type dofile("adslGD.lua") -- -- See: www.lua.org and http://lua-gd.luaforge.net/ for lua downloads -- -- unpack gd and copy lua5.1.exe and lua5.1.dll into lua-gd-2.0.33r2 -- -- dofile("adslGD.lua") -- Copyright: Doug Rice 2007 -- lua-GD: http://lua-gd.luaforge.net/manual.html#license.luagd -- http://www.lua.org/license.html -- -- log files are read from .\adslLogs -- plots are put into .\png directory -- -- -- -- telnetADLSthomsonLog.txt -- -------------------------------------------------- -- Sec 0.0 includes -- -------------------------------------------------- require "gd" -- -------------------------------------------------- -- Sec 1.0 Variables -- -------------------------------------------------- -- data files to be parsed -- -- Cut and paste output from dir /b *.log or ls 1 -- dataFilesStr = [==[ ]==] dataFilesA = {} local pat = "(%S+)%s+" cnt=1 for n1 in string.gmatch( dataFilesStr ,pat ) do --print( io.open( n1.."ddd" , "r" ) ) print( n1, #dataFilesA ) dataFilesA[ cnt ] = n1 cnt = cnt + 1 end dataFilesA = { --[==[ "adslCy.log", "adsl.log" ]==] "adslThomsonLog.txt" } dataFile = "adsl_f2f4_c1.log" gphA = {} timeStamp = "" downStr = "" upStr = "" -- -------------------------------------------------- -- Sec 1.1 Parse data to find the limits -- -------------------------------------------------- function firstPass( dataFile ) gphA["fname"]=dataFile gphA["dn"]={} gphA["up"]={} fname = dataFile:match( "(%w*).") print( fname ) -- fp = io.open( ".\\adslLogs\\" .. dataFile, "r+") fp = io.open( dataFile, "r+") if ( fp ) then else print("File Not Found: ".. dataFile .. "\n" ) return end instCnt = 0 trigger = false for line in fp:lines() do --[==[ ============================================ starting:Thu Jul 7 07:11:56 2011 ============================================ ]==] if line:match( "starting:" ) then timeStamp = line:match( "[^:]*:+(.+)$" ) end -- Bandwidth (Down/Up - kbit/s): 4544/444 if line:match( "Bandwidth " ) then downStr, upStr = line:match( "(%d*)\/(%d*)$" ) -- print( "speeds: ", downStr, upStr) end --[==[ ====== Tone : # Bits per tone 0 : 0 0 0 0 0 0 0 0 2 2 10 : 4 4 5 6 6 6 7 7 7 6 20 : 7 7 6 7 6 6 6 6 5 4 30 : 4 3 0 10 12 13 12 13 13 14 40 : 14 13 14 13 13 14 13 14 14 14 ]==] index = line:match("(%d*) :" ) if (index ) then -- print( "------" ) -- found string of values now put into array -- first value is index offset index=-1 for val in line:gmatch( "%s+:*(%d+)" ) do if index == -1 then index = val*1 else gphA[ "dn" ][ index ] = val -- print( index , val , gphA[ "dn" ][ index ]) index = index + 1 end end -- if index*1 == 510 then -- trigger=true -- end end -- ====plot============================================= if line:match( "^====plot====+" ) then -- print("trigger") trigger=true end if trigger then -- print( trigger ,"plotting ====================================================") -- print( "Upstream Bit Load :" ) dir = "dn" plotPass( dataFile , instCnt ) instCnt = instCnt + 1 index = -1 downStr = "" upStr = "" timeStamp = "" trigger = false end end fp:close() fname = dataFile:match( "([^.]*)") print( dataFile .. " \n" ) trigger=false end function plotPass( dataFile,inst ) fname = dataFile:match( "([^.]*)") xOff = 20 xScale = 2 yOff = 112 yOff2 = 15 yScale = 5 yMax = 10 im = gd.createTrueColor( (512+32) * xScale+4+xOff*2, yMax*yScale*2+yOff2*2) bg = im:colorAllocateAlpha(250, 250, 250 , 0) im:filledRectangle(0,0,(512+32) * xScale+4+xOff*2, yMax*yScale*2+yOff2*2, bg ) bg = im:colorAllocateAlpha(127, 127, 127 , 0) labelClr = im:colorAllocateAlpha(32, 32, 0 , 0) -- im:filledRectangle( 1,1,260,150, bg ) -- first allocated color defines the background. white = im:colorAllocate(255, 255, 255) black = im:colorAllocate(0, 0, 0) red = im:colorAllocate(255, 0, 0) yellow = im:colorAllocate(255, 255, 0) green = im:colorAllocate(0xb3, 0xb3, 0) green2 = im:colorAllocate(0xc3, 0xa3, 0) cyan = im:colorAllocate(0x66, 0x66, 0x00) blue = im:colorAllocate(0, 0, 255) mag = im:colorAllocate(255, 0, 255) gray = im:colorAllocateAlpha(255, 255, 0xCC, 64) gray2 = im:colorAllocateAlpha(0, 0, 0, 100) coloursA = { black,red,yellow,green, cyan,blue,mag,white,black,red,yellow,green, cyan,blue,mag,white } -- im:string(gd.FONT_LARGE, 10, 5, "dataFile: ".. fname .."_" .. inst .. ".png" .. " @ " .. timeStamp .. downStr , labelClr) -- --------------- -- plot grid -- --------------- print( "a_"..fname.."_" .. inst .. ".png" ) -- draw axis for down stream channels im:filledRectangle( 0*xScale+xOff , 0+yOff-(16*yScale) , 513*xScale+1+xOff , 0+yOff-(-1*yScale), gray ) im:rectangle( 0*xScale+xOff , 0+yOff-(16*yScale) , 513*xScale+1+xOff , 0+yOff-(-1*yScale), black ) for x = 0 , 512 , 16 do im:rectangle( x*xScale+xOff , 0+yOff+2 , x*xScale+1+xOff , 0+yOff+4, black ) end -- --------------- -- plot DownStream Bit Loads -- --------------- colour = cyan for x = 0 , 511 , 1 do if ( gphA[ "dn" ][x] ) then -- print( "debug", gphA[ "dn" ][x], yScale ) yMax = gphA[ "dn" ][x]*yScale if x == 32 then colour = green end if x == 256 then colour = green2 end im:filledRectangle( x*xScale+xOff , 0+yOff-yMax , x*xScale+1+xOff , 0+yOff, colour ) end end -- --------------- -- plot Y Axis -- --------------- for y = 0 , 12 , 4 do im:line( xOff+4 , 0+yOff-y*yScale , xOff+512*xScale , 0+yOff-y*yScale, gray2 ) -- im:line( 514 * xScale + xOff+4 , 0+yOff-y*yScale , 514 * xScale +xOff+32*xScale , 0+yOff-y*yScale, gray2 ) im:string(gd.FONT_TINY, 0*xScale+1, 0+yOff-y*yScale-2 , " " .. y , labelClr) end im:string(gd.FONT_LARGE, 10, 5, "dataFile: ".. fname .."_" .. inst .. ".png" .. " @ " .. timeStamp , labelClr) im:string(gd.FONT_TINY, xOff +8 , 0+yOff-(16*yScale) -10 , "plots ofThomson TG585 v8 modem 'xdsl debug bitloadinginfo' output" , labelClr) im:string(gd.FONT_TINY, (128 -8 )*xScale+xOff , 0+yOff + 7 , "Upstream / Downstream Bit Load: " ..upStr .. " / " .. downStr , labelClr) -- --------------- -- create .png file -- --------------- im:png("./png/"..fname.."_" .. inst .. ".png") im:png("./png/"..fname.."_latest.png") end -- --------------- -- Main Program -- --------------- cnt=1 while dataFilesA[cnt] do -- --------------- -- Work Through array of file names -- --------------- dataFile = dataFilesA[cnt] firstPass( dataFile ) cnt = cnt + 1 end