示例#1
0
    def stop(self):
        self._running = False
        self._tick_timer.cancel()
        self._stop_time = time.time()

        if self._app.args.profile and USE_YAPPI:
            yappi.print_stats(sort_type=yappi.SORTTYPE_TSUB, limit=15, thread_stats_on=False)
示例#2
0
    def stop(self):
        self._running = False
        self._tick_timer.cancel()
        self._stop_time = time.time()

        if self._app.args.profile and USE_YAPPI:
            yappi.print_stats(sort_type=yappi.SORTTYPE_TSUB,
                              limit=15,
                              thread_stats_on=False)
def profile_cpu_bound_program():
    real_dog = DogStatsApi()
    real_dog.reporter = NullReporter()
    fake_dog = NullDogStatsApi()
    for type_, dog in [('real', real_dog), ('fake', fake_dog)]:
        print('\n\n\nTESTING %s\n\n' % type_)
        dog.start()
        program = CPUBoundProgram(dog)
        yappi.start()
        program.run()
        yappi.print_stats(sort_type=yappi.SORTTYPE_TSUB, sort_order=yappi.SORTORDER_DESC)
        yappi.stop()
        yappi.clear_stats()
示例#4
0
def profile_cpu_bound_program():
    real_dog = DogStatsApi()
    real_dog.reporter = NullReporter()
    fake_dog = NullDogStatsApi()
    for type_, dog in [('real', real_dog), ('fake', fake_dog)]:
        print('\n\n\nTESTING %s\n\n' % type_)
        dog.start()
        program = CPUBoundProgram(dog)
        yappi.start()
        program.run()
        yappi.print_stats(sort_type=yappi.SORTTYPE_TSUB,
                          sort_order=yappi.SORTORDER_DESC)
        yappi.stop()
        yappi.clear_stats()
def measure_thousands_of_metrics():
    dog = DogStatsApi()
    dog.start(api_key='apikey_3', api_host="https://app.datad0g.com")
    yappi.start()
    @dog.timed('timed')
    def timed():
        pass
    for i in range(100):
        for j in range(1000):
            name = j % 100
            dog.gauge('gauge.%s' % name, j)
            dog.increment('counter.%s' % name, j)
            dog.histogram('histogram.%s' % name, j)
            timed()
        print('run %s' % i)
    yappi.print_stats(sort_type=yappi.SORTTYPE_TSUB, sort_order=yappi.SORTORDER_DESC)
示例#6
0
    def DrawGLScene(self):
        if self.exiting:
            self.logger.debug("total number of rendered frames: %s" % self._frame_count)
            self.logger.debug("total FPS: %s" % (float(self._frame_count) / self.stopwatch.get_elapsed_time()))
            if self.args.profile:
                import yappi
                yappi.print_stats(sys.stdout, yappi.SORTTYPE_TTOT)
            glutDestroyWindow(glutGetWindow())
            return

        try:
            self._draw_gl_scene_error_handled()
        except Exception as error:
            traceback_printer.print_traceback()
            self.exiting = True
            raise error
示例#7
0
def measure_thousands_of_metrics():
    dog = DogStatsApi()
    dog.start(api_key='apikey_3', api_host="https://app.datad0g.com")
    yappi.start()

    @dog.timed('timed')
    def timed():
        pass

    for i in range(100):
        for j in range(1000):
            name = j % 100
            dog.gauge('gauge.%s' % name, j)
            dog.increment('counter.%s' % name, j)
            dog.histogram('histogram.%s' % name, j)
            timed()
        print('run %s' % i)
    yappi.print_stats(sort_type=yappi.SORTTYPE_TSUB,
                      sort_order=yappi.SORTORDER_DESC)
# in ipython or similar

import yappi
import os
from totalimpact import backend

rootdir = "."
logfile = '/tmp/total-impact.log'

yappi.clear_stats()
yappi.start()
backend.main(logfile)

### Now, in another window run
# ./services/api start
# ./services/proxy start
# ./extras/functional_test.py -i 6 -n 6
# then when it is done, in python do a Cntl C to stop the backend and return to python prompt

yappi.stop()

yappi.print_stats(sort_type=yappi.SORTTYPE_TTOT,
                  limit=30,
                  thread_stats_on=False)
示例#9
0
	def __exit__(self,*args):
		import yappi
		yappi.stop()
		yappi.print_stats()
		yappi.clear_stats()
示例#10
0
 def __exit__(self, *args):
     import yappi
     yappi.stop()
     yappi.print_stats()
     yappi.clear_stats()
