示例#1
0
    def show(self):
        self.DeleteAllItems()
        r = 0
        for k, v in iter(self.itemDataMap.items()):
            self.InsertStringItem(r, v[0])
            self.SetStringItem(r, 1, f8(v[1]))
            self.SetStringItem(r, 2, f8(v[2]))
            self.SetStringItem(r, 3, f8(v[3]))
            self.SetStringItem(r, 4, f8(v[4]))
            self.SetStringItem(r, 5, v[5])

            self.SetItemData(r, r)
            r = r + 1
        self.SortListItems(3, 0)
示例#2
0
 def print_line(self, func):  # hack : should print percentages
     cc, nc, tt, ct, callers = self.stats[func] #@UnusedVariable
     c = str(nc)
     if nc != cc:
         c = c + '/' + str(cc)
     print >> self.stream, c.rjust(5),
     print >> self.stream, pstats.f8(ct),
     if cc == 0:
         print >> self.stream, ' '*8,
     else:
         percall = float(ct) / cc
         result = pstats.f8(percall)
         if percall > 0.1:
             result = self.style.LONGRUN(result)
         print >> self.stream, result,
     print >> self.stream, self.func_std_string(func)
示例#3
0
 def print_line(self, func):  # hack : should print percentages
     cc, nc, tt, ct, callers = self.stats[
         func]  # @UnusedVariable
     c = str(nc)
     if nc != cc:
         c = c + '/' + str(cc)
     print >> self.stream, c.rjust(5),
     print >> self.stream, pstats.f8(ct),
     if cc == 0:
         print >> self.stream, ' ' * 8,
     else:
         percall = float(ct) / cc
         result = pstats.f8(percall)
         if percall > 0.1:
             result = self.style.LONGRUN(result)
         print >> self.stream, result,
     print >> self.stream, self.func_std_string(func)
def print_line(self, func):  # hack: should print percentages
    cc, nc, tt, ct, callers = self.stats[func]
    c = str(nc)
    if nc != cc:
        c = c + '/' + str(cc)
    print('       ', c.rjust(15), end=' ', file=self.stream)
    print(f8(tt), end=' ', file=self.stream)
    if nc == 0:
        print(' ' * 8, end=' ', file=self.stream)
    else:
        print(f8(tt / nc), end=' ', file=self.stream)
    print(f8(ct), end=' ', file=self.stream)
    if cc == 0:
        print(' ' * 8, end=' ', file=self.stream)
    else:
        print(f8(ct / cc), end=' ', file=self.stream)
    print(func_std_string(func), file=self.stream)
示例#5
0
 def print_line(self, func):  # hack : should print percentages
     cc, nc, tt, ct, callers = self.stats[func]
     c = str(nc)
     if nc != cc:
         c = c + '/' + str(cc)
     print >> self.stream, c.rjust(12),   # Rob, was 9
     print >> self.stream, pstats.f8(tt),
     if nc == 0:
         print >> self.stream, ' '*8,
     else:
         print >> self.stream, pstats.f8(tt/nc),
     print >> self.stream, pstats.f8(ct),
     if cc == 0:
         print >> self.stream, ' '*8,
     else:
         print >> self.stream, pstats.f8(ct/cc),
     print >> self.stream, '  ' + pstats.func_std_string(func)
示例#6
0
def main():
    import optparse
    parser = optparse.OptionParser('%prog: [opts] <profile>...')
    opt,args = parser.parse_args()
    if len(args) == 0:
        parser.print_help()
        sys.exit(0)


    for fn in args:

        print
        print 'Cumulative time'
        print

        p = pstats.Stats(fn)
        p = p.strip_dirs()
        p.sort_stats('cumulative').print_stats(100)

        print
        print 'Callees ordered by cumulative time:'
        print
        p.print_callees(40)

        print
        print 'Time'
        print

        p = pstats.Stats(fn)
        p.sort_stats('time').print_stats(40)
        p.print_callees()


        width,lst = p.get_print_list([40])
        #print 'lst', lst
        if lst:
            p.calc_callees()
            name_size = width
            arrow = '->'
            print 'lst length:', len(lst)
            for func in lst:
                #print 'func', func
                if func in p.all_callees:
                    p.print_call_heading(width, "called...")
                    print pstats.func_std_string(func).ljust(name_size) + arrow,
                    print
                    #p.print_call_line(width, func, p.all_callees[func])
                    cc = p.all_callees[func]
                    #print 'Callees:', cc
                    TT = []
                    CT = []
                    for func,value in cc.items():
                        #print 'func,value', func, value
                        if isinstance(value, tuple):
                            nc, ccx, tt, ct = value
                            TT.append(tt)
                            CT.append(ct)
                            #print '  ', func, ct, tt
                        else:
                            print 'NON-TUPLE', value

                    I = np.argsort(CT)
                    FV = list(cc.items())
                    for i in reversed(I[-40:]):
                        func,value = FV[i]
                        name = pstats.func_std_string(func)
                        if isinstance(value, tuple):
                            nc, ccx, tt, ct = value
                            if nc != ccx:
                                substats = '%d/%d' % (nc, ccx)
                            else:
                                substats = '%d' % (nc,)
                            substats = '%-20s %s %s  %s' % (substats, pstats.f8(tt), pstats.f8(ct), name)
                        print '   ' + substats

                else:
                    p.print_call_line(width, func, {})
                print
                print
