Ejemplo n.º 1
0
    def test_get_clock(self):
        yappi.set_clock_type('cpu')
        self.assertEqual('cpu', yappi.get_clock_type())
        clock_info = yappi.get_clock_info()
        self.assertTrue('api' in clock_info)
        self.assertTrue('resolution' in clock_info)

        yappi.set_clock_type('wall')
        self.assertEqual('wall', yappi.get_clock_type())

        t0 = yappi.get_clock_time()
        time.sleep(0.1)
        duration = yappi.get_clock_time() - t0
        self.assertAlmostEqual(0.1, duration, places=2)
Ejemplo n.º 2
0
    def test_get_clock(self):
        yappi.set_clock_type("cpu")
        self.assertEqual("cpu", yappi.get_clock_type())
        clock_info = yappi.get_clock_info()
        self.assertTrue("api" in clock_info)
        self.assertTrue("resolution" in clock_info)

        yappi.set_clock_type("wall")
        self.assertEqual("wall", yappi.get_clock_type())

        t0 = yappi.get_clock_time()
        time.sleep(0.1)
        duration = yappi.get_clock_time() - t0
        self.assertTrue(0.05 < duration < 0.2)
Ejemplo n.º 3
0
    def test_get_clock(self):
        yappi.set_clock_type('cpu')
        self.assertEqual('cpu', yappi.get_clock_type())
        clock_info = yappi.get_clock_info()
        self.assertTrue('api' in clock_info)
        self.assertTrue('resolution' in clock_info)

        yappi.set_clock_type('wall')
        self.assertEqual('wall', yappi.get_clock_type())

        t0 = yappi.get_clock_time()
        time.sleep(0.1)
        duration = yappi.get_clock_time() - t0
        self.assertAlmostEqual(0.1, duration, places=2)
Ejemplo n.º 4
0
def main(argv):
    parser = argparse.ArgumentParser(description='Anonymous Tunnel CLI interface')

    try:
        parser.add_argument('-p', '--socks5', help='Socks5 port')
        parser.add_argument('-x', '--exit', help='Allow being an exit-node')
        parser.add_argument('-i', '--introduce', help='Introduce the dispersy port of another tribler instance')
        parser.add_argument('-d', '--dispersy', help='Dispersy port')
        parser.add_argument('-c', '--crawl', help='Enable crawler and use the keypair specified in the given filename')
        parser.add_argument('-j', '--json', help='Enable JSON api, which will run on the provided port number ' +
                                                 '(only available if the crawler is enabled)', type=int)
        parser.add_argument('-y', '--yappi', help="Profiling mode, either 'wall' or 'cpu'")
        parser.add_help = True
        args = parser.parse_args(sys.argv[1:])

    except argparse.ArgumentError:
        parser.print_help()
        sys.exit(2)

    socks5_port = int(args.socks5) if args.socks5 else None
    introduce_port = int(args.introduce) if args.introduce else None
    dispersy_port = int(args.dispersy) if args.dispersy else -1
    crawl_keypair_filename = args.crawl
    profile = args.yappi if args.yappi in ['wall', 'cpu'] else None

    if profile:
        yappi.set_clock_type(profile)
        yappi.start(builtins=True)
        logger.error("Profiling using %s time" % yappi.get_clock_type()['type'])

    if crawl_keypair_filename and not os.path.exists(crawl_keypair_filename):
        logger.error("Could not find keypair filename", crawl_keypair_filename)
        sys.exit(1)

    settings = TunnelSettings()

    # For disbling anonymous downloading, limiting download to hidden services only
    settings.min_circuits = 0
    settings.max_circuits = 0

    if socks5_port is not None:
        settings.socks_listen_ports = range(socks5_port, socks5_port + 5)
    else:
        settings.socks_listen_ports = [random.randint(1000, 65535) for _ in range(5)]

    settings.become_exitnode = True if args.exit in ['true'] else False
    if settings.become_exitnode:
        logger.info("Exit-node enabled")
    else:
        logger.info("Exit-node disabled")

    tunnel = Tunnel(settings, crawl_keypair_filename, dispersy_port)
    StandardIO(LineHandler(tunnel, profile))
    tunnel.start(introduce_port)

    if crawl_keypair_filename and args.json > 0:
        cherrypy.config.update({'server.socket_host': '0.0.0.0', 'server.socket_port': args.json})
        cherrypy.quickstart(tunnel)
    else:
        while True:
            time.sleep(1)
