2 # (Be in -*- python -*- mode.)
4 # ====================================================================
5 # Copyright (c) 2000-2008 CollabNet. All rights reserved.
7 # This software is licensed as described in the file COPYING, which
8 # you should have received as part of this distribution. The terms
9 # are also available at http://subversion.tigris.org/license-1.html.
10 # If newer versions of this license are posted there, you may use a
11 # newer version instead, at your option.
13 # This software consists of voluntary contributions made by many
14 # individuals. For exact contribution history, see the revision
15 # history and logs, available at http://cvs2svn.tigris.org/.
16 # ====================================================================
18 """Run cvs2svn, but logging memory usage.
20 Memory use is logged every MemoryLogger.interval seconds. This script
21 takes the same parameters as cvs2svn.
23 Memory use is determined by reading from the /proc filesystem. This
24 method is not very portable, but should hopefully work on a typical
31 # Make sure that a supported version of Python is being used. Do this
32 # as early as possible, using only code compatible with Python 1.5.2
33 # and Python 3.x before the check.
34 if not (0x02040000 <= sys
.hexversion
< 0x03000000):
35 sys
.stderr
.write("ERROR: Python 2, version 2.4 or higher required.\n")
38 sys
.path
.insert(0, os
.path
.dirname(os
.path
.dirname(sys
.argv
[0])))
45 from cvs2svn_lib
.common
import FatalException
46 from cvs2svn_lib
.log
import Log
47 from cvs2svn_lib
.main
import main
50 usage
= '%prog [--interval=VALUE] [--help|-h] -- CVS2SVN-ARGS'
53 Run cvs2svn while logging its memory usage. ('--' is required to
54 separate %(progname)s options from the options and arguments that will
55 be passed through to cvs2svn.)
59 rss_re
= re
.compile(r
'^VmRSS\:\s+(?P<mem>.*)$')
61 def get_memory_used():
62 filename
= '/proc/%d/status' % (os
.getpid(),)
63 for l
in open(filename
).readlines():
72 class MemoryLogger(threading
.Thread
):
73 def __init__(self
, interval
):
74 threading
.Thread
.__init
__(self
)
76 self
.start_time
= time
.time()
77 self
.interval
= interval
82 delay
= self
.start_time
+ self
.interval
* i
- time
.time()
85 Log().write('Memory used: %s' % (get_memory_used(),))
89 parser
= optparse
.OptionParser(usage
=usage
, description
=description
)
90 parser
.set_defaults(interval
=1.0)
93 action
='store', type='float',
94 help='the time in seconds between memory logs',
97 (options
, args
) = parser
.parse_args()
99 MemoryLogger(interval
=options
.interval
).start()
102 main(sys
.argv
[0], args
)
103 except FatalException
, e
:
104 sys
.stderr
.write(str(e
) + '\n')