示例#7
0
def main():
    import optparse
    parser = optparse.OptionParser('%prog: [opts] <profile>...')
    parser.add_option('--merge',
                      action='store_true',
                      help='Merge input files into one big profile')
    opt, args = parser.parse_args()
    if len(args) == 0:
        parser.print_help()
        sys.exit(0)

    if opt.merge:
        p = pstats.Stats(args[0])
        #p.add(*args[1:])
        for fn in args[1:]:
            p.add(fn)
        P = [p]
    else:
        P = [pstats.Stats(fn) for fn in args]

    for p in P:
        print()
        print('Cumulative time')
        print()
        #p = pstats.Stats(fn)
        p = p.strip_dirs()
        p.sort_stats('cumulative').print_stats(100)

        print()
        print('Callees ordered by cumulative time:')
        print()
        p.print_callees(40)

        print()
        print('Time')
        print()

        #p = pstats.Stats(fn)
        p.sort_stats('time').print_stats(40)
        p.print_callees()

        width, lst = p.get_print_list([40])
        #print 'lst', lst
        if lst:
            p.calc_callees()
            name_size = width
            arrow = '->'
            print('lst length:', len(lst))
            for func in lst:
                #print 'func', func
                if func in p.all_callees:
                    p.print_call_heading(width, "called...")
                    print(pstats.func_std_string(func).ljust(name_size) +
                          arrow,
                          end=' ')
                    print()
                    #p.print_call_line(width, func, p.all_callees[func])
                    cc = p.all_callees[func]
                    #print 'Callees:', cc
                    TT = []
                    CT = []
                    for func, value in cc.items():
                        #print 'func,value', func, value
                        if isinstance(value, tuple):
                            nc, ccx, tt, ct = value
                            TT.append(tt)
                            CT.append(ct)
                            #print '  ', func, ct, tt
                        else:
                            print('NON-TUPLE', value)

                    I = np.argsort(CT)
                    FV = list(cc.items())
                    for i in reversed(I[-40:]):
                        func, value = FV[i]
                        name = pstats.func_std_string(func)
                        if isinstance(value, tuple):
                            nc, ccx, tt, ct = value
                            if nc != ccx:
                                substats = '%d/%d' % (nc, ccx)
                            else:
                                substats = '%d' % (nc, )
                            substats = '%-20s %s %s  %s' % (
                                substats, pstats.f8(tt), pstats.f8(ct), name)
                        print('   ' + substats)

                else:
                    p.print_call_line(width, func, {})
                print()
                print()
示例#8
0
def profile_rpc(endpoint):
    print '-' * 80
    print 'profiling rpc'
    client = RPCClientWrapper(endpoint)
    cycle = 10000
    results = []

    # get rid of additional overhead of first few rpcs
    # introduced by threadpool init
    for i in range(20):
        client.measure(1)
    # only enable rtt profile for regresion test.
    client.server_profile_enable(False, True)
    client.set_profile(False, True)
    for i in xrange(cycle):
        start = time.time()
        ret = client.measure(1)
        assert ret == 1
        results.append(time.time() - start)
        # sleep 10ms to simulate actual command channel use case
        # time.sleep(0.01)
    print '-----client profile result-----'
    print 'avg of {} measure(1) rpc: \t\t {:.3f}us'.format(
        cycle, 1000 * 1000 * sum(results) / cycle)
    client.set_profile(False, False)
    client.server_profile_enable(False, False)
    # client.rpc_client.profiler.print_stats()

    result = client.rpc_client.profile_rtt_result
    num = len(result)
    avg_rtt_call_us = 1000 * 1000 * sum(result) / num
    print 'Average RTT of {} profiled RPC (call(), no proxy): {:.3f}us'.format(
        num, avg_rtt_call_us)

    breakdown, server_profile_result = client.server_get_profile_stats(
        timeout_ms=10000)
    print 'ncall'.rjust(10), 'total time', 'cumulative time', 'func'
    for k, v in sorted(breakdown.items(),
                       key=lambda (k, v): v['cum_avg'],
                       reverse=True):
        print str(v['ncall']).rjust(10), pstats.f8(v['tot_avg']), pstats.f8(
            v['cum_avg']), k

    # print breakdown of different point
    profile_result = client.rpc_client.generate_profile_result()
    avg_list = [
        sum(profile_result[key]) / len(profile_result[key])
        for key in profile_result['keys']
    ]
    print ''.join(key.rjust(15)
                  for key in profile_result['keys']) + 'sub-total'.rjust(15)
    print ''.join(['{:.3f}us'.format(data).rjust(15) for data in avg_list
                   ]) + '{:.3f}us'.format(sum(avg_list)).rjust(15)

    print '-----server profile result-----'
    any_key = server_profile_result['keys'][0]
    num = len(server_profile_result[any_key])
    avg_list = [
        sum(server_profile_result[key]) / len(server_profile_result[key])
        for key in server_profile_result['keys']
    ]
    print ''.join(
        key.rjust(15)
        for key in server_profile_result['keys']) + 'sub-total'.rjust(15)
    print ''.join(['{:.3f}us'.format(data).rjust(15) for data in avg_list
                   ]) + '{:.3f}us'.format(sum(avg_list)).rjust(15)
    # reply_got is transport + server handle time;
    avg_reply_got = sum(profile_result['reply_got']) / len(
        profile_result['reply_got'])
    print 'avg transport time for {} rpc: {:.3f}us'.format(
        num, avg_reply_got - sum(avg_list))
    client.server_clear_profile_stats()
    client.clear_profile_stats()