How to use snakeviz - 10 common examples

To help you get started, we’ve selected a few snakeviz examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jiffyclub / snakeviz / tests / test_snakeviz.py View on Github external
def test_version():
    vcall = sp.Popen(
        ['snakeviz', '--version'], stdout=sp.PIPE, stderr=sp.PIPE)
    out, err = vcall.communicate()
    # in Python <= 3.3 this comes out on stderr, otherwise on stdout
    assert version.version in out.decode('utf-8') or \
        version.version in err.decode('utf-8')
github jiffyclub / snakeviz / tests / test_snakeviz.py View on Github external
def test_version():
    vcall = sp.Popen(
        ['snakeviz', '--version'], stdout=sp.PIPE, stderr=sp.PIPE)
    out, err = vcall.communicate()
    # in Python <= 3.3 this comes out on stderr, otherwise on stdout
    assert version.version in out.decode('utf-8') or \
        version.version in err.decode('utf-8')
github jiffyclub / snakeviz / snakeviz / pstatsloader.py View on Github external
self.location_rows = self.rows.copy()
        for child in self.rows.values():
            current = directories.get( child.directory )
            directory, filename = child.directory, child.filename
            if current is None:
                if directory == '':
                    current = root
                else:
                    current = PStatLocation( directory, '' )
                    self.location_rows[ current.key ] = current
                directories[ directory ] = current
            if filename == '~':
                filename = ''
            file_current = files.get( (directory,filename) )
            if file_current is None:
                file_current = PStatLocation( directory, filename )
                self.location_rows[ file_current.key ] = file_current
                files[ (directory,filename) ] = file_current
                current.children.append( file_current )
            file_current.children.append( child )
        # now link the directories...
        for key,value in directories.items():
            if value is root:
                continue
            found = False
            while key:
                new_key,rest = os.path.split( key )
                if new_key == key:
                    break
                key = new_key
                parent = directories.get( key )
                if parent:
github inpho / topic-explorer / topicexplorer / __main__.py View on Github external
benchmark(metadata.main)(args)
    
    elif args.func == 'export':
        benchmark(export.main)(args)

    elif args.func == 'export-html':
        benchmark(export_html.main)(args)

    elif args.func == 'import':
        benchmark(tezimport.main)(args)

    if args.profile:
        try:
            import snakeviz.cli
            print("\n\n")
            snakeviz.cli.main([args.profile])
        except ImportError:
            print("""\nSnakeviz is not installed. Install with `pip install snakeviz`,
            then run `snakeviz {}`.""".format(args.profile))
    
    if platform.system() == 'Windows':
        win_unicode_console.disable()
github jiffyclub / snakeviz / snakeviz / __main__.py View on Github external
import sys
from .cli import main

if __name__ == "__main__":
    # __main__.py is ugly and confusing, monkey patch executable to say snakeviz
    sys.argv[0] = "snakeviz"
    sys.exit(main())
github jiffyclub / snakeviz / snakeviz / pstatsloader.py View on Github external
def load_location( self ):
        """Build a squaremap-compatible model for location-based hierarchy"""
        directories = {}
        files = {}
        root = PStatLocation( '/', 'PYTHONPATH' )
        self.location_rows = self.rows.copy()
        for child in self.rows.values():
            current = directories.get( child.directory )
            directory, filename = child.directory, child.filename
            if current is None:
                if directory == '':
                    current = root
                else:
                    current = PStatLocation( directory, '' )
                    self.location_rows[ current.key ] = current
                directories[ directory ] = current
            if filename == '~':
                filename = ''
            file_current = files.get( (directory,filename) )
            if file_current is None:
                file_current = PStatLocation( directory, filename )
github jiffyclub / snakeviz / snakeviz / pstatsloader.py View on Github external
def load_location( self ):
        """Build a squaremap-compatible model for location-based hierarchy"""
        directories = {}
        files = {}
        root = PStatLocation( '/', 'PYTHONPATH' )
        self.location_rows = self.rows.copy()
        for child in self.rows.values():
            current = directories.get( child.directory )
            directory, filename = child.directory, child.filename
            if current is None:
                if directory == '':
                    current = root
                else:
                    current = PStatLocation( directory, '' )
                    self.location_rows[ current.key ] = current
                directories[ directory ] = current
            if filename == '~':
                filename = ''
            file_current = files.get( (directory,filename) )
            if file_current is None:
                file_current = PStatLocation( directory, filename )
                self.location_rows[ file_current.key ] = file_current
                files[ (directory,filename) ] = file_current
                current.children.append( file_current )
            file_current.children.append( child )
        # now link the directories...
        for key,value in directories.items():
            if value is root:
                continue
            found = False
github jiffyclub / snakeviz / snakeviz / pstatsloader.py View on Github external
def __init__( self, directory, filename, tree=TREE_FILES):
        super( PStatLocation, self ).__init__( directory=directory, filename=filename, name='package', tree=tree )
    def filter_children( self ):
github jiffyclub / snakeviz / snakeviz / upload.py View on Github external
tree_dict : dict
        Tree of nested dictionaries representing the profile call tree.

    """
    # recursive_seen prevents us from repeatedly traversing
    # recursive structures. only want to show the first set.
    if recursive_seen is None:
        recursive_seen = set()

    d = {}

    d['name'] = node.name
    d['filename'] = node.filename
    d['directory'] = node.directory

    if isinstance(node, pstatsloader.PStatRow):
        d['calls'] = node.calls
        d['recursive'] = node.recursive
        d['local'] = node.local
        d['localPer'] = node.localPer
        d['cumulative'] = node.cummulative
        d['cumulativePer'] = node.cummulativePer
        d['line_number'] = node.lineno

        recursive_seen.add(node)

    if parent:
        # figure out the size of this node. This is an arbitrary value
        # but it's important that the child size is no larger
        # than the parent size.
        if isinstance(parent, pstatsloader.PStatGroup):
            if parent.cummulative:
github jiffyclub / snakeviz / snakeviz / upload.py View on Github external
def prof_to_json(prof_name):
    """
    Convert profiles stats in a `pstats` compatible file to a JSON string.

    Parameters
    ----------
    prof_name : str
        Path to to a `pstats` compatible profile.

    Returns
    -------
    json_stats : str
        Profile as a JSON string.

    """
    loader = pstatsloader.PStatsLoader(prof_name)

    d = _stats_to_tree_dict(loader.tree.children[0])

    return json.dumps(d, indent=1)