Last active
October 18, 2023 02:19
-
-
Save dixsonhuie/454cdd3d41e48d633e38768d75dbef5b to your computer and use it in GitHub Desktop.
scala
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
package gclogreader | |
import scala.io.Source | |
import scala.util.matching.Regex | |
object GCAdaptive extends App { | |
val filename = raw"C:\Users\Dixson\gc_pid16200.log" | |
def process_young(s: String): Unit = { | |
// (?s) - DOTALL, (?m) - MULTILINE | |
val youngR = raw"(?s)(?m)^(\d*\.\d*): \[GC pause [ \w\(\)]* \(young\).+?, (\d*\.\d*) secs\]$$".r | |
val m = youngR.findAllIn(s) | |
while (m.hasNext) { | |
val young = m.next | |
val process_time = m.group(1) | |
val gc_time = m.group(2) | |
println(s"GC pause (young), $process_time, $gc_time") | |
} | |
} | |
def process_mixed(s: String): Unit = { | |
// (?s) - DOTALL, (?m) - MULTILINE | |
val mixedR: Regex = raw"(?s)(?m)^(\d*\.\d*): \[GC pause \(mixed\).+?, (\d*\.\d*) secs\]$$".r | |
val m = mixedR.findAllIn(s) | |
while (m.hasNext) { | |
val young = m.next | |
val process_time = m.group(1) | |
val gc_time = m.group(2) | |
println(s"GC pause (mixed), $process_time, $gc_time") | |
} | |
} | |
def process_remark_cleanup_fullgc(s: String): Unit = { | |
var (gc_type, process_time, gc_time, gc_size_before, gc_size_after, total_size) = ("", "", "", "", "", "") | |
// not quite raw - need $$ to escape String interpolation | |
val remarkR = raw"^(\d*\.\d*): \[GC remark \d*\.\d*: .+, (\d*\.\d*) secs\]$$".r() | |
val cleanupR = raw"^(\d*\.\d*): \[GC cleanup .+, (\d*\.\d*) secs\]$$".r() | |
val fullgcR = raw"^(\d*\.\d*): \[Full GC.+ (\d+[MG])->(\d*[MG])\((\d*[MG])\), (\d*\.\d*) secs\]$$".r() | |
// match regex | |
val m: Option[String] = s match { | |
case remarkR(a, b) => gc_type = "GC remark" | |
process_time = a | |
gc_time = b | |
Some(s) | |
case cleanupR(a, b) => gc_type = "GC cleanup" | |
process_time = a | |
gc_time = b | |
Some(s) | |
case fullgcR(proc_t, before, after, size, gc_t) => | |
gc_type = "Full GC" | |
process_time = proc_t | |
gc_size_before = before | |
gc_size_after = after | |
total_size = size | |
gc_time = gc_t | |
Some(s) | |
case _ => None | |
} | |
if( m.isDefined ) { | |
if( gc_size_after != "") | |
println(s"$gc_type, $process_time, $gc_time, $gc_size_before, $gc_size_after, $total_size") | |
else | |
println(s"$gc_type, $process_time, $gc_time") | |
println(m.get) | |
} | |
} | |
for (line <- Source.fromFile(filename).getLines) { | |
//println(line) | |
line match { | |
case l if l.startsWith(" ") == false => process_remark_cleanup_fullgc(line) | |
case _ => | |
} | |
} | |
// requires multi-line processing | |
val text : String = Source.fromFile(filename).getLines.toList.mkString(scala.util.Properties.lineSeparator) | |
process_young(text) | |
process_mixed(text) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment