def tree_stats_to_response(filename, response):
    stats = vmprof.read_profile(filename)

    response.tree_stats = TreeStats()
    response.tree_stats.sampling_interval = vmprof.DEFAULT_PERIOD

    try:
        tree = stats.get_tree()
    except vmprof.stats.EmptyProfileFile:
        tree = None

    def convert(parent, node):
        tstats = CallTreeStat()
        tstats.name = node.name
        tstats.count = node.count
        tstats.children = []

        if parent is not None:
            if parent.children is None:
                parent.children = []
            parent.children.append(tstats)

        return tstats

    response.tree_stats.call_tree = _walk_tree(None, tree, convert)
Beispiel #2
0
    def test(self):
        # XXX: this test is known to fail since rev a4f077ba651c, but buildbot
        # never ran it. FIXME.
        from vmprof import read_profile
        from vmprof.show import PrettyPrinter
        assert self.rpy_entry_point(3, 0.5) == 42000
        assert self.tmpfile.check()
        #
        prof = read_profile(self.tmpfilename)
        tree = prof.get_tree()
        p = PrettyPrinter()
        p._print_tree(tree)

        def walk(tree, symbols):
            symbols.append(tree.name)
            if len(tree.children) == 0:
                return
            for child in tree.children.values():
                walk(child, symbols)

        symbols = []
        walk(tree, symbols)
        not_found = ['n:native_func']
        for sym in symbols:
            for i, name in enumerate(not_found):
                if sym.startswith(name):
                    del not_found[i]
                    break
        assert not_found == []
Beispiel #3
0
 def test_mem(self):
     from vmprof import read_profile
     assert self.rpy_entry_point(10**4, 0.5, 1) == 99990000
     assert self.tmpfile.check()
     prof = read_profile(self.tmpfilename)
     assert prof.profile_memory
     assert all(p[-1] > 0 for p in prof.profiles)
Beispiel #4
0
def test_read_simple():
    lib_cache = get_or_write_libcache('simple_nested.pypy.prof')
    path = py.path.local(__file__).join('..', 'simple_nested.pypy.prof')
    stats = vmprof.read_profile(path, virtual_only=True,
                                include_extra_info=True, lib_cache=lib_cache)
    tree = stats.get_tree()
    main_name = 'py:<module>:2:foo.py'
    foo_name = 'py:foo:6:foo.py'
    bar_name = 'py:bar:2:foo.py'
    assert tree['foo'].name == foo_name
    assert tree['foo'].meta['jit'] == 120
    assert tree['foo']['bar'].name == bar_name
    assert tree['foo']['bar'].meta['jit'] == 101
    assert tree['foo']['bar'].jitcodes == {140523638277712: 101, 140523638275600: 27, 140523638276656: 12}
    assert tree['foo'].jitcodes == {140523638277712: 19}
    assert not tree['foo']['bar'].children
    assert tree['foo']['bar'].meta['gc:minor'] == 2
    data = json.loads(tree.as_json())
    main_addr = str(tree.addr)
    foo_addr = str(tree['foo'].addr)
    bar_addr = str(tree['foo']['bar'].addr)
    expected = [main_name, main_addr, 120, {}, [
        [foo_name, foo_addr, 120, {'jit': 120, 'gc:minor': 2}, [
            [bar_name, bar_addr, 101, {'gc:minor': 2, 'jit': 101}, []]]]]]
    assert data == expected
Beispiel #5
0
    def test(self):
        from vmprof import read_profile
        # from vmprof.show import PrettyPrinter
        assert self.rpy_entry_point(3, 0.5) == 42000
        assert self.tmpfile.check()

        prof = read_profile(self.tmpfilename)
        tree = prof.get_tree()

        # p = PrettyPrinter()
        # p._print_tree(tree)
        def walk(tree, symbols):
            symbols.append(tree.name)
            if len(tree.children) == 0:
                return
            for child in tree.children.values():
                walk(child, symbols)

        symbols = []
        walk(tree, symbols)
        not_found = ['py:code:7:native_func']
        for sym in symbols:
            for i, name in enumerate(not_found):
                if sym.startswith(name):
                    del not_found[i]
                    break
        assert not_found == []
Beispiel #6
0
 def test_wsgi_tree(self):
     prof = read_profile(str(py.path.local(__file__).join(
         '..', 'wsgi.prof')))
     tree = prof.get_tree()
     assert repr(tree) == '<Node: py:__call__:162:/vmprof/vmprof-test/.env/local/lib/python2.7/site-packages/django/core/handlers/wsgi.py (367) [(367, py:get_response:94:/vmprof/vmprof-test/.env/local/lib/python2.7/site-packages/django/core/handlers/base.py)]>'
     values = list(tree.children.values())
     assert repr(values[0]) == '<Node: py:get_response:94:/vmprof/vmprof-test/.env/local/lib/python2.7/site-packages/django/core/handlers/base.py (367) [(365, py:index:23:/vmprof/vmprof-test/app/main.py), (2, py:resolve:360:/vmprof/vmprof-test/.env/local/lib/python2.7/site-packages/django/core/urlresolvers.py)]>'
Beispiel #7
0
def test_read_simple():
    py.test.skip("think later")
    lib_cache = get_or_write_libcache('simple_nested.pypy.prof')
    path = py.path.local(__file__).join('..', 'simple_nested.pypy.prof')
    stats = vmprof.read_profile(path, virtual_only=True,
                                include_extra_info=True, lib_cache=lib_cache)
    tree = stats.get_tree()
    main_name = 'py:<module>:2:foo.py'
    foo_name = 'py:foo:6:foo.py'
    bar_name = 'py:bar:2:foo.py'
    assert tree['foo'].name == foo_name
    assert tree['foo'].meta['jit'] == 19
    assert tree['foo']['bar'].name == bar_name
    assert tree['foo']['bar'].meta['jit'] == 101
    assert tree['foo'].jitcodes == {140523638277712: 120}
    assert tree['foo']['bar'].jitcodes == {140523638275600: 27,
                                           140523638276656: 3}
    assert not tree['foo']['bar'].children
    assert tree['foo']['bar'].meta['gc:minor'] == 2
    data = json.loads(tree.as_json())
    main_addr = str(tree.addr)
    foo_addr = str(tree['foo'].addr)
    bar_addr = str(tree['foo']['bar'].addr)
    expected = [main_name, main_addr, 120, {}, [
        [foo_name, foo_addr, 120, {'jit': 19, 'gc:minor': 2}, [
            [bar_name, bar_addr, 101, {'gc:minor': 2, 'jit': 101}, []]]]]]
    assert data == expected
Beispiel #8
0
 def check_vmprof_output():
     from vmprof import read_profile
     tmpfile = str(udir.join('test_rvmprof'))
     stats = read_profile(tmpfile)
     t = stats.get_tree()
     assert t.name == 'py:x:foo:3'
     assert len(t.children) == 1  # jit
Beispiel #9
0
    def show(self, profile):
        """
        Read and display a vmprof profile file.

        :param profile: The filename of the vmprof profile file to display.
        :type profile: str
        """
        try:
            stats = vmprof.read_profile(profile)
        except Exception as e:
            print("Fatal: could not read vmprof profile file '{}': {}".format(
                profile, e))
            return

        if stats.get_runtime_in_microseconds() < 1000000:
            msg = color(
                "WARNING: The profiling completed in less than 1 seconds. Please run your programs longer!\r\n",
                color.RED)
            sys.stderr.write(msg)

        try:
            tree = stats.get_tree()
            self._show(tree)
        except EmptyProfileFile as e:
            print("No stack trace has been recorded (profile is empty)!")
Beispiel #10
0
 def check_vmprof_output():
     from vmprof import read_profile
     tmpfile = str(udir.join('test_rvmprof'))
     stats = read_profile(tmpfile)
     t = stats.get_tree()
     assert t.name == 'py:x:foo:3'
     assert len(t.children) == 1 # jit
Beispiel #11
0
 def process_response(self, request, response):
     vmprof.disable()
     terrible_performance.release()
     stats = vmprof.read_profile(self.output.name)
     tree = stats.get_tree()
     self.record_stats({'tree': tree})
     os.unlink(self.output.name)
Beispiel #12
0
 def test_tree(self):
     prof = read_profile(str(py.path.local(__file__).join(
         '..', 'test.prof')))
     tree = prof.get_tree()
     assert repr(tree) == '<Node: py:<module>:2:x.py (92) [(92, py:f:7:x.py)]>'
     values = list(tree.children.values())
     assert repr(values[0]) == '<Node: py:f:7:x.py (92) []>'
