Created
December 9, 2013 18:38
-
-
Save ykubota/7878034 to your computer and use it in GitHub Desktop.
ClassHistrogram集計用クラス。
クラスヒストグラムを1回以上出力させたログを読み込ませると、[クラス名][クラスヒストグラムインデックス] = [ランク, インスタンス, バイト数] となる二次元配列を取得する。
This file contains 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
def static calc(filename){ | |
def sheet = [:]; | |
def h=[:]; | |
def time = 0; | |
def seek = false | |
// ファイル読み込み | |
new File(filename).eachLine { | |
// 正規表現 | |
if (it ==~ /^num\s+#instances\s+#bytes\s+class\sname/){ | |
// Start of ClassHistogram | |
h=[:];seek=true | |
} else if(it ==~ /^Total\s+(\d+)\s+(\d+)/) { | |
// End of ClassHistogram | |
// マップイテレータ | |
h.each { klass, value -> | |
// 多重仮想 | |
if (!sheet.containsKey(klass)) { | |
// 変数を key にする場合は()で括る | |
sheet.put(klass,[(time):value]) | |
} else { | |
sheet[klass][time] = value | |
} | |
} | |
seek=false;time++ | |
} else if (seek) { | |
// 正規表現 + Matcher | |
(it =~ /^\s*(\d+):\s+(\d+)\s+(\d+)\s+([a-zA-Z\[\];\.\$\d\<\>].*$)/).each{ m0,m1,m2,m3,m4-> | |
def _rank=m1.toInteger();_ | |
def _instance=m2.toInteger(); | |
def _byte=m3.toInteger(); | |
if (!h.containsKey(m4)){ | |
h[m4] = [_rank, _instance, _byte] | |
}else{ | |
h[m4] = [h[m4][0], h[m4][1]+_instance, h[m4][2]+_byte] | |
} | |
} | |
} | |
} | |
// 穴埋め | |
sheet.each{ klass, histo -> | |
0.upto(time){ | |
if (!histo.containsKey(it)) sheet[klass][it] = [0,0,0] | |
} | |
} | |
} |
This file contains 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
% #usage | |
% groovyc ClassHistrogram.groovy | |
% groovysh | |
Groovy Shell (2.2.1, JVM: 1.7.0_45) | |
Type 'help' or '\h' for help. | |
------------------------------------------------------------------------------------------------------------------- | |
groovy:000> import static ClassHistrogram.* | |
===> [import static ClassHistrogram.*] | |
groovy:000> ch = calc("*.log") | |
groovy:000> ch[クラス名][クラスヒストグラムID]=[rank,instance,byte] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment