util: available_memory + missing declarations for gettime :)

This commit is contained in:
Michele Caini 2023-05-19 14:25:21 +02:00
parent bd90d77bc7
commit 8743dfc155
3 changed files with 17 additions and 1 deletions

View File

@ -306,6 +306,10 @@ UVW_INLINE uint64_t utilities::constrained_memory() noexcept {
return uv_get_constrained_memory();
}
UVW_INLINE uint64_t utilities::available_memory() noexcept {
return uv_get_available_memory();
}
UVW_INLINE double utilities::uptime() noexcept {
double ret;

View File

@ -86,6 +86,7 @@ using file_handle = details::uv_type_wrapper<uv_file>; /*!< Utility c
using os_socket_handle = details::uv_type_wrapper<uv_os_sock_t>; /*!< Utility class that wraps an os socket handle. */
using os_file_descriptor = details::uv_type_wrapper<uv_os_fd_t>; /*!< Utility class that wraps an os file descriptor. */
using pid_type = details::uv_type_wrapper<uv_pid_t>; /*!< Utility class that wraps a cross platform representation of a pid. */
using clock_id = details::uvw_clock_id; /*!< Utility class that wraps a clock source. */
constexpr file_handle std_in{0}; /*!< Placeholder for stdin descriptor. */
constexpr file_handle std_out{1}; /*!< Placeholder for stdout descriptor. */
@ -99,6 +100,7 @@ using gid_type = uv_gid_t; /*!< Library equivalent for uv_gid_t. */
using timeval = uv_timeval_t; /*!< Library equivalent for uv_timeval_t. */
using timeval64 = uv_timeval64_t; /*!< Library equivalent for uv_timeval64_t. */
using timespec64 = uv_timespec64_t; /*!< Library equivalent for uv_timespec64_t. */
using resource_usage = uv_rusage_t; /*!< Library equivalent for uv_rusage_t. */
/**
@ -596,6 +598,12 @@ struct utilities {
*/
static uint64_t constrained_memory() noexcept;
/**
* @brief Gets the amount of free memory still available to the process.
* @return Amount of free memory still available to the process (in bytes).
*/
static uint64_t available_memory() noexcept;
/**
* @brief Gets the current system uptime.
* @return The current system uptime or 0 in case of errors.

View File

@ -4,7 +4,9 @@
#include <uvw.hpp>
template<typename T>
struct tag { using type = T; };
struct tag {
using type = T;
};
TEST(Util, Utilities) {
ASSERT_EQ(uvw::pid_type{}, uvw::pid_type{});
@ -81,6 +83,8 @@ TEST(Util, Utilities) {
ASSERT_NO_THROW(uvw::utilities::load_average());
ASSERT_NE(uvw::utilities::total_memory(), decltype(uvw::utilities::total_memory()){0});
ASSERT_NE(uvw::utilities::constrained_memory(), decltype(uvw::utilities::constrained_memory()){0});
ASSERT_NE(uvw::utilities::available_memory(), decltype(uvw::utilities::available_memory()){0});
ASSERT_NE(uvw::utilities::uptime(), decltype(uvw::utilities::uptime()){0});
ASSERT_NO_THROW(uvw::utilities::rusage());
ASSERT_NO_THROW(uvw::utilities::gettime(uvw::clock_id::MONOTONIC));