fluent-stackprof 0.1.0

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: 82a160fc8283e42ba170c8fcb9e725c74ec77167
4
+ data.tar.gz: 9239a270a426601eb6f3c6ebd6ae9317ade37a93
5
+ SHA512:
6
+ metadata.gz: f5d8c80c23e3f0cd21a346136e8e2ce736ea9215525a1092341808502f6b004c18ec517d8bb213e52952858475a759f4d2db26134ed4a261decccd9104c2bfc4
7
+ data.tar.gz: 773919b0e9691996c339e11d1e3cf975db69c18807ae3c8d4017c256e1432a9218832bfe098daaff5420c98a704765532d6e617d844af38e60570ba9c422f645
@@ -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,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1
@@ -0,0 +1,3 @@
1
+ # 0.1.0 (2014/08/03)
2
+
3
+ First version
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+ gem 'fluentd'
5
+ gem 'stackprof'
6
+ gem 'pry'
7
+ 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,77 @@
1
+ # Fluent::Stackprof
2
+
3
+ Using fluent-stackprof, you can start and stop [stackprof](https://github.com/tmm1/stackprof) dynamically from outside of fluentd without any configuration changes.
4
+
5
+ ## Installation
6
+
7
+ ```
8
+ $ fluent-gem install fluent-stackprof
9
+ ```
10
+
11
+
12
+ ## Prerequisite
13
+
14
+ Ruby 2.1 is required to use `stackprof`.
15
+
16
+ `in_debug_agent` plugin is required to be enabled.
17
+
18
+ ```
19
+ <source>
20
+ type debug_agent
21
+ </source>
22
+ ```
23
+
24
+ And, `stackprof` gem is required.
25
+
26
+ ```
27
+ $ fluent-gem install stackprof
28
+ ```
29
+
30
+ ## Usage
31
+
32
+ Start
33
+
34
+ ```
35
+ $ fluent-stackprof start
36
+ ```
37
+
38
+ Stop and write a profiling result.
39
+
40
+ ```
41
+ $ fluent-stackprof stop -o /tmp/fluent-stackprof.dump
42
+ ```
43
+
44
+ Then, use `stackprof` to analyze the resulting file:
45
+
46
+ ```
47
+ $ stackprof /tmp/fluent-stackprof.dump --text --limit 1
48
+ ```
49
+
50
+ See [stackprof#run](https://github.com/tmm1/stackprof#run) for more details.
51
+ The author's blog article is also helpful [Ruby 2.1: Profiling Ruby by @tmm1](http://tmm1.net/ruby21-profiling).
52
+
53
+ ## Options
54
+
55
+ |parameter|description|default|
56
+ |---|---|---|
57
+ |-h, --host HOST|fluent host|127.0.0.1|
58
+ |-p, --port PORT|debug_agent|24230|
59
+ |-u, --unix PATH|use unix socket instead of tcp||
60
+ |-o, --output PATH|output file|/tmp/fluent-stackprof.txt|
61
+ |-m, --mode MODE|stackprof measure mode. See [stackprof#sampling](https://github.com/tmm1/stackprof#sampling)|cpu|
62
+
63
+ ## ChangeLog
64
+
65
+ See [CHANGELOG.md](./CHANGELOG.md)
66
+
67
+ ## Contributing
68
+
69
+ 1. Fork it ( http://github.com/sonots/fluent-stackprof/fork )
70
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
71
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
72
+ 4. Push to the branch (`git push origin my-new-feature`)
73
+ 5. Create new Pull Request
74
+
75
+ ## Copyright
76
+
77
+ 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/stackprof'
7
+ Fluent::Stackprof.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-stackprof"
7
+ spec.version = "0.1.0"
8
+ spec.authors = ["Naotoshi Seo"]
9
+ spec.email = ["sonots@gmail.com"]
10
+ spec.summary = %q{Tools for start/stop stackprof dynamically from outside of fluentd}
11
+ spec.description = spec.summary
12
+ spec.homepage = "https://github.com/sonots/fluent-stackprof"
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,101 @@
1
+ require 'optparse'
2
+ require 'drb/drb'
3
+
4
+ module Fluent
5
+ class Stackprof
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
23
+ output: '/tmp/fluent-stackprof.dump',
24
+ mode: 'cpu',
25
+ }
26
+
27
+ op.on('-h', '--host HOST', "fluent host (default: #{opts[:host]})") {|v|
28
+ opts[:host] = v
29
+ }
30
+
31
+ op.on('-p', '--port PORT', "debug_agent tcp port (default: #{opts[:host]})", Integer) {|v|
32
+ opts[:port] = v
33
+ }
34
+
35
+ op.on('-u', '--unix PATH', "use unix socket instead of tcp") {|v|
36
+ opts[:unix] = v
37
+ }
38
+
39
+ op.on('-o', '--output PATH', "output path (default: #{opts[:output]})") {|v|
40
+ opts[:output] = v
41
+ }
42
+
43
+ op.on('-m', '--mode MODE', "stackprof measure mode (default: #{opts[:mode]})") {|v|
44
+ opts[:mode] = v
45
+ }
46
+
47
+ op.parse!(argv)
48
+
49
+ opts[:command] = argv.shift
50
+ unless %w[start stop].include?(opts[:command])
51
+ raise OptionParser::InvalidOption.new("`start` or `stop` must be specified as the 1st argument")
52
+ end
53
+
54
+ modes = %w[wall cpu object custom]
55
+ unless modes.include?(opts[:mode])
56
+ raise OptionParser::InvalidOption.new("-m allows one of #{modes.join(', ')}")
57
+ end
58
+
59
+ opts
60
+ end
61
+
62
+ def run
63
+ begin
64
+ opts = parse_options
65
+ rescue OptionParser::InvalidOption => e
66
+ usage e.message
67
+ end
68
+
69
+ unless opts[:unix].nil?
70
+ uri = "drbunix:#{opts[:unix]}"
71
+ else
72
+ uri = "druby://#{opts[:host]}:#{opts[:port]}"
73
+ end
74
+
75
+ $remote_engine = DRb::DRbObject.new_with_uri(uri)
76
+
77
+ case opts[:command]
78
+ when 'start'
79
+ remote_code = <<-CODE
80
+ require 'stackprof'
81
+ StackProf.start(mode: :#{opts[:mode]})
82
+ CODE
83
+ when 'stop'
84
+ remote_code = <<-"CODE"
85
+ StackProf.stop
86
+ StackProf.results('#{opts[:output]}')
87
+ CODE
88
+ end
89
+
90
+ puts remote_code
91
+ $remote_engine.method_missing(:instance_eval, remote_code)
92
+
93
+ case opts[:command]
94
+ when 'start'
95
+ $stdout.puts 'fluent-stackprof: started'
96
+ when 'stop'
97
+ $stdout.puts "fluent-stackprof: outputs to #{opts[:output]}"
98
+ end
99
+ end
100
+ end
101
+ 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,45 @@
1
+ require 'json'
2
+ require 'spec_helper'
3
+ require 'fluent/stackprof'
4
+
5
+ describe Fluent::Stackprof 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.dump')
9
+
10
+ context '#parse_options' do
11
+ it 'incorrect subcommand' do
12
+ expect { Fluent::Stackprof.new.parse_options(['foo']) }.to raise_error(OptionParser::InvalidOption)
13
+ end
14
+
15
+ it 'correct measure_mode' do
16
+ expect { Fluent::Stackprof.new.parse_options(['start', '-m', 'cpu']) }.not_to raise_error
17
+ end
18
+
19
+ it 'incorrect measure_mode' do
20
+ expect { Fluent::Stackprof.new.parse_options(['start', '-m', 'foo']) }.to raise_error(OptionParser::InvalidOption)
21
+ end
22
+ end
23
+
24
+ context 'profiling' do
25
+ before :all do
26
+ @fluentd_pid = spawn('fluentd', '-c', CONFIG_PATH, out: '/dev/null')
27
+ sleep 2
28
+
29
+ system("#{File.join(BIN_DIR, 'fluent-stackprof')} start -m wall")
30
+ sleep 2
31
+
32
+ system("#{File.join(BIN_DIR, 'fluent-stackprof')} stop -o #{OUTPUT_FILE}")
33
+ sleep 1
34
+ end
35
+
36
+ after :all do
37
+ Process.kill(:TERM, @fluentd_pid)
38
+ Process.waitall
39
+ end
40
+
41
+ it 'should output' do
42
+ expect(File.size?(OUTPUT_FILE)).to be_truthy
43
+ end
44
+ end
45
+ 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-stackprof
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Naotoshi Seo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-03 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 stackprof dynamically from outside of fluentd
56
+ email:
57
+ - sonots@gmail.com
58
+ executables:
59
+ - fluent-stackprof
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-stackprof
72
+ - fluent-stackprof.gemspec
73
+ - lib/fluent/stackprof.rb
74
+ - spec/fluent-stackprof/fluent.conf
75
+ - spec/fluent-stackprof/stackprof_spec.rb
76
+ - spec/spec_helper.rb
77
+ homepage: https://github.com/sonots/fluent-stackprof
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 stackprof dynamically from outside of fluentd
101
+ test_files:
102
+ - spec/fluent-stackprof/fluent.conf
103
+ - spec/fluent-stackprof/stackprof_spec.rb
104
+ - spec/spec_helper.rb