1 //===-- MemoryGauge.h -------------------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #ifndef __PerfTestDriver__MemoryGauge__ 11 #define __PerfTestDriver__MemoryGauge__ 12 13 #include "Gauge.h" 14 #include "Results.h" 15 16 #include <mach/task_info.h> 17 18 namespace lldb_perf { 19 20 class MemoryStats 21 { 22 public: 23 MemoryStats (mach_vm_size_t virtual_size = 0, 24 mach_vm_size_t resident_size = 0, 25 mach_vm_size_t max_resident_size = 0); 26 MemoryStats (const MemoryStats& rhs); 27 28 MemoryStats& 29 operator = (const MemoryStats& rhs); 30 31 MemoryStats& 32 operator += (const MemoryStats& rhs); 33 34 MemoryStats 35 operator - (const MemoryStats& rhs); 36 37 MemoryStats 38 operator + (const MemoryStats& rhs); 39 40 MemoryStats 41 operator / (size_t rhs); 42 43 MemoryStats 44 operator * (const MemoryStats& rhs); 45 46 mach_vm_size_t GetVirtualSize()47 GetVirtualSize () const 48 { 49 return m_virtual_size; 50 } 51 52 mach_vm_size_t GetResidentSize()53 GetResidentSize () const 54 { 55 return m_resident_size; 56 } 57 58 mach_vm_size_t GetMaxResidentSize()59 GetMaxResidentSize () const 60 { 61 return m_max_resident_size; 62 } 63 64 void SetVirtualSize(mach_vm_size_t vs)65 SetVirtualSize (mach_vm_size_t vs) 66 { 67 m_virtual_size = vs; 68 } 69 70 void SetResidentSize(mach_vm_size_t rs)71 SetResidentSize (mach_vm_size_t rs) 72 { 73 m_resident_size = rs; 74 } 75 76 void SetMaxResidentSize(mach_vm_size_t mrs)77 SetMaxResidentSize (mach_vm_size_t mrs) 78 { 79 m_max_resident_size = mrs; 80 } 81 82 Results::ResultSP 83 GetResult (const char *name, const char *description) const; 84 private: 85 mach_vm_size_t m_virtual_size; 86 mach_vm_size_t m_resident_size; 87 mach_vm_size_t m_max_resident_size; 88 }; 89 90 class MemoryGauge : public Gauge<MemoryStats> 91 { 92 public: 93 MemoryGauge (); 94 95 virtual ~MemoryGauge()96 ~MemoryGauge () 97 { 98 } 99 100 void 101 Start (); 102 103 ValueType 104 Stop (); 105 106 virtual ValueType GetStartValue()107 GetStartValue() const 108 { 109 return m_start; 110 } 111 112 virtual ValueType GetStopValue()113 GetStopValue() const 114 { 115 return m_stop; 116 } 117 118 virtual ValueType 119 GetDeltaValue() const; 120 121 private: 122 enum class State 123 { 124 eNeverUsed, 125 eCounting, 126 eStopped 127 }; 128 129 ValueType 130 Now (); 131 132 State m_state; 133 ValueType m_start; 134 ValueType m_stop; 135 ValueType m_delta; 136 }; 137 138 template <> 139 Results::ResultSP 140 GetResult (const char *description, MemoryStats value); 141 142 } // namespace lldb_perf 143 144 lldb_perf::MemoryStats 145 sqrt (const lldb_perf::MemoryStats& arg); 146 147 #endif // #ifndef __PerfTestDriver__MemoryGauge__ 148