1 | // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
2 | // for details. All rights reserved. Use of this source code is governed by a |
3 | // BSD-style license that can be found in the LICENSE file. |
4 | |
5 | #ifndef RUNTIME_VM_METRICS_H_ |
6 | #define RUNTIME_VM_METRICS_H_ |
7 | |
8 | #include "vm/allocation.h" |
9 | |
10 | namespace dart { |
11 | |
12 | class Isolate; |
13 | class IsolateGroup; |
14 | class JSONStream; |
15 | |
16 | // Metrics for each isolate group. |
17 | #define ISOLATE_GROUP_METRIC_LIST(V) \ |
18 | V(MetricHeapOldUsed, HeapOldUsed, "heap.old.used", kByte) \ |
19 | V(MaxMetric, HeapOldUsedMax, "heap.old.used.max", kByte) \ |
20 | V(MetricHeapOldCapacity, HeapOldCapacity, "heap.old.capacity", kByte) \ |
21 | V(MaxMetric, HeapOldCapacityMax, "heap.old.capacity.max", kByte) \ |
22 | V(MetricHeapOldExternal, HeapOldExternal, "heap.old.external", kByte) \ |
23 | V(MetricHeapNewUsed, HeapNewUsed, "heap.new.used", kByte) \ |
24 | V(MaxMetric, HeapNewUsedMax, "heap.new.used.max", kByte) \ |
25 | V(MetricHeapNewCapacity, HeapNewCapacity, "heap.new.capacity", kByte) \ |
26 | V(MaxMetric, HeapNewCapacityMax, "heap.new.capacity.max", kByte) \ |
27 | V(MetricHeapNewExternal, HeapNewExternal, "heap.new.external", kByte) \ |
28 | V(MetricHeapUsed, HeapGlobalUsed, "heap.global.used", kByte) \ |
29 | V(MaxMetric, HeapGlobalUsedMax, "heap.global.used.max", kByte) |
30 | |
31 | // Metrics for each isolate. |
32 | #define ISOLATE_METRIC_LIST(V) \ |
33 | V(Metric, RunnableLatency, "isolate.runnable.latency", kMicrosecond) \ |
34 | V(Metric, RunnableHeapSize, "isolate.runnable.heap", kByte) |
35 | |
36 | #define VM_METRIC_LIST(V) \ |
37 | V(MetricIsolateCount, IsolateCount, "vm.isolate.count", kCounter) \ |
38 | V(MetricCurrentRSS, CurrentRSS, "vm.memory.current", kByte) \ |
39 | V(MetricPeakRSS, PeakRSS, "vm.memory.max", kByte) |
40 | |
41 | class Metric { |
42 | public: |
43 | enum Unit { |
44 | kCounter, |
45 | kByte, |
46 | kMicrosecond, |
47 | }; |
48 | |
49 | Metric(); |
50 | |
51 | #if !defined(PRODUCT) |
52 | static void Init(); |
53 | static void Cleanup(); |
54 | #endif // !defined(PRODUCT) |
55 | |
56 | // Initialize a metric for an isolate. |
57 | void InitInstance(Isolate* isolate, |
58 | const char* name, |
59 | const char* description, |
60 | Unit unit); |
61 | |
62 | // Initialize a metric for an isolate group. |
63 | void InitInstance(IsolateGroup* isolate_group, |
64 | const char* name, |
65 | const char* description, |
66 | Unit unit); |
67 | |
68 | // Initialize a metric for the VM. |
69 | void InitInstance(const char* name, const char* description, Unit unit); |
70 | |
71 | virtual ~Metric(); |
72 | |
73 | #ifndef PRODUCT |
74 | void PrintJSON(JSONStream* stream); |
75 | #endif // !PRODUCT |
76 | |
77 | // Returns a zone allocated string. |
78 | static char* ValueToString(int64_t value, Unit unit); |
79 | |
80 | // Returns a zone allocated string. |
81 | char* ToString(); |
82 | |
83 | int64_t value() const { return value_; } |
84 | void set_value(int64_t value) { value_ = value; } |
85 | |
86 | void increment() { value_++; } |
87 | |
88 | const char* name() const { return name_; } |
89 | const char* description() const { return description_; } |
90 | Unit unit() const { return unit_; } |
91 | |
92 | // Only non-null for isolate specific metrics. |
93 | Isolate* isolate() const { return isolate_; } |
94 | |
95 | // Only non-null for isolate group specific metrics. |
96 | IsolateGroup* isolate_group() const { return isolate_group_; } |
97 | |
98 | static Metric* vm_head() { return vm_list_head_; } |
99 | |
100 | // Override to get a callback when value is serialized to JSON. |
101 | // Use this for metrics that produce their value on demand. |
102 | virtual int64_t Value() const { return value(); } |
103 | |
104 | private: |
105 | Isolate* isolate_ = nullptr; |
106 | IsolateGroup* isolate_group_ = nullptr; |
107 | const char* name_ = nullptr; |
108 | const char* description_ = nullptr; |
109 | Unit unit_; |
110 | int64_t value_; |
111 | |
112 | static Metric* vm_list_head_; |
113 | DISALLOW_COPY_AND_ASSIGN(Metric); |
114 | }; |
115 | |
116 | // A Metric class that reports the maximum value observed. |
117 | // Initial maximum is kMinInt64. |
118 | class MaxMetric : public Metric { |
119 | public: |
120 | MaxMetric(); |
121 | |
122 | void SetValue(int64_t new_value); |
123 | }; |
124 | |
125 | // A Metric class that reports the minimum value observed. |
126 | // Initial minimum is kMaxInt64. |
127 | class MinMetric : public Metric { |
128 | public: |
129 | MinMetric(); |
130 | |
131 | void SetValue(int64_t new_value); |
132 | }; |
133 | |
134 | class MetricHeapOldUsed : public Metric { |
135 | public: |
136 | virtual int64_t Value() const; |
137 | }; |
138 | |
139 | class MetricHeapOldCapacity : public Metric { |
140 | public: |
141 | virtual int64_t Value() const; |
142 | }; |
143 | |
144 | class MetricHeapOldExternal : public Metric { |
145 | public: |
146 | virtual int64_t Value() const; |
147 | }; |
148 | |
149 | class MetricHeapNewUsed : public Metric { |
150 | public: |
151 | virtual int64_t Value() const; |
152 | }; |
153 | |
154 | class MetricHeapNewCapacity : public Metric { |
155 | public: |
156 | virtual int64_t Value() const; |
157 | }; |
158 | |
159 | class MetricHeapNewExternal : public Metric { |
160 | public: |
161 | virtual int64_t Value() const; |
162 | }; |
163 | |
164 | #if !defined(PRODUCT) |
165 | class MetricIsolateCount : public Metric { |
166 | public: |
167 | virtual int64_t Value() const; |
168 | }; |
169 | |
170 | class : public Metric { |
171 | public: |
172 | virtual int64_t () const; |
173 | }; |
174 | |
175 | class : public Metric { |
176 | public: |
177 | virtual int64_t () const; |
178 | }; |
179 | #endif // !defined(PRODUCT) |
180 | |
181 | class MetricHeapUsed : public Metric { |
182 | public: |
183 | virtual int64_t Value() const; |
184 | }; |
185 | |
186 | #if !defined(PRODUCT) |
187 | #define VM_METRIC_VARIABLE(type, variable, name, unit) \ |
188 | extern type vm_metric_##variable; |
189 | VM_METRIC_LIST(VM_METRIC_VARIABLE); |
190 | #undef VM_METRIC_VARIABLE |
191 | #endif // !defined(PRODUCT) |
192 | |
193 | } // namespace dart |
194 | |
195 | #endif // RUNTIME_VM_METRICS_H_ |
196 | |