mem-watcher 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 713b8aaab622178d7c8f41b764d94891474d9de5
4
+ data.tar.gz: d90f43a695d928bee081471b91190529e6ea8116
5
+ SHA512:
6
+ metadata.gz: 076d7bfdd6b6ca6e4a2cf7f0cad48a115ddd8132886abf14ea77a1afb6501056bfae845243e15f578800ea27d2a9940ea66f2257108111cead65da8c5fc78ded
7
+ data.tar.gz: 2c96a3f2d67bd535bd3ec5cbba0aa0335d550b43d239c4a8594de1e3b83e8e3c8e5db0eb972056ddfebdf97067e7b4d6d72b78423ae91000a074817ebca6a67e
data/README.md ADDED
@@ -0,0 +1,52 @@
1
+ # MemWatcher
2
+
3
+ Helps you keep an eye on your RubyMotion iOS app's memory and CPU usage.
4
+
5
+ Adds a little UILabel in the top left of the screen that shows CPU % and memory usage in MB.
6
+
7
+ ## Setup/Usage
8
+
9
+ ```ruby
10
+ gem 'mem-watcher'
11
+ ```
12
+
13
+ ```ruby
14
+ class AppDelegate
15
+ def application(app, didFinishLaunchingWithOptions: options)
16
+ # ...
17
+ MemWatcher.watch
18
+ true
19
+ end
20
+ end
21
+ ```
22
+
23
+ ### Options
24
+
25
+ The `env:` option controls what environments MemWatcher will watch in. It defaults to `"development"` and can be a string or array of acceptable RubyMotion environments.
26
+
27
+ ```ruby
28
+ MemWatcher.watch(env: [ "development", "test" ])
29
+ ```
30
+
31
+ If you want to attach the view to another view, provide it:
32
+
33
+ ```ruby
34
+ MemWatcher.watch(parent_view: "development")
35
+ ```
36
+
37
+ ### Caveats
38
+
39
+ * It only reports on the current app main process.
40
+ * I have no idea how accurate it is. It does accurately show memory leaks, from what I can see.
41
+
42
+ ## Contributing
43
+
44
+ 1. Fork it
45
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
46
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
47
+ 4. Push to the branch (`git push origin my-new-feature`)
48
+ 5. Create new Pull Request
49
+
50
+ ## License
51
+
52
+ MIT, yo.
@@ -0,0 +1,55 @@
1
+ class MemWatcher
2
+
3
+ def self.watch(args={})
4
+ new.watch(args)
5
+ end
6
+
7
+ def watch(args={})
8
+ return false unless correct_env?(args)
9
+ parent_view = args[:parent_view] if args[:parent_view]
10
+ parent_view ||= UIApplication.sharedApplication.delegate.window if UIApplication.sharedApplication.delegate.respond_to?(:window)
11
+ parent_view || abort("MemWatcher needs a `display_on:` view or access to the window in your AppDelegate via a `window` accessor.")
12
+ parent_view.addSubview label
13
+ label.text = "Loading..."
14
+ start_watcher
15
+ end
16
+
17
+ private
18
+
19
+ def correct_env?(args={})
20
+ args[:env] ||= [ "development" ]
21
+ Array(args[:env]).map(&:to_s).include?(RUBYMOTION_ENV)
22
+ end
23
+
24
+ def start_watcher
25
+ every 1 do
26
+ cpu, memory = cpu_memory
27
+ label.text = "#{memory} MB #{cpu}%"
28
+ end
29
+ end
30
+
31
+ def every(interval, user_info=nil, &fire)
32
+ NSTimer.scheduledTimerWithTimeInterval(interval, target: fire, selector: 'call:', userInfo: user_info, repeats: true)
33
+ end
34
+
35
+ def pid
36
+ @pid ||= Process.pid
37
+ end
38
+
39
+ def cpu_memory
40
+ output = `ps -p #{pid} -o %cpu,%mem`
41
+ output.split("\n").last.strip.split(" ").map(&:strip)
42
+ end
43
+
44
+ def label
45
+ @label ||= begin
46
+ l = UILabel.alloc.initWithFrame([[ 10, 10 ], [ 50, 24 ]])
47
+ l.backgroundColor = UIColor.colorWithWhite(1.0, alpha:0.5)
48
+ l.font = UIFont.systemFontOfSize(10.0)
49
+ l.sizeToFit
50
+ l
51
+ end
52
+ end
53
+
54
+ end
55
+
@@ -0,0 +1,10 @@
1
+ # encoding: utf-8
2
+
3
+ unless defined?(Motion::Project::Config)
4
+ raise "This file must be required within a RubyMotion project Rakefile."
5
+ end
6
+
7
+ lib_dir_path = File.dirname(File.expand_path(__FILE__))
8
+ Motion::Project::App.setup do |app|
9
+ app.files.unshift(Dir.glob(File.join(lib_dir_path, "mem-watcher/**/*.rb")))
10
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mem-watcher
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jamon Holmgren
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: Simple gem that Helps you keep an eye on your RubyMotion iOS app's memory
28
+ and CPU usage. Adds a little UILabel in the top left of the screen that shows CPU
29
+ % and memory usage in MB.
30
+ email:
31
+ - jamon@clearsightstudio.com
32
+ executables: []
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - README.md
37
+ - lib/mem-watcher.rb
38
+ - lib/mem-watcher/mem-watcher.rb
39
+ homepage: https://github.com/jamonholmgren/mem-watcher
40
+ licenses:
41
+ - MIT
42
+ metadata: {}
43
+ post_install_message:
44
+ rdoc_options: []
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ requirements: []
58
+ rubyforge_project:
59
+ rubygems_version: 2.4.5
60
+ signing_key:
61
+ specification_version: 4
62
+ summary: Simple gem that Helps you keep an eye on your RubyMotion iOS app's memory
63
+ and CPU usage.
64
+ test_files: []