Created
July 24, 2015 13:25
-
-
Save nicolasbrugneaux/d27d9bee40c39430f92d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- zcat 2015/07/0723*trace* | | |
-- grep -o "__id.*duration_..__" | | |
-- sed 's/__*\|id\|duration/ /g' | | |
-- sed 's/^ *\| *$//g' | | |
-- sed 's/ */ /' | | |
-- nawk '{ | |
-- max[$1] = !($1 in max) ? $2 : ($2 > max[$1]) ? $2 : max[$1] | |
-- } END { | |
-- for (i in max) | |
-- print i, max[i] | |
-- }' | | |
-- sed 's/..* //' | | |
-- sort -n | uniq -c | |
module Main where | |
import Control.Arrow | |
import Data.Function (on) | |
import Data.List (sortBy, groupBy) | |
import Data.Ord (comparing) | |
import Text.Regex.PCRE | |
groupLog :: [(Int, Int)] -> [(Int, [Int])] | |
groupLog logs = map (\l -> (fst . head $ l, map snd l)) $ groupBy ((==) `on` fst) $ sortBy (comparing fst) logs | |
removeDuplicate :: [(Int, [Int])] -> [(Int, Int)] | |
removeDuplicate = map (second maximum) | |
getInfo :: String -> (Int, Int) | |
getInfo line = (user, duration) | |
where | |
(user:duration:_) = concatMap (map read . (drop 1)) userAndDuration | |
userAndDuration = line =~ "__id_(.*?)__duration_(..)__" :: [[String]] | |
main :: IO () | |
main = do | |
logs <- readFile "./072300_trace-adv.log" | |
print (removeDuplicate . groupLog $ map getInfo $ (take 100) (lines logs)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment