New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
can I use apitrace to trace OpenGL leaks ? #416
Comments
No, not directly.
It's feasible to do so in apitrace, but a fair amount of work, either:
One way or the other, I'd imagine it would take 2-4 weeks to get this working reliably and across most objects. If you're determined to pursue this I can give a more detailed explanation. But there might be simpler alternatives as below. What OS and GPU are you developing on? If you're developing on Linux with open-source Mesa drivers, it would be much easier to implement this on the Mesa drivers themselves -- they already keep track of live objects -- so it would be just a matter of adding a KHR_debug callback to the apitrace notifying of the live application. I'd expect it would take no more than a couple of days to implement this. I'm familiar with Mesa source code, so I can also give you a few hints on this. Another strategy is to use a C/C++ structure/object for every OpenGL object. and ensure every OpenGL object is only created/destroyoed through these wrapper structures. Then you could use an ordinary C/C++ memory leak detector (e.g., valgrind, or whatever): if the OpenGL object leaked, the C/C++ object would leak too, and vice/versa. Most C/C++ applications will probably wrap OpenGL objects on C/C++ objects anyway. The drawback is of course you'd have to do it for every application. |
I'll try this, but may take care only one context at first. OpenGL object create/destroy all spell as Gen/Delete, so I think a common "GLObj" with Tex/Shader/xxx enum is enough for leak tracing .I'm not familiar with python so seems cli_dump can be my template.
sadly I work with both linux and windows, with some 3rd party libs, so hack on apitrace seems easier for me. |
Gen* doesn't really do much these days. TexImage/TexStorage is what actually does the work nowadays. But maybe that's close enough.
I don't think that's a good way to go about it. If you want to do this while running glretrace, then you need to modify On the other hand, if you're going to write a "state tracker", ie, not do this while retracing, then a scripting language like Python is the ideal. Trying to do with with pure C++, based of cli_dump will take a lot of manual labour (deserializing all arguments), and the code will quickly rot as nobody will maintain it. The reason that apitrace even exists without an army of developers behind it is because we use code generation to cope with the several thousands of OpenGL API functions. All efforts to add features that try to accomplish something based on sheer brute force have and will continue failing. I hope this makes sense. |
Thanks for advices . so I'll try python way |
a little questions: which script I can reference to do same thing likes cli_dump |
For #416 Run as: ./scripts/leaks.py --apitrace /path/to/apitrace /path/to/app.trace
since I need a quick working prototype for my work's deadline,so I've still implemented this basic check in C++ part (comicfans@7a77d4a). it adds cli command: apitrace leak-trace and qapitrace->Trace->LeakTrace entry |
I also just pushed a quick prototype to https://github.com/apitrace/apitrace/tree/leaks . It only detects texture leaks, and does not keep track of current context across multiple threads, not shared contexts. But this should get your started. |
Greate help ,but I can only spend my spare time on this so I can't guarantee the completeness. |
Based on comicfans change, but adapted to invoke `apitrace leaks`. Issue #416.
Understood. My main job is not working on apitrace neither -- just something I do to make ends meet at work and on spare time, though not much of the latter lately. Rather than achieving completeness from the start, my main goal as maintainer is try we follow a least resistence path towards completeness. I integrated your GUI changes with the python script. |
I think the Python script is now as capable as your C++ code. But I think long term it should be easier to maintain. Let me know if it still works for you. If it still works for you, I see no impediment to get this merged into master. I don't plan to do further work myself, but hopefully others can weigh in. |
Based on comicfans change, but adapted to invoke `apitrace leaks`. Issue #416. v2: Add missing file.
Just noticed I had forgotten to add |
Greate, I'll try later. |
For #416 Run as: ./scripts/leaks.py --apitrace /path/to/apitrace /path/to/app.trace
Based on comicfans change, but adapted to invoke `apitrace leaks`. Issue #416. v2: Add missing file.
I've merged into master. Thanks. Feel free to contribute further improvements anytime. I think a note in |
I've found lastest windows binary package didn't contain leaks.py, |
Ah. I forgot to add it.. I'll fix it. I should probably add an wildcard to include app |
Using a glob might fail to detect a new script, if there was no CMakeLists.txt change. However it seems less likely than me forgetting to manually add the scripts to the CMakeLists.txt. #416 (comment)
is there any scripts to help trace OpenGL object leaks ? (textures/buffers not deleted) if not , I'm planning to implement some basic leak trace function . any suggestion ?
The text was updated successfully, but these errors were encountered: