fluent-gcprofiler 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 54256376aa0f68c1b4df565c73ad461232c25832
4
+ data.tar.gz: 09e64cbacb04d71a5c1dbcc295b35aeb426f7029
5
+ SHA512:
6
+ metadata.gz: 77b54d0708838c46085cb0d83e6d04374b582fb30527067385afd147618bb1904481e45304f2e190d50e8d45ea4a7e3ca82366a2d74632f3c7a16031bbff83cf
7
+ data.tar.gz: cbe4b658d17766949dd61a1d046133781cb1ec991ae5976135f370c0cd2a9adee6ad74035030fe920a93bffb8dc2db6e1ff2eab4e6d7fd6ebc9aa8a4146507c3
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ test.txt
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - 2.1
@@ -0,0 +1,3 @@
1
+ # 0.0.1 (2014/08/1
2
+
3
+ First version
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+ gem 'fluentd'
5
+ gem 'pry'
6
+ gem 'pry-nav'
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Naotoshi Seo
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,71 @@
1
+ # fluent-gcprofiler
2
+
3
+ Using fluent-gcprofiler, you can start and stop [GC::Profiler](http://docs.ruby-lang.org/ja/2.1.0/class/GC=3a=3aProfiler.html) dynamically from outside of fluentd without any configuration changes.
4
+
5
+ ## Installation
6
+
7
+ ```
8
+ $ fluent-gem install fluent-gcprofiler
9
+ ```
10
+
11
+ ## Prerequisite
12
+
13
+ `in_debug_agent` plugin is required to be enabled.
14
+
15
+ ```
16
+ <source>
17
+ type debug_agent
18
+ </source>
19
+ ```
20
+
21
+ GC::Profiler is a ruby built-in profiler, you do not need to install another gem.
22
+
23
+ ## Usage
24
+
25
+ Start
26
+
27
+ ```
28
+ $ fluent-gcprofiler start
29
+ ```
30
+
31
+ Stop and write a profiling result.
32
+
33
+ ```
34
+ $ fluent-gcprofiler stop -o /tmp/fluent-gcprofiler.txt
35
+ ```
36
+
37
+ ## Options
38
+
39
+ |parameter|description|default|
40
+ |---|---|---|
41
+ |-h, --host HOST|fluent host|127.0.0.1|
42
+ |-p, --port PORT|debug_agent|24230|
43
+ |-u, --unix PATH|use unix socket instead of tcp||
44
+ |-o, --output PATH|output file|/tmp/fluent-gcprofiler.txt|
45
+
46
+ ## Sample Output
47
+
48
+ `/tmp/fluent-gcprofiler.txt` as default:
49
+
50
+ ```
51
+ GC 21 invokes.
52
+ Index Invoke Time(sec) Use Size(byte) Total Size(byte) Total Object GC Time(ms)
53
+ 1 0.452 722640 1668720 83436 5.05216200000002046977
54
+ 2 0.458 722600 1668720 83436 3.76476800000001832203
55
+ ```
56
+
57
+ ## ChangeLog
58
+
59
+ See [CHANGELOG.md](./CHANGELOG.md)
60
+
61
+ ## Contributing
62
+
63
+ 1. Fork it ( http://github.com/sonots/fluent-gcprofiler/fork )
64
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
65
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
66
+ 4. Push to the branch (`git push origin my-new-feature`)
67
+ 5. Create new Pull Request
68
+
69
+ ## Copyright
70
+
71
+ See [LICENSE.txt](./LICENSE.txt)
@@ -0,0 +1,14 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rspec/core'
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new(:spec) do |spec|
6
+ spec.pattern = FileList['spec/**/*_spec.rb']
7
+ end
8
+ task :default => :spec
9
+
10
+ desc 'Open an irb session preloaded with the gem library'
11
+ task :console do
12
+ sh 'irb -rubygems -I lib'
13
+ end
14
+ task :c => :console
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems' unless defined?(gem)
4
+ here = File.dirname(__FILE__)
5
+ $LOAD_PATH << File.expand_path(File.join(here, '..', 'lib'))
6
+ require 'fluent/gcprofiler'
7
+ Fluent::Gcprofiler.new.run
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "fluent-gcprofiler"
7
+ spec.version = "0.0.1"
8
+ spec.authors = ["Naotoshi Seo"]
9
+ spec.email = ["sonots@gmail.com"]
10
+ spec.summary = %q{Tools for start/stop GC::Profiler dynamically from outside of fluentd}
11
+ spec.description = spec.summary
12
+ spec.homepage = "https://github.com/sonots/fluent-gcprofiler"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.5"
21
+ spec.add_development_dependency "rake"
22
+ spec.add_development_dependency "rspec"
23
+ end
@@ -0,0 +1,98 @@
1
+ require 'optparse'
2
+ require 'drb/drb'
3
+
4
+ module Fluent
5
+ class Gcprofiler
6
+ def parse_options(argv = ARGV)
7
+ op = OptionParser.new
8
+ op.banner += ' <start/stop> [output_file]'
9
+
10
+ (class<<self;self;end).module_eval do
11
+ define_method(:usage) do |msg|
12
+ puts op.to_s
13
+ puts "error: #{msg}" if msg
14
+ exit 1
15
+ end
16
+ end
17
+
18
+ opts = {
19
+ host: '127.0.0.1',
20
+ port: 24230,
21
+ unix: nil,
22
+ command: nil, # start or stop or gc
23
+ output: '/tmp/fluent-gcprofiler.txt',
24
+ }
25
+
26
+ op.on('-h', '--host HOST', "fluent host (default: #{opts[:host]})") {|v|
27
+ opts[:host] = v
28
+ }
29
+
30
+ op.on('-p', '--port PORT', "debug_agent tcp port (default: #{opts[:host]})", Integer) {|v|
31
+ opts[:port] = v
32
+ }
33
+
34
+ op.on('-u', '--unix PATH', "use unix socket instead of tcp") {|v|
35
+ opts[:unix] = v
36
+ }
37
+
38
+ op.on('-o', '--output PATH', "output path (default: #{opts[:output]})") {|v|
39
+ opts[:output] = v
40
+ }
41
+
42
+ op.parse!(argv)
43
+
44
+ opts[:command] = argv.shift
45
+ unless %w[start stop gc].include?(opts[:command])
46
+ raise OptionParser::InvalidOption.new("`start` or `stop` or `gc` must be specified as the 1st argument")
47
+ end
48
+
49
+ opts
50
+ end
51
+
52
+ def run
53
+ begin
54
+ opts = parse_options
55
+ rescue OptionParser::InvalidOption => e
56
+ usage e.message
57
+ end
58
+
59
+ unless opts[:unix].nil?
60
+ uri = "drbunix:#{opts[:unix]}"
61
+ else
62
+ uri = "druby://#{opts[:host]}:#{opts[:port]}"
63
+ end
64
+
65
+ $remote_engine = DRb::DRbObject.new_with_uri(uri)
66
+
67
+ case opts[:command]
68
+ when 'start'
69
+ remote_code = <<-CODE
70
+ GC::Profiler.enable
71
+ CODE
72
+ when 'stop'
73
+ remote_code = <<-"CODE"
74
+ File.open('#{opts[:output]}', 'w') {|f|
75
+ GC::Profiler.report(f)
76
+ }
77
+ GC::Profiler.disable
78
+ GC::Profiler.clear
79
+ CODE
80
+ when 'gc' # for debug
81
+ remote_code = <<-"CODE"
82
+ GC.start
83
+ CODE
84
+ end
85
+
86
+ $remote_engine.method_missing(:instance_eval, remote_code)
87
+
88
+ case opts[:command]
89
+ when 'start'
90
+ $stdout.puts 'fluent-gcprofiler: started'
91
+ when 'stop'
92
+ $stdout.puts "fluent-gcprofiler: outputs to #{opts[:output]}"
93
+ when 'gc'
94
+ $stdout.puts 'fluent-gcprofiler: run GC.start remotely'
95
+ end
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,8 @@
1
+ <source>
2
+ type debug_agent
3
+ </source>
4
+
5
+ # just as a sample to profile
6
+ <source>
7
+ type forward
8
+ </source>
@@ -0,0 +1,38 @@
1
+ require 'json'
2
+ require 'spec_helper'
3
+ require 'fluent/gcprofiler'
4
+
5
+ describe Fluent::Gcprofiler do
6
+ CONFIG_PATH = File.join(File.dirname(__FILE__), 'fluent.conf')
7
+ BIN_DIR = File.join(ROOT, 'bin')
8
+ OUTPUT_FILE = File.join(File.dirname(__FILE__), 'test.txt')
9
+
10
+ context '#parse_options' do
11
+ it 'incorrect subcommand' do
12
+ expect { Fluent::Gcprofiler.new.parse_options(['foo']) }.to raise_error(OptionParser::InvalidOption)
13
+ end
14
+ end
15
+
16
+ context 'profiling' do
17
+ before :all do
18
+ @fluentd_pid = spawn('fluentd', '-c', CONFIG_PATH, out: '/dev/null')
19
+ sleep 2
20
+
21
+ system("#{File.join(BIN_DIR, 'fluent-gcprofiler')} start")
22
+
23
+ system("#{File.join(BIN_DIR, 'fluent-gcprofiler')} gc")
24
+
25
+ system("#{File.join(BIN_DIR, 'fluent-gcprofiler')} stop -o #{OUTPUT_FILE}")
26
+ sleep 1
27
+ end
28
+
29
+ after :all do
30
+ Process.kill(:TERM, @fluentd_pid)
31
+ Process.waitall
32
+ end
33
+
34
+ it 'should output' do
35
+ expect(File.size?(OUTPUT_FILE)).to be_truthy
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,2 @@
1
+ ROOT = File.expand_path('../../', __FILE__)
2
+ $LOAD_PATH.unshift File.join(ROOT, 'lib')
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-gcprofiler
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Naotoshi Seo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Tools for start/stop GC::Profiler dynamically from outside of fluentd
56
+ email:
57
+ - sonots@gmail.com
58
+ executables:
59
+ - fluent-gcprofiler
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".rspec"
65
+ - ".travis.yml"
66
+ - CHANGELOG.md
67
+ - Gemfile
68
+ - LICENSE.txt
69
+ - README.md
70
+ - Rakefile
71
+ - bin/fluent-gcprofiler
72
+ - fluent-gcprofiler.gemspec
73
+ - lib/fluent/gcprofiler.rb
74
+ - spec/fluent-gcprofiler/fluent.conf
75
+ - spec/fluent-gcprofiler/gcprofiler_spec.rb
76
+ - spec/spec_helper.rb
77
+ homepage: https://github.com/sonots/fluent-gcprofiler
78
+ licenses:
79
+ - MIT
80
+ metadata: {}
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 2.2.0
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: Tools for start/stop GC::Profiler dynamically from outside of fluentd
101
+ test_files:
102
+ - spec/fluent-gcprofiler/fluent.conf
103
+ - spec/fluent-gcprofiler/gcprofiler_spec.rb
104
+ - spec/spec_helper.rb