Skip to content

Commit b6fa2a9

Browse files
authored
Merge pull request #3 from Watson1978/fix
Support ruby-prof 1.x API
2 parents 556081a + 79f2cfd commit b6fa2a9

4 files changed

Lines changed: 53 additions & 8 deletions

File tree

.github/dependabot.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: 'github-actions'
4+
directory: '/'
5+
schedule:
6+
interval: 'monthly'

.github/workflows/test.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: test
2+
on:
3+
push:
4+
branches: [master]
5+
pull_request:
6+
branches: [master]
7+
schedule:
8+
- cron: '0 0 1 * *'
9+
jobs:
10+
ruby-versions:
11+
uses: ruby/actions/.github/workflows/ruby_versions.yml@master
12+
with:
13+
engine: cruby
14+
min_version: 2.7
15+
build:
16+
needs: ruby-versions
17+
runs-on: ${{ matrix.os }}
18+
strategy:
19+
fail-fast: false
20+
matrix:
21+
ruby: ${{ fromJson(needs.ruby-versions.outputs.versions) }}
22+
exclude:
23+
- ruby: head
24+
os:
25+
- ubuntu-latest
26+
name: Ruby ${{ matrix.ruby }} ${{ matrix.os }}
27+
steps:
28+
- uses: actions/checkout@v6
29+
- uses: ruby/setup-ruby@v1
30+
with:
31+
ruby-version: ${{ matrix.ruby }}
32+
- name: unit testing
33+
run: |
34+
bundle install --jobs 4 --retry 3
35+
bundle exec rake spec

fluent-rubyprof.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
1717
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
1818
spec.require_paths = ["lib"]
1919

20-
spec.add_development_dependency "bundler", "~> 1.5"
20+
spec.add_development_dependency "bundler"
2121
spec.add_development_dependency "rake"
2222
spec.add_development_dependency "rspec"
2323
end

lib/fluent/rubyprof.rb

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def parse_options(argv = ARGV)
6969
raise OptionParser::InvalidOption.new("`start` or `stop` must be specified as the 1st argument")
7070
end
7171

72-
measure_modes = %w[PROCESS_TIME WALL_TIME CPU_TIME ALLOCATIONS MEMORY GC_RUNS GC_TIME]
72+
measure_modes = %w[PROCESS_TIME WALL_TIME CPU_TIME ALLOCATIONS MEMORY GC_RUNS GC_TIME]
7373
unless measure_modes.include?(opts[:measure_mode])
7474
raise OptionParser::InvalidOption.new("-m allows one of #{measure_modes.join(', ')}")
7575
end
@@ -96,15 +96,19 @@ def run
9696
when 'start'
9797
remote_code = <<-CODE
9898
require 'ruby-prof'
99-
RubyProf.measure_mode = eval("RubyProf::#{opts[:measure_mode]}")
100-
RubyProf.start
99+
$fluent_rubyprof_instance = RubyProf::Profile.new(measure_mode: RubyProf::#{opts[:measure_mode]})
100+
$fluent_rubyprof_instance.start
101101
CODE
102102
when 'stop'
103103
remote_code = <<-"CODE"
104-
result = RubyProf.stop
105-
File.open('#{opts[:output]}', 'w') {|f|
106-
RubyProf::#{PRINTERS[opts[:printer]]}.new(result).print(f)
107-
}
104+
require 'ruby-prof'
105+
if defined?($fluent_rubyprof_instance) && $fluent_rubyprof_instance
106+
result = $fluent_rubyprof_instance.stop
107+
File.open('#{opts[:output]}', 'w') {|f|
108+
RubyProf::#{PRINTERS[opts[:printer]]}.new(result).print(f)
109+
}
110+
$fluent_rubyprof_instance = nil
111+
end
108112
CODE
109113
end
110114

0 commit comments

Comments
 (0)