Archive for January, 2008
I spent a good part of last night and today trying to find a handful of leaks in Mail Unread Menu. However, in trying to use the leaks tool, I became tired of continuously searching for my running application’s pid after restarting it. So, I wrote a small bit of python which I called lleaks (not too much of a muscle-memory change). You can use it just like leaks, but with the name of the application, for example: lleaks Mail Unread Menu.
#! /usr/bin/python
from commands import getoutput
from sys import argv
def main():
# get program name from arguments, escaping the spaces
programName = "\ ".join(argv[1:])
# run ps ax
output = getoutput("ps ax | grep " + programName)
output = output.split('\n')
# filter out this program from the output
filteredOutput = []
for item in output:
if -1 == item.find('lleaks') and -1 == item.find('ps ax') and -1 == item.find('grep'):
filteredOutput.append(item)
# there is no program
if 0 == len(filteredOutput):
print "lleaks cannot examine program " + " ".join(programName.split("\ ")) + " because the program does not exist."
return
# use first instance of the program
program = filteredOutput[0]
# remove white space at beginning of string
while 0 == program.find(' '):
program = program[1:]
# get process for program
process = program[:program.find(' ')]
# run leaks
print getoutput("leaks " + process)
if __name__ == '__main__': main()