conary / scripts / showprofile

#!/usr/bin/env python
# -*- mode: python -*-
# Copyright (c) 2004-2006 rPath, Inc.
# This program is distributed under the terms of the Common Public License,
# version 1.0. A copy of this license should have been distributed with this
# source file in a file called LICENSE. If it is not present, the license
# is always available at
# This program is distributed in the hope that it will be useful, but
# without any warranty; without even the implied warranty of merchantability
# or fitness for a particular purpose. See the Common Public License for
# full details.

import cPickle
import sys

def progress(msg):
    sys.stderr.write(msg + '\n')

def usage():
    print 'usage: %s profile [pickle output]'

if len(sys.argv) < 2 or len(sys.argv) > 3:

filename = sys.argv[1]
picklefilename = None
if len(sys.argv) == 3:
    picklefilename = sys.argv[2]

if filename.endswith('.pickle'):
    if picklefilename:
        print 'input file is pickled and an output pickle name is specified'
    f = open(filename)
    stats = cPickle.load(f)
    import pstats
    progress('loading %s' %filename)
    stats = pstats.Stats(filename)

if picklefilename:
    f = open(sys.argv[2], 'w')
    cPickle.dump(stats, f)
    stats.sort_stats('time', 'calls')
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.