Home | History | Annotate | Download | only in Support
      1 //===- llvm/Support/Process.h ------------------------------------*- C++ -*-===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 //
     10 // This file declares the llvm::sys::Process class.
     11 //
     12 //===----------------------------------------------------------------------===//
     13 
     14 #ifndef LLVM_SYSTEM_PROCESS_H
     15 #define LLVM_SYSTEM_PROCESS_H
     16 
     17 #include "llvm/Support/TimeValue.h"
     18 
     19 namespace llvm {
     20 namespace sys {
     21 
     22   /// This class provides an abstraction for getting information about the
     23   /// currently executing process.
     24   /// @since 1.4
     25   /// @brief An abstraction for operating system processes.
     26   class Process {
     27     /// @name Accessors
     28     /// @{
     29     public:
     30       /// This static function will return the operating system's virtual memory
     31       /// page size.
     32       /// @returns The number of bytes in a virtual memory page.
     33       /// @brief Get the virtual memory page size
     34       static unsigned GetPageSize();
     35 
     36       /// This static function will return the total amount of memory allocated
     37       /// by the process. This only counts the memory allocated via the malloc,
     38       /// calloc and realloc functions and includes any "free" holes in the
     39       /// allocated space.
     40       /// @brief Return process memory usage.
     41       static size_t GetMallocUsage();
     42 
     43       /// This static function will return the total memory usage of the
     44       /// process. This includes code, data, stack and mapped pages usage. Notei
     45       /// that the value returned here is not necessarily the Running Set Size,
     46       /// it is the total virtual memory usage, regardless of mapped state of
     47       /// that memory.
     48       static size_t GetTotalMemoryUsage();
     49 
     50       /// This static function will set \p user_time to the amount of CPU time
     51       /// spent in user (non-kernel) mode and \p sys_time to the amount of CPU
     52       /// time spent in system (kernel) mode.  If the operating system does not
     53       /// support collection of these metrics, a zero TimeValue will be for both
     54       /// values.
     55       static void GetTimeUsage(
     56         TimeValue& elapsed,
     57           ///< Returns the TimeValue::now() giving current time
     58         TimeValue& user_time,
     59           ///< Returns the current amount of user time for the process
     60         TimeValue& sys_time
     61           ///< Returns the current amount of system time for the process
     62       );
     63 
     64       /// This static function will return the process' current user id number.
     65       /// Not all operating systems support this feature. Where it is not
     66       /// supported, the function should return 65536 as the value.
     67       static int GetCurrentUserId();
     68 
     69       /// This static function will return the process' current group id number.
     70       /// Not all operating systems support this feature. Where it is not
     71       /// supported, the function should return 65536 as the value.
     72       static int GetCurrentGroupId();
     73 
     74       /// This function makes the necessary calls to the operating system to
     75       /// prevent core files or any other kind of large memory dumps that can
     76       /// occur when a program fails.
     77       /// @brief Prevent core file generation.
     78       static void PreventCoreFiles();
     79 
     80       /// This function determines if the standard input is connected directly
     81       /// to a user's input (keyboard probably), rather than coming from a file
     82       /// or pipe.
     83       static bool StandardInIsUserInput();
     84 
     85       /// This function determines if the standard output is connected to a
     86       /// "tty" or "console" window. That is, the output would be displayed to
     87       /// the user rather than being put on a pipe or stored in a file.
     88       static bool StandardOutIsDisplayed();
     89 
     90       /// This function determines if the standard error is connected to a
     91       /// "tty" or "console" window. That is, the output would be displayed to
     92       /// the user rather than being put on a pipe or stored in a file.
     93       static bool StandardErrIsDisplayed();
     94 
     95       /// This function determines if the given file descriptor is connected to
     96       /// a "tty" or "console" window. That is, the output would be displayed to
     97       /// the user rather than being put on a pipe or stored in a file.
     98       static bool FileDescriptorIsDisplayed(int fd);
     99 
    100       /// This function determines the number of columns in the window
    101       /// if standard output is connected to a "tty" or "console"
    102       /// window. If standard output is not connected to a tty or
    103       /// console, or if the number of columns cannot be determined,
    104       /// this routine returns zero.
    105       static unsigned StandardOutColumns();
    106 
    107       /// This function determines the number of columns in the window
    108       /// if standard error is connected to a "tty" or "console"
    109       /// window. If standard error is not connected to a tty or
    110       /// console, or if the number of columns cannot be determined,
    111       /// this routine returns zero.
    112       static unsigned StandardErrColumns();
    113 
    114       /// This function determines whether the terminal connected to standard
    115       /// output supports colors. If standard output is not connected to a
    116       /// terminal, this function returns false.
    117       static bool StandardOutHasColors();
    118 
    119       /// This function determines whether the terminal connected to standard
    120       /// error supports colors. If standard error is not connected to a
    121       /// terminal, this function returns false.
    122       static bool StandardErrHasColors();
    123 
    124       /// Whether changing colors requires the output to be flushed.
    125       /// This is needed on systems that don't support escape sequences for
    126       /// changing colors.
    127       static bool ColorNeedsFlush();
    128 
    129       /// This function returns the colorcode escape sequences.
    130       /// If ColorNeedsFlush() is true then this function will change the colors
    131       /// and return an empty escape sequence. In that case it is the
    132       /// responsibility of the client to flush the output stream prior to
    133       /// calling this function.
    134       static const char *OutputColor(char c, bool bold, bool bg);
    135 
    136       /// Same as OutputColor, but only enables the bold attribute.
    137       static const char *OutputBold(bool bg);
    138 
    139       /// Resets the terminals colors, or returns an escape sequence to do so.
    140       static const char *ResetColor();
    141 
    142       /// Change the program working directory to that given by \arg Path.
    143       static void SetWorkingDirectory(std::string Path);
    144     /// @}
    145   };
    146 }
    147 }
    148 
    149 #endif
    150