1 //===- Unix/Process.cpp - Unix Process Implementation --------- -*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by Reid Spencer and is distributed under the
6 // University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file provides the generic Unix implementation of the Process class.
12 //===----------------------------------------------------------------------===//
15 #ifdef HAVE_SYS_TIME_H
18 #ifdef HAVE_SYS_RESOURCE_H
19 #include <sys/resource.h>
25 //===----------------------------------------------------------------------===//
26 //=== WARNING: Implementation here must contain only generic UNIX code that
27 //=== is guaranteed to work on *all* UNIX variants.
28 //===----------------------------------------------------------------------===//
34 Process::GetPageSize()
36 #if defined(HAVE_GETPAGESIZE)
37 static const int page_size = ::getpagesize();
38 #elif defined(HAVE_SYSCONF)
39 static long page_size = ::sysconf(_SC_PAGE_SIZE);
41 #warning Cannot get the page size on this machine
43 return static_cast<unsigned>(page_size);
46 #if defined(HAVE_SBRK)
47 static char* som = reinterpret_cast<char*>(::sbrk(0));
51 Process::GetMallocUsage()
53 #if defined(HAVE_MALLINFO)
57 #elif defined(HAVE_SBRK)
58 // Note this is only an approximation and more closely resembles
59 // the value returned by mallinfo in the arena field.
61 if (eom != ((char*)-1) && som != ((char*)-1))
66 #warning Cannot get malloc info on this platform
72 Process::GetTotalMemoryUsage()
74 #if defined(HAVE_MALLINFO)
75 struct mallinfo mi = ::mallinfo();
76 return mi.uordblks + mi.hblkhd;
77 #elif defined(HAVE_GETRUSAGE)
79 ::getrusage(RUSAGE_SELF, &usage);
80 return usage.ru_maxrss;
82 #warning Cannot get total memory size on this platform
88 Process::GetTimeUsage(TimeValue& elapsed, TimeValue& user_time,
91 elapsed = TimeValue::now();
92 #if defined(HAVE_GETRUSAGE)
94 ::getrusage(RUSAGE_SELF, &usage);
95 user_time.seconds( usage.ru_utime.tv_sec );
96 user_time.microseconds( usage.ru_utime.tv_usec );
97 sys_time.seconds( usage.ru_stime.tv_sec );
98 sys_time.microseconds( usage.ru_stime.tv_usec );
100 #warning Cannot get usage times on this platform
101 user_time.seconds(0);
102 user_time.microseconds(0);
104 sys_time.microseconds(0);
110 // vim: sw=2 smartindent smarttab tw=80 autoindent expandtab