clava icon indicating copy to clipboard operation
clava copied to clipboard

Platform-agnostic C timers

Open tiagolascasas opened this issue 2 years ago • 1 comments

When using the lara.code.Timer API, the timers inserted into the code are those from the current OS, i.e., Windows timers if Clava is running on Windows, and UNIX timers if it is running on Linux or other *nix.

However, I've run into the use case where I am working with Linux-specific input C code, but since I am running Clava on Windows it inserts Windows timers into the Linux application.

Therefore, I suggest an additional (optional) argument to the Timer constructor, specifying which kinds of timers we want to use, like so:

const timer = new Timer("MICROSECONDS", this.filename);

becomes

const timer = new Timer("MICROSECONDS", this.filename, "UNIX");

As an added note, I don't think this problem happens with C++, as it uses STL timers in that scenario. This is a C-only issue.

tiagolascasas avatar Mar 17 '23 00:03 tiagolascasas

The Timer API, as well as other APIs that generate code that depends on the platform, use the API Platforms to check on which platform they are currently executing.

The API contains setters (e.g. Platforms.setLinux()) which can be used to set a particular platform. That is the preferred way to generate code for a target platform that is not the same as the host platform.

joaobispo avatar Mar 17 '23 18:03 joaobispo