/[pcsx2_0.9.7]/branch/debug/0.X/0.9.X/0.9.7/r3113/plugins/zzogl-pg/opengl/Profile.cpp
ViewVC logotype

Contents of /branch/debug/0.X/0.9.X/0.9.7/r3113/plugins/zzogl-pg/opengl/Profile.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 59 - (show annotations) (download)
Tue Sep 7 06:17:51 2010 UTC (10 years, 2 months ago) by william
File size: 6199 byte(s)
create working branch for pcsx2-0.9.7-r3113-debug
1 /* ZeroGS KOSMOS
2 * Copyright (C) 2005-2006 zerofrog@gmail.com
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18
19
20 ////////////////////
21 // Small profiler //
22 ////////////////////
23 #include <list>
24 #include <string>
25 #include <map>
26 #include "Profile.h"
27
28 using namespace std;
29
30 #define GET_PROFILE_TIME() GetCPUTicks()
31
32 #if !defined(ZEROGS_DEVBUILD)
33 #define g_bWriteProfile 0
34 #else
35 bool g_bWriteProfile = 0;
36 #endif
37
38 u64 luPerfFreq;
39
40 struct DVPROFSTRUCT;
41
42 struct DVPROFSTRUCT
43 {
44
45 struct DATA
46 {
47 DATA(u64 time, u32 user = 0) : dwTime(time), dwUserData(user) {}
48
49 DATA() : dwTime(0), dwUserData(0) {}
50
51 u64 dwTime;
52 u32 dwUserData;
53 };
54
55 ~DVPROFSTRUCT()
56 {
57 list<DVPROFSTRUCT*>::iterator it = listpChild.begin();
58
59 while (it != listpChild.end())
60 {
61 SAFE_DELETE(*it);
62 ++it;
63 }
64 }
65
66 list<DATA> listTimes; // before DVProfEnd is called, contains the global time it started
67 // after DVProfEnd is called, contains the time it lasted
68 // the list contains all the tracked times
69 char pname[256];
70
71 list<DVPROFSTRUCT*> listpChild; // other profilers called during this profiler period
72 };
73
74 struct DVPROFTRACK
75 {
76 u32 dwUserData;
77 DVPROFSTRUCT::DATA* pdwTime;
78 DVPROFSTRUCT* pprof;
79 };
80
81 list<DVPROFTRACK> g_listCurTracking; // the current profiling functions, the back element is the
82 // one that will first get popped off the list when DVProfEnd is called
83 // the pointer is an element in DVPROFSTRUCT::listTimes
84 list<DVPROFSTRUCT> g_listProfilers; // the current profilers, note that these are the parents
85 // any profiler started during the time of another is held in
86 // DVPROFSTRUCT::listpChild
87 list<DVPROFSTRUCT*> g_listAllProfilers; // ignores the hierarchy, pointer to elements in g_listProfilers
88
89 void DVProfRegister(char* pname)
90 {
91 if (!g_bWriteProfile) return;
92
93 list<DVPROFSTRUCT*>::iterator it = g_listAllProfilers.begin();
94
95 // while(it != g_listAllProfilers.end() ) {
96 //
97 // if( _tcscmp(pname, (*it)->pname) == 0 ) {
98 // (*it)->listTimes.push_back(timeGetTime());
99 // DVPROFTRACK dvtrack;
100 // dvtrack.pdwTime = &(*it)->listTimes.back();
101 // dvtrack.pprof = *it;
102 // g_listCurTracking.push_back(dvtrack);
103 // return;
104 // }
105 //
106 // ++it;
107 // }
108
109 // else add in a new profiler to the appropriate parent profiler
110 DVPROFSTRUCT* pprof = NULL;
111
112 if (g_listCurTracking.size() > 0)
113 {
114 assert(g_listCurTracking.back().pprof != NULL);
115 g_listCurTracking.back().pprof->listpChild.push_back(new DVPROFSTRUCT());
116 pprof = g_listCurTracking.back().pprof->listpChild.back();
117 }
118 else
119 {
120 g_listProfilers.push_back(DVPROFSTRUCT());
121 pprof = &g_listProfilers.back();
122 }
123
124 strncpy(pprof->pname, pname, 256);
125
126 // setup the profiler for tracking
127 pprof->listTimes.push_back(DVPROFSTRUCT::DATA(GET_PROFILE_TIME()));
128
129 DVPROFTRACK dvtrack;
130 dvtrack.pdwTime = &pprof->listTimes.back();
131 dvtrack.pprof = pprof;
132 dvtrack.dwUserData = 0;
133
134 g_listCurTracking.push_back(dvtrack);
135
136 // add to all profiler list
137 g_listAllProfilers.push_back(pprof);
138 }
139
140 void DVProfEnd(u32 dwUserData)
141 {
142 if (!g_bWriteProfile)
143 return;
144
145 B_RETURN(g_listCurTracking.size() > 0);
146
147 DVPROFTRACK dvtrack = g_listCurTracking.back();
148
149 assert(dvtrack.pdwTime != NULL && dvtrack.pprof != NULL);
150
151 dvtrack.pdwTime->dwTime = 1000000 * (GET_PROFILE_TIME() - dvtrack.pdwTime->dwTime) / luPerfFreq;
152
153 dvtrack.pdwTime->dwUserData = dwUserData;
154
155 g_listCurTracking.pop_back();
156 }
157
158 struct DVTIMEINFO
159 {
160 DVTIMEINFO() : uInclusive(0), uExclusive(0) {}
161
162 u64 uInclusive, uExclusive;
163 };
164
165 map<string, DVTIMEINFO> mapAggregateTimes;
166
167 u64 DVProfWriteStruct(FILE* f, DVPROFSTRUCT* p, int ident)
168 {
169 fprintf(f, "%*s%s - ", ident, "", p->pname);
170
171 list<DVPROFSTRUCT::DATA>::iterator ittime = p->listTimes.begin();
172
173 u32 utime = 0;
174
175 while (ittime != p->listTimes.end())
176 {
177 utime += (u32)ittime->dwTime;
178
179 if (ittime->dwUserData)
180 fprintf(f, "time: %d, user: 0x%8.8x", (u32)ittime->dwTime, ittime->dwUserData);
181 else
182 fprintf(f, "time: %d", (u32)ittime->dwTime);
183
184 ++ittime;
185 }
186
187 mapAggregateTimes[p->pname].uInclusive += utime;
188
189 fprintf(f, "\n");
190
191 list<DVPROFSTRUCT*>::iterator itprof = p->listpChild.begin();
192
193 u32 uex = utime;
194
195 while (itprof != p->listpChild.end())
196 {
197
198 uex -= DVProfWriteStruct(f, *itprof, ident + 4);
199 ++itprof;
200 }
201
202 mapAggregateTimes[p->pname].uExclusive += uex;
203
204 return utime;
205 }
206
207 void DVProfWrite(char* pfilename, u32 frames)
208 {
209 assert(pfilename != NULL);
210 FILE* f = fopen(pfilename, "wb");
211
212 mapAggregateTimes.clear();
213 list<DVPROFSTRUCT>::iterator it = g_listProfilers.begin();
214
215 while (it != g_listProfilers.end())
216 {
217 DVProfWriteStruct(f, &(*it), 0);
218 ++it;
219 }
220
221 {
222 map<string, DVTIMEINFO>::iterator it;
223 fprintf(f, "\n\n-------------------------------------------------------------------\n\n");
224
225 u64 uTotal[2] = {0};
226 double fiTotalTime[2];
227
228 for (it = mapAggregateTimes.begin(); it != mapAggregateTimes.end(); ++it)
229 {
230 uTotal[0] += it->second.uExclusive;
231 uTotal[1] += it->second.uInclusive;
232 }
233
234 fprintf(f, "total times (%d): ex: %Lu ", frames, uTotal[0] / frames);
235
236 fprintf(f, "inc: %Lu\n", uTotal[1] / frames);
237
238 fiTotalTime[0] = 1.0 / (double)uTotal[0];
239 fiTotalTime[1] = 1.0 / (double)uTotal[1];
240
241 // output the combined times
242
243 for (it = mapAggregateTimes.begin(); it != mapAggregateTimes.end(); ++it)
244 {
245 fprintf(f, "%s - ex: %f inc: %f\n", it->first.c_str(), (double)it->second.uExclusive * fiTotalTime[0],
246 (double)it->second.uInclusive * fiTotalTime[1]);
247 }
248 }
249
250
251 fclose(f);
252 }
253
254 void DVProfClear()
255 {
256 g_listCurTracking.clear();
257 g_listProfilers.clear();
258 g_listAllProfilers.clear();
259 }

  ViewVC Help
Powered by ViewVC 1.1.22