GCログの整形 その2
GCログのタイムスタンプ(JavaVMを起動してからの秒数)をシステム時刻に整形するスクリプト。
ファイルの最終更新時刻と最終エントリのタイムスタンプを突き合わせる発想は凄い。
http://www.theserverlabs.com/blog/2010/05/26/human-readable-jvm-gc-timestamps/
以下転載
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | #!/usr/bin/env python import sys, os, datetime # true if string is a positive float def validSeconds(str_sec): try : return 0 < float (str_sec) except ValueError: return False # show usage if len (sys.argv) < 2 : print "Usage: %s <gc.log>" % (sys.argv[ 0 ]) sys.exit( 1 ) file_str = sys.argv[ 1 ] lastmod_date = datetime.datetime.fromtimestamp(os.path.getmtime(file_str)) file = open (file_str, 'r' ) lines = file .readlines() file .close() # get last elapsed time for line in reversed (lines): parts = line.split( ':' ) if validSeconds(parts[ 0 ]): break # calculate start time start_date = lastmod_date - datetime.timedelta(seconds = float (parts[ 0 ])) # print file prepending human readable time where appropiate for line in lines: parts = line.split( ':' ) if not validSeconds(parts[ 0 ]): print line.rstrip() continue line_date = start_date + datetime.timedelta(seconds = float (parts[ 0 ])) print "%s: %s" % (line_date.isoformat(), line.rstrip()) |
0 件のコメント:
コメントを投稿