Beispiel #13
0
def test_read_simple():
    lib_cache = get_or_write_libcache('simple_nested.pypy.prof')
    path = py.path.local(__file__).join('..', 'simple_nested.pypy.prof')
    stats = vmprof.read_profile(path, virtual_only=True,
                                include_extra_info=True, lib_cache=lib_cache)
    tree = stats.get_tree()
    main_name = 'py:<module>:2:foo.py'
    foo_name = 'py:foo:6:foo.py'
    bar_name = 'py:bar:2:foo.py'
    assert tree['foo'].name == foo_name
    assert tree['foo']['bar'].name == bar_name
    assert tree['foo']['bar']['jit'].name.startswith('jit')
    flat = tree.flatten()
    assert tree['foo']['bar']['jit'].name.startswith('jit')
    assert not flat['foo']['bar'].children
    assert flat['foo']['bar'].meta['jit'] == 101
    assert flat['foo']['bar'].meta['gc:minor'] == 2
    data = json.loads(tree.as_json())
    main_addr = str(tree.addr)
    foo_addr = str(tree['foo'].addr)
    bar_addr = str(tree['foo']['bar'].addr)
    expected = [main_name, main_addr, 120, {}, [
        [foo_name, foo_addr, 120, {'jit': 19, 'gc:minor': 2}, [
            [bar_name, bar_addr, 101, {'gc:minor': 2, 'jit': 101}, []]]]]]
    assert data == expected
def tree_stats_to_response(filename, response):
    stats = vmprof.read_profile(filename)

    response.tree_stats = TreeStats()
    response.tree_stats.sampling_interval = vmprof.DEFAULT_PERIOD

    try:
        tree = stats.get_tree()
    except vmprof.stats.EmptyProfileFile:
        tree = None

    def convert(parent, node):
        tstats = CallTreeStat()
        tstats.name = node.name
        tstats.count = node.count
        tstats.children = []
        tstats.line_count = getattr(node, 'lines', {})

        if parent is not None:
            if parent.children is None:
                parent.children = []
            parent.children.append(tstats)

        return tstats

    response.tree_stats.call_tree = _walk_tree(None, tree, convert)
Beispiel #15
0
 def test_tree(self):
     prof = read_profile(
         str(py.path.local(__file__).join('..', 'test.prof')))
     tree = prof.get_tree()
     assert repr(
         tree) == '<Node: py:<module>:2:x.py (92) [(92, py:f:7:x.py)]>'
     values = list(tree.children.values())
     assert repr(values[0]) == '<Node: py:f:7:x.py (92) []>'
Beispiel #16
0
def show_stats(filename, output_mode, web_url, web_auth):
    if output_mode == OUTPUT_FILE:
        return

    if output_mode == OUTPUT_CLI:
        stats = vmprof.read_profile(filename)
        vmprof.cli.show(stats)
    elif output_mode == OUTPUT_WEB:
        upload_stats(filename, web_url, web_auth)
Beispiel #17
0
def show_stats(filename, output_mode, args):
    if output_mode == OUTPUT_FILE:
        return

    stats = vmprof.read_profile(filename)

    if output_mode == OUTPUT_CLI:
        vmprof.cli.show(stats)
    elif output_mode == OUTPUT_WEB:
        upload_stats(stats, args)
Beispiel #18
0
def show_stats(filename, output_mode, args):
    if output_mode == OUTPUT_FILE:
        return

    stats = vmprof.read_profile(filename)

    if output_mode == OUTPUT_CLI:
        vmprof.cli.show(stats)
    elif output_mode == OUTPUT_WEB:
        upload_stats(stats, args)
Beispiel #19
0
 def test_tree(self):
     prof = read_profile(
         str(py.path.local(__file__).join('..', 'test.prof')))
     tree = prof.get_tree()
     assert repr(
         tree
     ) == '<Node: py:entry_point:726:app_main.py (1) [(92, py:run_command_line:496:app_main.py)]>'
     assert repr(
         tree.children.values()[0]
     ) == '<Node: py:run_command_line:496:app_main.py (92) [(92, py:run_toplevel:66:app_main.py)]>'
Beispiel #20
0
    def __call__(self, environ, start_response):
        prof_file = tempfile.NamedTemporaryFile()

        vmprof.enable(prof_file.fileno(), 0.0005)
        self.application(environ, start_response)
        vmprof.disable()

        stats = vmprof.read_profile(prof_file.name)
        stats_log = self.stats(stats, getattr(settings, "VMPROF_EXCLUDE", None))

        return HttpResponse("<pre>VMprof \n\n===========\n%s</pre>" % stats_log)
Beispiel #21
0
 def test_wsgi_tree(self):
     prof = read_profile(
         str(py.path.local(__file__).join('..', 'wsgi.prof')))
     tree = prof.get_tree()
     assert repr(
         tree
     ) == '<Node: py:__call__:162:/vmprof/vmprof-test/.env/local/lib/python2.7/site-packages/django/core/handlers/wsgi.py (367) [(367, py:get_response:94:/vmprof/vmprof-test/.env/local/lib/python2.7/site-packages/django/core/handlers/base.py)]>'
     values = list(tree.children.values())
     assert repr(
         values[0]
     ) == '<Node: py:get_response:94:/vmprof/vmprof-test/.env/local/lib/python2.7/site-packages/django/core/handlers/base.py (367) [(365, py:index:23:/vmprof/vmprof-test/app/main.py), (2, py:resolve:360:/vmprof/vmprof-test/.env/local/lib/python2.7/site-packages/django/core/urlresolvers.py)]>'
Beispiel #22
0
 def test(self):
     from vmprof import read_profile
     assert self.entry_point(10**4, 0.1) == 99990000
     assert self.tmpfile.check()
     self.tmpfile.remove()
     #
     assert self.rpy_entry_point(10**4, 0.5) == 99990000
     assert self.tmpfile.check()
     prof = read_profile(self.tmpfilename)
     tree = prof.get_tree()
     assert tree.name == 'py:code:52:test_enable'
     assert self.approx_equal(tree.count, 0.5 / self.SAMPLING_INTERVAL)
Beispiel #23
0
def get_or_write_libcache(filename):
    libache_filename = str(py.path.local(__file__).join('..', filename + '.libcache'))
    try:
        with open(libache_filename) as f:
            d = json.loads(zlib.decompress(f.read()))
        lib_cache = {}
        for k, v in d.iteritems():
            lib_cache[k] = LibraryData(v[0], v[1], v[2], v[3], v[4])
        return lib_cache
    except (IOError, OSError):
        pass
    path = py.path.local(__file__).join('..', filename)
    lib_cache = {}
    vmprof.read_profile(path, virtual_only=True,
                        include_extra_info=True, lib_cache=lib_cache)
    d = {}
    for k, lib in lib_cache.iteritems():
        d[k] = (lib.name, lib.start, lib.end, lib.is_virtual, lib.symbols)
    with open(libache_filename, "w") as f:
        f.write(zlib.compress(json.dumps(d)))
    return lib_cache
Beispiel #24
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("profile")
    parser.add_argument("--web-url", default='http://vmprof.com', help='Target host')
    parser.add_argument("--web-auth", default=None, help='Authtoken for your acount on the server')
    args = parser.parse_args()

    stats = vmprof.read_profile(args.profile)
    sys.stderr.write("Compiling and uploading to %s...\n" % args.web_url)

    res = upload(stats, args.profile, [], args.web_url, args.web_auth)
    sys.stderr.write("Available at:\n%s\n" % res)
Beispiel #25
0
def show_stats(filename, output_mode, args):
    if output_mode == OUTPUT_FILE:
        return
    elif output_mode == OUTPUT_CLI:
        stats = vmprof.read_profile(filename)
        vmprof.cli.show(stats)
    elif output_mode == OUTPUT_WEB:
        host, auth = args.web_url, args.web_auth
        service = Service(host, auth)
        service.post({ Service.FILE_CPU_PROFILE: filename,
                       Service.FILE_JIT_PROFILE: filename + '.jit',
                       'argv': ' '.join(sys.argv[:]),
                       'VM': platform.python_implementation() })
Beispiel #26
0
 def _upload():
     try:
         stats = vmprof.read_profile(tmpfile.name)
         top_level_function = func.__module__ + "." + func.__name__
         period = merged_options['period'] * 10**6
         meta = {
             'start_date': start_date.isoformat(),
             'top_level_function': top_level_function
         }
         upload(merged_options['url'],
                merged_options['project_name'], stats, period, meta)
     finally:
         tmpfile.close()
Beispiel #27
0
def show_stats(filename, output_mode, args):
    if output_mode == OUTPUT_FILE:
        return

    stats = vmprof.read_profile(
        filename,
        virtual_only=not args.enable_nonvirtual
    )

    if output_mode == OUTPUT_CLI:
        vmprof.cli.show(stats)
    elif output_mode == OUTPUT_WEB:
        upload_stats(stats, args)
Beispiel #28
0
    def __call__(self, environ, start_response):
        prof_file = tempfile.NamedTemporaryFile()

        vmprof.enable(prof_file.fileno(), 0.0005)
        self.application(environ, start_response)
        vmprof.disable()

        stats = vmprof.read_profile(prof_file.name)
        stats_log = self.stats(stats, getattr(settings, 'VMPROF_EXCLUDE',
                                              None))

        return HttpResponse("<pre>VMprof \n\n===========\n%s</pre>" %
                            stats_log)
Beispiel #29
0
def show_stats(filename, output_mode, args):
    if output_mode == OUTPUT_FILE:
        return

    stats = vmprof.read_profile(filename)
    forest = None
    jitlog_filename = filename + '.jitlog'

    if output_mode == OUTPUT_CLI:
        vmprof.cli.show(stats)
    elif output_mode == OUTPUT_WEB:
        if os.path.exists(jitlog_filename):
            forest = parse_jitlog(jitlog_filename)
        upload_stats(stats, forest, args)
Beispiel #30
0
def show_stats(filename, output_mode, args):
    if output_mode == OUTPUT_FILE:
        return

    stats = vmprof.read_profile(
        filename,
        virtual_only=not args.enable_nonvirtual
    )

    if output_mode == OUTPUT_CLI:
        vmprof.cli.show(stats)
    elif output_mode == OUTPUT_WEB:
        sys.stderr.write("Compiling and uploading to %s...\n" % (args.web,))
        vmprof.com.send(stats, args)
Beispiel #31
0
def get_profile_data(fobj, program_argv=""):
    stats = vmprof.read_profile(fobj)
    data = {
        'VM': stats.interp,
        'profiles': stats.get_tree()._serialize(),
        'argv': program_argv,
        'version': 1,
    }
    return {
        'data': data,
        'checksum': hashlib.md5(json.dumps(data).encode('ascii')).hexdigest(),
        'vm': data['VM'],
        'name': data['argv']
    }
Beispiel #32
0
def show_stats(filename, output_mode, args):
    if output_mode == OUTPUT_FILE:
        return

    stats = vmprof.read_profile(filename)
    forest = None
    jitlog_filename = filename + '.jitlog'

    if output_mode == OUTPUT_CLI:
        vmprof.cli.show(stats)
    elif output_mode == OUTPUT_WEB:
        if os.path.exists(jitlog_filename):
            forest = parse_jitlog(jitlog_filename)
        upload_stats(stats, forest, args)
Beispiel #33
0
    def show(self, profile):
        # (str) -> None
        """Read and display a vmprof profile file.

        :param profile: The filename of the vmprof profile file to convert.
        """
        try:
            stats = vmprof.read_profile(profile)
        except Exception as e:
            print("Fatal: could not read vmprof profile file '{}': {}".format(profile, e),
                  file=sys.stderr)
            return
        tree = stats.get_tree()
        self.print_tree(tree)
def get_or_write_libcache(filename):
    libache_filename = str(py.path.local(__file__).join('..', filename + '.libcache'))
    try:
        with open(libache_filename, 'rb') as f:
            s = zlib.decompress(f.read())
            if not isinstance(s, str):
                s = s.decode('utf-8')
            d = json.loads(s)
        lib_cache = {}
        for k, v in d.items():
            lib_cache[k] = LibraryData(v[0], v[1], v[2], v[3], [tuple(x) for x in v[4]])
        return lib_cache
    except (IOError, OSError):
        pass
    path = py.path.local(__file__).join('..', filename)
    lib_cache = {}
    vmprof.read_profile(path, virtual_only=True,
                        include_extra_info=True, lib_cache=lib_cache)
    d = {}
    for k, lib in six.iteritems(lib_cache):
        d[k] = (lib.name, lib.start, lib.end, lib.is_virtual, lib.symbols)
    with open(libache_filename, "wb") as f:
        f.write(zlib.compress(json.dumps(d).encode('utf-8')))
    return lib_cache
Beispiel #35
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("profile")
    parser.add_argument("--web-url", default='http://vmprof.com', help='Target host')
    parser.add_argument("--web-auth", default=None, help='Authtoken for your acount on the server')
    args = parser.parse_args()

    stats = vmprof.read_profile(args.profile)
    jitlog_path = args.profile + ".jitlog"
    if os.path.exists(jitlog_path):
        jitlog.upload(jitlog_path, args)
    sys.stderr.write("Compiling and uploading to %s...\n" % args.web_url)

    upload(stats, args.profile, [], args.web_url,
                 args.web_auth, None)
