package uwt

  1. Overview
  2. Docs

This section contains miscellaneous functions that don't really belong in any other section.

type timeval = {
  1. sec : int;
  2. usec : int;
}
type rusage = {
  1. utime : timeval;
    (*

    user CPU time used

    *)
  2. stime : timeval;
    (*

    system CPU time used

    *)
  3. maxrss : int64;
    (*

    maximum resident set size

    *)
  4. ixrss : int64;
    (*

    integral shared memory size (X)

    *)
  5. idrss : int64;
    (*

    integral unshared data size (X)

    *)
  6. isrss : int64;
    (*

    integral unshared stack size (X)

    *)
  7. minflt : int64;
    (*

    page reclaims (soft page faults) (X)

    *)
  8. majflt : int64;
    (*

    page faults (hard page faults)

    *)
  9. nswap : int64;
    (*

    swaps (X)

    *)
  10. inblock : int64;
    (*

    block input operations

    *)
  11. outblock : int64;
    (*

    block output operations

    *)
  12. msgsnd : int64;
    (*

    IPC messages sent (X)

    *)
  13. msgrcv : int64;
    (*

    IPC messages received (X)

    *)
  14. nsignals : int64;
    (*

    signals received (X)

    *)
  15. nvcsw : int64;
    (*

    voluntary context switches (X)

    *)
  16. nivcsw : int64;
    (*

    involuntary context switches (X)

    *)
}

Data type for resource usage results. Members marked with (X) are unsupported on Windows.

type cpu_times = {
  1. user : int64;
  2. nice : int64;
  3. sys : int64;
  4. idle : int64;
  5. irq : int64;
}
type cpu_info = {
  1. model : string;
  2. speed : int;
  3. cpu_times : cpu_times;
}

Data type for CPU information

type interface_address = {
  1. name : string;
  2. phys_addr : string;
  3. is_internal : bool;
  4. address : sockaddr option;
  5. netmask : sockaddr option;
}

Data type for interface addresses.

type handle_type =
  1. | File
  2. | Tty
  3. | Pipe
  4. | Tcp
  5. | Udp
  6. | Unknown
val guess_handle : Unix.file_descr -> handle_type

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

For isatty(3) equivalent functionality use this function and test for UV_TTY.

val resident_set_memory : unit -> int64 uv_result

Gets the resident set size (RSS) for the current process.

val resident_set_memory_exn : unit -> int64
val uptime : unit -> float uv_result

Gets the current system uptime.

val uptime_exn : unit -> float
val getrusage : unit -> rusage uv_result

Gets the resource usage measures for the current process. On Windows not all fields are set

val getrusage_exn : unit -> rusage
val cpu_info : unit -> cpu_info array uv_result

Gets information about the CPUs on the system.

val cpu_info_exn : unit -> cpu_info array
val interface_addresses : unit -> interface_address array uv_result

Gets address information about the network interfaces on the system.

val interface_addresses_exn : unit -> interface_address array
val load_avg : unit -> float * float * float

Gets the load average. Returns 0,0,0 on Windows

val ip4_addr : string -> int -> sockaddr uv_result

Convert a string containing an IPv4 addresses to a binary structure.

val ip4_addr_exn : string -> int -> sockaddr
val ip4_name : sockaddr -> string uv_result

Convert a binary structure containing an IPv4 address to a string.

val ip4_name_exn : sockaddr -> string
val ip6_addr : string -> int -> sockaddr uv_result

Convert a string containing an IPv6 addresses to a binary structure.

val ip6_addr_exn : string -> int -> sockaddr
val ip6_name : sockaddr -> string uv_result

Convert a binary structure containing an IPv6 address to a string.

val ip6_name_exn : sockaddr -> string
val get_total_memory : unit -> int64

Gets memory information (in bytes).

val hrtime : unit -> int64

Returns the current high-resolution real time. This is expressed in nanoseconds. It is relative to an arbitrary time in the past. It is not related to the time of day and therefore not subject to clock drift. The primary use is for measuring performance between intervals.

Note: Not every platform can support nanosecond resolution; however, this value will always be in nanoseconds.

type version = {
  1. major : int;
  2. minor : int;
  3. patch : int;
}
val version : unit -> version

libuv version used

val version_raw : unit -> int
val version_string : unit -> string

Many of the functions below are not thread safe and might block. Functions like cwd are useful nevertheless, if you target windows. Unlike Sys.getcwd() they return UTF8-encoded names

val os_homedir : unit -> string uv_result

Gets the current user's home directory. On Windows, homedir first checks the USERPROFILE environment variable using GetEnvironmentVariableW(). If USERPROFILE is not set, GetUserProfileDirectoryW() is called.

On all other operating systems, os_homedir first checks the HOME environment variable using getenv(3). If HOME is not set, getpwuid_r(3) is called.

val os_tmpdir : unit -> string uv_result

Gets the temp directory. On Windows, uv_os_tmpdir() uses GetTempPathW(). On all other operating systems, uv_os_tmpdir() uses the first environment variable found in the ordered list TMPDIR, TMP, TEMP, and TEMPDIR. If none of these are found, the path "/tmp" is used, or, on Android, "/data/local/tmp" is used.

val get_passwd : unit -> Unix.passwd_entry uv_result

pw_passwd and pw_gecos will currently always contain an empty string. This function does work on Windows (unlike Unix.getpwnam or Unix.getwuid )

val exepath : unit -> string uv_result

like Sys.executable_name , but utf-8 encoded under windows and perhaps more reliable under niche operating systems

val cwd : unit -> string uv_result

Gets the current working directory

val chdir : string -> Int_result.unit

Changes the current working directory.

val getenv : string -> string uv_result

Return the value associated to a variable in the process environment. ENOENT is returned, if the variable is unbound.

val putenv : key:string -> data:string -> Int_result.unit

putenv ~key ~data sets the value associated to a variable in the process environment. key is the name of the environment variable, and data its new associated value.

val unsetenv : string -> Int_result.unit

Deletes the environment variable specified by name. If no such environment variable exists, this function returns successfully.

val getppid : unit -> Int_result.int

Returns the parent process ID. Similar to Unix.getppid, but also works under Windows

The following two functions don't work reliable, especially with byte code.

val set_process_title : string -> Int_result.unit

Sets the process title. It won't necessary report an error, if it fails

val get_process_title : unit -> string uv_result
val setpriority : pid:int -> priority:int -> Int_result.unit

Sets the scheduling priority of the process specified by `pid`. The `priority` value range is between -20 (high priority) and 19 (low priority).

On Windows, this function utilizes `SetPriorityClass()`. The `priority` argument is mapped to a Windows priority class. When retrieving the process priority, the result will not necessarily equal the exact value of `priority`.

val setpriority_exn : pid:int -> priority:int -> unit
val getpriority : int -> int uv_result

Retrieves the scheduling priority of the process specified by `pid`. The returned value of `priority` is between -20 (high priority) and 19 (low priority).

val getpriority_exn : int -> int
val getpid : unit -> int uv_result

Returns the current process ID. Useful for Windows. Unix.getpid doesn't return the current Process Id. See: https://caml.inria.fr/mantis/view.php?id=4034

val getpid_exn : unit -> int
OCaml

Innovation. Community. Security.