示例#11
0
def handle(request):
    time_start = now()
    print(request)
    environ = copy.copy(request.environ)
    # Redirect www. links to naked URL
    if request.host.startswith('www.'):
        return base_controller.redirect(Response(),
                                        re.sub('//www.', '//', request.url, 1),
                                        permanent=True)
    # Redirect thenewhive.com links to newhive.com
    if re.search('thenewhive.com', environ['HTTP_HOST']):
        return base_controller.redirect(Response(),
                                        re.sub(r'//((.+\.)?)thenewhive\.com',
                                               r'//\1newhive.com',
                                               request.url),
                                        permanent=True)

    prefix, site = split_domain(environ['HTTP_HOST'])
    # Convert any ip v4 address into a specific dns
    # site = re.sub('([0-9]+\.){3}[0-9]+','site',site) #//!!
    # Convert the specified DNS into the shorthand DNS (without search dns)
    # site = re.sub('(.*)\.(office|cos)\.newhive\.com','\g<1>',site) #//!!
    environ['HTTP_HOST'] = site
    if prefix and prefix not in config.live_prefixes:
        base_controller.redirect(
            Response(),
            'https://' + site + '/' + prefix + environ['PATH_INFO'])
    stats = False
    # stats = True
    if stats:
        pass
        # statprof.start()
        # if not yappi.is_running():
        #     yappi.start()
    try:
        (controller, handler), args = routes.bind_to_environ(environ).match()
    except exceptions.NotFound as e:
        err = True
        if not config.live_server:
            try:
                err = False
                #dev = config.dev_prefix + '.' if config.dev_prefix else ''
                environ['HTTP_HOST'] = config.server_name + ':' + environ[
                    'SERVER_PORT']
                (controller,
                 handler), args = routes.bind_to_environ(environ).match()
            except exceptions.NotFound as e:
                err = True
        if err:
            print "Gap in routing table!"
            print request
            return base_controller.serve_500(
                base_controller.new_transaction(request),
                exception=e,
                json=False)
    except RequestRedirect as e:
        # bugbug: what's going on here anyway?
        raise Exception('redirect not implemented: from: ' + request.url +
                        ', to: ' + e.new_url)

    # print controller
    # print handler
    try:
        if stats:
            pr = cProfile.Profile()
            pr.enable()
            doflags(
                functools.partial(controller.dispatch, handler, request,
                                  **args), ("iterations", "feed_max"), [5],
                [2000, 1000, 500, 100])

        response = controller.dispatch(handler, request, **args)
        if stats:
            pr.disable()
            s = io.StringIO()
            ps = pstats.Stats(pr)
            ps.sort_stats('cumulative')
            ps.print_stats(25)

            ps.dump_stats(os.path.join(config.src_home, 'stats'))
            # To view stats graphically, use:
            # alias gprof='gprof2dot.py -f pstats stats | dot -Tpng -o output.png;open output.png'

    except:
        (blah, exception, traceback) = sys.exc_info()
        response = base_controller.serve_500(
            base_controller.new_transaction(request),
            exception=exception,
            traceback=traceback,
            json=False)

    print "time %s ms" % (1000. * (now() - time_start))
    if stats and yappi.is_running():
        # statprof.stop()
        # statprof.display()
        yappi.stop()
        yappi.print_stats(sys.stdout, yappi.SORTTYPE_TTOT,
                          yappi.SORTORDER_DESC, 25)
        yappi.clear_stats()

    # this allows unsecure pages to make API calls to https
    # response.headers.add('Access-Control-Allow-Origin', config.abs_url().strip('/'))
    # TODO-security: CONSIDER. Allow pages on custom domains to make API calls
    response.headers.add('Access-Control-Allow-Origin', '*')
    response.headers.add('Access-Control-Allow-Headers',
                         'Content-Type, Authorization, X-Requested-With')
    return response
示例#12
0
 def __del__(self):
     if self.__profile and use_yappi:
         yappi.print_stats(sort_type=yappi.SORTTYPE_TSUB,
                           limit=15,
                           thread_stats_on=False)
示例#13
0
文件: usage.py 项目: OuO/yappi
import time
import threading
import yappi
	
def foo():
    time.sleep(0.1)

def profileme():
    for i in range(5):
        mythread = t()
        mythread.start()
        mythread.join()
    foo()

class t(threading.Thread):
    def run(self):
        self.foo2()
    def foo2(self):
        time.sleep(1.0)

if __name__ == "__main__":
	yappi.start(True)
	profileme()
	yappi.stop()
	yappi.print_stats(2)
示例#14
0
	def YappiProfiling():
		yappi.start()
		yield
		yappi.stop()
		yappi.print_stats()
示例#15
0
 def print_stats(self, *args, **kwrds):
     yappi.print_stats(*args, **kwrds)
