From 42aee49f3b183a8b20598f3f814a8d76ba718134 Mon Sep 17 00:00:00 2001 From: Eric Henderson Date: Tue, 29 Jul 2014 16:20:27 -0400 Subject: [PATCH] Make some changes to auto-threshold to hopefully improve it. --- README.md | 2 ++ Rakefile | 4 ++-- app/app_delegate.rb | 50 +++++++++++++++++++++++++-------------------- appcast.xml | 9 ++++++++ 4 files changed, 41 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 999007a..bcc0ebf 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,7 @@ A RubyMotion application for keeping memory usage in check. Shows up in the men * **v0.8.1:** add an option to control whether or not growl notifications are sticky * **v0.8.2:** add ability to run Memory Trimming on demand * **v0.9:** New experimental feature: auto-threshold. Designed to automatically adjust your thresholds to the target frequency. If you try it out, please provide feedback at +* **v0.9.1:** Make some changes to auto-threshold to hopefully improve it. If you try it out, please provide feedback at ###Versions (code-signed with developer ID): * **v0.3:** (Mavericks-only) @@ -54,3 +55,4 @@ A RubyMotion application for keeping memory usage in check. Shows up in the men * **v0.8.1:** * **v0.8.2:** * **v0.9:** +* **v0.9.1:** diff --git a/Rakefile b/Rakefile index 3ded306..27137fa 100644 --- a/Rakefile +++ b/Rakefile @@ -27,8 +27,8 @@ Motion::Project::App.setup do |app| app.icon = 'Icon.icns' app.info_plist['CFBundleIconFile'] = 'Icon.icns' app.name = 'MemoryTamer' - app.version = '0.9' - app.short_version = '0.9' + app.version = '0.9.1' + app.short_version = '0.9.1' app.identifier = 'us.myepg.MemoryTamer' app.info_plist['NSUIElement'] = 1 app.info_plist['SUFeedURL'] = 'https://raw.githubusercontent.com/henderea/MemoryTamer/master/appcast.xml' diff --git a/app/app_delegate.rb b/app/app_delegate.rb index f9ea863..fc98bd8 100644 --- a/app/app_delegate.rb +++ b/app/app_delegate.rb @@ -109,29 +109,23 @@ def applicationDidFinishLaunching(notification) NSLog "Starting up with memory = #{dfm}; pressure = #{App::Persistence['pressure']}" Thread.start { @last_free = NSDate.date - 30 + @last_trim = NSDate.date loop do cfm = get_free_mem @statusItem.setTitle(App::Persistence['show_mem'] ? format_bytes(cfm) : '') if App::Persistence['update_while'] || !@freeing diff = (NSDate.date - @last_free) - if (cfm < dfm || diff > (App::Persistence['auto_threshold'] == 'low' ? 60*11 : 60*6)) && !@freeing - if App::Persistence['auto_threshold'] == 'low' - mem_tweak('mem', diff, cfm, 60*5, 60*10) - elsif App::Persistence['auto_threshold'] == 'high' - mem_tweak('mem', diff, cfm, 60*3, 60*5) - end - set_mem_display - end - if (cfm < dtm || diff > (App::Persistence['auto_threshold'] == 'low' ? 60*6 : 60*3)) && !@freeing - if App::Persistence['auto_threshold'] == 'low' - mem_tweak('trim_mem', diff, cfm, 60*3, 60*5) - elsif App::Persistence['auto_threshold'] == 'high' - mem_tweak('trim_mem', diff, cfm, 60*2, 60*3) - end - set_trim_display - end - if cfm <= dfm && diff >= 60 && !@freeing + diff_t = (NSDate.date - @last_trim) + mem_tweak_default('mem', cfm, dfm, [diff, diff_t + 30].min, 60*10, 60*15, 60*5, 60*10) + mem_tweak_default('trim_mem', cfm, dtm, diff_t, 60*5, 60*10, 60*3, 60*5) + App::Persistence['mem'] = [App::Persistence['mem'], App::Persistence['trim_mem']].min + set_mem_display + if cfm <= dfm && diff >= 60 && diff_t >= 30 && !@freeing + NSLog "seconds since last full freeing: #{diff}" + NSLog "seconds since last trim: #{diff_t}" Thread.start { free_mem_default(cfm) } - elsif cfm <= dtm && diff >= 60 && !@freeing + elsif cfm <= dtm && diff >= 30 && diff_t >= 30 && !@freeing + NSLog "seconds since last full freeing: #{diff}" + NSLog "seconds since last trim: #{diff_t}" Thread.start { trim_mem(cfm) } end sleep(2) @@ -139,6 +133,18 @@ def applicationDidFinishLaunching(notification) } end + def mem_tweak_default(var, cfm, dm, diff, low_min, low_max, high_min, high_max) + if (cfm < dm || diff > ((App::Persistence['auto_threshold'] == 'low' ? low_max : high_max) + 60)) && !@freeing + if App::Persistence['auto_threshold'] == 'low' + mem_tweak(var, diff, cfm, low_min, low_max) + elsif App::Persistence['auto_threshold'] == 'high' + mem_tweak(var, diff, cfm, high_min, high_max) + end + set_mem_display + set_trim_display + end + end + def mem_tweak(var, diff, cfm, min, max) if diff < min App::Persistence[var] = (App::Persistence[var].to_f * [0.9, (diff.to_f / min.to_f)].max).ceil @@ -250,12 +256,12 @@ def free_mem_default(cfm) def trim_mem(cfm) @freeing = true notify 'Beginning memory trimming', 'Start Freeing' - free_mem_old(0.5) + free_mem_old(true) nfm = get_free_mem notify "Finished trimming #{format_bytes(nfm - cfm)}", 'Finish Freeing' NSLog "Freed #{format_bytes(nfm - cfm, true)}" @freeing = false - @last_free = NSDate.date - 30 + @last_trim = NSDate.date end def format_bytes(bytes, show_raw = false) @@ -314,8 +320,8 @@ def free_mem(pressure) end end - def free_mem_old(inactive_multiplier = 1) - mtf = get_free_mem(inactive_multiplier) + def free_mem_old(trim = false) + mtf = trim ? [get_free_mem(1) * 0.75, get_free_mem(0.5)].min : get_free_mem(1) NSLog "#{mtf}" ep = NSBundle.mainBundle.pathForResource('inactive', ofType: '') op = `'#{ep}' '#{mtf}'` diff --git a/appcast.xml b/appcast.xml index 9fc26e0..461f026 100755 --- a/appcast.xml +++ b/appcast.xml @@ -5,6 +5,15 @@ https://raw.githubusercontent.com/henderea/MemoryTamer/master/appcast.xml Most recent changes with links to updates. en + + Version 0.9.1 + + http://releases.io/henderea/MemoryTamer/0.9.1?heading=true + + Tue, 29 Jul 2014 16:20:00 -0400 + + 10.7 + Version 0.9