Merge lp:~mterry/deja-dup/more-idle into lp:deja-dup/26

Proposed by Michael Terry
Status: Merged
Merged at revision: 1444
Proposed branch: lp:~mterry/deja-dup/more-idle
Merge into: lp:deja-dup/26
Diff against target: 153 lines (+82/-22)
3 files modified
common/CommonUtils.vala (+46/-5)
tests/unit/unit-tests.vala (+33/-0)
tools/duplicity/DuplicityPlugin.vala (+3/-17)
To merge this branch: bzr merge lp:~mterry/deja-dup/more-idle
Reviewer Review Type Date Requested Status
Robert Bruce Park (community) Approve
Review via email: mp+154725@code.launchpad.net

Description of the change

Newer versions of Linux support more aggressively idle states for processes.

In particular, non-root users can call "ionice -c3" in linux 2.6.25 and up. And "chrt --idle 0" is available in linux 2.6.23 and up.

So, we might as well use them, to reduce the strain of a backup on the system. Ideally the user never notices.

To post a comment you must log in.
Revision history for this message
Robert Bruce Park (robru) wrote :

Simple diff, good code-reuse, tests are passing, I like it ;-)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'common/CommonUtils.vala'
2--- common/CommonUtils.vala 2013-03-14 20:40:57 +0000
3+++ common/CommonUtils.vala 2013-03-21 15:10:02 +0000
4@@ -72,20 +72,61 @@
5 settings.apply();
6 }
7
8+public bool parse_version(string version_string, out int major, out int minor,
9+ out int micro)
10+{
11+ major = 0;
12+ minor = 0;
13+ micro = 0;
14+
15+ var ver_tokens = version_string.split(".");
16+ if (ver_tokens == null || ver_tokens[0] == null)
17+ return false;
18+
19+ major = int.parse(ver_tokens[0]);
20+ // Don't error out if no minor or micro.
21+ if (ver_tokens[1] != null) {
22+ minor = int.parse(ver_tokens[1]);
23+ if (ver_tokens[2] != null)
24+ micro = int.parse(ver_tokens[2]);
25+ }
26+
27+ return true;
28+}
29+
30+public bool meets_version(int major, int minor, int micro,
31+ int req_major, int req_minor, int req_micro)
32+{
33+ return (major > req_major) ||
34+ (major == req_major && minor > req_minor) ||
35+ (major == req_major && minor == req_minor && micro >= req_micro);
36+}
37+
38 public void run_deja_dup(string args, AppLaunchContext? ctx = null,
39 List<File>? files = null)
40 {
41 var cmd = "deja-dup %s".printf(args);
42
43+ int major, minor, micro;
44+ var utsname = Posix.utsname();
45+ parse_version(utsname.release, out major, out minor, out micro);
46+
47 // Check for ionice to be a good disk citizen
48 if (Environment.find_program_in_path("ionice") != null) {
49- // lowest priority in best-effort class
50- // (can't use idle class as normal user on <2.6.25)
51- cmd = "ionice -c2 -n7 " + cmd;
52+ // In Linux 2.6.25 and up, even normal users can request idle class
53+ if (utsname.sysname == "Linux" && meets_version(major, minor, micro, 2, 6, 25))
54+ cmd = "ionice -c3 " + cmd; // idle class
55+ else
56+ cmd = "ionice -c2 -n7 " + cmd; // lowest priority in best-effort class
57 }
58
59- if (Environment.find_program_in_path("nice") != null)
60- cmd = "nice " + cmd;
61+ // chrt's idle class is more-idle than nice, so prefer it
62+ if (utsname.sysname == "Linux" &&
63+ meets_version(major, minor, micro, 2, 6, 23) &&
64+ Environment.find_program_in_path("chrt") != null)
65+ cmd = "chrt --idle 0 " + cmd;
66+ else if (Environment.find_program_in_path("nice") != null)
67+ cmd = "nice -n19 " + cmd;
68
69 var flags = AppInfoCreateFlags.SUPPORTS_STARTUP_NOTIFICATION |
70 AppInfoCreateFlags.SUPPORTS_URIS;
71
72=== modified file 'tests/unit/unit-tests.vala'
73--- tests/unit/unit-tests.vala 2012-12-04 16:08:06 +0000
74+++ tests/unit/unit-tests.vala 2013-03-21 15:10:02 +0000
75@@ -46,6 +46,38 @@
76 assert(DejaDup.parse_dir("file:VIDEOS").equal(File.parse_name("file:VIDEOS")));
77 }
78
79+void parse_one_version(string str, int maj, int min, int mic)
80+{
81+ int pmaj, pmin, pmic;
82+ assert(DejaDup.parse_version(str, out pmaj, out pmin, out pmic));
83+ assert(pmaj == maj);
84+ assert(pmin == min);
85+ assert(pmic == mic);
86+}
87+
88+void parse_bad_version(string str)
89+{
90+ int pmaj, pmin, pmic;
91+ assert(!DejaDup.parse_version(str, out pmaj, out pmin, out pmic));
92+ assert(pmaj == 0);
93+ assert(pmin == 0);
94+ assert(pmic == 0);
95+}
96+
97+void parse_version()
98+{
99+ parse_bad_version("");
100+ parse_one_version("a", 0, 0, 0);
101+ parse_one_version("1", 1, 0, 0);
102+ parse_one_version("1.2", 1, 2, 0);
103+ parse_one_version("1.2.3", 1, 2, 3);
104+ parse_one_version("1.2.3.4", 1, 2, 3);
105+ parse_one_version("1.2.3a4", 1, 2, 3);
106+ parse_one_version("1.2a3.4", 1, 2, 4);
107+ parse_one_version("1.2 3.4", 1, 2, 4);
108+ parse_one_version("1.2-3.4", 1, 2, 4);
109+}
110+
111 void setup()
112 {
113 }
114@@ -64,6 +96,7 @@
115
116 var unit = new TestSuite("unit");
117 unit.add(new TestCase("parse-dir", setup, parse_dir, teardown));
118+ unit.add(new TestCase("parse-version", setup, parse_version, teardown));
119 TestSuite.get_root().add_suite(unit);
120
121 return Test.run();
122
123=== modified file 'tools/duplicity/DuplicityPlugin.vala'
124--- tools/duplicity/DuplicityPlugin.vala 2013-01-23 22:04:16 +0000
125+++ tools/duplicity/DuplicityPlugin.vala 2013-03-21 15:10:02 +0000
126@@ -42,25 +42,11 @@
127
128 // First token is 'duplicity' and is ignorable. Second looks like '0.5.03'
129 var version_string = tokens[1].strip();
130- var ver_tokens = version_string.split(".");
131- if (ver_tokens == null || ver_tokens[0] == null)
132+ int major, minor, micro;
133+ if (!DejaDup.parse_version(version_string, out major, out minor, out micro))
134 throw new SpawnError.FAILED(_("Could not understand duplicity version ‘%s’.").printf(version_string));
135
136- int major = 0;
137- int minor = 0;
138- int micro = 0;
139- major = int.parse(ver_tokens[0]);
140- // Don't error out if no minor or micro. Duplicity might not have them?
141- if (ver_tokens[1] != null) {
142- minor = int.parse(ver_tokens[1]);
143- if (ver_tokens[2] != null)
144- micro = int.parse(ver_tokens[2]);
145- }
146-
147- var meets = (major > REQUIRED_MAJOR) ||
148- (major == REQUIRED_MAJOR && minor > REQUIRED_MINOR) ||
149- (major == REQUIRED_MAJOR && minor == REQUIRED_MINOR && micro >= REQUIRED_MICRO);
150- if (!meets)
151+ if (!DejaDup.meets_version(major, minor, micro, REQUIRED_MAJOR, REQUIRED_MINOR, REQUIRED_MICRO))
152 throw new SpawnError.FAILED(_("Déjà Dup Backup Tool requires at least version %d.%d.%.2d of duplicity, but only found version %d.%d.%.2d").printf(REQUIRED_MAJOR, REQUIRED_MINOR, REQUIRED_MICRO, major, minor, micro));
153 }
154

Subscribers

People subscribed via source and target branches