1 //===- Win32/Process.cpp - Win32 Process Implementation ------- -*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by Jeff Cohen and is distributed under the
6 // University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file provides the Win32 specific implementation of the Process class.
12 //===----------------------------------------------------------------------===//
16 //===----------------------------------------------------------------------===//
17 //=== WARNING: Implementation here must contain only Win32 specific code
18 //=== and must not be UNIX code
19 //===----------------------------------------------------------------------===//
24 // This function retrieves the page size using GetSystemInfo and is present
25 // solely so it can be called once in Process::GetPageSize to initialize the
26 // static variable PageSize.
27 inline unsigned GetPageSizeOnce() {
28 // NOTE: A 32-bit application running under WOW64 is supposed to use
29 // GetNativeSystemInfo. However, this interface is not present prior
30 // to Windows XP so to use it requires dynamic linking. It is not clear
31 // how this affects the reported page size, if at all. One could argue
32 // that LLVM ought to run as 64-bits on a 64-bit system, anyway.
35 return static_cast<unsigned>(info.dwPageSize);
39 Process::GetPageSize() {
40 static const unsigned PageSize = GetPageSizeOnce();
46 Process::GetMallocUsage()
49 struct mallinfo mi = ::mallinfo();
51 #warning Cannot get malloc info on this platform
57 Process::GetTotalMemoryUsage()
60 struct mallinfo mi = ::mallinfo();
61 return mi.uordblks + mi.hblkhd
63 #warning Cannot get total memory size on this platform
69 Process::GetTimeUsage(
70 TimeValue& elapsed, TimeValue& user_time, TimeValue& sys_time)
72 elapsed = TimeValue::now();
74 unsigned __int64 ProcCreate, ProcExit, KernelTime, UserTime;
75 GetProcessTimes(GetCurrentProcess(), (FILETIME*)&ProcCreate,
76 (FILETIME*)&ProcExit, (FILETIME*)&KernelTime,
80 // FILETIME's are # of 100 nanosecond ticks (1/10th of a microsecond)
81 user_time.seconds( UserTime / 10000000 );
82 user_time.nanoseconds( (UserTime % 10000000) * 100 );
83 sys_time.seconds( KernelTime / 10000000 );
84 user_time.nanoseconds( (UserTime % 10000000) * 100 );
88 // vim: sw=2 smartindent smarttab tw=80 autoindent expandtab