/[pcsx2_0.9.7]/trunk/plugins/zzogl-pg/opengl/Profile.cpp
ViewVC logotype

Contents of /trunk/plugins/zzogl-pg/opengl/Profile.cpp

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.22