VirtualBox

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

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

Biggest check-in ever. New source code headers for all (C) innotek files.

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