File: debugtime.py

package info (click to toggle)
python-pyepics 3.5.7%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,336 kB
  • sloc: python: 10,539; makefile: 112; javascript: 104; sh: 53
file content (44 lines) | stat: -rwxr-xr-x 1,239 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import time
import sys
class debugtime(object):
    def __init__(self):
        self.clear()
        self.add('debugtime init')

    def clear(self):
        self.times = []

    def add(self,msg='', verbose=False):
        # print msg
        self.times.append((msg,time.time()))
        if verbose:
            sys.stdout.write("%s\n"% msg)
            
    def show(self, writer=None, clear=True):
        if writer is None:
            writer = sys.stdout.write
        writer('%s\n' % self.get_report())
        if clear:
            self.clear()
            

    def get_report(self):
        m0, t0 = self.times[0]
        tlast= t0
        out  = ["# %s  %s " % (m0,time.ctime(t0))]
        lmsg = 0
        for m, t in self.times[1:]:
            lmsg = max(lmsg, len(m))            
        m = '#      Message'
        m = m + ' '*(lmsg-len(m))

        out.append("#--------------------" + '-'*lmsg)
        out.append('%s        Delta(s)     Total(s)' % (m))
        for m,t in self.times[1:]:
            tt = t-t0
            dt = t-tlast
            if len(m)<lmsg:
                m = m + ' '*(lmsg-len(m))
            out.append(" %s   %10.3f    %10.3f" % (m,dt, tt))
            tlast = t
        return '\n'.join(out)