Ejemplo n.º 5
0
# Requires yappi to be installed, use easy_install yappi

import yappi
import sys
from time import time
from tribler import run

if __name__ == '__main__':
    t1 = time()
    yappi.start()
    run()
    yappi.stop()
    print >> sys.stderr, "YAPPI: %s tribler has run for %s seconds" % \
        (yappi.get_clock_type(), time() - t1)
    yappi_stats = yappi.get_func_stats()
    yappi_stats.sort("tsub")
    count = 0
    for func_stat in yappi_stats:
        print >> sys.stderr, "YAPPI: %10dx  %10.3fs %s" % \
            (func_stat.ncall, func_stat.tsub, func_stat.name)
        count += 1
        if count >= 50:
            break
Ejemplo n.º 6
0
def main(argv):
    parser = argparse.ArgumentParser(
        description='Anonymous Tunnel CLI interface')

    try:
        parser.add_argument('-p', '--socks5', help='Socks5 port')
        parser.add_argument('-x', '--exit', help='Allow being an exit-node')
        parser.add_argument(
            '-i',
            '--introduce',
            help='Introduce the dispersy port of another tribler instance')
        parser.add_argument('-d', '--dispersy', help='Dispersy port')
        parser.add_argument(
            '-c',
            '--crawl',
            help=
            'Enable crawler and use the keypair specified in the given filename'
        )
        parser.add_argument(
            '-j',
            '--json',
            help='Enable JSON api, which will run on the provided port number '
            + '(only available if the crawler is enabled)',
            type=int)
        parser.add_argument('-y',
                            '--yappi',
                            help="Profiling mode, either 'wall' or 'cpu'")
        parser.add_help = True
        args = parser.parse_args(sys.argv[1:])

    except argparse.ArgumentError:
        parser.print_help()
        sys.exit(2)

    socks5_port = int(args.socks5) if args.socks5 else None
    introduce_port = int(args.introduce) if args.introduce else None
    dispersy_port = int(args.dispersy) if args.dispersy else -1
    crawl_keypair_filename = args.crawl
    profile = args.yappi if args.yappi in ['wall', 'cpu'] else None

    if profile:
        yappi.set_clock_type(profile)
        yappi.start(builtins=True)
        logger.error("Profiling using %s time" %
                     yappi.get_clock_type()['type'])

    if crawl_keypair_filename and not os.path.exists(crawl_keypair_filename):
        logger.error("Could not find keypair filename", crawl_keypair_filename)
        sys.exit(1)

    settings = TunnelSettings()

    # For disbling anonymous downloading, limiting download to hidden services only
    settings.min_circuits = 0
    settings.max_circuits = 0

    if socks5_port is not None:
        settings.socks_listen_ports = range(socks5_port, socks5_port + 5)
    else:
        settings.socks_listen_ports = [
            random.randint(1000, 65535) for _ in range(5)
        ]

    settings.become_exitnode = True if args.exit in ['true'] else False
    if settings.become_exitnode:
        logger.info("Exit-node enabled")
    else:
        logger.info("Exit-node disabled")

    tunnel = Tunnel(settings, crawl_keypair_filename, dispersy_port)
    StandardIO(LineHandler(tunnel, profile))
    tunnel.start(introduce_port)

    if crawl_keypair_filename and args.json > 0:
        cherrypy.config.update({
            'server.socket_host': '0.0.0.0',
            'server.socket_port': args.json
        })
        cherrypy.quickstart(tunnel)
    else:
        while True:
            time.sleep(1)