summaryrefslogtreecommitdiffstats
path: root/abs/core-testing/tweaker/bin/twk_RAM.pl
blob: 2eea598c5bede61abac3d9c5d7b8fe0c76ea80e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/perl -w

# Copyright 2007-2009 Robert ("Bob") Igo of StormLogic, LLC and mythic.tv.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

use Switch;
use Tweaker::Script;
package Tweaker::Script;

set_known_options( 'low', 'medium', 'high' );

# ??? Need to make this update a class variable so it only ever needs to run once.
sub determine_RAM_size() {
    my $result = execute_shell_command("cat /proc/meminfo | grep MemTotal");
    if ($result =~ m/.*MemTotal:\s*(\d+) .*/) {
	return $1;
    }
    return 0;
}

# Try to implement the given option.
sub implement_option {
    my($option) = @_;

    $dbconnectionstring = get_mythtv_connection_string();
	
    if (connect_to_db("DBI:mysql:$dbconnectionstring")) {
	# MythTV's GUI allows setting this value in multiples of 4700kB.
	# We will arbitrarily set the HDRingbufferSize to the value that is closest to
	# 3.3% of the total RAM.
	my $RAM_size = determine_RAM_size();
	my $ringbuffer_size = int($RAM_size * 0.033 / 4700) * 4700;
	change_or_make_setting('HDRingbufferSize', $ringbuffer_size) || exit -1;

	# change any existing mplayer cache setting to one based on available RAM size
	# We will arbitrarily set the cache size to 1/16 of available RAM
	my $cachesize = int($RAM_size / 16);
	execute_shell_command("if [[ `grep -e cache.*=.*\$ /etc/mplayer/mplayer.conf` ]]; then sed -i 's/cache.*=.*/cache=$cachesize/g' /etc/mplayer/mplayer.conf; else echo 'cache=$cachesize' >> /etc/mplayer/mplayer.conf; fi") || exit -1;

	# If there's enough RAM, make mtd run by default.
	# ??? unimplemented
    } else {
	exit -1;
    }
    disconnect_from_db();
}

# Poll the system to see what recommendationlevel the given option has on the system.
sub poll_options {
    my($option) = @_;
    my $fudge_factor = .985;
    my $low_RAM = int($fudge_factor * 512*1024);     # ~512MB
    my $medium_RAM = int($fudge_factor * 1024*1024); # ~1GB
    my $high_RAM = int($fudge_factor * 2048*1024);   # ~2GB

    threshold_test($option, determine_RAM_size(), "RAM", $low_RAM, $medium_RAM, $high_RAM);
}

# Unimplemented in 0.7
sub check_option {
    help;
}

# Unimplemented in 0.7
sub count_iterations {
    help;
}

process_parameters;