Skip to content

Commit

Permalink
Make some changes to auto-threshold to hopefully improve it.
Browse files Browse the repository at this point in the history
  • Loading branch information
henderea committed Jul 29, 2014
1 parent de33a8e commit 42aee49
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 24 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <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>

###Versions (code-signed with developer ID):
* **v0.3:** <http://memorytamer.s3.amazonaws.com/MemoryTamer-0.3.zip> (Mavericks-only)
Expand All @@ -54,3 +55,4 @@ A RubyMotion application for keeping memory usage in check. Shows up in the men
* **v0.8.1:** <https://memorytamer.s3.amazonaws.com/MemoryTamer-0.8.1.zip>
* **v0.8.2:** <https://memorytamer.s3.amazonaws.com/MemoryTamer-0.8.2.zip>
* **v0.9:** <https://memorytamer.s3.amazonaws.com/MemoryTamer-0.9.zip>
* **v0.9.1:** <https://memorytamer.s3.amazonaws.com/MemoryTamer-0.9.1.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'
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'
Expand Down
50 changes: 28 additions & 22 deletions app/app_delegate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,36 +109,42 @@ 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)
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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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}'`
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.1</title>
<sparkle:releaseNotesLink>
http://releases.io/henderea/MemoryTamer/0.9.1?heading=true
</sparkle:releaseNotesLink>
<pubDate>Tue, 29 Jul 2014 16:20:00 -0400</pubDate>
<enclosure url="http://memorytamer.s3.amazonaws.com/MemoryTamer-0.9.1.zip" sparkle:version="0.9.1" length="4571160" type="application/octet-stream" />
<sparkle:minimumSystemVersion>10.7</sparkle:minimumSystemVersion>
</item>
<item>
<title>Version 0.9</title>
<sparkle:releaseNotesLink>
Expand Down

0 comments on commit 42aee49

Please sign in to comment.