Merge lp:~mbp/launchpad/884997-rusage into lp:launchpad

Proposed by Martin Pool
Status: Superseded
Proposed branch: lp:~mbp/launchpad/884997-rusage
Merge into: lp:launchpad
Diff against target: 77 lines (+26/-5)
2 files modified
lib/canonical/buildd/buildrecipe (+25/-4)
lib/canonical/buildd/sourcepackagerecipe.py (+1/-1)
To merge this branch: bzr merge lp:~mbp/launchpad/884997-rusage
Reviewer Review Type Date Requested Status
Launchpad code reviewers Pending
Review via email: mp+80970@code.launchpad.net

This proposal has been superseded by a proposal from 2011-11-02.

Description of the change

This makes buildrecipe log the rusage of bzr dailydeb which will let us see how close to the edge we are wrt memory.

It also fixes some confusing code whereby the argv[0] of buildrecipe is buildrecipe.py.

I have tested this manually by calling in to this code from a python shell. I would like to write an automatic test but it's a little bit hard because this is a script not a module, and I'm concerned that renaming it will break things in the complicated deployment process.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/canonical/buildd/buildrecipe'
2--- lib/canonical/buildd/buildrecipe 2011-02-09 21:10:55 +0000
3+++ lib/canonical/buildd/buildrecipe 2011-11-02 01:23:28 +0000
4@@ -1,5 +1,5 @@
5-#!/usr/bin/env python
6-# Copyright 2010 Canonical Ltd. This software is licensed under the
7+#! /usr/bin/env python -u
8+# Copyright 2010, 2011 Canonical Ltd. This software is licensed under the
9 # GNU Affero General Public License version 3 (see the file LICENSE).
10
11 """A script that builds a package from a recipe and a chroot."""
12@@ -12,7 +12,10 @@
13 import pwd
14 from resource import RLIMIT_AS, setrlimit
15 import socket
16-from subprocess import call
17+from subprocess import (
18+ Popen,
19+ call,
20+ )
21 import sys
22
23
24@@ -30,6 +33,20 @@
25 Exception.__init__(self, 'Not running under Xen.')
26
27
28+def call_report_rusage(args):
29+ """Run a subprocess.
30+
31+ Report that it was run, and the resources used, and complain if it fails.
32+
33+ :return: The process wait status.
34+ """
35+ print 'RUN %r' % args
36+ proc = Popen(args)
37+ pid, status, rusage = os.wait4(proc.pid, 0)
38+ print(rusage)
39+ return status
40+
41+
42 class RecipeBuilder:
43 """Builds a package from a recipe."""
44
45@@ -92,6 +109,10 @@
46 hostname = socket.gethostname()
47 bzr_email = 'buildd@%s' % hostname
48
49+ print 'Bazaar versions:'
50+ check_call(['bzr', 'version'])
51+ check_call(['bzr', 'plugins'])
52+
53 print 'Building recipe:'
54 print recipe
55 sys.stdout.flush()
56@@ -99,7 +120,7 @@
57 'DEBEMAIL': self.author_email,
58 'DEBFULLNAME': self.author_name.encode('utf-8'),
59 'BZR_EMAIL': bzr_email}
60- retcode = call([
61+ retcode = call_report_rusage([
62 'bzr', 'dailydeb', '--safe', '--no-build', recipe_path,
63 self.tree_path, '--manifest', manifest_path,
64 '--append-version', '~%s1' % self.distroseries_name], env=env)
65
66=== modified file 'lib/canonical/buildd/sourcepackagerecipe.py'
67--- lib/canonical/buildd/sourcepackagerecipe.py 2010-06-30 16:07:47 +0000
68+++ lib/canonical/buildd/sourcepackagerecipe.py 2011-11-02 01:23:28 +0000
69@@ -86,7 +86,7 @@
70 recipe_path = get_chroot_path(self._buildid, 'work/recipe')
71 splat_file(recipe_path, self.recipe_text)
72 args = [
73- "buildrecipe.py", self._buildid, self.author_name.encode('utf-8'),
74+ "buildrecipe", self._buildid, self.author_name.encode('utf-8'),
75 self.author_email, self.suite, self.distroseries_name,
76 self.component, self.archive_purpose]
77 self.runSubProcess(self.build_recipe_path, args)