VirtualBox

source: vbox/trunk/include/VBox/stam.mac@ 8113

Last change on this file since 8113 was 5999, checked in by vboxsync, 17 years ago

The Giant CDDL Dual-License Header Change.

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette