uvw  2.1.0
Classes | Static Public Member Functions | List of all members
uvw::Utilities Struct Reference

Miscellaneous utilities. More...

#include <util.hpp>

Classes

struct  OS
 OS dedicated utilities. More...
 

Static Public Member Functions

static int osPriority (PidType pid)
 Retrieves the scheduling priority of a process. More...
 
static bool osPriority (PidType pid, int prio)
 Sets the scheduling priority of a process. More...
 
static HandleType guessHandle (HandleCategory category) noexcept
 Gets the type of the handle given a category. More...
 
static HandleType guessHandle (FileHandle file) noexcept
 Gets the type of the stream to be used with the given descriptor. More...
 
static std::vector< CPUInfocpuInfo () noexcept
 Gets information about the CPUs on the system. More...
 
static std::vector< InterfaceAddressinterfaceAddresses () noexcept
 Gets a set of descriptors of all the available interfaces. More...
 
static std::string indexToName (unsigned int index) noexcept
 IPv6-capable implementation of if_indextoname. More...
 
static std::string indexToIid (unsigned int index) noexcept
 Retrieves a network interface identifier. More...
 
static bool replaceAllocator (MallocFuncType mallocFunc, ReallocFuncType reallocFunc, CallocFuncType callocFunc, FreeFuncType freeFunc) noexcept
 Override the use of some standard library’s functions. More...
 
static std::array< double, 3 > loadAverage () noexcept
 Gets the load average. More...
 
static char ** setupArgs (int argc, char **argv)
 Store the program arguments. More...
 
static std::string processTitle ()
 Gets the title of the current process. More...
 
static bool processTitle (std::string title)
 Sets the current process title. More...
 
static uint64_t totalMemory () noexcept
 Gets memory information (in bytes). More...
 
static uint64_t constrainedMemory () noexcept
 Gets the amount of memory available to the process (in bytes). More...
 
static double uptime () noexcept
 Gets the current system uptime. More...
 
static RUsage rusage () noexcept
 Gets the resource usage measures for the current process. More...
 
static uint64_t hrtime () noexcept
 Gets the current high-resolution real time. More...
 
static std::string path () noexcept
 Gets the executable path. More...
 
static std::string cwd () noexcept
 Gets the current working directory. More...
 
static bool chdir (const std::string &dir) noexcept
 Changes the current working directory. More...
 
static TimeVal64 timeOfDay ()
 Cross-platform implementation of gettimeofday More...
 

Detailed Description

Miscellaneous utilities.

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

Definition at line 473 of file util.hpp.

Member Function Documentation

◆ chdir()

static bool uvw::Utilities::chdir ( const std::string &  dir)
inlinestaticnoexcept

Changes the current working directory.

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

Definition at line 965 of file util.hpp.

◆ constrainedMemory()

static uint64_t uvw::Utilities::constrainedMemory ( )
inlinestaticnoexcept

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.

Definition at line 902 of file util.hpp.

◆ cpuInfo()

static std::vector<CPUInfo> uvw::Utilities::cpuInfo ( )
inlinestaticnoexcept

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.

Definition at line 723 of file util.hpp.

◆ cwd()

static std::string uvw::Utilities::cwd ( )
inlinestaticnoexcept

Gets the current working directory.

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

Definition at line 956 of file util.hpp.

◆ guessHandle() [1/2]

static HandleType uvw::Utilities::guessHandle ( HandleCategory  category)
inlinestaticnoexcept

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 HandleType

Definition at line 651 of file util.hpp.

◆ guessHandle() [2/2]

static HandleType uvw::Utilities::guessHandle ( FileHandle  file)
inlinestaticnoexcept

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:
  • HandleType::UNKNOWN
  • HandleType::PIPE
  • HandleType::TCP
  • HandleType::TTY
  • HandleType::UDP
  • HandleType::FILE

Definition at line 710 of file util.hpp.

◆ hrtime()

static uint64_t uvw::Utilities::hrtime ( )
inlinestaticnoexcept

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.

Definition at line 940 of file util.hpp.

◆ indexToIid()

static std::string uvw::Utilities::indexToIid ( unsigned int  index)
inlinestaticnoexcept

Retrieves a network interface identifier.

See the official documentation for further details.

Parameters
indexNetwork interface index.
Returns
Network interface identifier.

Definition at line 806 of file util.hpp.

◆ indexToName()

static std::string uvw::Utilities::indexToName ( unsigned int  index)
inlinestaticnoexcept

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.

Definition at line 792 of file util.hpp.

◆ interfaceAddresses()

static std::vector<InterfaceAddress> uvw::Utilities::interfaceAddresses ( )
inlinestaticnoexcept

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.

Definition at line 748 of file util.hpp.

◆ loadAverage()

static std::array<double, 3> uvw::Utilities::loadAverage ( )
inlinestaticnoexcept

Gets the load average.

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

Definition at line 841 of file util.hpp.

◆ osPriority() [1/2]

static int uvw::Utilities::osPriority ( PidType  pid)
inlinestatic

Retrieves the scheduling priority of a process.

The returned value is between -20 (high priority) and 19 (low priority). A value that is out of range is returned in case of errors.

Note
On Windows, the result won't equal necessarily the exact value of the priority because of a mapping to a Windows priority class.
Parameters
pidA valid process id.
Returns
The scheduling priority of the process.

Definition at line 617 of file util.hpp.

◆ osPriority() [2/2]

static bool uvw::Utilities::osPriority ( PidType  pid,
int  prio 
)
inlinestatic

Sets the scheduling priority of a process.

The returned value range is between -20 (high priority) and 19 (low priority).

Note
On Windows, the priority is mapped to a Windows priority class. When retrieving the process priority, the result won't equal necessarily the exact value of the priority.
Parameters
pidA valid process id.
prioThe scheduling priority to set to the process.
Returns
True in case of success, false otherwise.

Definition at line 642 of file util.hpp.

◆ path()

static std::string uvw::Utilities::path ( )
inlinestaticnoexcept

Gets the executable path.

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

Definition at line 948 of file util.hpp.

◆ processTitle() [1/2]

static std::string uvw::Utilities::processTitle ( )
inlinestatic

Gets the title of the current process.

Returns
The process title.

Definition at line 862 of file util.hpp.

◆ processTitle() [2/2]

static bool uvw::Utilities::processTitle ( std::string  title)
inlinestatic

Sets the current process title.

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

Definition at line 879 of file util.hpp.

◆ replaceAllocator()

static bool uvw::Utilities::replaceAllocator ( MallocFuncType  mallocFunc,
ReallocFuncType  reallocFunc,
CallocFuncType  callocFunc,
FreeFuncType  freeFunc 
)
inlinestaticnoexcept

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
mallocFuncReplacement function for malloc.
reallocFuncReplacement function for realloc.
callocFuncReplacement function for calloc.
freeFuncReplacement function for free.
Returns
True in case of success, false otherwise.

Definition at line 833 of file util.hpp.

◆ rusage()

static RUsage uvw::Utilities::rusage ( )
inlinestaticnoexcept

Gets the resource usage measures for the current process.

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

Definition at line 924 of file util.hpp.

◆ setupArgs()

static char** uvw::Utilities::setupArgs ( int  argc,
char **  argv 
)
inlinestatic

Store the program arguments.

Required for getting / setting the process title.

Returns
Arguments that haven't been consumed internally.

Definition at line 854 of file util.hpp.

◆ timeOfDay()

static TimeVal64 uvw::Utilities::timeOfDay ( )
inlinestatic

Cross-platform implementation of gettimeofday

Returns
The current time.

Definition at line 974 of file util.hpp.

◆ totalMemory()

static uint64_t uvw::Utilities::totalMemory ( )
inlinestaticnoexcept

Gets memory information (in bytes).

Returns
Memory information.

Definition at line 887 of file util.hpp.

◆ uptime()

static double uvw::Utilities::uptime ( )
inlinestaticnoexcept

Gets the current system uptime.

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

Definition at line 910 of file util.hpp.


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