uvw 3.1.0
Loading...
Searching...
No Matches
Classes | Static Public Member Functions | List of all members
uvw::utilities Struct Reference

Miscellaneous utilities. More...

#include <util.h>

Classes

struct  os
 OS dedicated utilities. More...
 

Static Public Member Functions

static handle_type guess_handle (handle_category category) noexcept
 Gets the type of the handle given a category.
 
static handle_type guess_handle (file_handle file) noexcept
 Gets the type of the stream to be used with the given descriptor.
 
static std::vector< cpu_infocpu () noexcept
 Gets information about the CPUs on the system.
 
static std::vector< interface_addressinterface_addresses () noexcept
 Gets a set of descriptors of all the available interfaces.
 
static std::string index_to_name (unsigned int index) noexcept
 IPv6-capable implementation of if_indextoname.
 
static std::string index_to_iid (unsigned int index) noexcept
 Retrieves a network interface identifier.
 
static bool replace_allocator (malloc_func_type malloc_func, realloc_func_type realloc_func, calloc_func_type calloc_func, free_func_type free_func) noexcept
 Override the use of some standard library’s functions.
 
static std::array< double, 3 > load_average () noexcept
 Gets the load average.
 
static char ** setup_args (int argc, char **argv)
 Store the program arguments.
 
static std::string process_title ()
 Gets the title of the current process.
 
static bool process_title (const std::string &title)
 Sets the current process title.
 
static uint64_t total_memory () noexcept
 Gets memory information (in bytes).
 
static uint64_t constrained_memory () noexcept
 Gets the amount of memory available to the process (in bytes).
 
static uint64_t available_memory () noexcept
 Gets the amount of free memory still available to the process.
 
static double uptime () noexcept
 Gets the current system uptime.
 
static resource_usage rusage () noexcept
 Gets the resource usage measures for the current process.
 
static timespec64 gettime (clock_id source) noexcept
 Gets the current system time from a high-resolution clock source.
 
static uint64_t hrtime () noexcept
 Gets the current high-resolution real time.
 
static std::string path () noexcept
 Gets the executable path.
 
static std::string cwd () noexcept
 Gets the current working directory.
 
static bool chdir (const std::string &dir) noexcept
 Changes the current working directory.
 
static timeval64 time_of_day () noexcept
 Cross-platform implementation of gettimeofday
 
static void sleep (unsigned int msec) noexcept
 Causes the calling thread to sleep for a while.
 
static unsigned int available_parallelism () noexcept
 Returns an estimate of the amount of parallelism a program should use (always a non-zero value).
 

Detailed Description

Miscellaneous utilities.

Miscellaneous functions that don’t really belong to any other class.

Definition at line 288 of file util.h.

Member Function Documentation

◆ available_memory()

static uint64_t uvw::utilities::available_memory ( )
staticnoexcept

Gets the amount of free memory still available to the process.

Returns
Amount of free memory still available to the process (in bytes).

◆ available_parallelism()

static unsigned int uvw::utilities::available_parallelism ( )
staticnoexcept

Returns an estimate of the amount of parallelism a program should use (always a non-zero value).

Returns
Estimate of the amount of parallelism a program should use.

◆ chdir()

static bool uvw::utilities::chdir ( const std::string &  dir)
staticnoexcept

Changes the current working directory.

Parameters
dirThe working directory to be set.
Returns
True in case of success, false otherwise.

◆ constrained_memory()

static uint64_t uvw::utilities::constrained_memory ( )
staticnoexcept

Gets the amount of memory available to the process (in bytes).

Gets the amount of memory available to the process based on limits imposed by the OS. If there is no such constraint, or the constraint is unknown, 0 is returned.
Note that it is not unusual for this value to be less than or greater than totalMemory.

Returns
Amount of memory available to the process.

◆ cpu()

static std::vector< cpu_info > uvw::utilities::cpu ( )
staticnoexcept

Gets information about the CPUs on the system.

This function can be used to query the underlying system and get a set of descriptors of all the available CPUs.

Returns
A set of descriptors of all the available CPUs.

◆ cwd()

static std::string uvw::utilities::cwd ( )
staticnoexcept

Gets the current working directory.

Returns
The current working directory, an empty string in case of errors.

◆ gettime()

static timespec64 uvw::utilities::gettime ( clock_id  source)
staticnoexcept

Gets the current system time from a high-resolution clock source.

Parameters
sourceClock source, either real-time or monotonic.
Returns
Current system time from the given high-resolution clock source.

◆ guess_handle() [1/2]

static handle_type uvw::utilities::guess_handle ( file_handle  file)
staticnoexcept