示例#16
0
 def signal_handler(signal_n, frame):
     print('You pressed Ctrl+C!')
     yappi.stop()
     yappi.print_stats(open("yappi.out", "w"))
     sys.exit(0)
#Requires yappi to be installed, use easy_install yappi

import yappi
from tribler import run

if __name__ == '__main__':
    yappi.start()
    run()
    yappi.print_stats(yappi.SORTTYPE_TTOTAL)
示例#18
0
 def __del__(self):
     if self.__profile and use_yappi:
         yappi.print_stats(sort_type = yappi.SORTTYPE_TSUB, 
                           limit = 15, 
                           thread_stats_on = False)
示例#19
0
import time
import threading
import yappi


def foo():
    time.sleep(0.1)


def profileme():
    for i in range(5):
        mythread = t()
        mythread.start()
        mythread.join()
    foo()


class t(threading.Thread):
    def run(self):
        self.foo2()

    def foo2(self):
        time.sleep(1.0)


if __name__ == "__main__":
    yappi.start(True)
    profileme()
    yappi.stop()
    yappi.print_stats(2)
# in ipython or similar

import yappi
import os
from totalimpact import backend

rootdir = "."
logfile = '/tmp/total-impact.log'


yappi.clear_stats()
yappi.start()
backend.main(logfile)

### Now, in another window run
# ./services/api start
# ./services/proxy start
# ./extras/functional_test.py -i 6 -n 6
# then when it is done, in python do a Cntl C to stop the backend and return to python prompt

yappi.stop()

yappi.print_stats(sort_type=yappi.SORTTYPE_TTOT, limit=30, thread_stats_on=False)
示例#21
0
    r = features.outputs["Output"][:50,:50,:50,:]
    requests.append(r)

for r in requests:
    r.submit()

for r in requests:
    r.wait()
t2 = time.time()
print "\n\n"
print "LAZYFLOW ASYNC WAIT FEATURES:   %f seconds for %d iterations" % (t2-t1,mcountf)
print "                                %0.3fms latency" % ((t2-t1)*1e3/mcountf,)

if doProfile:
    yappi.stop()
    yappi.print_stats(sort_type = yappi.SORTTYPE_TTOT)




def empty_func(b):
    a = 7 + b
    a = "lksejhkl JSFLAJSSDFJH   AKDHAJKSDH ADKJADHK AJHSKA AKJ KAJSDH AKDAJHSKAJHD KASHDAKDJH".split(" ")

t1 = time.time()

def lots_of_work():
    requests = []
    for i in range(mcount):
        req = Request(functools.partial(empty_func, b = 11))
        req.submit()
示例#22
0
for r in requests:
    r.submit()

for r in requests:
    r.wait()
t2 = time.time()
print "\n\n"
print "LAZYFLOW ASYNC WAIT FEATURES:   %f seconds for %d iterations" % (
    t2 - t1, mcountf)
print "                                %0.3fms latency" % (
    (t2 - t1) * 1e3 / mcountf, )

if doProfile:
    yappi.stop()
    yappi.print_stats(sort_type=yappi.SORTTYPE_TTOT)


def empty_func(b):
    a = 7 + b
    a = "lksejhkl JSFLAJSSDFJH   AKDHAJKSDH ADKJADHK AJHSKA AKJ KAJSDH AKDAJHSKAJHD KASHDAKDJH".split(
        " ")


t1 = time.time()


def lots_of_work():
    requests = []
    for i in range(mcount):
        req = Request(functools.partial(empty_func, b=11))
示例#23
0
 def print_stats(self, *args, **kwrds):
     yappi.print_stats(*args, **kwrds)
