Reputation: 875
I wrote a daemon using the python-daemon library. And it uses about 20% of CPU all the time. Can I somehow check which part of the program uses all this CPU time cause well it actually just waits for userinput? Help is as always much appreciated!
My daemon is started:
python file1:
context = daemon.DaemonContext()
context.pidfile = PidFile(pidfile)
with context:
module.run()
python file2:
def run():
end = threading.Event()
# Do something here then:
try:
while not end.isSet():
# Do some more stuff
except KeyboardInterrupt, SystemExit:
pass
# Except some more stuff
** EDIT
Maybe you could help me again, now I ran a profiler but can't really tell who the "baddie" is. Here is my profile results
Upvotes: 1
Views: 1061
Reputation: 83498
You can attach a Python profiler to your software:
http://docs.python.org/library/profile.html
... and make the profiler start when the daemon is started. Then let the profiler collect profiling information a while and use a signal sent to process (e.g. SIGUSR1) to make your deamon to dump the profiling data to a file.
http://docs.python.org/library/signal.html
...or alternative write profiling log when the process exits at atexit handler.
Then you can read this file and see which function has most cumulative CPU usage.
Upvotes: 4