Last active
October 5, 2015 06:48
-
-
Save ytoshima/2766729 to your computer and use it in GitHub Desktop.
misc snippets
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 collection.JavaConversions._ | |
import java.lang.management._ | |
val MB = (1024*1024).toFloat | |
def b2mb(bval: Long): Float = bval / MB | |
def mpoolSum(mp: MemoryPoolMXBean) = "%s: use %.2f comm %.2f max %.2f".format(mp.getName, b2mb(mp.getUsage.getUsed), b2mb(mp.getUsage.getCommitted), b2mb(mp.getUsage.getMax)) | |
def minfo = ManagementFactory.getMemoryPoolMXBeans.filter(_.getType == MemoryType.HEAP).map(mpoolSum).mkString("\n") | |
def toucm(mp: MemoryPoolMXBean) = { | |
val u = mp.getUsage | |
(u.getUsed, u.getCommitted, u.getMax) | |
} | |
def mtot0 = ManagementFactory.getMemoryPoolMXBeans.filter(_.getType == MemoryType.HEAP).map(toucm).reduceLeft((s,p) => (s._1+p._1, s._2+p._2, s._3+p._3)) | |
def lt2ft3(a: Long, b: Long, c:Long) = (b2mb(a), b2mb(b), b2mb(c)) | |
def mtot0f = { | |
val cv = mtot0 | |
lt2ft3(cv._1, cv._2, cv._3) | |
} | |
def mtot = "tot: use %.2f comm %.2f max %.2f".format(mtot0f._1, mtot0f._2, mtot0f._3) | |
println(mtot) |
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 scala.io._ | |
def parseFile(path: String) { | |
val tms: Seq[Double] = (for (l <- Source.fromFile(path).getLines.filter(_.contains("ParNew:")); | |
val t = l.split(Array(' ', '\t'))(5)) yield { | |
t.toDouble*1000 | |
}).toSeq | |
val avg = tms.sum/tms.size | |
println("size: " + tms.size) | |
println("sum: " + tms.sum) | |
println("max: " + tms.max + " min: " + tms.min) | |
println("avg: " + avg) | |
val sigma = scala.Math.sqrt((tms.map(avg - _).map(x=>x*x).sum) / tms.size) | |
println("sigma: " + sigma) | |
} | |
for (path <- args) { | |
parseFile(path) | |
} |
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 scala.io._ | |
def dovmsavg(path: String) { | |
val ptn = """^[ 0-9]+$""".r | |
val mat = (for (l <- Source.fromFile(path).getLines.flatMap(ptn.findFirstIn(_))) yield { | |
l.split(' ').filter(_.length > 0).toList.map(_.toDouble) | |
}).toList | |
val nls : Double = mat.size | |
val base = mat.head.map(x=>0.0) | |
val rx = mat.foldLeft(base){(b:List[Double], e:List[Double]) => | |
(for (i <- 0 until b.size) yield { b(i) + e(i)/nls }).toList | |
} | |
val rs = rx.map("%7.2f".format(_)).mkString(" ") | |
println(rs) | |
} | |
for (path <- args) { | |
dovmsavg(path) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment