diff options
author | Jose Fonseca <jfonseca@vmware.com> | 2016-01-19 14:52:49 +0000 |
---|---|---|
committer | Jose Fonseca <jfonseca@vmware.com> | 2016-01-22 22:37:46 +0000 |
commit | d1caa422cc784a99f200d6f96ff0578d112a05c4 (patch) | |
tree | c1a97f07554168241058aed4d1f4db1c11c51152 | |
parent | 771c34f3caba89becd97cb819a2241538571966b (diff) |
scripts: Keep count of all live contexts.
Issue #416.
-rwxr-xr-x | scripts/leaks.py | 44 |
1 files changed, 28 insertions, 16 deletions
diff --git a/scripts/leaks.py b/scripts/leaks.py index 1115bfb1..0459060c 100755 --- a/scripts/leaks.py +++ b/scripts/leaks.py @@ -34,13 +34,6 @@ import re import unpickle -class ContextState: - - def __init__(self): - # a map of maps - self.objectDicts = {} - - class LeakDetector(unpickle.Unpickler): def __init__(self, apitrace, trace): @@ -50,13 +43,16 @@ class LeakDetector(unpickle.Unpickler): unpickle.Unpickler.__init__(self, p.stdout) - self.context = ContextState() + self.numContexts = 0 + + # a map of maps + self.objectDicts = {} def parse(self): unpickle.Unpickler.parse(self) # Reached the end of the trace -- dump any live objects - self.dumpLeaks("<EOF>", self.context) + self.dumpLeaks("<EOF>") genDelRegExp = re.compile('^gl(Gen|Delete)(Buffers|Textures|FrameBuffers|RenderBuffers)[A-Z]*$') @@ -69,16 +65,13 @@ class LeakDetector(unpickle.Unpickler): if 0: sys.stderr.write('%s\n' % call) - # FIXME: keep track of current context on each thread (*MakeCurrent) - context = self.context - mo = self.genDelRegExp.match(call.functionName) if mo: verb = mo.group(1) subject = mo.group(2) subject = subject.lower().rstrip('s') - objectDict = context.objectDicts.setdefault(subject, {}) + objectDict = self.objectDicts.setdefault(subject, {}) if verb == 'Gen': self.handleGenerate(call, objectDict) @@ -87,18 +80,37 @@ class LeakDetector(unpickle.Unpickler): else: assert 0 + # TODO: Track labels via glObjectLabel* calls + + if call.functionName in [ + 'CGLCreateContext', + 'eglCreateContext', + 'glXCreateContext', + 'glXCreateContextAttribsARB', + 'glXCreateContextWithConfigSGIX', + 'wglCreateContext', + 'wglCreateContextAttribsARB', + ]: + # FIXME: Ignore failing context creation calls + self.numContexts += 1 + if call.functionName in [ + 'CGLDestroyContext', 'glXDestroyContext', 'eglDestroyContext', 'wglDeleteContext', ]: - self.dumpLeaks(call.no, context) + assert self.numContexts > 0 + self.numContexts -= 1 + if self.numContexts == 0: + self.dumpLeaks(call.no) def handleGenerate(self, call, objectDict): n, names = call.argValues() for i in range(n): name = names[i] objectDict[name] = call.no + # TODO: Keep track of call stack backtrace too def handleDelete(self, call, objectDict): n, names = call.argValues() @@ -110,8 +122,8 @@ class LeakDetector(unpickle.Unpickler): # Ignore if texture name was never generated pass - def dumpLeaks(self, currentCallNo, context): - for kind, objectDict in context.objectDicts.iteritems(): + def dumpLeaks(self, currentCallNo): + for kind, objectDict in self.objectDicts.iteritems(): self.dumpNamespaceLeaks(currentCallNo, objectDict, kind) def dumpNamespaceLeaks(self, currentCallNo, objectDict, kind): |