motion-simple-profiler 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 Francis Chong
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,59 @@
1
+ Simple Profiler for RubyMotion
2
+ ==============================
3
+
4
+ motion-simple-profiler is a RubyMotion extension to log method runtime without adding a single line of code to original class.
5
+
6
+ Use it when you need to know how long it takes for a function to run, but you don't want to use tools like instruments.
7
+
8
+ ## Install
9
+
10
+ 1. ```gem 'motion-simple-profiler'```
11
+ 2. ```require 'motion-simple-profiler'``` or add to your ```Gemfile```
12
+
13
+ ## Usage
14
+
15
+ ```ruby
16
+ class MyClass
17
+ def long_running_task
18
+ # ... run the task
19
+ end
20
+ end
21
+
22
+ Profiler.profile MyClass, :long_running_task
23
+ ```
24
+
25
+ Running `self.long_running_task` will print:
26
+
27
+ ```
28
+ MyClass#long_running_task runtime: 1.63304 s
29
+ ```
30
+
31
+ ## Customization
32
+
33
+ You can modify the profiler log output by override the Profiler::ObjectExt#profile_log method.
34
+
35
+ For example:
36
+
37
+ ```ruby
38
+ module Profiler
39
+ module ObjectExt
40
+ def profile_log(clazz_name, method_name, start_time, end_time)
41
+ puts "*** %s#%s -> %.5fs" % [clazz_name, method_name, (end_time-start_time).to_f]
42
+ end
43
+ end
44
+ end
45
+ ```
46
+
47
+ Same example above will print:
48
+
49
+ ```
50
+ *** MyClass#long_running_task -> 1.63304s
51
+ ```
52
+
53
+ ## About
54
+
55
+ motion-simple-profiler is inspired by [Ruby AOP in 12 lines of Code](http://uberpwn.wordpress.com/2011/03/14/ruby-aop-in-12-lines-of-code/) and [NanoProfiler](https://raw.github.com/tomersh/NanoProfiler).
56
+
57
+ ## License
58
+
59
+ Please refer to [LICENSE](https://raw.github.com/siuying/motion-simple-profiler/master/LICENSE).
@@ -0,0 +1,7 @@
1
+ unless defined?(Motion::Project::Config)
2
+ raise "This file must be required within a RubyMotion project Rakefile."
3
+ end
4
+
5
+ Motion::Project::App.setup do |app|
6
+ app.files.unshift(File.join(File.dirname(__FILE__), 'simple-profiler.rb'))
7
+ end
@@ -0,0 +1,32 @@
1
+ module Profiler
2
+ module ObjectExt
3
+ def profile(symbol)
4
+ _symbol = ("_rm_profile_" + symbol.to_s).to_sym
5
+ alias_method _symbol, symbol
6
+
7
+ self.send(:define_method, symbol.to_s) do |*args|
8
+ clazz_name = self.send(:class).to_s
9
+ method_name = symbol.to_s
10
+
11
+ start_time = Time.now
12
+ result = self.send(_symbol, *args)
13
+ end_time = Time.now
14
+
15
+ profile_log(clazz_name, method_name, start_time, end_time)
16
+
17
+ result
18
+ end
19
+ end
20
+
21
+ def profile_log(clazz_name, method_name, start_time, end_time)
22
+ puts "%s#%s runtime: %.5f s" % [clazz_name, method_name, (end_time-start_time).to_f]
23
+ end
24
+ end
25
+ Object.send(:include, ::Profiler::ObjectExt)
26
+
27
+ def self.profile(clazz, method)
28
+ clazz.instance_eval do
29
+ profile method
30
+ end
31
+ end
32
+ end
metadata ADDED
@@ -0,0 +1,50 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: motion-simple-profiler
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Francis Chong
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-21 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: RubyMotion extension to log method runtime without adding a single line
15
+ of code to original class.
16
+ email: francis@ignition.hk
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - LICENSE
22
+ - README.md
23
+ - lib/motion-simple-profiler.rb
24
+ - lib/simple-profiler.rb
25
+ homepage: http://github.com/siuying/motion-simple-profiler
26
+ licenses: []
27
+ post_install_message:
28
+ rdoc_options: []
29
+ require_paths:
30
+ - lib
31
+ required_ruby_version: !ruby/object:Gem::Requirement
32
+ none: false
33
+ requirements:
34
+ - - ! '>='
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ required_rubygems_version: !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ! '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ requirements: []
44
+ rubyforge_project:
45
+ rubygems_version: 1.8.23
46
+ signing_key:
47
+ specification_version: 3
48
+ summary: RubyMotion extension to log method runtime without adding a single line of
49
+ code to original class.
50
+ test_files: []