How to time widget draw time, and what are acceptable values?

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?

Thanks!
Bret

For me I don’t like any of my modules to take more than 1% of the resource in question. Most of my modules have the code you are looking for,

Are you referring to…

#ifdef _TIME_DRAWING
    // Gray: avg = 52.826101, stddev = 16.951956 (us) Quota frac=0.316957
    void draw(const DrawArgs &args) override
    {
        DrawLocker l(drawTimer);
        ModuleWidget::draw(args);
    }
#endif

It looks really promising! I see it defined here: SquinkyVCV/DrawTimer.h at 167322541dcdc6852cc165267edc5e671c23fd04 · squinkylabs/SquinkyVCV · GitHub

Which seems to rely on SquinkyVCV/SqTime.h at 167322541dcdc6852cc165267edc5e671c23fd04 · squinkylabs/SquinkyVCV · GitHub

Would you happen to have any documentation for this code? Maybe a simple “how to” on it?

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:

#ifdef _TIME_DRAWING
static DrawTimer drawTimer("LFN");
#endif

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.

1 Like

Awesome, thanks!!

I think that I’m really close to getting your code working. But I ran into one snag. How do I view the output from:

    printf("%s: avg = %f, stddev = %f (us) Quota frac=%f\n",
        name.c_str(),
        avg * million,
        stdDev * million,
        avg / quotaSeconds);
    fflush(stdout);

Thanks!

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.

It does sound like you are very close.

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. :thinking: 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.

Galacto: avg = 13.298000, stddev = 3.710868 (us) Quota frac=0.079788
Galacto: avg = 13.274250, stddev = 1.908288 (us) Quota frac=0.079646
Galacto: avg = 13.946000, stddev = 2.432629 (us) Quota frac=0.083676
Galacto: avg = 13.658250, stddev = 2.509329 (us) Quota frac=0.081949
Galacto: avg = 13.606250, stddev = 0.992767 (us) Quota frac=0.081638
Galacto: avg = 13.579500, stddev = 1.327452 (us) Quota frac=0.081477
Galacto: avg = 13.675000, stddev = 1.194686 (us) Quota frac=0.082050

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.

1 Like