def test_100_sort_calls(self):
     result = get_pstats_print2list(self.fstats_fib,
                                    sort='calls',
                                    exclude_fnames=['>', 'profile'])
     self.assertEqual(len(result), 2)
     self.assertEqual(os.path.basename(result[0]['file']), 'fib.py')
     self.assertEqual(os.path.basename(result[1]['file']), 'fib_seq.py')
 def test_020_filter(self):
     result = get_pstats_print2list(self.fstats_fib,
                                    filter_fnames='seq',
                                    exclude_fnames=None,
                                    limit=None)
     self.assertEqual(len(result), 1)
     self.assertEqual(os.path.basename(result[0]['file']), 'fib_seq.py')
 def test_110_sort_calls_reverse(self):
     result = get_pstats_print2list(
         self.fstats_fib, sort='calls', sort_reverse=True,
         exclude_fnames=['>', 'profile'])
     self.assertEqual(len(result), 2)
     self.assertEqual(os.path.basename(result[0]['file']), 'fib_seq.py')
     self.assertEqual(os.path.basename(result[1]['file']), 'fib.py')
 def test_030_exclude(self):
     result = get_pstats_print2list(self.fstats_fib,
                                    filter_fnames=None,
                                    exclude_fnames=['seq', '>', 'profile'],
                                    limit=None)
     self.assertEqual(len(result), 1)
     self.assertEqual(os.path.basename(result[0]['file']), 'fib.py')
 def test_080_fnovalid(self):
     fname = self.get_fname_stats('_novalid')
     Profile().dump_stats(fname)
     result = get_pstats_print2list(
         fname,
         filter_fnames=[], exclude_fnames=None, limit=None)
     self.assertFalse(result)
 def test_090_sort_cumulative(self):
     result = get_pstats_print2list(
         self.fstats_fib, sort='cumulative',
         exclude_fnames=['>', 'profile'])
     self.assertEqual(len(result), 2)
     self.assertEqual(os.path.basename(result[0]['file']), 'fib_seq.py')
     self.assertEqual(os.path.basename(result[1]['file']), 'fib.py')
 def test_080_fnovalid(self):
     fname = self.get_fname_stats('_novalid')
     Profile().dump_stats(fname)
     result = get_pstats_print2list(fname,
                                    filter_fnames=[],
                                    exclude_fnames=None,
                                    limit=None)
     self.assertFalse(result)
 def test_070_fempty(self):
     fname = self.get_fname_stats('_empty')
     fobj = open(fname, "w")
     result = get_pstats_print2list(
         fname,
         filter_fnames=[], exclude_fnames=None, limit=None)
     fobj.close()
     self.assertFalse(result)
 def test_120_sort_cumulative_reverse(self):
     result = get_pstats_print2list(self.fstats_fib,
                                    sort='cumulative',
                                    sort_reverse=True,
                                    exclude_fnames=['>', 'profile'])
     self.assertEqual(len(result), 2)
     self.assertEqual(os.path.basename(result[0]['file']), 'fib.py')
     self.assertEqual(os.path.basename(result[1]['file']), 'fib_seq.py')
 def test_070_fempty(self):
     fname = self.get_fname_stats('_empty')
     fobj = open(fname, "w")
     result = get_pstats_print2list(fname,
                                    filter_fnames=[],
                                    exclude_fnames=None,
                                    limit=None)
     fobj.close()
     self.assertFalse(result)
示例#11
0
    def dump(self, token, **post):
        """Provide the stats as a file download.

        Uses a temporary file, because apparently there's no API to
        dump stats in a stream directly.
        """
        exclude_fname = self.get_exclude_fname()
        with tools.osutil.tempdir() as dump_dir:
            ts = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
            filename = 'openerp_%s' % ts
            stats_path = os.path.join(dump_dir, '%s.stats' % filename)
            core.profile.dump_stats(stats_path)
            _logger.info("Pstats Command:")
            params = {
                'fnames': stats_path,
                'sort': 'cumulative',
                'limit': 45,
                'exclude_fnames': exclude_fname
            }
            _logger.info(
                "fnames=%(fnames)s, sort=%(sort)s,"
                " limit=%(limit)s, exclude_fnames=%(exclude_fnames)s", params)
            pstats_list = get_pstats_print2list(**params)
            with Capturing() as output:
                print_pstats_list(pstats_list)
            result_path = os.path.join(dump_dir, '%s.txt' % filename)
            with open(result_path, "a") as res_file:
                for line in output:
                    res_file.write('%s\n' % line)
            # PG_BADGER
            self.dump_pgbadger(dump_dir, 'pgbadger_output.txt', request.cr)
            t_zip = tempfile.TemporaryFile()
            tools.osutil.zip_dir(dump_dir, t_zip, include_dir=False)
            t_zip.seek(0)
            headers = [('Content-Type',
                        'application/octet-stream; charset=binary'),
                       ('Content-Disposition',
                        content_disposition('%s.zip' % filename))]
            _logger.info('Download Profiler zip: %s', t_zip.name)
            return request.make_response(t_zip,
                                         headers=headers,
                                         cookies={'fileToken': token})
 def test_130_multifiles(self):
     result_onefile = get_pstats_print2list(self.fstats_fib)
     result_multifiles = get_pstats_print2list(self.fstats_fib_list)
     self.assertEqual(result_onefile, result_multifiles)
示例#13
0
import sys
import pstats_print2list
from pstats_print2list import print_pstats_list
# print "Method docstring", pstats_print2list.get_pstats_print2list.__doc__
fname = sys.argv[1]
pstats_list = pstats_print2list.get_pstats_print2list([fname], filter_fnames=['/root/'], exclude_fnames=['/root/odoo-8.0'])
print_pstats_list(pstats_list)
 def test_150_print_empty_list(self):
     pstats_list = get_pstats_print2list(self.fstats_fib, 'without_files')
     self.assertEqual(pstats_list, [])
     self.assertFalse(print_pstats_list(pstats_list))
 def test_010_limit(self):
     result = get_pstats_print2list(self.fstats_fib,
                                    filter_fnames=None,
                                    exclude_fnames=None,
                                    limit=1)
     self.assertEqual(len(result), 1)
 def test_130_multifiles(self):
     result_onefile = get_pstats_print2list(self.fstats_fib)
     result_multifiles = get_pstats_print2list(self.fstats_fib_list)
     self.assertEqual(result_onefile, result_multifiles)
 def test_140_print_list(self):
     pstats_list = get_pstats_print2list(self.fstats_fib)
     print("\n")
     self.assertTrue(print_pstats_list(pstats_list))
 def test_030_exclude(self):
     result = get_pstats_print2list(
         self.fstats_fib, filter_fnames=None,
         exclude_fnames=['seq', '>', 'profile'], limit=None)
     self.assertEqual(len(result), 1)
     self.assertEqual(os.path.basename(result[0]['file']), 'fib.py')
 def test_060_wo_filter_fnames(self):
     result = get_pstats_print2list(
         self.fstats_fib,
         filter_fnames=[], exclude_fnames=None, limit=None)
     self.assertEqual(len(result), 4)
示例#20
0
#!/usr/bin/python
import sys
from pstats_print2list import get_pstats_print2list, print_pstats_list
fname_stats = sys.argv[1]
pstats_list = get_pstats_print2list(
    fname_stats,
    filter_fnames=['myfile1.py', 'myfile2.py', 'root_path1'],
    exclude_fnames=['dontshow.py', 'path_dont_show'],
    sort='cumulative',
    limit=5,
)
print_pstats_list(pstats_list)
 def test_060_wo_filter_fnames(self):
     result = get_pstats_print2list(self.fstats_fib,
                                    filter_fnames=[],
                                    exclude_fnames=None,
                                    limit=None)
     self.assertEqual(len(result), 4)
 def test_150_print_empty_list(self):
     pstats_list = get_pstats_print2list(self.fstats_fib, 'without_files')
     self.assertEqual(pstats_list, [])
     self.assertFalse(print_pstats_list(pstats_list))
 def test_040_none(self):
     result = get_pstats_print2list(
         self.fstats_fib, exclude_fnames=['>', 'profile'])
     self.assertEqual(len(result), 2)
 def test_060_fnonexistent(self):
     result = get_pstats_print2list(
         '/tmp/nonexistent.stats',
         filter_fnames=[], exclude_fnames=None, limit=None)
     self.assertFalse(result)
 def test_040_none(self):
     result = get_pstats_print2list(self.fstats_fib,
                                    exclude_fnames=['>', 'profile'])
     self.assertEqual(len(result), 2)
 def test_020_filter(self):
     result = get_pstats_print2list(
         self.fstats_fib,
         filter_fnames='seq', exclude_fnames=None, limit=None)
     self.assertEqual(len(result), 1)
     self.assertEqual(os.path.basename(result[0]['file']), 'fib_seq.py')
 def test_050_filter_exclude(self):
     result = get_pstats_print2list(self.fstats_fib,
                                    filter_fnames='seq',
                                    exclude_fnames='fib',
                                    limit=None)
     self.assertEqual(len(result), 0)
 def test_050_filter_exclude(self):
     result = get_pstats_print2list(
         self.fstats_fib,
         filter_fnames='seq', exclude_fnames='fib', limit=None)
     self.assertEqual(len(result), 0)
 def test_060_fnonexistent(self):
     result = get_pstats_print2list('/tmp/nonexistent.stats',
                                    filter_fnames=[],
                                    exclude_fnames=None,
                                    limit=None)
     self.assertFalse(result)
 def test_140_print_list(self):
     pstats_list = get_pstats_print2list(self.fstats_fib)
     print("\n")
     self.assertTrue(print_pstats_list(pstats_list))
示例#31
0
import sys
import pstats_print2list
from pstats_print2list import print_pstats_list
# print "Method docstring", pstats_print2list.get_pstats_print2list.__doc__
fname = sys.argv[1]
pstats_list = pstats_print2list.get_pstats_print2list(
    [fname], filter_fnames=['/root/'], exclude_fnames=['/root/odoo-8.0'])
print_pstats_list(pstats_list)
 def test_010_limit(self):
     result = get_pstats_print2list(
         self.fstats_fib, filter_fnames=None, exclude_fnames=None, limit=1)
     self.assertEqual(len(result), 1)