object_profiler 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +64 -0
- data/Rakefile +11 -0
- data/lib/object/profiler/middleware.rb +19 -0
- data/lib/object/profiler/probes/object_create.d +10 -0
- data/lib/object/profiler/profiler.rb +65 -0
- data/lib/object/profiler/version.rb +5 -0
- data/lib/object_profiler.rb +2 -0
- data/object_profiler.gemspec +23 -0
- metadata +84 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
YTZjZGUwNDI4MGVjMTM1ZjMxNjA0MzJkZDcyZmNmNzM1MWY1MDYxNg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ODg0ZWU5YjNkZGU4MjFjZGMxMDZkZjdkNDFiNmY3OTdiZjk3MDZkOQ==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MjJiNDVhNWY3ZmY5NTc0MzUzYjdhZjI0ZTJjYWI3YzdhYzQwZTlmNmM3ZDIz
|
10
|
+
ZjE0MjU5MmQyZWE0ZjkxMDkwODUxZGQ5Yzg0YmRmNjg5MjZhMmUxZTMwM2Y4
|
11
|
+
OTc2N2RkNjJlNzJmZjAzODMyMzIwMjYyMzlkZDhlNjE3Njk0YjY=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NWNhZDZmNjIwYTQ4MjlkYjA4YWZhY2FiMjNlODYxNmVmZmE5MWQyNzZkZTRk
|
14
|
+
OWM2MTc2Y2NkOWZkNjE1MmZkZTRlMjZmZDk0YmI1ZWFlOWNiOTA5YWE1ZTc1
|
15
|
+
ODljOWI0YjU2ZmVkMDE2MjlhZjE2Zjk2ODhlZjYwYTYwM2NjOWY=
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Tieg Zaharia
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
# Object::Profiler
|
2
|
+
|
3
|
+
Track how many Ruby objects your code is creating. In the style of GC::Profiler and
|
4
|
+
inspired by memprof.
|
5
|
+
|
6
|
+
## Requirements
|
7
|
+
|
8
|
+
1. A platform that supports DTrace (Solaris, OSX, etc)
|
9
|
+
2. root access (required by DTrace)
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
gem 'object_profiler'
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install object_profiler
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
Object::Profiler.track {
|
28
|
+
require 'rdoc/rdoc'
|
29
|
+
}
|
30
|
+
# => Amount File:Line:Class
|
31
|
+
# => 1 /.../2.0.0/json/common.rb:67:JSON::Ext::Generator::State
|
32
|
+
# => 1 /.../2.0.0/json/common.rb:68:JSON::Ext::Generator::State
|
33
|
+
# => 1 /.../2.0.0/json/common.rb:75:JSON::Ext::Generator::State
|
34
|
+
# => 1 /.../2.0.0/rdoc/generator/markup.rb:65:Range
|
35
|
+
# => 1 /.../2.0.0/rdoc/text.rb:42:Hash
|
36
|
+
# => 1 /.../gems/2.0.0/gems/bundler-1.3.4/lib/bundler/rubygems_integration.rb:200:Gem::Dependency
|
37
|
+
# => 1 /.../gems/2.0.0/gems/bundler-1.3.4/lib/bundler/rubygems_integration.rb:207:Gem::LoadError
|
38
|
+
# => 1 /.../gems/2.0.0/gems/bundler-1.3.4/lib/bundler/shared_helpers.rb:23:Pathname
|
39
|
+
# => 1 /.../gems/2.0.0/gems/bundler-1.3.4/lib/bundler/shared_helpers.rb:23:String
|
40
|
+
# => 1 /.../site_ruby/2.0.0/rubygems/requirement.rb:52:Gem::Requirement
|
41
|
+
# => 2 /.../gems/2.0.0/gems/bundler-1.3.4/lib/bundler.rb:177:Pathname
|
42
|
+
# => 2 /.../gems/2.0.0/gems/bundler-1.3.4/lib/bundler.rb:177:String
|
43
|
+
# => 3 /.../gems/2.0.0/gems/bundler-1.3.4/lib/bundler/rubygems_ext.rb:23:Pathname
|
44
|
+
# => 5 /.../gems/2.0.0/gems/bundler-1.3.4/lib/bundler/rubygems_ext.rb:23:String
|
45
|
+
# => 6 /.../2.0.0/rdoc/class_module.rb:5:Range
|
46
|
+
# => 6 /.../2.0.0/rdoc/markdown/literals_1_9.rb:359:RDoc::Markdown::Literals::RuleInfo
|
47
|
+
# => 240 /.../2.0.0/rdoc/markdown.rb:508:RDoc::Markdown::RuleInfo
|
48
|
+
# => 274 Total
|
49
|
+
|
50
|
+
## Usage - Rails Middleware
|
51
|
+
|
52
|
+
Add to your app initializers, ie `config/initializers/object_profiler.rb`:
|
53
|
+
|
54
|
+
require 'object/profiler/middleware'
|
55
|
+
My::Application.config.middleware.use(::Object::Profiler::Middleware, {:output => 'object_profiler.log'})
|
56
|
+
|
57
|
+
Run the server and tail the log:
|
58
|
+
|
59
|
+
sudo rails s
|
60
|
+
|
61
|
+
## Useful DTrace links
|
62
|
+
|
63
|
+
1. https://wikis.oracle.com/display/DTrace/Documentation
|
64
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require ::File.expand_path('../profiler.rb', __FILE__)
|
2
|
+
|
3
|
+
class Object
|
4
|
+
class Profiler
|
5
|
+
class Middleware
|
6
|
+
def initialize(app, options={})
|
7
|
+
@app = app
|
8
|
+
@output = options[:output] ? File.open(options[:output], 'w+') : STDOUT
|
9
|
+
|
10
|
+
end
|
11
|
+
|
12
|
+
def call(env)
|
13
|
+
Object::Profiler.track(@output) {
|
14
|
+
@app.call(env)
|
15
|
+
}
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
ruby*:::object-create
|
2
|
+
{
|
3
|
+
/* FILE - LINE - CLASS */
|
4
|
+
this->val = copyinstr(arg1);
|
5
|
+
this->val = strjoin(this->val, ":");
|
6
|
+
this->val = strjoin(this->val, lltostr(arg2));
|
7
|
+
this->val = strjoin(this->val, ":");
|
8
|
+
this->val = strjoin(this->val, copyinstr(arg0));
|
9
|
+
@objs[this->val] = count();
|
10
|
+
}
|
@@ -0,0 +1,65 @@
|
|
1
|
+
if not system("dtrace -l -i :::jabberwocky")
|
2
|
+
raise "DTrace not responding. Are you running with sudo?"
|
3
|
+
end
|
4
|
+
|
5
|
+
require 'tempfile'
|
6
|
+
|
7
|
+
class Object
|
8
|
+
class Profiler
|
9
|
+
class << self
|
10
|
+
def track(output=nil)
|
11
|
+
raise "Object::Profiler.track requires a block." unless block_given?
|
12
|
+
|
13
|
+
enable
|
14
|
+
result = yield
|
15
|
+
disable
|
16
|
+
report(output)
|
17
|
+
|
18
|
+
return result
|
19
|
+
end
|
20
|
+
|
21
|
+
def enable
|
22
|
+
return if enabled?
|
23
|
+
|
24
|
+
@tmpfile = Tempfile.new("object::profiler")
|
25
|
+
@report = nil
|
26
|
+
probe = File.join(__dir__, 'probes', 'object_create.d')
|
27
|
+
@pid = Process.spawn "dtrace -q -s #{probe} -p #{$$} -o #{@tmpfile.path}"
|
28
|
+
|
29
|
+
# Better way to wait for dtrace to work?
|
30
|
+
sleep 1
|
31
|
+
end
|
32
|
+
|
33
|
+
def enabled?
|
34
|
+
!!@pid
|
35
|
+
end
|
36
|
+
|
37
|
+
def disable
|
38
|
+
return unless enabled?
|
39
|
+
|
40
|
+
Process.kill("SIGINT", @pid)
|
41
|
+
Process.wait
|
42
|
+
@pid = nil
|
43
|
+
end
|
44
|
+
|
45
|
+
def report(io=nil)
|
46
|
+
if !@report
|
47
|
+
@tmpfile.rewind
|
48
|
+
|
49
|
+
# TODO: Could this be done in the provider instead?
|
50
|
+
results = []
|
51
|
+
@tmpfile.read.strip.lines.each do |line|
|
52
|
+
file_line_type, amount = line.split(" ")
|
53
|
+
results << [amount.to_i, file_line_type]
|
54
|
+
end
|
55
|
+
@report = results.map { |r| "%10d %s" % r }
|
56
|
+
@report << "%10d %s" % [results.map(&:first).inject(0, &:+), "Total"]
|
57
|
+
@report.unshift "\n%10s %s" % ["Amount", "File:Line:Class"]
|
58
|
+
|
59
|
+
end
|
60
|
+
io ||= STDOUT
|
61
|
+
io.puts @report.join("\n")
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -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
|
+
require 'object/profiler/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "object_profiler"
|
8
|
+
spec.version = Object::Profiler::VERSION
|
9
|
+
spec.authors = ["Tieg Zaharia"]
|
10
|
+
spec.email = ["tieg.zaharia@gmail.com"]
|
11
|
+
spec.description = %q{Object::Profiler uses DTrace probes in Ruby 2.0 to help instrument your code.}
|
12
|
+
spec.summary = %q{Object::Profiler uses DTrace probes in Ruby 2.0 to help instrument your code.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
# spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
# spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: object_profiler
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tieg Zaharia
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-04-21 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.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
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
|
+
description: Object::Profiler uses DTrace probes in Ruby 2.0 to help instrument your
|
42
|
+
code.
|
43
|
+
email:
|
44
|
+
- tieg.zaharia@gmail.com
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- .gitignore
|
50
|
+
- Gemfile
|
51
|
+
- LICENSE.txt
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- lib/object/profiler/middleware.rb
|
55
|
+
- lib/object/profiler/probes/object_create.d
|
56
|
+
- lib/object/profiler/profiler.rb
|
57
|
+
- lib/object/profiler/version.rb
|
58
|
+
- lib/object_profiler.rb
|
59
|
+
- object_profiler.gemspec
|
60
|
+
homepage: ''
|
61
|
+
licenses:
|
62
|
+
- MIT
|
63
|
+
metadata: {}
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ! '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
requirements: []
|
79
|
+
rubyforge_project:
|
80
|
+
rubygems_version: 2.0.3
|
81
|
+
signing_key:
|
82
|
+
specification_version: 4
|
83
|
+
summary: Object::Profiler uses DTrace probes in Ruby 2.0 to help instrument your code.
|
84
|
+
test_files: []
|