Skip to content

Commit 25ad53a

Browse files
committed
Adding hotshot profiling and main() entry point for profiling.
1 parent ccd635a commit 25ad53a

File tree

1 file changed

+32
-15
lines changed

1 file changed

+32
-15
lines changed

watch

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
#!/usr/bin/python
22

3+
# To make this event driven, watch the root window for
4+
# _NET_ACTIVE_WINDOW property changes. The down side of event driven
5+
# is that the window observation may not coincide with the observed
6+
# property change event. (i.e. active window changes twice before we
7+
# can observe window focus once). Also, there's more back and forth
8+
# when windows do switch (prop change event + get_input_focus).
9+
310
import os
411
import re
512
import time
@@ -8,6 +15,8 @@ from Xlib import display
815
from select import select
916
from subprocess import Popen, PIPE
1017

18+
import hotshot
19+
1120
D = display.Display()
1221

1322
oldname = newname = ''
@@ -56,18 +65,26 @@ xss_proc = Popen(['xscreensaver-command', '-watch'], stdout=PIPE)
5665
fd_handlers[xss_proc.stdout] = xss_event
5766
infds = [xss_proc.stdout]
5867

59-
winmon()
60-
running = True
61-
while running:
62-
try:
63-
(infda,outfda,errfda) = select(infds, outfds, errfds, 0.3)
64-
if infda:
65-
for fd in infda:
66-
fd_handlers[fd](fd)
67-
68-
# Always check window state
69-
winmon()
70-
except KeyboardInterrupt:
71-
running = False
72-
# Because otherwise they don't clean up when we go away...
73-
os.kill(xss_proc.pid, 15)
68+
#profiler = hotshot.Profile()
69+
70+
def main():
71+
72+
winmon()
73+
running = True
74+
while running:
75+
try:
76+
(infda,outfda,errfda) = select(infds, outfds, errfds, 0.3)
77+
if infda:
78+
for fd in infda:
79+
fd_handlers[fd](fd)
80+
81+
# Always check window state
82+
winmon()
83+
except KeyboardInterrupt:
84+
running = False
85+
# Because otherwise they don't clean up when we go away...
86+
os.kill(xss_proc.pid, 15)
87+
88+
#profiler.runcall(main)
89+
90+
main()

0 commit comments

Comments
 (0)