/////////////////////////////////////////////////////////////////////
| 235 | |
| 236 | ////////////////////////////////////////////////////////////////////////// |
| 237 | void CFrameProfileSystem::SetProfiling(bool on, bool display, char *prefix, ISystem *pSystem) |
| 238 | { |
| 239 | Enable( on,display ); |
| 240 | m_pPrefix = prefix; |
| 241 | if(on && m_nCurSample<0) |
| 242 | { |
| 243 | m_nCurSample = 0; |
| 244 | pSystem->GetILog()->Log("\001Profiling data started (%s), prefix = \"%s\"", display ? "display only" : "tracing", prefix); |
| 245 | |
| 246 | m_frameTimeOfflineHistory.m_selfTime.reserve(1000); |
| 247 | m_frameTimeOfflineHistory.m_count.reserve(1000); |
| 248 | } |
| 249 | else if(!on && m_nCurSample>=0) |
| 250 | { |
| 251 | pSystem->GetILog()->Log("\001Profiling data finished"); |
| 252 | { |
| 253 | #ifdef WIN32 |
| 254 | // find the "frameprofileXX" filename for the file |
| 255 | char outfilename[32] = "frameprofile.dat"; |
| 256 | // while there is such file already |
| 257 | for (int i = 0; (GetFileAttributes (outfilename) != INVALID_FILE_ATTRIBUTES) && i < 1000; ++i) |
| 258 | sprintf (outfilename, "frameprofile%02d.dat", i); |
| 259 | |
| 260 | FILE *f = fopen(outfilename, "wb"); |
| 261 | if(!f) |
| 262 | { |
| 263 | pSystem->GetILog()->Log("\001Could not write profiling data to file!"); |
| 264 | } |
| 265 | else |
| 266 | { |
| 267 | int i; |
| 268 | // Find out how many profilers was active. |
| 269 | int numProf = 0; |
| 270 | |
| 271 | for (i = 0; i < (int)m_pProfilers->size(); i++) |
| 272 | { |
| 273 | CFrameProfiler *pProfiler = (*m_pProfilers)[i]; |
| 274 | if (pProfiler->m_pOfflineHistory) |
| 275 | numProf++; |
| 276 | } |
| 277 | |
| 278 | fwrite("FPROFDAT", 8, 1, f); // magic header, for what its worth |
| 279 | int version = 2; // bump this if any of the format below changes |
| 280 | fwrite(&version, sizeof(int), 1, f); |
| 281 | |
| 282 | int numSamples = m_nCurSample; |
| 283 | fwrite(&numSamples, sizeof(int), 1, f); // number of samples per group (everything little endian) |
| 284 | int mapsize = numProf+1; // Plus 1 global. |
| 285 | fwrite(&mapsize, sizeof(int), 1, f); |
| 286 | |
| 287 | // Write global profiler. |
| 288 | fwrite( "__frametime",strlen("__frametime")+1,1, f); |
| 289 | int len = (int)m_frameTimeOfflineHistory.m_selfTime.size(); |
| 290 | assert( len == numSamples ); |
| 291 | for(i = 0; i<len; i++) |
| 292 | { |
| 293 | fwrite( &m_frameTimeOfflineHistory.m_selfTime[i], 1, sizeof(int), f); |
| 294 | fwrite( &m_frameTimeOfflineHistory.m_count[i], 1, sizeof(short), f); |