Beispiel #36
0
def show_stats(filename, output_mode, args):
    if output_mode == OUTPUT_FILE:
        return
    elif output_mode == OUTPUT_CLI:
        stats = vmprof.read_profile(filename)
        vmprof.cli.show(stats)
    elif output_mode == OUTPUT_WEB:
        host, auth = args.web_url, args.web_auth
        service = Service(host, auth)
        service.post({
            Service.FILE_CPU_PROFILE: filename,
            Service.FILE_JIT_PROFILE: filename + '.jit',
            'argv': ' '.join(sys.argv[:]),
            'VM': platform.python_implementation()
        })
Beispiel #37
0
def get_or_write_libcache(filename):
    libache_filename = str(py.path.local(__file__).join('..', filename + '.libcache'))
    try:
        with open(libache_filename, 'rb') as f:
            s = zlib.decompress(f.read())
            if not isinstance(s, str):
                s = s.decode('utf-8')
            d = json.loads(s)
        lib_cache = {}
        for k, v in d.items():
            lib_cache[k] = LibraryData(v[0], v[1], v[2], v[3], [tuple(x) for x in v[4]])
        return lib_cache
    except (IOError, OSError):
        pass
    path = py.path.local(__file__).join('..', filename)
    lib_cache = {}
    vmprof.read_profile(path, virtual_only=True,
                        include_extra_info=True, lib_cache=lib_cache)
    d = {}
    for k, lib in six.iteritems(lib_cache):
        d[k] = (lib.name, lib.start, lib.end, lib.is_virtual, lib.symbols)
    with open(libache_filename, "wb") as f:
        f.write(zlib.compress(json.dumps(d).encode('utf-8')))
    return lib_cache
Beispiel #38
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("profile")
    parser.add_argument("--web-url", default='http://vmprof.com', help='Target host')
    parser.add_argument("--web-auth", default=None, help='Authtoken for your acount on the server')
    args = parser.parse_args()

    stats = vmprof.read_profile(args.profile)
    jitlog_path = args.profile + ".jitlog"
    if os.path.exists(jitlog_path):
        jitlog.upload(jitlog_path, args)
    sys.stderr.write("Compiling and uploading to %s...\n" % args.web_url)

    upload(stats, args.profile, [], args.web_url,
                 args.web_auth, None)
Beispiel #39
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("profile")
    parser.add_argument("--web-url",
                        default='http://vmprof.com',
                        help='Target host')
    parser.add_argument("--web-auth",
                        default=None,
                        help='Authtoken for your acount on the server')
    args = parser.parse_args()

    stats = vmprof.read_profile(args.profile)
    sys.stderr.write("Compiling and uploading to %s...\n" % args.web_url)

    res = upload(stats, args.profile, [], args.web_url, args.web_auth)
    sys.stderr.write("Available at:\n%s\n" % res)
Beispiel #40
0
    def show(self, profile):
        """
        Read and display a vmprof profile file.

        :param profile: The filename of the vmprof profile file to display.
        :type profile: str
        """
        try:
            stats = vmprof.read_profile(profile)
        except Exception as e:
            print("Fatal: could not read vmprof profile file '{}': {}".format(profile, e))
            return

        #vmprof.cli.show(stats)
        tree = stats.get_tree()

        self._print_tree(tree)
Beispiel #41
0
def main():
    with tempfile.NamedTemporaryFile() as prof_file:
        vmprof.enable(prof_file.fileno(), 0.001)

        try:
            program = sys.argv[1]
            del sys.argv[1]

            #            sys.argv = [args.program] + args.args
            runpy.run_path(program, run_name="__main__")
        except BaseException as e:
            if not isinstance(e, (KeyboardInterrupt, SystemExit)):
                raise
        vmprof.disable()

        stats = vmprof.read_profile(prof_file.name, virtual_only=True)

        show(stats)
Beispiel #42
0
    def show(self, profile):
        """
        Read and display a vmprof profile file.

        :param profile: The filename of the vmprof profile file to display.
        :type profile: str
        """
        try:
            stats = vmprof.read_profile(profile)
        except Exception as e:
            print("Fatal: could not read vmprof profile file '{}': {}".format(profile, e))
            return

        tree = stats.get_tree()

        for (filename, funline, funname), line_stats in self.lines_stat(tree):
            if self.filter is None or funname.find(self.filter) != -1:
                self.show_func(filename, funline, funname, line_stats)
Beispiel #43
0
def main():
    with tempfile.NamedTemporaryFile() as prof_file:
        vmprof.enable(prof_file.fileno(), 0.001)

        try:
            program = sys.argv[1]
            del sys.argv[1]

            #            sys.argv = [args.program] + args.args
            runpy.run_path(program, run_name="__main__")
        except (KeyboardInterrupt, SystemExit):
            pass

        vmprof.disable()

        stats = vmprof.read_profile(prof_file.name, virtual_only=True)

        show(stats)
