blob: 53f46bb4151b25ed266e74a0d256a71d166cde49 [file] [log] [blame]
Greg Clayton5dbe5d42013-03-21 03:39:51 +00001//===-- MemoryGauge.h -------------------------------------------*- C++ -*-===//
Enrico Granataf58cece2013-03-08 20:29:13 +00002//
Greg Clayton5dbe5d42013-03-21 03:39:51 +00003// The LLVM Compiler Infrastructure
Enrico Granataf58cece2013-03-08 20:29:13 +00004//
Greg Clayton5dbe5d42013-03-21 03:39:51 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Enrico Granataf58cece2013-03-08 20:29:13 +00007//
Greg Clayton5dbe5d42013-03-21 03:39:51 +00008//===----------------------------------------------------------------------===//
Enrico Granataf58cece2013-03-08 20:29:13 +00009
10#ifndef __PerfTestDriver__MemoryGauge__
11#define __PerfTestDriver__MemoryGauge__
12
13#include "Gauge.h"
Greg Clayton880afc52013-03-22 02:31:35 +000014#include "Results.h"
Enrico Granataf58cece2013-03-08 20:29:13 +000015
16#include <mach/task_info.h>
17
Greg Clayton880afc52013-03-22 02:31:35 +000018namespace lldb_perf {
19
Enrico Granataf3fb83a2013-03-20 21:18:20 +000020class MemoryStats
21{
22public:
Greg Claytonef0d2142013-03-21 03:32:24 +000023 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);
Enrico Granataf3fb83a2013-03-20 21:18:20 +000026 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 / (size_t rhs);
39
40 mach_vm_size_t
Greg Clayton880afc52013-03-22 02:31:35 +000041 GetVirtualSize () const
Enrico Granataf3fb83a2013-03-20 21:18:20 +000042 {
43 return m_virtual_size;
44 }
45
46 mach_vm_size_t
Greg Clayton880afc52013-03-22 02:31:35 +000047 GetResidentSize () const
Enrico Granataf3fb83a2013-03-20 21:18:20 +000048 {
49 return m_resident_size;
50 }
51
52 mach_vm_size_t
Greg Clayton880afc52013-03-22 02:31:35 +000053 GetMaxResidentSize () const
Enrico Granataf3fb83a2013-03-20 21:18:20 +000054 {
55 return m_max_resident_size;
56 }
57
58 void
59 SetVirtualSize (mach_vm_size_t vs)
60 {
61 m_virtual_size = vs;
62 }
63
64 void
65 SetResidentSize (mach_vm_size_t rs)
66 {
67 m_resident_size = rs;
68 }
69
70 void
71 SetMaxResidentSize (mach_vm_size_t mrs)
72 {
73 m_max_resident_size = mrs;
74 }
75
Greg Clayton880afc52013-03-22 02:31:35 +000076 Results::ResultSP
77 GetResult (const char *name, const char *description) const;
Enrico Granataf3fb83a2013-03-20 21:18:20 +000078private:
79 mach_vm_size_t m_virtual_size;
80 mach_vm_size_t m_resident_size;
81 mach_vm_size_t m_max_resident_size;
82};
83
84class MemoryGauge : public Gauge<MemoryStats>
Enrico Granataf58cece2013-03-08 20:29:13 +000085{
Enrico Granataf58cece2013-03-08 20:29:13 +000086public:
87 MemoryGauge ();
88
89 virtual
90 ~MemoryGauge ()
Greg Claytonef0d2142013-03-21 03:32:24 +000091 {
92 }
Enrico Granataf58cece2013-03-08 20:29:13 +000093
94 void
Greg Claytonef0d2142013-03-21 03:32:24 +000095 Start ();
Enrico Granataf58cece2013-03-08 20:29:13 +000096
Greg Clayton880afc52013-03-22 02:31:35 +000097 ValueType
Greg Claytonef0d2142013-03-21 03:32:24 +000098 Stop ();
Enrico Granataf58cece2013-03-08 20:29:13 +000099
Greg Clayton880afc52013-03-22 02:31:35 +0000100 virtual ValueType
101 GetStartValue() const
102 {
103 return m_start;
104 }
105
106 virtual ValueType
107 GetStopValue() const
108 {
109 return m_stop;
110 }
111
112 virtual ValueType
113 GetDeltaValue() const;
Greg Claytonef0d2142013-03-21 03:32:24 +0000114
115private:
116 enum class State
117 {
118 eNeverUsed,
119 eCounting,
120 eStopped
121 };
122
Greg Clayton880afc52013-03-22 02:31:35 +0000123 ValueType
Greg Claytonef0d2142013-03-21 03:32:24 +0000124 Now ();
125
Greg Claytonef0d2142013-03-21 03:32:24 +0000126 State m_state;
Greg Clayton880afc52013-03-22 02:31:35 +0000127 ValueType m_start;
128 ValueType m_stop;
129 ValueType m_delta;
Enrico Granataf58cece2013-03-08 20:29:13 +0000130};
Enrico Granataf58cece2013-03-08 20:29:13 +0000131
Greg Clayton880afc52013-03-22 02:31:35 +0000132template <>
133Results::ResultSP
134GetResult (const char *description, MemoryStats value);
135
136} // namespace lldb_perf
137
138#endif // #ifndef __PerfTestDriver__MemoryGauge__