llvm.org GIT mirror llvm / 3f598f7
Remove dead code. NFC. This interface was added 2 years ago but users never developed. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@223368 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 4 years ago
9 changed file(s) with 15 addition(s) and 209 deletion(s). Raw diff Collapse all Expand all
3737
3838 namespace sys {
3939
40 class self_process;
41
42 /// \brief Generic base class which exposes information about an operating
43 /// system process.
44 ///
45 /// This base class is the core interface behind any OS process. It exposes
46 /// methods to query for generic information about a particular process.
47 ///
48 /// Subclasses implement this interface based on the mechanisms available, and
49 /// can optionally expose more interfaces unique to certain process kinds.
50 class process {
51 protected:
52 /// \brief Only specific subclasses of process objects can be destroyed.
53 virtual ~process();
54
55 public:
56 /// \brief Operating system specific type to identify a process.
57 ///
58 /// Note that the windows one is defined to 'unsigned long' as this is the
59 /// documented type for DWORD on windows, and we don't want to pull in the
60 /// Windows headers here.
61 #if defined(LLVM_ON_UNIX)
62 typedef pid_t id_type;
63 #elif defined(LLVM_ON_WIN32)
64 typedef unsigned long id_type; // Must match the type of DWORD.
65 #else
66 #error Unsupported operating system.
67 #endif
68
69 /// \brief Get the operating system specific identifier for this process.
70 virtual id_type get_id() = 0;
71
72 /// \brief Get the user time consumed by this process.
73 ///
74 /// Note that this is often an approximation and may be zero on platforms
75 /// where we don't have good support for the functionality.
76 virtual TimeValue get_user_time() const = 0;
77
78 /// \brief Get the system time consumed by this process.
79 ///
80 /// Note that this is often an approximation and may be zero on platforms
81 /// where we don't have good support for the functionality.
82 virtual TimeValue get_system_time() const = 0;
83
84 /// \brief Get the wall time consumed by this process.
85 ///
86 /// Note that this is often an approximation and may be zero on platforms
87 /// where we don't have good support for the functionality.
88 virtual TimeValue get_wall_time() const = 0;
89
90 /// \name Static factory routines for processes.
91 /// @{
92
93 /// \brief Get the process object for the current process.
94 static self_process *get_self();
95
96 /// @}
97
98 };
99
100 /// \brief The specific class representing the current process.
101 ///
102 /// The current process can both specialize the implementation of the routines
103 /// and can expose certain information not available for other OS processes.
104 class self_process : public process {
105 friend class process;
106
107 /// \brief Private destructor, as users shouldn't create objects of this
108 /// type.
109 virtual ~self_process();
110
111 public:
112 id_type get_id() override;
113 TimeValue get_user_time() const override;
114 TimeValue get_system_time() const override;
115 TimeValue get_wall_time() const override;
116
117 /// \name Process configuration (sysconf on POSIX)
118 /// @{
119
120 /// \brief Get the virtual memory page size.
121 ///
122 /// Query the operating system for this process's page size.
123 size_t page_size() const { return PageSize; };
124
125 /// @}
126
127 private:
128 /// \name Cached process state.
129 /// @{
130
131 /// \brief Cached page size, this cannot vary during the life of the process.
132 size_t PageSize;
133
134 /// @}
135
136 /// \brief Constructor, used by \c process::get_self() only.
137 self_process();
138 };
139
14040
14141 /// \brief A collection of legacy interfaces for querying information about the
14242 /// current executing process.
14343 class Process {
14444 public:
45 static unsigned getPageSize();
46
14547 /// \brief Return process memory usage.
14648 /// This static function will return the total amount of memory allocated
14749 /// by the process. This only counts the memory allocated via the malloc,
329329 getOpenFileImpl(int FD, const Twine &Filename, uint64_t FileSize,
330330 uint64_t MapSize, int64_t Offset, bool RequiresNullTerminator,
331331 bool IsVolatileSize) {
332 static int PageSize = sys::process::get_self()->page_size();
332 static int PageSize = sys::Process::getPageSize();
333333
334334 // Default is to map the full file.
335335 if (MapSize == uint64_t(-1)) {
2525 //=== independent code.
2626 //===----------------------------------------------------------------------===//
2727
28 // Empty virtual destructor to anchor the vtable for the process class.
29 process::~process() {}
30
31 self_process *process::get_self() {
32 // Use a function local static for thread safe initialization and allocate it
33 // as a raw pointer to ensure it is never destroyed.
34 static self_process *SP = new self_process();
35
36 return SP;
37 }
38
39 // The destructor for the self_process subclass must never actually be
40 // executed. There should be at most one instance of this class, and that
41 // instance should live until the process terminates to avoid the potential for
42 // racy accesses during shutdown.
43 self_process::~self_process() {
44 llvm_unreachable("This destructor must never be executed!");
45 }
46
4728 /// \brief A helper function to compute the elapsed wall-time since the program
4829 /// started.
4930 ///
6142 /// Note that this variable is never referenced elsewhere. Doing so could
6243 /// create race conditions during program startup or shutdown.
6344 static volatile TimeValue DummyTimeValue = getElapsedWallTime();
64
65 // Implement this routine by using the static helpers above. They're already
66 // portable.
67 TimeValue self_process::get_wall_time() const {
68 return getElapsedWallTime();
69 }
7045
7146 Optional Process::FindInEnvPath(const std::string& EnvName,
7247 const std::string& FileName)
8787 if (NumBytes == 0)
8888 return MemoryBlock();
8989
90 static const size_t PageSize = process::get_self()->page_size();
90 static const size_t PageSize = Process::getPageSize();
9191 const size_t NumPages = (NumBytes+PageSize-1)/PageSize;
9292
9393 int fd = -1;
180180 std::string *ErrMsg) {
181181 if (NumBytes == 0) return MemoryBlock();
182182
183 size_t PageSize = process::get_self()->page_size();
183 size_t PageSize = Process::getPageSize();
184184 size_t NumPages = (NumBytes+PageSize-1)/PageSize;
185185
186186 int fd = -1;
549549 }
550550
551551 int mapped_file_region::alignment() {
552 return process::get_self()->page_size();
552 return Process::getPageSize();
553553 }
554554
555555 std::error_code detail::directory_iterator_construct(detail::DirIterState &it,
5555
5656 using namespace llvm;
5757 using namespace sys;
58
59 process::id_type self_process::get_id() {
60 return getpid();
61 }
6258
6359 static std::pair getRUsageTimes() {
6460 #if defined(HAVE_GETRUSAGE)
7975 #endif
8076 }
8177
82 TimeValue self_process::get_user_time() const {
83 #if _POSIX_TIMERS > 0 && _POSIX_CPUTIME > 0
84 // Try to get a high resolution CPU timer.
85 struct timespec TS;
86 if (::clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &TS) == 0)
87 return TimeValue(static_cast(TS.tv_sec),
88 static_cast(TS.tv_nsec));
89 #endif
90
91 // Otherwise fall back to rusage based timing.
92 return getRUsageTimes().first;
93 }
94
95 TimeValue self_process::get_system_time() const {
96 // We can only collect system time by inspecting the results of getrusage.
97 return getRUsageTimes().second;
98 }
99
10078 // On Cygwin, getpagesize() returns 64k(AllocationGranularity) and
10179 // offset in mmap(3) should be aligned to the AllocationGranularity.
102 static unsigned getPageSize() {
80 unsigned Process::getPageSize() {
10381 #if defined(HAVE_GETPAGESIZE)
104 const int page_size = ::getpagesize();
82 static const int page_size = ::getpagesize();
10583 #elif defined(HAVE_SYSCONF)
106 long page_size = ::sysconf(_SC_PAGE_SIZE);
84 static long page_size = ::sysconf(_SC_PAGE_SIZE);
10785 #else
10886 #warning Cannot get the page size on this machine
10987 #endif
11088 return static_cast(page_size);
11189 }
112
113 // This constructor guaranteed to be run exactly once on a single thread, and
114 // sets up various process invariants that can be queried cheaply from then on.
115 self_process::self_process() : PageSize(getPageSize()) {
116 }
117
11890
11991 size_t Process::GetMallocUsage() {
12092 #if defined(HAVE_MALLINFO)
4848 using namespace llvm;
4949 using namespace sys;
5050
51 process::id_type self_process::get_id() {
52 return GetCurrentProcessId();
53 }
54
5551 static TimeValue getTimeValueFromFILETIME(FILETIME Time) {
5652 ULARGE_INTEGER TimeInteger;
5753 TimeInteger.LowPart = Time.dwLowDateTime;
6460 (TimeInteger.QuadPart % 10000000) * 100));
6561 }
6662
67 TimeValue self_process::get_user_time() const {
68 FILETIME ProcCreate, ProcExit, KernelTime, UserTime;
69 if (GetProcessTimes(GetCurrentProcess(), &ProcCreate, &ProcExit, &KernelTime,
70 &UserTime) == 0)
71 return TimeValue();
72
73 return getTimeValueFromFILETIME(UserTime);
74 }
75
76 TimeValue self_process::get_system_time() const {
77 FILETIME ProcCreate, ProcExit, KernelTime, UserTime;
78 if (GetProcessTimes(GetCurrentProcess(), &ProcCreate, &ProcExit, &KernelTime,
79 &UserTime) == 0)
80 return TimeValue();
81
82 return getTimeValueFromFILETIME(KernelTime);
83 }
84
8563 // This function retrieves the page size using GetNativeSystemInfo() and is
8664 // present solely so it can be called once to initialize the self_process member
8765 // below.
88 static unsigned getPageSize() {
66 static unsigned computePageSize() {
8967 // GetNativeSystemInfo() provides the physical page size which may differ
9068 // from GetSystemInfo() in 32-bit applications running under WOW64.
9169 SYSTEM_INFO info;
9573 return static_cast(info.dwPageSize);
9674 }
9775
98 // This constructor guaranteed to be run exactly once on a single thread, and
99 // sets up various process invariants that can be queried cheaply from then on.
100 self_process::self_process() : PageSize(getPageSize()) {
101 }
102
76 unsigned Process::getPageSize() {
77 static unsigned Ret = computePageSize();
78 return Ret;
79 }
10380
10481 size_t
10582 Process::GetMallocUsage()
2020 public:
2121 MappedMemoryTest() {
2222 Flags = GetParam();
23 PageSize = sys::process::get_self()->page_size();
23 PageSize = sys::Process::getPageSize();
2424 }
2525
2626 protected:
1717
1818 using namespace llvm;
1919 using namespace sys;
20
21 TEST(ProcessTest, SelfProcess) {
22 EXPECT_TRUE(process::get_self());
23 EXPECT_EQ(process::get_self(), process::get_self());
24
25 #if defined(LLVM_ON_UNIX)
26 EXPECT_EQ(getpid(), process::get_self()->get_id());
27 #elif defined(LLVM_ON_WIN32)
28 EXPECT_EQ(GetCurrentProcessId(), process::get_self()->get_id());
29 #endif
30
31 EXPECT_LT(1u, process::get_self()->page_size());
32
33 EXPECT_LT(TimeValue::MinTime(), process::get_self()->get_user_time());
34 EXPECT_GT(TimeValue::MaxTime(), process::get_self()->get_user_time());
35 EXPECT_LT(TimeValue::MinTime(), process::get_self()->get_system_time());
36 EXPECT_GT(TimeValue::MaxTime(), process::get_self()->get_system_time());
37 EXPECT_LT(TimeValue::MinTime(), process::get_self()->get_wall_time());
38 EXPECT_GT(TimeValue::MaxTime(), process::get_self()->get_wall_time());
39 }
4020
4121 TEST(ProcessTest, GetRandomNumberTest) {
4222 const unsigned r1 = Process::GetRandomNumber();