adc1f03deb41d09be93fd92a28d7fa019c93578d
[oota-llvm.git] / include / llvm / System / Process.h
1 //===- llvm/System/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/System/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       /// @throws nothing
34       /// @brief Get the virtual memory page size
35       static unsigned GetPageSize();
36
37       /// This static function will return the total amount of memory allocated
38       /// by the process. This only counts the memory allocated via the malloc,
39       /// calloc and realloc functions and includes any "free" holes in the
40       /// allocated space.
41       /// @throws nothing
42       /// @brief Return process memory usage.
43       static size_t GetMallocUsage();
44
45       /// This static function will return the total memory usage of the
46       /// process. This includes code, data, stack and mapped pages usage. Notei
47       /// that the value returned here is not necessarily the Running Set Size,
48       /// it is the total virtual memory usage, regardless of mapped state of
49       /// that memory.
50       static size_t GetTotalMemoryUsage();
51
52       /// This static function will set \p user_time to the amount of CPU time
53       /// spent in user (non-kernel) mode and \p sys_time to the amount of CPU
54       /// time spent in system (kernel) mode.  If the operating system does not
55       /// support collection of these metrics, a zero TimeValue will be for both
56       /// values.
57       static void GetTimeUsage(
58         TimeValue& elapsed,
59           ///< Returns the TimeValue::now() giving current time
60         TimeValue& user_time,
61           ///< Returns the current amount of user time for the process
62         TimeValue& sys_time
63           ///< Returns the current amount of system time for the process
64       );
65
66       /// This static function will return the process' current user id number.
67       /// Not all operating systems support this feature. Where it is not
68       /// supported, the function should return 65536 as the value.
69       static int GetCurrentUserId();
70
71       /// This static function will return the process' current group id number.
72       /// Not all operating systems support this feature. Where it is not
73       /// supported, the function should return 65536 as the value.
74       static int GetCurrentGroupId();
75
76       /// This function makes the necessary calls to the operating system to
77       /// prevent core files or any other kind of large memory dumps that can
78       /// occur when a program fails.
79       /// @brief Prevent core file generation.
80       static void PreventCoreFiles();
81
82       /// This function determines if the standard input is connected directly
83       /// to a user's input (keyboard probably), rather than coming from a file
84       /// or pipe.
85       static bool StandardInIsUserInput();
86
87       /// This function determines if the standard output is connected to a
88       /// "tty" or "console" window. That is, the output would be displayed to
89       /// the user rather than being put on a pipe or stored in a file.
90       static bool StandardOutIsDisplayed();
91
92       /// This function determines if the standard error is connected to a
93       /// "tty" or "console" window. That is, the output would be displayed to
94       /// the user rather than being put on a pipe or stored in a file.
95       static bool StandardErrIsDisplayed();
96
97       /// This function determines the number of columns in the window
98       /// if standard output is connected to a "tty" or "console"
99       /// window. If standard output is not connected to a tty or
100       /// console, or if the number of columns cannot be determined,
101       /// this routine returns zero.
102       static unsigned StandardOutColumns();
103
104       /// This function determines the number of columns in the window
105       /// if standard error is connected to a "tty" or "console"
106       /// window. If standard error is not connected to a tty or
107       /// console, or if the number of columns cannot be determined,
108       /// this routine returns zero.
109       static unsigned StandardErrColumns();
110
111       /// This function determines whether the terminal connected to standard
112       /// output supports colors. If standard output is not connected to a
113       /// terminal, this function returns false.
114       static bool StandardOutHasColors();
115
116       /// This function determines whether the terminal connected to standard
117       /// error supports colors. If standard error is not connected to a
118       /// terminal, this function returns false.
119       static bool StandardErrHasColors();
120
121       /// Whether changing colors requires the output to be flushed.
122       /// This is needed on systems that don't support escape sequences for
123       /// changing colors.
124       static bool ColorNeedsFlush();
125
126       /// This function returns the colorcode escape sequences, and sets Len to
127       /// the length of the escape sequence.
128       /// If ColorNeedsFlush() is true then this function will change the colors
129       /// and return an empty escape sequence. In that case it is the
130       /// responsibility of the client to flush the output stream prior to
131       /// calling this function.
132       static const char *OutputColor(char c, bool bold, bool bg);
133
134       /// Same as OutputColor, but only enables the bold attribute.
135       static const char *OutputBold(bool bg);
136
137       /// Resets the terminals colors, or returns an escape sequence to do so.
138       static const char *ResetColor();
139     /// @}
140   };
141 }
142 }
143
144 #endif