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 //===----------------------------------------------------------------------===//
18 #pragma comment(lib, "psapi.lib")
20 //===----------------------------------------------------------------------===//
21 //=== WARNING: Implementation here must contain only Win32 specific code
22 //=== and must not be UNIX code
23 //===----------------------------------------------------------------------===//
26 // This ban should be lifted when MinGW 1.0+ has defined this value.
33 // This function retrieves the page size using GetSystemInfo and is present
34 // solely so it can be called once in Process::GetPageSize to initialize the
35 // static variable PageSize.
36 inline unsigned GetPageSizeOnce() {
37 // NOTE: A 32-bit application running under WOW64 is supposed to use
38 // GetNativeSystemInfo. However, this interface is not present prior
39 // to Windows XP so to use it requires dynamic linking. It is not clear
40 // how this affects the reported page size, if at all. One could argue
41 // that LLVM ought to run as 64-bits on a 64-bit system, anyway.
44 return static_cast<unsigned>(info.dwPageSize);
48 Process::GetPageSize() {
49 static const unsigned PageSize = GetPageSizeOnce();
54 Process::GetMallocUsage()
61 while (_heapwalk(&hinfo) == _HEAPOK)
68 Process::GetTotalMemoryUsage()
70 PROCESS_MEMORY_COUNTERS pmc;
71 GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc));
72 return pmc.PagefileUsage;
76 Process::GetTimeUsage(
77 TimeValue& elapsed, TimeValue& user_time, TimeValue& sys_time)
79 elapsed = TimeValue::now();
81 uint64_t ProcCreate, ProcExit, KernelTime, UserTime;
82 GetProcessTimes(GetCurrentProcess(), (FILETIME*)&ProcCreate,
83 (FILETIME*)&ProcExit, (FILETIME*)&KernelTime,
84 (FILETIME*)&UserTime);
86 // FILETIME's are # of 100 nanosecond ticks (1/10th of a microsecond)
87 user_time.seconds( UserTime / 10000000 );
88 user_time.nanoseconds( unsigned(UserTime % 10000000) * 100 );
89 sys_time.seconds( KernelTime / 10000000 );
90 sys_time.nanoseconds( unsigned(KernelTime % 10000000) * 100 );
94 // vim: sw=2 smartindent smarttab tw=80 autoindent expandtab