Hello! This is related to another post of mine, but I thought it might be helpful to break it into a new post for easy reference and make it more of a general question.
Could someone share some code for timing and logging widget draw times? And what would be considered acceptable values?
Yeah, that’s it. If you have any specific questions I’d be happy to answer. Otherwise I’d say just take DrawTimer and DrawLocker and use them - I think other people have done that. In each module you want to time you just put that code in there (or the equivilent, if you already override draw.
And you can see in each module I also define a static draw timer:
The idea is that the DrawTimer object builds up averages of many runs, and the DrawLocker lets it now when the draw starts and stops. Every now and then it prints some stats to the log.
Oh, and no there isn’t any more documentation that what’s in the source code comments. Looking at the code (for the firs time in a really long time!) I see there isn’t much code. DrawTimer is pretty simple, and I just needed Sqtime to get a high resolution time on windows, as the normal timer resolution is terrible. It’s also extremely simple - should be easy to figure out if you want.
SqTime is super ancient - I wrote it to measure CPU usage of my first module, back in the early Rack 0.6 days.
It come out in the console - I always launch dev rack from an msys2 console. if you changed that to fprintf(stderr, I think it would go to the log file. maybe it would anyway, not sure.
Ah, great! That worked. I just now got it working, and I’m only testing it on one module. (My code isn’t as well structured as yours yet, and I hacked it in the short term.)
I can’t tell if these numbers are any good. They’re good compared to the values that you have in your source code, but perhaps my computer is faster. Tomorrow I’ll extend the code to time my simpler front panels and see how they compare.
I will have to take a look. those numbers do look pretty good, and when I did my original measurements I had a different computer, so your numbers should be better. Like I say, I’ll have to check, but usually my “quota” is for a module to use 1%.
Of course, as others will tell you, There’s much more to it than the draw time - there’s time the GPU spends afterward. But I will say this stuff helped me. I found the drawing the waveform buttons on EV-3 took a huge amount of time, so I fixed it.