splot 0.1.3 → 0.1.4
raw patch · 2 files changed
+12/−12 lines, 2 files
Files
- Tools/StatePlot.hs +11/−11
- splot.cabal +1/−1
Tools/StatePlot.hs view
@@ -43,8 +43,8 @@ diffToMillis t2 t1 = fromIntegral (truncate (1000000*d)) / 1000 where d = diffUTCTime (localTimeToUTC utc t2) (localTimeToUTC utc t1) -renderEvents :: Double -> Double -> [Event] -> Renderable ()-renderEvents bandHeight ticksIntervalMs es = Renderable {minsize = return (0,0), render = render'}+renderEvents :: Double -> Double -> [Event] -> (Event -> Event -> Ordering) -> Renderable ()+renderEvents bandHeight ticksIntervalMs es cmpTracks = Renderable {minsize = return (0,0), render = render'} where events = sortBy (comparing time) es minTime = time $ head events@@ -52,20 +52,17 @@ time2ms t = diffToMillis t minTime rangeMs = time2ms maxTime ticks = takeWhile (<rangeMs) $ iterate (+ticksIntervalMs) 0- tracks = sortBy (comparing (time . head)) . groupBy ((==) `on` track) . sortBy (comparing track) $ events+ tracks = sortBy (\as bs -> cmpTracks (head as) (head bs)) . groupBy ((==) `on` track) . sortBy (comparing track) $ events maybeM :: (Monad m) => (a -> m b) -> Maybe a -> m () maybeM f Nothing = return () maybeM f (Just x) = f x >> return () - bars track = execWriter $ evalStateT (mapM step (track++[Event maxTime undefined End])) Nothing+ bars track = execWriter . (`evalStateT` Nothing) . mapM_ step $ track++[Event maxTime undefined End] where- step (Event t _ (Begin c)) = do- get >>= maybeM (\(t0,c0) -> tell [(time2ms t0, time2ms t, c0)])- put (Just (t,c))- step (Event t _ End ) = do+ step (Event t _ edge) = do get >>= maybeM (\(t0,c0) -> tell [(time2ms t0, time2ms t, c0)])- put Nothing+ put (case edge of { Begin c -> Just (t,c); End -> Nothing }) render' (w,h) = do let ms2x ms = 10 + ms / rangeMs * (w - 10)@@ -101,7 +98,7 @@ showHelp = mapM_ putStrLn [ "splot - a tool for visualizing the lifecycle of many concurrent multi-stage processes. See http://www.haskell.org/haskellwiki/Splot",- "Usage: splot [-o PNGFILE] [-w WIDTH] [-h HEIGHT] [-bh BARHEIGHT] [-tf TIMEFORMAT]",+ "Usage: splot [-o PNGFILE] [-w WIDTH] [-h HEIGHT] [-bh BARHEIGHT] [-tf TIMEFORMAT] [-sort SORT]", " [-tickInterval TICKINTERVAL]", " -o PNGFILE - filename to which the output will be written in PNG format.", " If omitted, it will be shown in a window.",@@ -111,6 +108,8 @@ " -tf - time format, as in http://linux.die.net/man/3/strptime but with ", " fractional seconds supported via %OS - will parse 12.4039 or 12,4039", " -tickInterval - ticks on the X axis will be this often (in millis).",+ " -sort SORT - sort tracks by SORT, where: 'time' - sort by time of first event, ",+ " 'name' - sort by track name", "", "Input is read from stdin. Example input (speaks for itself):", "2010-10-21 16:45:09,431 >foo green",@@ -138,7 +137,8 @@ let outPNG = getArg "o" "" args input <- B.getContents let events = parse parseTime `map` B.lines input- let pic = renderEvents bandHeight ticksIntervalMs events+ let cmpTracks = case getArg "sort" "time" args of { "time" -> comparing time ; "name" -> comparing track }+ let pic = renderEvents bandHeight ticksIntervalMs events cmpTracks case outPNG of "" -> renderableToWindow pic w h f -> const () `fmap` renderableToPNGFile pic w h outPNG
splot.cabal view
@@ -1,5 +1,5 @@ Name: splot-Version: 0.1.3+Version: 0.1.4 License: BSD3 License-file: LICENSE Copyright: Eugene Kirpichov, 2010