Gets the type of the stream to be used with the given descriptor.

Returns the type of stream that should be used with a given file descriptor.
Usually this will be used during initialization to guess the type of the stdio streams.

Parameters
fileA valid descriptor.
Returns
One of the following types:
  • handle_type::UNKNOWN
  • handle_type::PIPE
  • handle_type::TCP
  • handle_type::TTY
  • handle_type::UDP
  • handle_type::FILE

◆ guess_handle() [2/2]

static handle_type uvw::utilities::guess_handle ( handle_category  category)
staticnoexcept

Gets the type of the handle given a category.

Parameters
categoryA properly initialized handle category.
Returns
The actual type of the handle as defined by handle_type

◆ hrtime()

static uint64_t uvw::utilities::hrtime ( )
staticnoexcept

Gets the current high-resolution real time.

The time is expressed in nanoseconds. It is relative to an arbitrary time in the past. It is not related to the time of the day and therefore not subject to clock drift. The primary use is for measuring performance between interval.

Returns
The current high-resolution real time.

◆ index_to_iid()

static std::string uvw::utilities::index_to_iid ( unsigned int  index)
staticnoexcept

Retrieves a network interface identifier.

See the official documentation for further details.

Parameters
indexNetwork interface index.
Returns
Network interface identifier.

◆ index_to_name()

static std::string uvw::utilities::index_to_name ( unsigned int  index)
staticnoexcept

IPv6-capable implementation of if_indextoname.

Mapping between network interface names and indexes.

See the official documentation for further details.

Parameters
indexNetwork interface index.
Returns
Network interface name.

◆ interface_addresses()

static std::vector< interface_address > uvw::utilities::interface_addresses ( )
staticnoexcept

Gets a set of descriptors of all the available interfaces.

This function can be used to query the underlying system and get a set of descriptors of all the available interfaces, either internal or not.

Returns
A set of descriptors of all the available interfaces.

◆ load_average()

static std::array< double, 3 > uvw::utilities::load_average ( )
staticnoexcept

Gets the load average.

Returns
[0,0,0] on Windows (not available), the load average otherwise.

◆ path()

static std::string uvw::utilities::path ( )
staticnoexcept

Gets the executable path.

Returns
The executable path, an empty string in case of errors.

◆ process_title() [1/2]

static std::string uvw::utilities::process_title ( )
static

Gets the title of the current process.

Returns
The process title.

◆ process_title() [2/2]

static bool uvw::utilities::process_title ( const std::string &  title)
static

Sets the current process title.

Parameters
titleThe process title to be set.
Returns
True in case of success, false otherwise.

◆ replace_allocator()

static bool uvw::utilities::replace_allocator ( malloc_func_type  malloc_func,
realloc_func_type  realloc_func,
calloc_func_type  calloc_func,
free_func_type  free_func 
)
staticnoexcept

Override the use of some standard library’s functions.

Override the use of the standard library’s memory allocation functions.
This method must be invoked before any other uvw function is called or after all resources have been freed and thus the underlying library doesn’t reference any allocated memory chunk.

If any of the function pointers is null, the invokation will fail.

Note
There is no protection against changing the allocator multiple times. If the user changes it they are responsible for making sure the allocator is changed while no memory was allocated with the previous allocator, or that they are compatible.
Parameters
malloc_funcReplacement function for malloc.
realloc_funcReplacement function for realloc.
calloc_funcReplacement function for calloc.
free_funcReplacement function for free.
Returns
True in case of success, false otherwise.

◆ rusage()

static resource_usage uvw::utilities::rusage ( )
staticnoexcept

Gets the resource usage measures for the current process.

Returns
Resource usage measures, zeroes-filled object in case of errors.

◆ setup_args()

static char ** uvw::utilities::setup_args ( int  argc,
char **  argv 
)
static

Store the program arguments.

Required for getting / setting the process title.

Returns
Arguments that haven't been consumed internally.

◆ sleep()

static void uvw::utilities::sleep ( unsigned int  msec)
staticnoexcept

Causes the calling thread to sleep for a while.

Parameters
msecNumber of milliseconds to sleep.

◆ time_of_day()

static timeval64 uvw::utilities::time_of_day ( )
staticnoexcept

Cross-platform implementation of gettimeofday

Returns
The current time.

◆ total_memory()

static uint64_t uvw::utilities::total_memory ( )
staticnoexcept

Gets memory information (in bytes).

Returns
Memory information.

◆ uptime()

static double uvw::utilities::uptime ( )
staticnoexcept

Gets the current system uptime.

Returns
The current system uptime or 0 in case of errors.

The documentation for this struct was generated from the following file: