motion-dtrace 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in Routable.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,16 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ motion-dtrace (0.1.0)
5
+ rake
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ rake (0.9.2.2)
11
+
12
+ PLATFORMS
13
+ ruby
14
+
15
+ DEPENDENCIES
16
+ motion-dtrace!
data/README.md ADDED
@@ -0,0 +1,53 @@
1
+ motion-dtrace
2
+ =============
3
+
4
+ Proof of concept to use dtrace on rubymotion.
5
+
6
+ Installation
7
+ ------------
8
+
9
+ ```
10
+ gem install motion-dtrace
11
+ ```
12
+
13
+ Usage
14
+ -----
15
+
16
+
17
+ 1. Edit the Rakefile of your RubyMotion project and add the following require line.
18
+
19
+ ```
20
+ require 'rubygems'
21
+ require 'motion-dtrace'
22
+ ```
23
+
24
+ 2. Start simulator process:
25
+
26
+ ```
27
+ rake
28
+ ```
29
+
30
+ 3. On another terminal, start dtrace:
31
+
32
+ ```
33
+ rake dtrace
34
+ ```
35
+
36
+ You may specify your own dtrace file via:
37
+
38
+ ```
39
+ rake dtrace DTRACE=/Users/siuying/Documents/workspace/motion/motion-dtrace/dtrace/methods_duration.d
40
+ ```
41
+
42
+ TODO
43
+ ----
44
+
45
+ Currently this gem is just a hack to simplify command lines.
46
+
47
+ We shall investigate can we do real integration with project.
48
+
49
+ Credit
50
+ ------
51
+
52
+ - [MacRuby DTrace examples](https://github.com/MacRuby/MacRuby/tree/master/sample-macruby/DTrace)
53
+ - [Using the DTrace](http://watson1978.github.com/MacRuby-DoJo/blog/2012/04/15/dtrace/)
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ desc "Build the gem"
4
+ task :gem do
5
+ sh "bundle exec gem build motion-dtrace.gemspec"
6
+ sh "mkdir -p pkg"
7
+ sh "mv *.gem pkg/"
8
+ end
@@ -0,0 +1,26 @@
1
+ #!/usr/sbin/dtrace -s
2
+ /* https://raw.github.com/MacRuby/MacRuby/master/sample-macruby/DTrace/methods_count.d */
3
+
4
+ #pragma D option quiet
5
+
6
+ BEGIN
7
+ {
8
+ printf("Target pid: %d\n\n", $target);
9
+ }
10
+
11
+ macruby$target:::method-entry
12
+ /copyinstr(arg0) != "TopLevel"/
13
+ {
14
+ /* printf("%30s:%-5d %s#%s\n", copyinstr(arg2), arg3,
15
+ copyinstr(arg0), copyinstr(arg1));
16
+ */
17
+ @methods_count[copyinstr(arg0), copyinstr(arg1)] = count();
18
+ }
19
+
20
+ END
21
+ {
22
+ printf("\n");
23
+ printf("%30s %-30s %s\n", "CLASS", "METHOD", "COUNT");
24
+ printf("--------------------------------------------------------------------------------\n");
25
+ printa("%30s %-30s %@d\n", @methods_count);
26
+ }
@@ -0,0 +1,25 @@
1
+ #!/usr/sbin/dtrace -s
2
+ /* https://raw.github.com/MacRuby/MacRuby/master/sample-macruby/DTrace/methods_duration.d */
3
+ #pragma D option quiet
4
+
5
+ BEGIN
6
+ {
7
+ printf("Target pid: %d\n\n", $target);
8
+ printf("%20s %-5s %10s %-30s %10s\n", "FILE", "LINE", "CLASS", "METHOD",
9
+ "DURATION");
10
+ printf("--------------------------------------------------------------------------------\n");
11
+ }
12
+
13
+ macruby$target:::method-entry
14
+ /copyinstr(arg0) != "TopLevel"/
15
+ {
16
+ self->starttime = walltimestamp / 1000;
17
+ }
18
+
19
+ macruby$target:::method-return
20
+ /copyinstr(arg0) != "TopLevel"/
21
+ {
22
+ printf("%20s:%-5d %10s#%-30s %10d\n", copyinstr(arg2), arg3,
23
+ copyinstr(arg0), copyinstr(arg1),
24
+ (walltimestamp / 1000) - self->starttime);
25
+ }
data/dtrace/time.d ADDED
@@ -0,0 +1,26 @@
1
+ #!/usr/sbin/dtrace -s
2
+
3
+ /* time.d */
4
+ /* http://watson1978.github.com/MacRuby-DoJo/blog/2012/04/15/dtrace/ */
5
+
6
+ #pragma D option quiet
7
+
8
+ macruby$target:::method-entry
9
+ /copyinstr(arg0) != "TopLevel"/
10
+ {
11
+ self->starttime = walltimestamp / 1000;
12
+ }
13
+
14
+ macruby$target:::method-return
15
+ /copyinstr(arg0) != "TopLevel"/
16
+ {
17
+ @invoked_time[copyinstr(arg0), copyinstr(arg1)] = sum((walltimestamp / 1000) - self->starttime);
18
+ }
19
+
20
+ END
21
+ {
22
+ printf("\n");
23
+ printf("%30s#%-30s %s\n", "CLASS", "METHOD", "TOTAL TIME µsec");
24
+ printf("--------------------------------------------------------------------------------\n");
25
+ printa("%30s#%-30s %@d\n", @invoked_time);
26
+ }
@@ -0,0 +1,8 @@
1
+ desc "Run dtrace on Simulator process"
2
+ task :dtrace do
3
+ trace_file = ENV['DTRACE'] || File.expand_path(File.join(File.dirname(__FILE__), "/../dtrace/time.d"))
4
+ trace_pid = `ps ax | grep -P 'iPhone Simulator/[0-9\.]+/Applications/[^/]+/[^/]+\.app' | awk '{print $1}'`
5
+ command = "sudo dtrace -qs #{trace_file} -p #{trace_pid}"
6
+ puts "#{command}"
7
+ exec command
8
+ end
@@ -0,0 +1,3 @@
1
+ module DTrace
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,18 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/motion-dtrace/version', __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "motion-dtrace"
6
+ s.version = DTrace::VERSION
7
+ s.authors = ["Francis Chong"]
8
+ s.email = ["francis@ignition.hk"]
9
+ s.homepage = "https://github.com/siuying/motion-dtrace"
10
+ s.summary = "use DTrace on motion"
11
+ s.description = "use DTrace on motion"
12
+
13
+ s.files = `git ls-files`.split($\)
14
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
15
+ s.require_paths = ["lib"]
16
+ s.add_dependency 'rake'
17
+
18
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: motion-dtrace
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Francis Chong
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-29 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: &70208847070540 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70208847070540
25
+ description: use DTrace on motion
26
+ email:
27
+ - francis@ignition.hk
28
+ executables: []
29
+ extensions: []
30
+ extra_rdoc_files: []
31
+ files:
32
+ - Gemfile
33
+ - Gemfile.lock
34
+ - README.md
35
+ - Rakefile
36
+ - dtrace/methods_count.d
37
+ - dtrace/methods_duration.d
38
+ - dtrace/time.d
39
+ - lib/motion-dtrace.rb
40
+ - lib/motion-dtrace/version.rb
41
+ - motion-dtrace.gemspec
42
+ homepage: https://github.com/siuying/motion-dtrace
43
+ licenses: []
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ! '>='
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements: []
61
+ rubyforge_project:
62
+ rubygems_version: 1.8.15
63
+ signing_key:
64
+ specification_version: 3
65
+ summary: use DTrace on motion
66
+ test_files: []