Skip to content

Commit

Permalink
How did that ever work
Browse files Browse the repository at this point in the history
  • Loading branch information
TrentHouliston committed Nov 12, 2023
1 parent 1d34461 commit e0aa92f
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/util/usage_clock.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#include "usage_clock.hpp"

namespace NUClear {
namespace util {

// Linux
#if defined(__linux__)
#include <sys/resource.h>

namespace NUClear {
namespace util {

user_cpu_clock::time_point user_cpu_clock::now() noexcept {
struct rusage usage;
int err = ::getrusage(RUSAGE_THREAD, &usage);
Expand All @@ -27,12 +28,19 @@ namespace util {
return time_point();
}

} // namespace util
} // namespace NUClear

// Mac OS X
#elif defined(__MACH__) && defined(__APPLE__)

#include <errno.h>
#include <mach/mach.h>
#include <sys/resource.h>

namespace NUClear {
namespace util {

user_cpu_clock::time_point user_cpu_clock::now() noexcept {
thread_basic_info_data_t info{};
mach_msg_type_number_t info_count = THREAD_BASIC_INFO_COUNT;
Expand Down Expand Up @@ -65,10 +73,16 @@ namespace util {
return time_point();
}

} // namespace util
} // namespace NUClear

// Windows
#elif defined(_WIN32)
#include "platform.hpp"

namespace NUClear {
namespace util {

user_cpu_clock::time_point user_cpu_clock::now() noexcept {
FILETIME creation_time;
FILETIME exit_time;
Expand All @@ -95,7 +109,7 @@ namespace util {
return time_point();
}

#endif

} // namespace util
} // namespace NUClear

#endif // OS

0 comments on commit e0aa92f

Please sign in to comment.