Gentoo Archives: gentoo-commits

From: "Alec Warner (antarus)" <antarus@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo commit in users/antarus/projects/infra: process_timer
Date: Fri, 02 May 2008 07:17:02
Message-Id: E1JrpVp-0000fu-RY@stork.gentoo.org
1 antarus 08/05/02 07:16:57
2
3 Modified: process_timer
4 Log:
5 Updates, changes times to a dict, add more debugging.
6
7 Revision Changes Path
8 1.3 users/antarus/projects/infra/process_timer
9
10 file : http://sources.gentoo.org/viewcvs.py/gentoo/users/antarus/projects/infra/process_timer?rev=1.3&view=markup
11 plain: http://sources.gentoo.org/viewcvs.py/gentoo/users/antarus/projects/infra/process_timer?rev=1.3&content-type=text/plain
12 diff : http://sources.gentoo.org/viewcvs.py/gentoo/users/antarus/projects/infra/process_timer?r1=1.2&r2=1.3
13
14 Index: process_timer
15 ===================================================================
16 RCS file: /var/cvsroot/gentoo/users/antarus/projects/infra/process_timer,v
17 retrieving revision 1.2
18 retrieving revision 1.3
19 diff -u -r1.2 -r1.3
20 --- process_timer 2 May 2008 04:37:17 -0000 1.2
21 +++ process_timer 2 May 2008 07:16:57 -0000 1.3
22 @@ -1,5 +1,5 @@
23 #!/usr/bin/python
24 -# $Header: /var/cvsroot/gentoo/users/antarus/projects/infra/process_timer,v 1.2 2008/05/02 04:37:17 robbat2 Exp $
25 +# $Header: /var/cvsroot/gentoo/users/antarus/projects/infra/process_timer,v 1.3 2008/05/02 07:16:57 antarus Exp $
26 # Copyright Alec Warner 2008
27 # Released in the public domain.
28
29 @@ -24,11 +24,15 @@
30
31 parser = optparse.OptionParser()
32 parser.add_option('-p', '--prog', help='program to search for')
33 - parser.add_option('-t', '--time', help='max time prog can run')
34 - parser.add_option('-w', '--walltime', help='match time against walltime')
35 + parser.add_option('-t', '--time', help='max time prog can run in seconds')
36 + parser.add_option('-w', '--walltime', action='store_true',
37 + help='match time against walltime')
38 parser.add_option('-v', '--verbose', help='increase loglevel')
39 opts, args = parser.parse_args()
40
41 + if opts.time:
42 + opts.time = int(opts.time)
43 +
44 if not opts.prog:
45 parser.error('--prog is required')
46
47 @@ -42,6 +46,7 @@
48
49 return opts, args
50
51 +
52 def FindPids(search_str):
53 """Return PIDS for all processes that have match search_str.
54 Args:
55 @@ -81,10 +86,10 @@
56 Args:
57 pid: pid to make time calculations for.
58 Returns:
59 - A tuple of random crap.
60 + A dict of random times.
61
62 These times are in 'jiffies' or as far as I can tell USER_HZ or 1/100ths
63 - of a second slices.
64 + of a second slices on recent linux kernels.
65 """
66
67 PID_DIR_PATH = os.path.join(PROC_PATH, pid)
68 @@ -95,7 +100,15 @@
69 wall = int(utime) + int(stime)
70 cwall = int(cutime) + int(cstime)
71
72 - return (utime, stime, cutime, cstime, wall, cwall, starttime)
73 + d = { 'utime' : utime,
74 + 'stime' : stime,
75 + 'cutime' : cutime,
76 + 'cstime' : cstime,
77 + 'wall' : wall,
78 + 'cwall' : cwall,
79 + 'starttime' : starttime }
80 +
81 + return d
82
83
84 def Main():
85 @@ -105,8 +118,13 @@
86 pids = FindPids(opts.prog)
87 for pid in pids:
88 times = CalculateTime(pid[0])
89 + logging.debug("Times: %s: %s" % (pid[1], times))
90 if opts.walltime:
91 - if times[4] / 100 > opts.time:
92 + import pdb
93 + pdb.set_trace()
94 + print times['wall'] / 100, opts.time
95 + if times['wall'] / 100 > opts.time:
96 + print 'ponies'
97 print pid[0]
98
99 if __name__ == "__main__":
100
101
102
103 --
104 gentoo-commits@l.g.o mailing list