Beispiel #44
0
    def show(self, profile):
        """
        Read and display a vmprof profile file.

        :param profile: The filename of the vmprof profile file to display.
        :type profile: str
        """
        try:
            stats = vmprof.read_profile(profile)
        except Exception as e:
            print("Fatal: could not read vmprof profile file '{}': {}".format(
                profile, e))
            return

        #vmprof.cli.show(stats)
        tree = stats.get_tree()

        self._print_tree(tree)
Beispiel #45
0
    def show(self, profile):
        """
        Read and display a vmprof profile file.

        :param profile: The filename of the vmprof profile file to display.
        :type profile: str
        """
        try:
            stats = vmprof.read_profile(profile)
        except Exception as e:
            print("Fatal: could not read vmprof profile file '{}': {}".format(
                profile, e))
            return

        tree = stats.get_tree()

        for (filename, funline, funname), line_stats in self.lines_stat(tree):
            if self.filter is None or funname.find(self.filter) != -1:
                self.show_func(filename, funline, funname, line_stats)
Beispiel #46
0
def main():
    import vmprof  # pylint: disable=I0021,import-error

    with tempfile.NamedTemporaryFile() as prof_file:
        vmprof.enable(prof_file.fileno(), 0.001)

        try:
            program = sys.argv[1]
            del sys.argv[1]

            #            sys.argv = [args.program] + args.args
            runpy.run_path(program, run_name="__main__")
        except (KeyboardInterrupt, SystemExit):
            pass

        vmprof.disable()

        stats = vmprof.read_profile(prof_file.name)

        show(stats)
Beispiel #47
0
    def show(self, profile):
        """
        Read and display a vmprof profile file.

        :param profile: The filename of the vmprof profile file to display.
        :type profile: str
        """
        try:
            stats = vmprof.read_profile(profile)
        except Exception as e:
            print("Fatal: could not read vmprof profile file '{}': {}".format(profile, e))
            return

        if stats.get_runtime_in_microseconds() < 1000000:
            msg = color("WARNING: The profiling completed in less than 1 seconds. Please run your programs longer!\r\n", color.RED)
            sys.stderr.write(msg)

        try:
            tree = stats.get_tree()
            self._show(tree)
        except EmptyProfileFile as e:
            print("No stack trace has been recorded (profile is empty)!")
Beispiel #48
0
    def check_profile(filename):
        from vmprof import read_profile
        from vmprof.show import PrettyPrinter

        prof = read_profile(filename)
        tree = prof.get_tree()
        p = PrettyPrinter()
        p._print_tree(tree)
        def walk(tree, symbols):
            symbols.append(tree.name)
            if len(tree.children) == 0:
                return
            for child in tree.children.values():
                walk(child, symbols)
        symbols = []
        walk(tree, symbols)
        not_found = ['n:native_func']
        for sym in symbols:
            for i,name in enumerate(not_found):
                if sym.startswith(name):
                    del not_found[i]
                    break
        assert not_found == []
Beispiel #49
0
            def convert_profile(profile_filename):
                self.log.info("Converting profile file {}".format(profile_filename))

                try:
                    stats = vmprof.read_profile(profile_filename, virtual_only=True, include_extra_info=True)
                except Exception as e:
                    self.log.error("Fatal: could not read vmprof profile file '{}': {}".format(profile_filename, e))
                    raise e

                tree = stats.get_tree()
                total = float(tree.count)

                res = []

                def process_node(parent, node, level):
                    parent_name = parent.name if parent else None

                    perc = round(100.0 * float(node.count) / total, 1)
                    if parent and parent.count:
                        perc_of_parent = round(100.0 * float(node.count) / float(parent.count), 1)
                    else:
                        perc_of_parent = 100.0

                    parts = node.name.count(":")

                    if parts == 3:
                        block_type, funname, funline, filename = node.name.split(":")
                        res.append(
                            {
                                "type": "py",
                                "level": level,
                                "parent": parent_name,
                                "fun": funname,
                                "filename": filename,
                                "dirname": os.path.dirname(filename),
                                "basename": os.path.basename(filename),
                                "line": funline,
                                "perc": perc,
                                "perc_of_parent": perc_of_parent,
                                "count": node.count,
                                "parent_count": parent.count if parent else None,
                            }
                        )
                    elif parts == 1:
                        block_type, funname = node.name.split(":")
                        res.append(
                            {
                                "type": "jit",
                                "level": level,
                                "parent": parent_name,
                                "fun": funname,
                                "perc": perc,
                                "perc_of_parent": perc_of_parent,
                                "count": node.count,
                                "parent_count": parent.count if parent else None,
                            }
                        )
                    else:
                        raise Exception("fail!")

                self._walk_tree(None, tree, 0, process_node)

                return res
Beispiel #50
0
            def convert_profile(profile_filename):
                self.log.info("Converting profile file {}".format(profile_filename))

                try:
                    stats = vmprof.read_profile(profile_filename, virtual_only=True, include_extra_info=True)
                except Exception as e:
                    self.log.error("Fatal: could not read vmprof profile file '{}': {}".format(profile_filename, e))
                    raise e

                tree = stats.get_tree()
                total = float(tree.count)

                res = []

                def process_node(parent, node, level):
                    parent_name = parent.name if parent else None

                    perc = round(100. * float(node.count) / total, 1)
                    if parent and parent.count:
                        perc_of_parent = round(100. * float(node.count) / float(parent.count), 1)
                    else:
                        perc_of_parent = 100.

                    parts = node.name.count(':')

                    if parts == 3:
                        block_type, funname, funline, filename = node.name.split(':')
                        res.append(
                            {
                                u'type': u'py',
                                u'level': level,
                                u'parent': parent_name,
                                u'fun': funname,
                                u'filename': filename,
                                u'dirname': os.path.dirname(filename),
                                u'basename': os.path.basename(filename),
                                u'line': funline,
                                u'perc': perc,
                                u'perc_of_parent': perc_of_parent,
                                u'count': node.count,
                                u'parent_count': parent.count if parent else None,
                            })
                    elif parts == 1:
                        block_type, funname = node.name.split(':')
                        res.append(
                            {
                                u'type': u'jit',
                                u'level': level,
                                u'parent': parent_name,
                                u'fun': funname,
                                u'perc': perc,
                                u'perc_of_parent': perc_of_parent,
                                u'count': node.count,
                                u'parent_count': parent.count if parent else None,
                            })
                    else:
                        raise Exception("fail!")

                self._walk_tree(None, tree, 0, process_node)

                return res
    'profile',
    help='Profile file'
)

parser.add_argument(
    '--program',
    default='Crossbar.io Router Worker',
    help='program'
)

parser.add_argument(
    '--web-auth',
    help='Authtoken for your acount on the server, works only when --web is used'
)

parser.add_argument(
    '--web',
    metavar='url',
    default='vmprof.baroquesoftware.com',
    help='Upload profiling stats to a remote server'
)

args = parser.parse_args()
args.args = []

stats = vmprof.read_profile(args.profile, virtual_only=True)

vmprof.cli.show(stats)

vmprof.com.send(stats, args)
Beispiel #52
0
#!/usr/bin/env python
""" Usage: vmemprof <vmprof.dat>

Run with output of vmprof run with memory profiling (like vmprof.enable(fileno, 0.01, True))
"""

import vmprof
import os, json, sys
from flask import Flask, Response, request
app = Flask(__name__)

if len(sys.argv) != 2:
    print __doc__
    sys.exit(1)

stats = vmprof.read_profile(sys.argv[1])

MAX = 60

def strip(s):
    s = s.replace("<", "&lt;").replace(">", "&gt;")
    l = s.split(":")
    if len(l[3]) > MAX:
        l[3] = "..." + l[3][-(MAX - 3):]
    l[1] = "<b>" + l[1] + "</b>"
    return "%s %s:%s" % (l[1], l[3], l[2])

def resample_and_pack(profiles, start, end, window_size):
    next = []
    mem = []
    i = start
Beispiel #53
0
    def check_profile(filename):
        from vmprof import read_profile

        prof = read_profile(filename)
        assert prof.get_tree().name.startswith("py:")
        assert prof.get_tree().count
Beispiel #54
0
def main(profile, web_url, web_auth):
    stats = vmprof.read_profile(profile, virtual_only=True)
    sys.stderr.write("Compiling and uploading to %s...\n" % (web_url, ))
    res = upload(stats, profile, [], web_url, web_auth)
    sys.stderr.write("Available at:\n%s\n" % res)
Beispiel #55
0
def main(profile, web_url, web_auth): 
    stats = vmprof.read_profile(profile, virtual_only=True)
    sys.stderr.write("Compiling and uploading to %s...\n" % (web_url,))
    res = upload(stats, profile, [], web_url, web_auth)
    sys.stderr.write("Available at:\n%s\n" % res)