This file is indexed.

/usr/share/pyshared/mvpa/tests/runner.py is in python-mvpa 0.4.8-3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

 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
82
83
84
85
86
87
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
#
#   See COPYING file distributed along with the PyMVPA package for the
#   copyright and license terms.
#
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
"""Helper module to enable profiling of the testcase

 If environment variable PROFILELEVEL is set it uses hotshot profiler
 for unittest.main() call. Value of PROFILELEVEL defines number of top
 busy functions to report.

 Environment variable PROFILELINES=1 makes hotshot store information
 per each line, so it could be easily inspected later on.

 Output:
   Profiler stores its Stats into a file named after original script
   (sys.argv[0]) with suffix".prof" appended

 Usage:
   Replace unittest.main() with import runner

 Visualization:
   kcachegrind provides nice interactive GUI to inspect profiler
   results. If PROFILELINES was set to 1, it provides information per
   each line.

   To convert .prof file into a file suitable for kcachegrind, use
   utility hotshot2calltree which comes in package
   kcachegrind-converters.

 Example:

 # profile and output 3 most expensive function calls
 PROFILELEVEL=3 PROFILELINES=1 PYTHONPATH=../ python test_searchlight.py
 # convert to kcachegrind format
 hotshot2calltree -o test_searchlight.py.kcache  test_searchlight.py.prof
 # inspect
 kcachegrind test_searchlight.py.kcache

"""

import unittest
import sys

from os import environ

from mvpa import _random_seed
profilelevel = None

if environ.has_key('PROFILELEVEL'):
    profilelevel = int(environ['PROFILELEVEL'])

# Extend TestProgram to print out the seed which was used
class TestProgramPyMVPA(unittest.TestProgram):
    def runTests(self):
        if self.verbosity:
            print "MVPA_SEED=%s:" % _random_seed,
            sys.stdout.flush()
        super(TestProgramPyMVPA, self).runTests()

if profilelevel is None:
    TestProgramPyMVPA()
else:
    profilelines = environ.has_key('PROFILELINES')

    import hotshot, hotshot.stats
    pname = "%s.prof" % sys.argv[0]
    prof = hotshot.Profile(pname, lineevents=profilelines)
    try:
        # actually return values are never setup
        # since unittest.main sys.exit's
        benchtime, stones = prof.runcall( unittest.main )
    except SystemExit:
        pass
    print "Saving profile data into %s" % pname
    prof.close()
    if profilelevel > 0:
        # we wanted to see the summary right here
        # instead of just storing it into a file
        print "Loading profile data from %s" % pname
        stats = hotshot.stats.load(pname)
        stats.strip_dirs()
        stats.sort_stats('time', 'calls')
        stats.print_stats(profilelevel)