Process.h revision 234982
1218885Sdim//===- llvm/Support/Process.h ------------------------------------*- C++ -*-===// 2218885Sdim// 3218885Sdim// The LLVM Compiler Infrastructure 4218885Sdim// 5218885Sdim// This file is distributed under the University of Illinois Open Source 6218885Sdim// License. See LICENSE.TXT for details. 7218885Sdim// 8218885Sdim//===----------------------------------------------------------------------===// 9218885Sdim// 10218885Sdim// This file declares the llvm::sys::Process class. 11218885Sdim// 12218885Sdim//===----------------------------------------------------------------------===// 13218885Sdim 14218885Sdim#ifndef LLVM_SYSTEM_PROCESS_H 15218885Sdim#define LLVM_SYSTEM_PROCESS_H 16218885Sdim 17218885Sdim#include "llvm/Support/TimeValue.h" 18218885Sdim 19218885Sdimnamespace llvm { 20218885Sdimnamespace sys { 21218885Sdim 22218885Sdim /// This class provides an abstraction for getting information about the 23218885Sdim /// currently executing process. 24218885Sdim /// @since 1.4 25218885Sdim /// @brief An abstraction for operating system processes. 26218885Sdim class Process { 27218885Sdim /// @name Accessors 28218885Sdim /// @{ 29218885Sdim public: 30218885Sdim /// This static function will return the operating system's virtual memory 31218885Sdim /// page size. 32218885Sdim /// @returns The number of bytes in a virtual memory page. 33218885Sdim /// @brief Get the virtual memory page size 34218885Sdim static unsigned GetPageSize(); 35218885Sdim 36218885Sdim /// This static function will return the total amount of memory allocated 37218885Sdim /// by the process. This only counts the memory allocated via the malloc, 38218885Sdim /// calloc and realloc functions and includes any "free" holes in the 39218885Sdim /// allocated space. 40218885Sdim /// @brief Return process memory usage. 41218885Sdim static size_t GetMallocUsage(); 42218885Sdim 43218885Sdim /// This static function will return the total memory usage of the 44218885Sdim /// process. This includes code, data, stack and mapped pages usage. Notei 45218885Sdim /// that the value returned here is not necessarily the Running Set Size, 46218885Sdim /// it is the total virtual memory usage, regardless of mapped state of 47218885Sdim /// that memory. 48218885Sdim static size_t GetTotalMemoryUsage(); 49218885Sdim 50218885Sdim /// This static function will set \p user_time to the amount of CPU time 51218885Sdim /// spent in user (non-kernel) mode and \p sys_time to the amount of CPU 52218885Sdim /// time spent in system (kernel) mode. If the operating system does not 53218885Sdim /// support collection of these metrics, a zero TimeValue will be for both 54218885Sdim /// values. 55218885Sdim static void GetTimeUsage( 56218885Sdim TimeValue& elapsed, 57218885Sdim ///< Returns the TimeValue::now() giving current time 58218885Sdim TimeValue& user_time, 59218885Sdim ///< Returns the current amount of user time for the process 60218885Sdim TimeValue& sys_time 61218885Sdim ///< Returns the current amount of system time for the process 62218885Sdim ); 63218885Sdim 64218885Sdim /// This static function will return the process' current user id number. 65218885Sdim /// Not all operating systems support this feature. Where it is not 66218885Sdim /// supported, the function should return 65536 as the value. 67218885Sdim static int GetCurrentUserId(); 68218885Sdim 69218885Sdim /// This static function will return the process' current group id number. 70218885Sdim /// Not all operating systems support this feature. Where it is not 71218885Sdim /// supported, the function should return 65536 as the value. 72218885Sdim static int GetCurrentGroupId(); 73218885Sdim 74218885Sdim /// This function makes the necessary calls to the operating system to 75218885Sdim /// prevent core files or any other kind of large memory dumps that can 76218885Sdim /// occur when a program fails. 77218885Sdim /// @brief Prevent core file generation. 78218885Sdim static void PreventCoreFiles(); 79218885Sdim 80218885Sdim /// This function determines if the standard input is connected directly 81218885Sdim /// to a user's input (keyboard probably), rather than coming from a file 82218885Sdim /// or pipe. 83218885Sdim static bool StandardInIsUserInput(); 84218885Sdim 85218885Sdim /// This function determines if the standard output is connected to a 86218885Sdim /// "tty" or "console" window. That is, the output would be displayed to 87218885Sdim /// the user rather than being put on a pipe or stored in a file. 88218885Sdim static bool StandardOutIsDisplayed(); 89218885Sdim 90218885Sdim /// This function determines if the standard error is connected to a 91218885Sdim /// "tty" or "console" window. That is, the output would be displayed to 92218885Sdim /// the user rather than being put on a pipe or stored in a file. 93218885Sdim static bool StandardErrIsDisplayed(); 94218885Sdim 95218885Sdim /// This function determines if the given file descriptor is connected to 96218885Sdim /// a "tty" or "console" window. That is, the output would be displayed to 97218885Sdim /// the user rather than being put on a pipe or stored in a file. 98218885Sdim static bool FileDescriptorIsDisplayed(int fd); 99218885Sdim 100218885Sdim /// This function determines the number of columns in the window 101218885Sdim /// if standard output is connected to a "tty" or "console" 102218885Sdim /// window. If standard output is not connected to a tty or 103218885Sdim /// console, or if the number of columns cannot be determined, 104218885Sdim /// this routine returns zero. 105218885Sdim static unsigned StandardOutColumns(); 106218885Sdim 107218885Sdim /// This function determines the number of columns in the window 108218885Sdim /// if standard error is connected to a "tty" or "console" 109218885Sdim /// window. If standard error is not connected to a tty or 110218885Sdim /// console, or if the number of columns cannot be determined, 111218885Sdim /// this routine returns zero. 112218885Sdim static unsigned StandardErrColumns(); 113218885Sdim 114218885Sdim /// This function determines whether the terminal connected to standard 115218885Sdim /// output supports colors. If standard output is not connected to a 116218885Sdim /// terminal, this function returns false. 117218885Sdim static bool StandardOutHasColors(); 118218885Sdim 119218885Sdim /// This function determines whether the terminal connected to standard 120218885Sdim /// error supports colors. If standard error is not connected to a 121218885Sdim /// terminal, this function returns false. 122218885Sdim static bool StandardErrHasColors(); 123218885Sdim 124218885Sdim /// Whether changing colors requires the output to be flushed. 125218885Sdim /// This is needed on systems that don't support escape sequences for 126218885Sdim /// changing colors. 127218885Sdim static bool ColorNeedsFlush(); 128218885Sdim 129218885Sdim /// This function returns the colorcode escape sequences. 130218885Sdim /// If ColorNeedsFlush() is true then this function will change the colors 131218885Sdim /// and return an empty escape sequence. In that case it is the 132218885Sdim /// responsibility of the client to flush the output stream prior to 133218885Sdim /// calling this function. 134218885Sdim static const char *OutputColor(char c, bool bold, bool bg); 135218885Sdim 136218885Sdim /// Same as OutputColor, but only enables the bold attribute. 137218885Sdim static const char *OutputBold(bool bg); 138218885Sdim 139234982Sdim /// This function returns the escape sequence to reverse forground and 140234982Sdim /// background colors. 141234982Sdim static const char *OutputReverse(); 142234982Sdim 143218885Sdim /// Resets the terminals colors, or returns an escape sequence to do so. 144218885Sdim static const char *ResetColor(); 145218885Sdim /// @} 146218885Sdim }; 147218885Sdim} 148218885Sdim} 149218885Sdim 150218885Sdim#endif 151