1 | ;; @file
|
---|
2 | ; STAM - Statistics Manager.
|
---|
3 | ;
|
---|
4 |
|
---|
5 | ;
|
---|
6 | ; Copyright (C) 2006-2022 Oracle and/or its affiliates.
|
---|
7 | ;
|
---|
8 | ; This file is part of VirtualBox base platform packages, as
|
---|
9 | ; available from https://www.virtualbox.org.
|
---|
10 | ;
|
---|
11 | ; This program is free software; you can redistribute it and/or
|
---|
12 | ; modify it under the terms of the GNU General Public License
|
---|
13 | ; as published by the Free Software Foundation, in version 3 of the
|
---|
14 | ; License.
|
---|
15 | ;
|
---|
16 | ; This program is distributed in the hope that it will be useful, but
|
---|
17 | ; WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
18 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
19 | ; General Public License for more details.
|
---|
20 | ;
|
---|
21 | ; You should have received a copy of the GNU General Public License
|
---|
22 | ; along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
23 | ;
|
---|
24 | ; The contents of this file may alternatively be used under the terms
|
---|
25 | ; of the Common Development and Distribution License Version 1.0
|
---|
26 | ; (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
27 | ; in the VirtualBox distribution, in which case the provisions of the
|
---|
28 | ; CDDL are applicable instead of those of the GPL.
|
---|
29 | ;
|
---|
30 | ; You may elect to license modified versions of this file under the
|
---|
31 | ; terms and conditions of either the GPL or the CDDL or both.
|
---|
32 | ;
|
---|
33 | ; SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
34 | ;
|
---|
35 |
|
---|
36 | %ifndef ___VBox_vmm_stam_mac__
|
---|
37 | %define ___VBox_vmm_stam_mac__
|
---|
38 |
|
---|
39 |
|
---|
40 | %ifndef VBOX_WITH_STATISTICS
|
---|
41 | %ifdef DEBUG
|
---|
42 | %define VBOX_WITH_STATISTICS
|
---|
43 | %endif
|
---|
44 | %endif
|
---|
45 |
|
---|
46 |
|
---|
47 |
|
---|
48 | ;;
|
---|
49 | ; Counter sample - STAMTYPE_COUNTER.
|
---|
50 | struc STAMCOUNTER
|
---|
51 | .c resd 2
|
---|
52 | endstruc
|
---|
53 |
|
---|
54 | ;;
|
---|
55 | ; Increments a counter sample by one.
|
---|
56 | ; @param %1 Pointer to the STAMCOUNTER structure to operate on.
|
---|
57 | %macro STAM32_COUNTER_INC 1
|
---|
58 | %ifdef VBOX_WITH_STATISTICS
|
---|
59 | push ebx
|
---|
60 | mov ebx, %1
|
---|
61 | inc dword [ebx + STAMCOUNTER.c]
|
---|
62 | adc dword [ebx + STAMCOUNTER.c + 1], byte 0
|
---|
63 | pop ebx
|
---|
64 | %endif
|
---|
65 | %endmacro
|
---|
66 |
|
---|
67 | %macro STAM64_COUNTER_INC 1
|
---|
68 | %ifdef VBOX_WITH_STATISTICS
|
---|
69 | push rbx
|
---|
70 | mov rbx, %1
|
---|
71 | inc qword [rbx + STAMCOUNTER.c]
|
---|
72 | pop rbx
|
---|
73 | %endif
|
---|
74 | %endmacro
|
---|
75 |
|
---|
76 | %macro STAM_COUNTER_INC 1
|
---|
77 | %ifdef VBOX_WITH_STATISTICS
|
---|
78 | %ifdef RT_ARCH_AMD64
|
---|
79 | STAM64_COUNTER_INC %1
|
---|
80 | %else
|
---|
81 | STAM32_COUNTER_INC %1
|
---|
82 | %endif
|
---|
83 | %endif
|
---|
84 | %endmacro
|
---|
85 |
|
---|
86 |
|
---|
87 | ;;
|
---|
88 | ; Increments a counter sample by a value.
|
---|
89 | ;
|
---|
90 | ; @param %1 Pointer to the STAMCOUNTER structure to operate on.
|
---|
91 | ; @param %2 The value to add to the counter.
|
---|
92 | %macro STAM32_COUNTER_ADD 2
|
---|
93 | %ifdef VBOX_WITH_STATISTICS
|
---|
94 | push ebx
|
---|
95 | mov ebx, %1
|
---|
96 | push eax
|
---|
97 | mov eax, %2
|
---|
98 |
|
---|
99 | add [ebx + STAMCOUNTER.c], eax
|
---|
100 | adc dword [ebx + STAMCOUNTER.c], byte 0
|
---|
101 |
|
---|
102 | pop eax
|
---|
103 | pop ebx
|
---|
104 | %endif
|
---|
105 | %endmacro
|
---|
106 |
|
---|
107 | %macro STAM64_COUNTER_ADD 2
|
---|
108 | %ifdef VBOX_WITH_STATISTICS
|
---|
109 | push rbx
|
---|
110 | mov rbx, %1
|
---|
111 | push rax
|
---|
112 | mov rax, %2
|
---|
113 |
|
---|
114 | add [rbx + STAMCOUNTER.c], rax
|
---|
115 |
|
---|
116 | pop rax
|
---|
117 | pop rbx
|
---|
118 | %endif
|
---|
119 | %endmacro
|
---|
120 |
|
---|
121 | %macro STAM_COUNTER_ADD 2
|
---|
122 | %ifdef VBOX_WITH_STATISTICS
|
---|
123 | %ifdef RT_ARCH_AMD64
|
---|
124 | STAM64_COUNTER_ADD %1, %2
|
---|
125 | %else
|
---|
126 | STAM32_COUNTER_ADD %1, %2
|
---|
127 | %endif
|
---|
128 | %endif
|
---|
129 | %endmacro
|
---|
130 |
|
---|
131 |
|
---|
132 | ;;
|
---|
133 | ; Profiling sample - STAMTYPE_PROFILE.
|
---|
134 | struc STAMPROFILE
|
---|
135 | .cPeriods resd 2
|
---|
136 | .cTicks resd 2
|
---|
137 | .cTicksMax resd 2
|
---|
138 | .cTicksMin resd 2
|
---|
139 | endstruc
|
---|
140 |
|
---|
141 |
|
---|
142 | ;;
|
---|
143 | ; Samples the start time of a profiling period.
|
---|
144 | ;
|
---|
145 | ; @param %1 Pointer to somewhere one can store a 64-bit timestamp until STAM_PROFILE_STOPP
|
---|
146 | %macro STAM32_PROFILE_START 1
|
---|
147 | %ifdef VBOX_WITH_STATISTICS
|
---|
148 | push ebx
|
---|
149 | mov ebx, %1
|
---|
150 | push eax
|
---|
151 | push edx
|
---|
152 |
|
---|
153 | rdtsc
|
---|
154 | mov [ebx], eax
|
---|
155 | mov [ebx + 4], edx
|
---|
156 |
|
---|
157 | pop edx
|
---|
158 | pop eax
|
---|
159 | pop ebx
|
---|
160 | %endif
|
---|
161 | %endmacro
|
---|
162 |
|
---|
163 | %macro STAM64_PROFILE_START 1
|
---|
164 | %ifdef VBOX_WITH_STATISTICS
|
---|
165 | push rbx
|
---|
166 | mov rbx, %1
|
---|
167 | push rax
|
---|
168 | push rdx
|
---|
169 |
|
---|
170 | rdtsc
|
---|
171 | mov [rbx], eax
|
---|
172 | mov [rbx + 4], edx
|
---|
173 |
|
---|
174 | pop rdx
|
---|
175 | pop rax
|
---|
176 | pop rbx
|
---|
177 | %endif
|
---|
178 | %endmacro
|
---|
179 |
|
---|
180 | %macro STAM_PROFILE_START 1
|
---|
181 | %ifdef VBOX_WITH_STATISTICS
|
---|
182 | %ifdef RT_ARCH_AMD64
|
---|
183 | STAM64_PROFILE_START %1
|
---|
184 | %else
|
---|
185 | STAM32_PROFILE_START %1
|
---|
186 | %endif
|
---|
187 | %endif
|
---|
188 | %endmacro
|
---|
189 |
|
---|
190 |
|
---|
191 | ;;
|
---|
192 | ; Samples the stop time of a profiling period and updates the sample.
|
---|
193 | ;
|
---|
194 | ; @param %1 Pointer to the STAMPROFILE structure to operate on.
|
---|
195 | ; @param %2 Pointer to where the 64-bit timestamp from STAM_PROFILE_START was stored.
|
---|
196 | %macro STAM32_PROFILE_STOP 2
|
---|
197 | %ifdef VBOX_WITH_STATISTICS
|
---|
198 | push ebx
|
---|
199 | mov ebx, %1
|
---|
200 | push eax
|
---|
201 | push edx
|
---|
202 |
|
---|
203 | ; calc cTicks
|
---|
204 | push ecx
|
---|
205 | mov ecx, %2
|
---|
206 | rdtsc
|
---|
207 | sub eax, [ecx]
|
---|
208 | sbb edx, [ecx + 4]
|
---|
209 | pop ecx
|
---|
210 |
|
---|
211 | ; update STAMPROFILE.cTicks
|
---|
212 | add [ebx + STAMPROFILE.cTicks], eax
|
---|
213 | adc [ebx + STAMPROFILE.cTicks + 4], edx
|
---|
214 | ; update STAMPROFILE.cPeriods
|
---|
215 | inc dword [ebx + STAMPROFILE.cPeriods]
|
---|
216 | adc dword [ebx + STAMPROFILE.cPeriods + 4], byte 0
|
---|
217 |
|
---|
218 | ; update max?
|
---|
219 | cmp edx, [ebx + STAMPROFILE.cTicksMax + 4]
|
---|
220 | jb short %%not_update_max
|
---|
221 | ja short %%update_max
|
---|
222 | cmp eax, [ebx + STAMPROFILE.cTicksMax]
|
---|
223 | jbe short %%not_update_max
|
---|
224 | %%update_max:
|
---|
225 | mov [ebx + STAMPROFILE.cTicksMax], eax
|
---|
226 | mov [ebx + STAMPROFILE.cTicksMax + 4], edx
|
---|
227 | %%not_update_max:
|
---|
228 |
|
---|
229 | ; update min?
|
---|
230 | cmp edx, [ebx + STAMPROFILE.cTicksMin + 4]
|
---|
231 | ja short %%not_update_min
|
---|
232 | jb short %%update_min
|
---|
233 | cmp eax, [ebx + STAMPROFILE.cTicksMin]
|
---|
234 | jae short %%not_update_min
|
---|
235 | %%update_min:
|
---|
236 | mov [ebx + STAMPROFILE.cTicksMin], eax
|
---|
237 | mov [ebx + STAMPROFILE.cTicksMin + 4], edx
|
---|
238 | %%not_update_min:
|
---|
239 |
|
---|
240 | pop edx
|
---|
241 | pop eax
|
---|
242 | pop ebx
|
---|
243 | %endif
|
---|
244 | %endmacro
|
---|
245 |
|
---|
246 | %macro STAM64_PROFILE_STOP 2
|
---|
247 | %ifdef VBOX_WITH_STATISTICS
|
---|
248 | push rbx
|
---|
249 | mov rbx, %1
|
---|
250 | push rax
|
---|
251 | push rdx
|
---|
252 |
|
---|
253 | ; calc cTicks
|
---|
254 | push rcx
|
---|
255 | mov rcx, %2
|
---|
256 | rdtsc
|
---|
257 | sub rax, [ecx]
|
---|
258 | sbb rdx, [ecx + 4]
|
---|
259 | pop rcx
|
---|
260 |
|
---|
261 | ; update STAMPROFILE.cTicks
|
---|
262 | shl rdx, 32
|
---|
263 | or rdx, rax
|
---|
264 | add [rbx + STAMPROFILE.cTicks], rdx
|
---|
265 | ; update STAMPROFILE.cPeriods
|
---|
266 | inc qword [rbx + STAMPROFILE.cPeriods]
|
---|
267 |
|
---|
268 | ; update max?
|
---|
269 | cmp rdx, [rbx + STAMPROFILE.cTicksMax]
|
---|
270 | jbe short %%not_update_max
|
---|
271 | mov [rbx + STAMPROFILE.cTicksMax], rdx
|
---|
272 | %%not_update_max:
|
---|
273 |
|
---|
274 | ; update min?
|
---|
275 | cmp rdx, [rbx + STAMPROFILE.cTicksMin]
|
---|
276 | jae short %%not_update_min
|
---|
277 | mov [rbx + STAMPROFILE.cTicksMin], rax
|
---|
278 | %%not_update_min:
|
---|
279 |
|
---|
280 | pop rdx
|
---|
281 | pop rax
|
---|
282 | pop rbx
|
---|
283 | %endif
|
---|
284 | %endmacro
|
---|
285 |
|
---|
286 | %macro STAM_PROFILE_STOP 2
|
---|
287 | %ifdef VBOX_WITH_STATISTICS
|
---|
288 | %ifdef RT_ARCH_AMD64
|
---|
289 | STAM64_PROFILE_STOP %1, %2
|
---|
290 | %else
|
---|
291 | STAM32_PROFILE_STOP %1, %2
|
---|
292 | %endif
|
---|
293 | %endif
|
---|
294 | %endmacro
|
---|
295 |
|
---|
296 |
|
---|
297 |
|
---|
298 | struc STAMPROFILEADV
|
---|
299 | .cPeriods resd 2
|
---|
300 | .cTicks resd 2
|
---|
301 | .cTicksMax resd 2
|
---|
302 | .cTicksMin resd 2
|
---|
303 | .tsStart resd 2
|
---|
304 | endstruc
|
---|
305 |
|
---|
306 |
|
---|
307 | ;;
|
---|
308 | ; Samples the start time of a profiling period.
|
---|
309 | ;
|
---|
310 | ; @param %1 Pointer to the STAMPROFILEADV structure to operate on.
|
---|
311 | %macro STAM32_PROFILE_ADV_START 1
|
---|
312 | %ifdef VBOX_WITH_STATISTICS
|
---|
313 | push ecx
|
---|
314 | mov ecx, %1
|
---|
315 | lea ecx, [ecx + STAMPROFILEADV.tsStart]
|
---|
316 | STAM32_PROFILE_START ecx
|
---|
317 | pop ecx
|
---|
318 | %endif
|
---|
319 | %endmacro
|
---|
320 |
|
---|
321 | %macro STAM64_PROFILE_ADV_START 1
|
---|
322 | %ifdef VBOX_WITH_STATISTICS
|
---|
323 | push rcx
|
---|
324 | mov rcx, %1
|
---|
325 | lea rcx, [rcx + STAMPROFILEADV.tsStart]
|
---|
326 | STAM64_PROFILE_START rcx
|
---|
327 | pop rcx
|
---|
328 | %endif
|
---|
329 | %endmacro
|
---|
330 |
|
---|
331 | %macro STAM_PROFILE_ADV_START 1
|
---|
332 | %ifdef VBOX_WITH_STATISTICS
|
---|
333 | %ifdef RT_ARCH_AMD64
|
---|
334 | STAM64_PROFILE_ADV_START %1
|
---|
335 | %else
|
---|
336 | STAM32_PROFILE_ADV_START %1
|
---|
337 | %endif
|
---|
338 | %endif
|
---|
339 | %endmacro
|
---|
340 |
|
---|
341 |
|
---|
342 | ;;
|
---|
343 | ; Samples the stop time of a profiling period and updates the sample.
|
---|
344 | ;
|
---|
345 | ; @param %1 Pointer to the STAMPROFILEADV structure to operate on.
|
---|
346 |
|
---|
347 | %macro STAM32_PROFILE_ADV_STOP 1
|
---|
348 | %ifdef VBOX_WITH_STATISTICS
|
---|
349 | push ecx
|
---|
350 | mov ecx, %1
|
---|
351 | lea ecx, [ecx + STAMPROFILEADV.tsStart]
|
---|
352 | cmp dword [ecx], byte 0
|
---|
353 | jnz short %%doit
|
---|
354 | cmp dword [ecx + 4], byte 0
|
---|
355 | jz short %%dont
|
---|
356 | %%doit:
|
---|
357 | STAM32_PROFILE_STOP %1, ecx
|
---|
358 | %%dont:
|
---|
359 | mov dword [ecx], 0
|
---|
360 | mov dword [ecx + 4], 0
|
---|
361 | pop ecx
|
---|
362 | %endif
|
---|
363 | %endmacro
|
---|
364 |
|
---|
365 | %macro STAM64_PROFILE_ADV_STOP 1
|
---|
366 | %ifdef VBOX_WITH_STATISTICS
|
---|
367 | push rcx
|
---|
368 | mov rcx, %1
|
---|
369 | lea rcx, [rcx + STAMPROFILEADV.tsStart]
|
---|
370 | cmp qword [rcx], byte 0
|
---|
371 | jz short %%dont
|
---|
372 | %%doit:
|
---|
373 | STAM64_PROFILE_STOP %1, rcx
|
---|
374 | %%dont:
|
---|
375 | mov qword [rcx], 0
|
---|
376 | pop rcx
|
---|
377 | %endif
|
---|
378 | %endmacro
|
---|
379 |
|
---|
380 | %macro STAM_PROFILE_ADV_STOP 1
|
---|
381 | %ifdef VBOX_WITH_STATISTICS
|
---|
382 | %ifdef RT_ARCH_AMD64
|
---|
383 | STAM64_PROFILE_ADV_STOP %1
|
---|
384 | %else
|
---|
385 | STAM32_PROFILE_ADV_STOP %1
|
---|
386 | %endif
|
---|
387 | %endif
|
---|
388 | %endmacro
|
---|
389 |
|
---|
390 |
|
---|
391 |
|
---|
392 | %endif
|
---|