Created
April 24, 2012 10:59
-
-
Save ytoshima/2478777 to your computer and use it in GitHub Desktop.
A filter for pmap putout
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
import System.Environment (getArgs) | |
import Text.Regex.Posix | |
import Numeric | |
type Vaddr = Integer | |
data MemRec = MemRec { | |
start :: Vaddr | |
, end :: Vaddr | |
, desc :: String | |
} | |
instance Show MemRec where | |
show rec = "0x" ++ (showHex $ start rec) "" ++ | |
" 0x" ++ (showHex $ end rec) "" ++ " " ++ | |
show ((end rec - start rec) `div` 1024) ++ "k " ++ | |
desc rec | |
str2mr str = case str =~ "^([0-9a-f]{8,16})-([0-9a-f]{8,16}) (.*)$" :: | |
(String,String,String,[String]) of | |
(_,_,_,[ss, se, rem]) -> MemRec (fst . head . readHex $ ss) | |
(fst . head . readHex $ se) | |
rem | |
procMr :: MemRec -> Vaddr -> String | |
procMr current pend | |
| pend == 0 = show current | |
| pend == start current = show current | |
| otherwise = " << GAP " ++ show ((start current - pend) `div` 1024) ++ | |
"k >>\n" ++ show current | |
procLines (x:xs) pend = procMr x pend : procLines xs (end x) | |
procLines [] pend = [] | |
processFile path = do | |
lns <- readFile path | |
let ents = map str2mr . lines $ lns | |
let ls = procLines ents 0 | |
mapM putStrLn ls | |
-- mapM (putStrLn . show) ents | |
main = do | |
args <- getArgs | |
mapM processFile args |
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
object PmapFilter { | |
case class Mr(start: Long, end: Long, desc: String) { | |
override def toString = | |
"%08x-%08x %6dk %s".format(start, end, (end-start)/1024, desc) | |
} | |
def process(path: String) : String = { | |
import scala.io.Source | |
def procMr(current: Mr, prevEnd: Long) = prevEnd match { | |
case 0 => current.toString | |
case x if prevEnd == current.start => current.toString | |
case x => " << GAP %dk >>".format((current.start - prevEnd)/1024) + | |
"\n" + current.toString | |
} | |
def lstr(l: Seq[Mr], prevEnd: Long) : List[String] = l match { | |
case Nil => Nil | |
case x::xs => procMr(x, prevEnd) :: lstr(xs, x.end) | |
} | |
val MemLine = "([0-9a-f]{8,16})-([0-9a-f]{8,16}) (.*)".r | |
val lns = (for (line <- Source.fromFile(path).getLines) yield { | |
MemLine findFirstMatchIn line match { | |
case Some(m) => { | |
val MemLine(s, e, r) = line | |
Some(Mr(java.lang.Long.parseLong(s,16), | |
java.lang.Long.parseLong(e,16), r)) | |
} | |
case x => None | |
} | |
}).flatMap(s=>s).toList | |
// lns should be sorted.... | |
val lhead = lns.head | |
val ltail = lns.tail | |
lhead.toString + "\n" + lstr(ltail, lhead.end).mkString("\n") | |
} | |
def main(args: Array[String]) { | |
args.map((path: String) => println(process(path))) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment