1 /**************************************************************************
3 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
32 * @author José Fonseca <jrfonseca@tungstengraphics.com>
34 * @sa http://blogs.msdn.com/joshpoley/archive/2008/03/12/poor-man-s-profiler.aspx
35 * @sa http://www.johnpanzer.com/aci_cuj/index.html
38 #include "pipe/p_config.h"
40 #if defined(PROFILE) && defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY)
45 #include "pipe/p_debug.h"
46 #include "util/u_string.h"
49 #define PROFILE_FILE_SIZE 4*1024*1024
50 #define FILE_NAME_SIZE 256
52 static WCHAR wFileName
[FILE_NAME_SIZE
];
53 static ULONG_PTR iFile
= 0;
54 static void *pMap
= NULL
;
55 static void *pMapEnd
= NULL
;
59 * Called at the start of every method or function.
61 * @sa http://msdn.microsoft.com/en-us/library/c63a9b7h.aspx
63 void __declspec(naked
) __cdecl
92 * Called at the end of Calls the end of every method or function.
94 * @sa http://msdn.microsoft.com/en-us/library/xc11y76y.aspx
96 void __declspec(naked
) __cdecl
124 void __declspec(naked
)
125 __debug_profile_reference1(void) {
134 void __declspec(naked
)
135 __debug_profile_reference2(void) {
138 call __debug_profile_reference1
146 debug_profile_start(void)
148 static unsigned no
= 0;
149 char filename
[FILE_NAME_SIZE
];
152 util_snprintf(filename
, sizeof(filename
), "\\??\\c:\\%03u.prof", ++no
);
153 for(i
= 0; i
< FILE_NAME_SIZE
; ++i
)
154 wFileName
[i
] = (WCHAR
)filename
[i
];
156 pMap
= EngMapFile(wFileName
, PROFILE_FILE_SIZE
, &iFile
);
158 pMapEnd
= (unsigned char*)pMap
+ PROFILE_FILE_SIZE
;
159 /* reference functions for calibration purposes */
160 __debug_profile_reference2();
165 debug_profile_stop(void)
169 /* TODO: truncate file */
172 pMapEnd
= pMap
= NULL
;