/[projet1]/users/dbug/tests/IrqBenchmark/profiler/profile.h
Defence Force logotype

Contents of /users/dbug/tests/IrqBenchmark/profiler/profile.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 938 - (show annotations)
Sun Jun 9 19:22:25 2013 UTC (6 years, 11 months ago) by coco
File MIME type: text/plain
File size: 5627 byte(s)


1 //
2 // User settings
3 //
4 #define PROFILER_ENABLE // Comment out to disable profiling
5 #define PROFILER_USE_PRINTER // Comment out to disable the usage of printer
6 #define PROFILER_USE_NAMES // Comment out to disable the usage of function names
7
8 #ifdef PROFILER_MAIN
9 #define FUNCTIONNAME(function_id,function_name) .byte function_id,function_name,0
10 #else
11 #define FUNCTIONNAME(function_id,function_name)
12 #endif
13
14
15 //
16 // List of routines (need an enum !)
17 // Should have incrementing numbers, finishing by PROFILER_ROUTINE_COUNT as the number of routines to profile
18 //
19 #define ROUTINE_TEST20000 0
20 #define ROUTINE_DOSOMETHING 1
21 #define ROUTINE_DOSOMETHINGELSE 2
22 #define ROUTINE_SUBROUTINE 3
23 #define ROUTINE_GLOBAL 4
24 #define ROUTINE_ASM 5
25 #define PROFILER_ROUTINE_COUNT 6
26
27
28 FUNCTIONNAME(ROUTINE_TEST20000,"Test20000")
29 FUNCTIONNAME(ROUTINE_DOSOMETHING,"DoSomething")
30 FUNCTIONNAME(ROUTINE_DOSOMETHINGELSE,"DoSomethingElse")
31 FUNCTIONNAME(ROUTINE_SUBROUTINE,"SubRoutine")
32 FUNCTIONNAME(ROUTINE_GLOBAL,"Global")
33 FUNCTIONNAME(ROUTINE_ASM,"Asm")
34 FUNCTIONNAME(PROFILER_ROUTINE_COUNT,0) // End marker
35
36
37
38
39 //
40 // Profiler API
41 //
42 #ifdef PROFILER_ENABLE
43 // Profiler is enabled
44
45 #ifdef PROFILER_ASM
46 // Assembler API
47 #define PROFILE_ENTER(id) .byte $08,$48,$a9,id,$20,<_ProfilerEnterFunctionAsm,>_ProfilerEnterFunctionAsm,$68,$28
48 #define PROFILE_LEAVE(id) .byte $08,$48,$a9,id,$20,<_ProfilerLeaveFunctionAsm,>_ProfilerLeaveFunctionAsm,$68,$28
49 #define PROFILE(id) .byte $08,$08,$08,$48,$a9,id,$20,<_ProfilerEnterFunctionStack,>_ProfilerEnterFunctionStack,$68,$28
50
51 #else
52 // C API
53 #define PROFILE_ENTER(id) {profiler_function_id=id;ProfilerEnterFunctionC();}
54 #define PROFILE_LEAVE(id) {profiler_function_id=id;ProfilerLeaveFunctionC();}
55
56 extern unsigned char ProfilerRoutineCount[PROFILER_ROUTINE_COUNT];
57 extern unsigned char ProfilerRoutineTimeLow[PROFILER_ROUTINE_COUNT];
58 extern unsigned char ProfilerRoutineTimeHigh[PROFILER_ROUTINE_COUNT];
59 extern unsigned int ProfilerFrameCount;
60 extern unsigned char profiler_function_id;
61
62 void ProfilerInitialize();
63 void ProfilerTerminate();
64 void ProfilerNextFrame();
65 void ProfilerDisplay();
66 void ProfilerEnterFunction();
67 void ProfilerLeaveFunction();
68 #endif
69
70
71 #else
72 // Profiler is disabled, "do nothing" macros
73
74 #define PROFILE_ENTER(id)
75 #define PROFILE_LEAVE(id)
76 #define PROFILE(id)
77
78 #ifdef PROFILER_ASM
79 // Assembler API
80 #else
81 // C API
82 #define ProfilerInitialize()
83 #define ProfilerTerminate()
84 #define ProfilerNextFrame()
85 #define ProfilerDisplay()
86 #endif
87
88 #endif
89
90 /*
91
92 I wonder if we could hack a profiler, which would compute the average
93 time/count spent in some routines, perhaps with a "enter/leave" function
94 that would take the value of the VIA timer, and increment a counter.
95
96 Let's imagine a PROFILE macro, and a set of defines:
97
98 #define PROFILER_ENABLE
99
100 #define ROUTINE_PROJECTION 0
101 #define ROUTINE_CLIPPING 1
102 #define ROUTINE_DRAWING 2
103 #define ROUTINE_AI 3
104 #define ROUTINE_STARFIELD 4
105 #define ROUTINE_COUNT 5
106
107 etc...
108
109 Then some tables to store the data:
110
111 #ifdef PROFILER_ENABLE
112 ProfilerRoutineCount .dsb ROUTINE_COUNT
113 ProfilerRoutineTimeLow .dsb ROUTINE_COUNT
114 ProfilerRoutineTimeHigh .dsb ROUTINE_COUNT
115 #endif
116
117 Then the PROFILE macro itself, would be use that way:
118
119 ProjectionRoutine
120 PROFILE_ENTER(ROUTINE_PROJECTION)
121 bla
122 bla
123 bla
124 jsr something
125 bne loopsomewhere
126 PROFILE_LEAVE(ROUTINE_PROJECTION)
127 rts
128
129 This would increment the ProfilerRoutineCount entry for this routine, and
130 add the VIA timer to the ProfilerRoutineTimeLow/High.
131 Obviously you have to put the LEAVE on every single exit point, which kind
132 of suck, so a solution for that would be to also have an additional smart
133 one that automaticaly does the LEAVE when exiting a routine.
134
135 Something like that:
136
137 ProjectionRoutine
138 PROFILE(ROUTINE_PROJECTION) // Do the ENTER and push the LEAVE
139 bla
140 bla
141 bla
142 jsr something
143 bne loopsomewhere
144 rts // Automaticall calls the LEAVE function
145
146 Of course all the macros should no nothing if the ENABLE_PROFILE is not
147 enabled.
148
149 I guess the PROFILE routine could be doing something like that:
150
151 lda #<ProfileEnd
152 pha
153 lda #>ProfileEnd
154 pha
155
156 So it would call the ProfileEnd when performing a rts in the profiled
157 function.
158 Just an idea, need to think about it :)
159
160 Perhaps something I could implement as displayed in the 3 last lines of the
161 screen :)
162
163 Screen layout:
164
165 0123456789012345678901234567890123456789
166 Frame:0123
167 1:0123/01 2:0123/01 3:0123/01 4:0123/01
168 5:0123/01 6:0123/01 7:0123/01 8:0123/01
169
170 0123456789012345678901234567890123456789
171 Frame:0123
172 1x01 2x01 3x01 4x01 5x01 6x01 7x01 8x01
173 0123 0123 0123 0123 0123 0123 0123 0123
174
175
176 0123456789012345678901234567890123456789
177 Frame:0123
178 0x01 1x01 2x01 3x01 4x01
179 012345 012345 012345 012345 012345
180
181 0123456789012345678901234567890123456789
182 Frame:0123
183 0x01 1x01 2x01 3x01 4x01
184 12345 12345 12345 12345 12345 12345 12345
185
186
187
188
189 0123456789012345678901234567890123456789
190 Frame:0123 Cycles:012345 Fps:23
191 0:012345 1:012345 2:012345 3:012345
192 4:012345 5:012345 6:012345 7:012345
193
194 0123456789012345678901234567890123456789
195 Frame:0123 Cycles:012345 Fps:23
196 0:0123451:0123452:0123453:0123454:012345
197 5:0123456:0123457:0123458:0123459:012345
198
199
200 012345 012345 012345 012345 012345
201
202 Infos for each profile group:
203 - Number of calls
204 - Total duration
205 - Average duration
206 - Percentage of frame
207
208
209
210
211
212
213 +0 +10 +20...
214 */
215
216

  ViewVC Help
Powered by ViewVC 1.1.26