2004-09-11 04:18:05 +00:00
|
|
|
//===- llvm/System/Process.h ------------------------------------*- C++ -*-===//
|
2005-04-21 20:48:15 +00:00
|
|
|
//
|
2004-09-11 04:18:05 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 19:59:42 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-21 20:48:15 +00:00
|
|
|
//
|
2004-09-11 04:18:05 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file declares the llvm::sys::Process class.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_SYSTEM_PROCESS_H
|
|
|
|
#define LLVM_SYSTEM_PROCESS_H
|
|
|
|
|
2004-12-20 00:58:53 +00:00
|
|
|
#include "llvm/System/TimeValue.h"
|
|
|
|
|
2004-09-11 04:18:05 +00:00
|
|
|
namespace llvm {
|
|
|
|
namespace sys {
|
|
|
|
|
|
|
|
/// This class provides an abstraction for getting information about the
|
2005-04-21 20:48:15 +00:00
|
|
|
/// currently executing process.
|
2004-09-11 04:18:05 +00:00
|
|
|
/// @since 1.4
|
|
|
|
/// @brief An abstraction for operating system processes.
|
|
|
|
class Process {
|
|
|
|
/// @name Accessors
|
|
|
|
/// @{
|
|
|
|
public:
|
|
|
|
/// This static function will return the operating system's virtual memory
|
|
|
|
/// page size.
|
|
|
|
/// @returns The number of bytes in a virtual memory page.
|
|
|
|
/// @brief Get the virtual memory page size
|
|
|
|
static unsigned GetPageSize();
|
|
|
|
|
2004-12-20 00:58:53 +00:00
|
|
|
/// This static function will return the total amount of memory allocated
|
|
|
|
/// by the process. This only counts the memory allocated via the malloc,
|
2005-04-21 20:48:15 +00:00
|
|
|
/// calloc and realloc functions and includes any "free" holes in the
|
|
|
|
/// allocated space.
|
2004-12-20 00:58:53 +00:00
|
|
|
/// @brief Return process memory usage.
|
2005-01-08 20:15:57 +00:00
|
|
|
static size_t GetMallocUsage();
|
2004-12-20 00:58:53 +00:00
|
|
|
|
2005-04-21 20:48:15 +00:00
|
|
|
/// This static function will return the total memory usage of the
|
2004-12-20 00:58:53 +00:00
|
|
|
/// process. This includes code, data, stack and mapped pages usage. Notei
|
|
|
|
/// that the value returned here is not necessarily the Running Set Size,
|
|
|
|
/// it is the total virtual memory usage, regardless of mapped state of
|
|
|
|
/// that memory.
|
2005-01-08 20:15:57 +00:00
|
|
|
static size_t GetTotalMemoryUsage();
|
2004-12-20 00:58:53 +00:00
|
|
|
|
2005-04-21 20:48:15 +00:00
|
|
|
/// This static function will set \p user_time to the amount of CPU time
|
2004-12-20 00:58:53 +00:00
|
|
|
/// spent in user (non-kernel) mode and \p sys_time to the amount of CPU
|
|
|
|
/// time spent in system (kernel) mode. If the operating system does not
|
|
|
|
/// support collection of these metrics, a zero TimeValue will be for both
|
|
|
|
/// values.
|
|
|
|
static void GetTimeUsage(
|
|
|
|
TimeValue& elapsed,
|
|
|
|
///< Returns the TimeValue::now() giving current time
|
2005-04-21 20:48:15 +00:00
|
|
|
TimeValue& user_time,
|
2004-12-20 00:58:53 +00:00
|
|
|
///< Returns the current amount of user time for the process
|
|
|
|
TimeValue& sys_time
|
|
|
|
///< Returns the current amount of system time for the process
|
|
|
|
);
|
|
|
|
|
2005-04-21 16:12:04 +00:00
|
|
|
/// This static function will return the process' current user id number.
|
2005-04-21 20:48:15 +00:00
|
|
|
/// Not all operating systems support this feature. Where it is not
|
|
|
|
/// supported, the function should return 65536 as the value.
|
2005-04-21 16:12:04 +00:00
|
|
|
static int GetCurrentUserId();
|
2005-07-27 05:53:44 +00:00
|
|
|
|
2005-04-21 16:12:04 +00:00
|
|
|
/// This static function will return the process' current group id number.
|
2005-04-21 20:48:15 +00:00
|
|
|
/// Not all operating systems support this feature. Where it is not
|
|
|
|
/// supported, the function should return 65536 as the value.
|
2005-04-21 16:12:04 +00:00
|
|
|
static int GetCurrentGroupId();
|
|
|
|
|
2005-04-21 20:48:15 +00:00
|
|
|
/// This function makes the necessary calls to the operating system to
|
|
|
|
/// prevent core files or any other kind of large memory dumps that can
|
2004-12-27 06:17:27 +00:00
|
|
|
/// occur when a program fails.
|
|
|
|
/// @brief Prevent core file generation.
|
|
|
|
static void PreventCoreFiles();
|
|
|
|
|
2005-01-01 22:29:26 +00:00
|
|
|
/// This function determines if the standard input is connected directly
|
|
|
|
/// to a user's input (keyboard probably), rather than coming from a file
|
|
|
|
/// or pipe.
|
|
|
|
static bool StandardInIsUserInput();
|
|
|
|
|
2005-04-21 20:48:15 +00:00
|
|
|
/// This function determines if the standard output is connected to a
|
2005-01-01 22:29:26 +00:00
|
|
|
/// "tty" or "console" window. That is, the output would be displayed to
|
|
|
|
/// the user rather than being put on a pipe or stored in a file.
|
|
|
|
static bool StandardOutIsDisplayed();
|
|
|
|
|
2005-04-21 20:48:15 +00:00
|
|
|
/// This function determines if the standard error is connected to a
|
2005-01-01 22:29:26 +00:00
|
|
|
/// "tty" or "console" window. That is, the output would be displayed to
|
|
|
|
/// the user rather than being put on a pipe or stored in a file.
|
|
|
|
static bool StandardErrIsDisplayed();
|
|
|
|
|
2009-09-11 20:46:33 +00:00
|
|
|
/// This function determines if the given file descriptor is connected to
|
|
|
|
/// a "tty" or "console" window. That is, the output would be displayed to
|
|
|
|
/// the user rather than being put on a pipe or stored in a file.
|
|
|
|
static bool FileDescriptorIsDisplayed(int fd);
|
|
|
|
|
2009-05-11 18:05:52 +00:00
|
|
|
/// This function determines the number of columns in the window
|
|
|
|
/// if standard output is connected to a "tty" or "console"
|
|
|
|
/// window. If standard output is not connected to a tty or
|
|
|
|
/// console, or if the number of columns cannot be determined,
|
|
|
|
/// this routine returns zero.
|
|
|
|
static unsigned StandardOutColumns();
|
|
|
|
|
|
|
|
/// This function determines the number of columns in the window
|
|
|
|
/// if standard error is connected to a "tty" or "console"
|
|
|
|
/// window. If standard error is not connected to a tty or
|
|
|
|
/// console, or if the number of columns cannot be determined,
|
|
|
|
/// this routine returns zero.
|
|
|
|
static unsigned StandardErrColumns();
|
2009-06-04 07:09:50 +00:00
|
|
|
|
|
|
|
/// This function determines whether the terminal connected to standard
|
|
|
|
/// output supports colors. If standard output is not connected to a
|
|
|
|
/// terminal, this function returns false.
|
|
|
|
static bool StandardOutHasColors();
|
|
|
|
|
|
|
|
/// This function determines whether the terminal connected to standard
|
|
|
|
/// error supports colors. If standard error is not connected to a
|
|
|
|
/// terminal, this function returns false.
|
|
|
|
static bool StandardErrHasColors();
|
|
|
|
|
|
|
|
/// Whether changing colors requires the output to be flushed.
|
|
|
|
/// This is needed on systems that don't support escape sequences for
|
|
|
|
/// changing colors.
|
|
|
|
static bool ColorNeedsFlush();
|
|
|
|
|
2009-06-04 08:18:25 +00:00
|
|
|
/// This function returns the colorcode escape sequences.
|
2009-06-04 07:09:50 +00:00
|
|
|
/// If ColorNeedsFlush() is true then this function will change the colors
|
|
|
|
/// and return an empty escape sequence. In that case it is the
|
|
|
|
/// responsibility of the client to flush the output stream prior to
|
|
|
|
/// calling this function.
|
|
|
|
static const char *OutputColor(char c, bool bold, bool bg);
|
|
|
|
|
|
|
|
/// Same as OutputColor, but only enables the bold attribute.
|
|
|
|
static const char *OutputBold(bool bg);
|
|
|
|
|
|
|
|
/// Resets the terminals colors, or returns an escape sequence to do so.
|
|
|
|
static const char *ResetColor();
|
2004-09-11 04:18:05 +00:00
|
|
|
/// @}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|