def main():
    parser = argparsers.sql_parser(description="Load a genome summary file from the pipeline into the MySQL cluster database")
    parser.add_argument('genome_summary_file', nargs="*")
    parser.add_argument("--delim", default=",", help="delimiter")
    parser.add_argument("--quote", default='"', help="quote character")
    parser.add_argument("--dry-run", action="store_true", help="skip insertion")
    parser.add_argument("--quiet", action="store_true", help="don't print insertions when --dry-run is set")
    parser.add_argument("--no-progress", action="store_true", help="don't show a progress bar (skips line counting input files at the beginning, which could take a while)")
    parser.add_argument("--records", type=int, help="skip line counting input files, and use --records as the total number of lines in the input files")
    parser.add_argument("--threads", type=int, default=1, help="split input into --threads chunks")
    parser.add_argument("--no-skip-header", action="store_true", help="don't skip the first line (header line)")
    parser.add_argument("--buffer", type=int, required=False, help="size of the buffer for dividing input amongst threads (lower this if you're thrashing; if left to the default, it is multiplied by --threads)")
    parser.add_argument("--profile", help="run yappi and output profiling results to --profile")
    parser.add_argument("--autocommit", action="store_true", help="SET autocommit = 1 (good for ndb, bad for innodb)")
    args = parser.parse_args()
    thread_buffer_default = 1000
    args.buffer = thread_buffer_default * min(1, args.threads)

    if args.profile is not None:
        import yappi
        yappi.start()

    records = args.records
    if records is None and not args.no_progress and len(args.genome_summary_file) != 0 and '-' not in args.genome_summary_file:
        records = sum(file_len(f) for f in args.genome_summary_file)
    input = fileinput.FileInput(args.genome_summary_file)

    # warnings.filterwarnings('error', category=MySQLdb.Warning)

    widgets = ['loading data: ', Counter(), '/', str(records), '(', Percentage(), ')', ' ', Bar(marker=RotatingMarker()), ' ', ETA()]
    pbar = ProgressBar(widgets=widgets, maxval=records).start() if records is not None else None

    skip_header = not args.no_skip_header
    if skip_header:
        try:
            input.next()
        except StopIteration:
            # empty input
            pass


    if args.threads > 1:
        load_genome_summary_parallel(input, records, pbar, args)
    else:
        processed = [0]
        def sequential_input():
            for line in input:
                if records != None:
                    processed[0] += 1
                    if pbar is not None:
                        pbar.update(processed[0])
                yield line
        load_genome_summary(
                connect(args), 
                sequential_input(),
                **lgs_kwargs(args))

    pbar.finish()

    if args.profile is not None:
        yappi.stop()
        with open(args.profile, 'w') as f:
            yappi.print_stats(out=f)
示例#25
0
	pass

class myclass(threading.Thread):
	def myfunc(self):
		pass
	def run(self):
		self.myfunc()
		time.sleep(0.001)

if __name__ == "__main__":
	yappi.start(True)
	myt = myclass()	
	myt.start()
	myt.join()
	yappi.enum_stats(estat)
	myt = myclass()	
	myt.start()
	myt.join()
	yappi.stop()
	yappi.enum_stats(estat)
	yappi.print_stats()
	yappi.clear_stats()
	yappi.start(True)
	myt = myclass()	
	myt.start()
	myt.join()
	yappi.stop()
	yappi.print_stats(yappi.SORTTYPE_NAME, yappi.SORTORDER_ASCENDING)
	yappi.clear_stats()
	
示例#26
0
import nose
import yappi

try:
    yappi.start()
    nose.main()
finally:
    yappi.print_stats()
示例#27
0
def main():
    global log
    global yappi

    if args.list_protocols:
        from friends.utils.manager import protocol_manager
        for name in sorted(protocol_manager.protocols):
            cls = protocol_manager.protocols[name]
            package, dot, class_name = cls.__name__.rpartition('.')
            print(class_name)
        return

    # Disallow multiple instances of friends-dispatcher
    bus = dbus.SessionBus()
    obj = bus.get_object('org.freedesktop.DBus', '/org/freedesktop/DBus')
    iface = dbus.Interface(obj, 'org.freedesktop.DBus')
    if DBUS_INTERFACE in iface.ListNames():
        sys.exit('friends-dispatcher is already running! Abort!')

    if args.performance:
        with ignored(ImportError):
            import yappi
            yappi.start()

    # Initialize the logging subsystem.
    gsettings = Gio.Settings.new('com.canonical.friends')
    initialize(console=args.console,
               debug=args.debug or gsettings.get_boolean('debug'))
    log = logging.getLogger(__name__)
    log.info('Friends backend dispatcher starting')

    # ensure friends-service is available to provide the Dee.SharedModel
    server = bus.get_object('com.canonical.Friends.Service',
                            '/com/canonical/friends/Service')

    # Determine which messages to notify for.
    notify_level = gsettings.get_string('notifications')
    if notify_level == 'all':
        Base._do_notify = lambda protocol, stream: True
    elif notify_level == 'none':
        Base._do_notify = lambda protocol, stream: False
    else:
        Base._do_notify = lambda protocol, stream: stream in (
            'mentions',
            'private',
        )

    Dispatcher(gsettings, loop)

    # Don't initialize caches until the model is synchronized
    Model.connect('notify::synchronized', setup)

    with ignored(KeyboardInterrupt):
        log.info('Starting friends-dispatcher main loop')
        loop.run()

    log.info('Stopped friends-dispatcher main loop')

    # This bit doesn't run until after the mainloop exits.
    if args.performance and yappi is not None:
        yappi.print_stats(sys.stdout, yappi.SORTTYPE_TTOT)