Skip to content

Commit

Permalink
change auto-threshold to a different strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
henderea committed Jul 30, 2014
1 parent 3e5e0a9 commit a65154e
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 24 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ A RubyMotion application for keeping memory usage in check. Shows up in the men
* **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 <https://github.com/henderea/MemoryTamer/issues/4>
* **v0.9.1:** Make some changes to auto-threshold to hopefully improve it. If you try it out, please provide feedback at <https://github.com/henderea/MemoryTamer/issues/4>
* **v0.9.2:** fix a bug introduced in v0.9.1 where memory threshold would be set to 0 if trim threshold was 0
* **v0.9.3:** Auto-threshold has changed. My original design for it didn't turn out well, so I changed it to set the thresholds to a certain percent of post-freeing memory on a full freeing. Hopefully this will work better.

###Versions (code-signed with developer ID):
* **v0.3:** <http://memorytamer.s3.amazonaws.com/MemoryTamer-0.3.zip> (Mavericks-only)
Expand All @@ -58,3 +59,4 @@ A RubyMotion application for keeping memory usage in check. Shows up in the men
* **v0.9:** <https://memorytamer.s3.amazonaws.com/MemoryTamer-0.9.zip>
* **v0.9.1:** <https://memorytamer.s3.amazonaws.com/MemoryTamer-0.9.1.zip>
* **v0.9.2:** <https://memorytamer.s3.amazonaws.com/MemoryTamer-0.9.2.zip>
* **v0.9.3:** <https://memorytamer.s3.amazonaws.com/MemoryTamer-0.9.3.zip>
4 changes: 2 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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.2'
app.short_version = '0.9.2'
app.version = '0.9.3'
app.short_version = '0.9.3'
app.identifier = 'us.myepg.MemoryTamer'
app.info_plist['NSUIElement'] = 1
app.info_plist['SUFeedURL'] = 'https://raw.githubusercontent.com/henderea/MemoryTamer/master/appcast.xml'
Expand Down
51 changes: 29 additions & 22 deletions app/app_delegate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ def applicationDidFinishLaunching(notification)
@statusItem.setTitle(App::Persistence['show_mem'] ? format_bytes(cfm) : '') if App::Persistence['update_while'] || !@freeing
diff = (NSDate.date - @last_free)
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 if App::Persistence['trim_mem'] > 0 && App::Persistence['auto_threshold'] != 'off'
# 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 if App::Persistence['trim_mem'] > 0 && App::Persistence['auto_threshold'] != 'off'
set_mem_display
if cfm <= dfm && diff >= 60 && diff_t >= 30 && !@freeing
NSLog "seconds since last full freeing: #{diff}"
Expand All @@ -133,25 +133,25 @@ 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
elsif diff > max
App::Persistence[var] = (App::Persistence[var].to_f * [1.1, (diff.to_f / max.to_f)].min).ceil
end
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
# elsif diff > max
# App::Persistence[var] = (App::Persistence[var].to_f * [1.1, (diff.to_f / max.to_f)].min).ceil
# end
# end

def set_all_displays
set_notification_display
Expand Down Expand Up @@ -251,6 +251,13 @@ def free_mem_default(cfm)
NSLog "Freed #{format_bytes(nfm - cfm, true)}"
@freeing = false
@last_free = NSDate.date
if App::Persistence['auto_threshold'] == 'low'
App::Persistence['mem'] = ((nfm.to_f * 0.3) / 1024**2).ceil
App::Persistence['trim_mem'] = ((nfm.to_f * 0.6) / 1024**2).ceil if App::Persistence['trim_mem'] > 0
elsif App::Persistence['auto_threshold'] == 'high'
App::Persistence['mem'] = ((nfm.to_f * 0.5) / 1024**2).ceil
App::Persistence['trim_mem'] = ((nfm.to_f * 0.8) / 1024**2).ceil if App::Persistence['trim_mem'] > 0
end
end

def trim_mem(cfm)
Expand Down
9 changes: 9 additions & 0 deletions appcast.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@
<link>https://raw.githubusercontent.com/henderea/MemoryTamer/master/appcast.xml</link>
<description>Most recent changes with links to updates.</description>
<language>en</language>
<item>
<title>Version 0.9.3</title>
<sparkle:releaseNotesLink>
http://releases.io/henderea/MemoryTamer/0.9.3?heading=true
</sparkle:releaseNotesLink>
<pubDate>Wed, 30 Jul 2014 9:05:00 -0400</pubDate>
<enclosure url="http://memorytamer.s3.amazonaws.com/MemoryTamer-0.9.3.zip" sparkle:version="0.9.3" length="4569566" type="application/octet-stream" />
<sparkle:minimumSystemVersion>10.7</sparkle:minimumSystemVersion>
</item>
<item>
<title>Version 0.9.2</title>
<sparkle:releaseNotesLink>
Expand Down

0 comments on commit a65154e

Please sign in to comment.