Discussion:
[brlcad-devel] librt timer
Christopher Sean Morrison
2016-10-27 18:10:15 UTC
Permalink
Cliff et al.,

I revisited the librt timer given your comment about it. It does indeed track both user and wallclock time uing platform-specific means. It also does its own string printing, but lets ignore that for now. Code is in the various src/librt/timer-*.c per-platform files.

You’re right that it should be in libbu. However, it can’t be moved as-is because it’s designed to use globals and we shouldn’t introduce any more globals to any lib.

To move it, we need an api either parallel to or replacing bu_gettime() and bu_utctime(). Fortunately, both those names kind of suck, so I’m thinking we just design a better replacement api. The difficulty is that the current bu timer is really simple:

int64_t start = bu_gettime();

printf(“elapsed is %lf\n”, bu_gettime() - start);

The bu timer says its supposed to be a wallclock timer, which means it might be wrong on Windows due to the timer being used — I’ll check on that. The only way I can see keeping any new usage that simple, **without introducing a whole other function**, is to have bu_gettime() take bitflags and perhaps return an array of int64_t’s (with the bitflags doubling as indices). Something like this:

int64_t start[2], stop[2];
bu_time(&start, sizeof(start), BU_TIME_WALLCLOCK | BU_TIME_CPU);

bu_time(&stop, sizeof(stop), BU_TIME_WALLCLOCK);
printf(“elapsed is %lf\n”, stop[BU_TIME_WALLCLOCK] - start[BU_TIME_WALLCLOCK]);

There are obviously other options. Anyone have any suggestions? This would probably make a great couple GCI tasks… ;)

Cheers!
Sean
Clifford Yapp
2016-10-28 19:32:36 UTC
Permalink
On Thu, Oct 27, 2016 at 2:10 PM, Christopher Sean Morrison
Post by Christopher Sean Morrison
To move it, we need an api either parallel to or replacing bu_gettime() and bu_utctime().
Fortunately, both those names kind of suck, so I’m thinking we just design a better
replacement api. [snip] The only way I can see keeping any new usage that simple,
**without introducing a whole other function**, is to have bu_gettime() take bitflags
int64_t start[2], stop[2];
bu_time(&start, sizeof(start), BU_TIME_WALLCLOCK | BU_TIME_CPU);

bu_time(&stop, sizeof(stop), BU_TIME_WALLCLOCK);
printf(“elapsed is %lf\n”, stop[BU_TIME_WALLCLOCK] - start[BU_TIME_WALLCLOCK]);
There are obviously other options. Anyone have any suggestions? This would probably
make a great couple GCI tasks… ;)
Hmm. Are you proposing returning an array to allow for the
possibility of (essentially) simultaneous setting of wall clock and
cpu clock values? I like the idea of passing an argument to the time
function to get different types of time, but absent a hard need for
simultaneous stamping of wall and cpu clocks my suggestion would be to
go really simple:

int64_t wall, cpu;
wall = bu_time(BU_TIME_WALLCLOCK);
cpu = bu_time(BU_TIME_CPU);
...
printf(“wallclock elapsed is %lf\n”, bu_time(BU_TIME_WALLCLOCK) - start);
printf(“cpu elapsed is %lf\n”, bu_time(BU_TIME_CPU) - start);

but I'm less familiar with some of the subtler issues of timing so
there may be some aspect of this that is not practical.

CY

Loading...