Reid Spencer | 437b079 | 2004-09-15 05:47:40 +0000 | [diff] [blame] | 1 | //===- Win32/Process.cpp - Win32 Process Implementation ------- -*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 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. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file provides the Win32 specific implementation of the Process class. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "Win32.h" |
Reid Spencer | 437b079 | 2004-09-15 05:47:40 +0000 | [diff] [blame] | 15 | |
| 16 | //===----------------------------------------------------------------------===// |
| 17 | //=== WARNING: Implementation here must contain only Win32 specific code |
| 18 | //=== and must not be UNIX code |
| 19 | //===----------------------------------------------------------------------===// |
| 20 | |
| 21 | namespace llvm { |
| 22 | using namespace sys; |
| 23 | |
| 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. |
| 33 | SYSTEM_INFO info; |
| 34 | GetSystemInfo(&info); |
| 35 | return static_cast<unsigned>(info.dwPageSize); |
| 36 | } |
| 37 | |
| 38 | unsigned |
| 39 | Process::GetPageSize() { |
| 40 | static const unsigned PageSize = GetPageSizeOnce(); |
| 41 | return PageSize; |
| 42 | } |
| 43 | |
Reid Spencer | 721d9aa | 2004-12-20 00:59:28 +0000 | [diff] [blame^] | 44 | void* |
| 45 | uint64_t |
| 46 | Process::GetMallocUsage() |
| 47 | { |
| 48 | #ifdef HAVE_MALLINFO |
| 49 | struct mallinfo mi = ::mallinfo(); |
| 50 | return mi.uordblks; |
| 51 | #warning Cannot get malloc info on this platform |
| 52 | return 0; |
| 53 | #endif |
| 54 | } |
| 55 | |
| 56 | uint64_t |
| 57 | Process::GetTotalMemoryUsage() |
| 58 | { |
| 59 | #ifdef HAVE_MALLINFO |
| 60 | struct mallinfo mi = ::mallinfo(); |
| 61 | return mi.uordblks + mi.hblkhd |
| 62 | #else |
| 63 | #warning Cannot get total memory size on this platform |
| 64 | return 0; |
| 65 | #endif |
| 66 | } |
| 67 | |
| 68 | void |
| 69 | Process::GetTimeUsage( |
| 70 | TimeValue& elapsed, TimeValue& user_time, TimeValue& sys_time) |
| 71 | { |
| 72 | elapsed = TimeValue::now(); |
| 73 | |
| 74 | unsigned __int64 ProcCreate, ProcExit, KernelTime, UserTime; |
| 75 | GetProcessTimes(GetCurrentProcess(), (FILETIME*)&ProcCreate, |
| 76 | (FILETIME*)&ProcExit, (FILETIME*)&KernelTime, |
| 77 | (FILETIME*)&UserTime |
| 78 | ); |
| 79 | |
| 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 ); |
| 85 | } |
| 86 | |
Reid Spencer | 437b079 | 2004-09-15 05:47:40 +0000 | [diff] [blame] | 87 | } |
| 88 | // vim: sw=2 smartindent smarttab tw=80 autoindent expandtab |