jvm_gc_graph 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
4
+ .rvmrc*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in jvm_gc_graph.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,52 @@
1
+ ## JVM GC Graph
2
+
3
+ This gem creates a static HTML page that uses Google's
4
+ Interactive Charts to display JVM heap usage. In order of this to
5
+ work, you need to pass the following options to the JVM at startup:
6
+
7
+ -XX:-PrintGCTimeStamps -XX:-PrintGCDetails -Xloggc:<location of log file>
8
+
9
+ Here is an example:
10
+
11
+ java -XX:-PrintGCTimeStamps -XX:-PrintGCDetails -Xloggc:/path/to/memory_gc.log MyApp
12
+
13
+ ## Installation
14
+
15
+ gem install jvm_gc_graph
16
+
17
+ Does require the json_pure gem if on 1.8.7.
18
+
19
+ ## Usage
20
+
21
+ jvm_gc_graph -f /path/to/memory_gc.log -o /www/gc_log.html
22
+
23
+ 1. Looks at /path/to/memory_gc.log which contains the gc log
24
+ 2. Writes the result to the gc_log.html file.
25
+
26
+ See `jvm_gc_graph -h` for more options.
27
+
28
+ ## Other
29
+
30
+ For a much richer tool, try [GCViewer](http://www.tagtraum.com/gcviewer.html).
31
+
32
+ ## License
33
+
34
+ Copyright (c) 2010 Richard Outten
35
+
36
+ Permission is hereby granted, free of charge, to any person obtaining a copy
37
+ of this software and associated documentation files (the "Software"), to deal
38
+ in the Software without restriction, including without limitation the rights
39
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
40
+ copies of the Software, and to permit persons to whom the Software is
41
+ furnished to do so, subject to the following conditions:
42
+
43
+ The above copyright notice and this permission notice shall be included in
44
+ all copies or substantial portions of the Software.
45
+
46
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
47
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
48
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
49
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
50
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
51
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
52
+ THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
data/bin/jvm_gc_graph ADDED
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'jvm_gc_graph'
4
+ require 'optparse'
5
+
6
+ options = {}
7
+ op = OptionParser.new do |opts|
8
+ opts.banner = "Usage: #{File.basename($0)} [options]"
9
+
10
+ # Mandatory argument.
11
+ opts.on("-f", "--file FILE", "FILE containing the output from -Xloggc:filename") do |f|
12
+ options[:file] = f
13
+ end
14
+
15
+ opts.on("-o", "--output OUTPUT", "Generated HTML file.") do |o|
16
+ options[:output] = o
17
+ end
18
+
19
+ opts.on("-t", "--title TITLE", "The TITLE to add to the html page.") do |t|
20
+ options[:title] = t
21
+ end
22
+
23
+ opts.on('-h', "--help", "Display help message.") do |h|
24
+ options[:help] = true
25
+ end
26
+ end
27
+ op.parse!
28
+
29
+ if options[:help]
30
+ puts op
31
+ exit(0)
32
+ end
33
+
34
+ if options[:file].nil?
35
+ puts op
36
+ exit(1)
37
+ end
38
+
39
+ options[:output] = STDOUT if options[:output].nil?
40
+ options[:title] = "Memory Usage" if options[:title].nil?
41
+
42
+ JvmGcGraph::Runner.run(options)
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "jvm_gc_graph/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "jvm_gc_graph"
7
+ s.version = JvmGcGraph::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Richard Outten"]
10
+ s.email = ["outtenr@gmail.com"]
11
+ s.homepage = "https://github.com/outten45/jvm_gc_graph"
12
+ s.summary = %q{Creates an HTML output for graphing Java GC.}
13
+ s.description = %q{Creates an HTML output that uses Google Interactive Charts
14
+ to display the GC in graph format.}
15
+
16
+ s.rubyforge_project = "jvm_gc_graph"
17
+ s.add_dependency('json_pure', '~> 1.4.6') if RUBY_VERSION =~ /1.8/
18
+
19
+ s.files = `git ls-files`.split("\n")
20
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
+ s.executables = %w(jvm_gc_graph)
22
+ #`git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
23
+ s.require_paths = ["lib"]
24
+ end
@@ -0,0 +1,83 @@
1
+ require 'json'
2
+ require 'erb'
3
+
4
+ module JvmGcGraph
5
+
6
+ class Runner
7
+
8
+ class << self
9
+ def run(opts)
10
+ pml = JvmGcGraph::ParseMemoryLog.new(opts)
11
+ pml.json
12
+ html = output(pml)
13
+ if opts[:output].is_a?(IO)
14
+ opts[:output].puts html
15
+ else
16
+ File.open(opts[:output],'w') {|f| f.write(html)}
17
+ end
18
+ end
19
+
20
+ def output(parse_memory_log)
21
+ file = File.join(File.dirname(__FILE__),'templates','gc_chart.html.erb')
22
+ template = File.read(File.expand_path(file))
23
+ erb = ERB.new(template)
24
+ erb.result(parse_memory_log.get_binding)
25
+ end
26
+ end
27
+ end
28
+
29
+ class ParseMemoryLog
30
+
31
+ GC_REGEX = /^(([0-9]|\.)*):\s\[(GC\s([0-9]*)K->([0-9]*)K\(([0-9]*)K\)),\s(([0-9]|\.)*).*\]/
32
+ FULL_GC_REGEX = /^(([0-9]|\.)*):\s\[(Full GC\s([0-9]*)K->([0-9]*)K\(([0-9]*)K\)),\s(([0-9]|\.)*).*\]/
33
+ ANY_GC_REGEX = /^(([0-9]|\.)*):\s\[((Full )?GC\s([0-9]*)K->([0-9]*)K\(([0-9]*)K\)),\s(([0-9]|\.)*).*\]/
34
+
35
+ attr_accessor :lines, :start_time, :data, :gc_data
36
+
37
+ def initialize(opts)
38
+ File.open(opts[:file], "r") do |f|
39
+ @lines = f.readlines
40
+ end
41
+ if m = @lines.last.match(ANY_GC_REGEX)
42
+ @start_time = Time.now.to_i - m[0].to_f
43
+ end
44
+ @data = []
45
+ @gc_data = []
46
+ self.class.send(:define_method, :title) {opts[:title]}
47
+ end
48
+
49
+ def parse_lines
50
+ lines.each do |line|
51
+ if m = line.match(GC_REGEX)
52
+ add_gc_arrays(m)
53
+ elsif m = line.match(FULL_GC_REGEX)
54
+ # might want to do something different with Full GC
55
+ add_gc_arrays(m)
56
+ end
57
+ end
58
+ end
59
+
60
+ def add_gc_arrays(matches)
61
+ add_to_array(@data, matches[0].to_i,
62
+ [matches[4].to_f, nil,nil,
63
+ matches[5].to_f, nil,nil,
64
+ matches[6].to_f, nil,nil])
65
+ add_to_array(@gc_data, matches[0].to_i, [(matches[7].to_f*1000), nil,nil])
66
+ end
67
+
68
+ def add_to_array(data_values, time, values)
69
+ d = [((@start_time + time)*1000)]
70
+ data_values << (d + values)
71
+ end
72
+
73
+ def json
74
+ parse_lines
75
+ @data
76
+ end
77
+
78
+ def get_binding
79
+ binding
80
+ end
81
+ end
82
+
83
+ end
@@ -0,0 +1,3 @@
1
+ module JvmGcGraph
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,69 @@
1
+ <html>
2
+ <head>
3
+ <title><%= title %></title>
4
+ <script type='text/javascript' src='https://www.google.com/jsapi'></script>
5
+ <script type='text/javascript'>
6
+ google.load('visualization', '1', {'packages':['annotatedtimeline']});
7
+ google.setOnLoadCallback(drawChart);
8
+ var lineData = <%= data.to_json %>;
9
+ var gcLineData = <%= gc_data.to_json %>;
10
+
11
+ var generator = {
12
+ createData: function(data) {
13
+ var d = [];
14
+ for(var i=0; i < data.length; i++) {
15
+ var tt = [];
16
+ var ll = data[i];
17
+ var dt = new Date(ll.shift());
18
+ tt.push(dt);
19
+ for(var j=0; j < ll.length; j++) {
20
+ tt.push(ll[j]);
21
+ }
22
+ d.push(tt);
23
+ }
24
+ return d;
25
+ }
26
+ };
27
+ function drawChart() {
28
+ var d = generator.createData(lineData);
29
+ var data = new google.visualization.DataTable();
30
+ data.addColumn('date', 'Date');
31
+ data.addColumn('number', 'Pre');
32
+ data.addColumn('string', 'title1');
33
+ data.addColumn('string', 'text1');
34
+ data.addColumn('number', 'After');
35
+ data.addColumn('string', 'title2');
36
+ data.addColumn('string', 'text2');
37
+ data.addColumn('number', 'Total');
38
+ data.addColumn('string', 'title3');
39
+ data.addColumn('string', 'text3');
40
+ data.addRows(d);
41
+
42
+ var chart = new google.visualization.AnnotatedTimeLine(document.getElementById('chart_div'));
43
+ chart.draw(data, {displayAnnotations: true, dateFormat: 'HH:mm MMMM dd, yyyy'});
44
+
45
+ var d2 = generator.createData(gcLineData);
46
+ var data2 = new google.visualization.DataTable();
47
+ data2.addColumn('date', 'Date');
48
+ data2.addColumn('number', 'Time (umsec)');
49
+ data2.addColumn('string', 'title4');
50
+ data2.addColumn('string', 'text4');
51
+ data2.addRows(d2);
52
+
53
+ var chart2 = new google.visualization.AnnotatedTimeLine(document.getElementById('chart_gc_time_div'));
54
+ chart2.draw(data2, {displayAnnotations: true, dateFormat: 'HH:mm MMMM dd, yyyy'});
55
+
56
+ }
57
+ </script>
58
+ </head>
59
+
60
+ <body>
61
+ <h2><%= title %></h2>
62
+ <div id='chart_div' style='width: 900px; height: 500px;'></div>
63
+
64
+ <h2>Collection Time</h2>
65
+ <div id='chart_gc_time_div' style='width: 900px; height: 500px;'></div>
66
+
67
+ <h5>Generated: <%= Time.now %></h5>
68
+ </body>
69
+ </html>
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jvm_gc_graph
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Richard Outten
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-12-27 00:00:00 -05:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: |-
22
+ Creates an HTML output that uses Google Interactive Charts
23
+ to display the GC in graph format.
24
+ email:
25
+ - outtenr@gmail.com
26
+ executables:
27
+ - jvm_gc_graph
28
+ extensions: []
29
+
30
+ extra_rdoc_files: []
31
+
32
+ files:
33
+ - .gitignore
34
+ - Gemfile
35
+ - README.md
36
+ - Rakefile
37
+ - bin/jvm_gc_graph
38
+ - jvm_gc_graph.gemspec
39
+ - lib/jvm_gc_graph.rb
40
+ - lib/jvm_gc_graph/version.rb
41
+ - lib/templates/gc_chart.html.erb
42
+ has_rdoc: true
43
+ homepage: https://github.com/outten45/jvm_gc_graph
44
+ licenses: []
45
+
46
+ post_install_message:
47
+ rdoc_options: []
48
+
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ segments:
57
+ - 0
58
+ version: "0"
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ segments:
65
+ - 0
66
+ version: "0"
67
+ requirements: []
68
+
69
+ rubyforge_project: jvm_gc_graph
70
+ rubygems_version: 1.3.7
71
+ signing_key:
72
+ specification_version: 3
73
+ summary: Creates an HTML output for graphing Java GC.
74
+ test_files: []
75
+