profiler.cc 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #include "platform/platform.h"
  23. #include "debug/profiler.h"
  24. #include "string/stringTable.h"
  25. #include <stdlib.h> // gotta use malloc and free directly
  26. #include <string.h>
  27. #include "console/console.h"
  28. #include "collection/vector.h"
  29. #include "io/fileStream.h"
  30. #include "platform/threads/thread.h"
  31. #include "profiler_ScriptBinding.h"
  32. #ifdef TORQUE_ENABLE_PROFILER
  33. ProfilerRootData *ProfilerRootData::sRootList = NULL;
  34. Profiler *gProfiler = NULL;
  35. #ifdef TORQUE_MULTITHREAD
  36. ThreadIdent gMainThread = 0;
  37. #endif
  38. #if defined(TORQUE_SUPPORTS_VC_INLINE_X86_ASM)
  39. // platform specific get hires times...
  40. void startHighResolutionTimer(U32 time[2])
  41. {
  42. //time[0] = Platform::getRealMilliseconds();
  43. __asm
  44. {
  45. push eax
  46. push edx
  47. push ecx
  48. rdtsc
  49. mov ecx, time
  50. mov DWORD PTR [ecx], eax
  51. mov DWORD PTR [ecx + 4], edx
  52. pop ecx
  53. pop edx
  54. pop eax
  55. }
  56. }
  57. U32 endHighResolutionTimer(U32 time[2])
  58. {
  59. U32 ticks;
  60. //ticks = Platform::getRealMilliseconds() - time[0];
  61. //return ticks;
  62. __asm
  63. {
  64. push eax
  65. push edx
  66. push ecx
  67. //db 0fh, 31h
  68. rdtsc
  69. mov ecx, time
  70. sub edx, DWORD PTR [ecx+4]
  71. sbb eax, DWORD PTR [ecx]
  72. mov DWORD PTR ticks, eax
  73. pop ecx
  74. pop edx
  75. pop eax
  76. }
  77. return ticks;
  78. }
  79. #elif defined(TORQUE_SUPPORTS_GCC_INLINE_X86_ASM)
  80. // platform specific get hires times...
  81. void startHighResolutionTimer(U32 time[2])
  82. {
  83. __asm__ __volatile__(
  84. "rdtsc\n"
  85. : "=a" (time[0]), "=d" (time[1])
  86. );
  87. }
  88. U32 endHighResolutionTimer(U32 time[2])
  89. {
  90. U32 ticks;
  91. __asm__ __volatile__(
  92. "rdtsc\n"
  93. "sub 0x4(%%ecx), %%edx\n"
  94. "sbb (%%ecx), %%eax\n"
  95. : "=a" (ticks) : "c" (time)
  96. );
  97. return ticks;
  98. }
  99. #elif defined(TORQUE_OS_MAC_CARB)
  100. #include <Timer.h>
  101. #include <Math64.h>
  102. void startHighResolutionTimer(U32 time[2]) {
  103. UnsignedWide t;
  104. Microseconds(&t);
  105. time[0] = t.lo;
  106. time[1] = t.hi;
  107. }
  108. U32 endHighResolutionTimer(U32 time[2]) {
  109. UnsignedWide t;
  110. Microseconds(&t);
  111. return t.lo - time[0];
  112. // given that we're returning a 32 bit integer, and this is unsigned subtraction...
  113. // it will just wrap around, we don't need the upper word of the time.
  114. // NOTE: the code assumes that more than 3 hrs will not go by between calls to startHighResolutionTimer() and endHighResolutionTimer().
  115. // I mean... that damn well better not happen anyway.
  116. }
  117. #elif defined(TORQUE_OS_IOS)
  118. //-Mat added high resolution iPhone timer
  119. #import <mach/mach_time.h>
  120. #include <Math64.h>
  121. void startHighResolutionTimer(U32 time[2]) {
  122. time[0] = mach_absolute_time();
  123. }
  124. U32 endHighResolutionTimer(U32 time[2]) {
  125. return mach_absolute_time() - time[0];
  126. }
  127. #else
  128. void startHighResolutionTimer(U32 time[2])
  129. {
  130. }
  131. U32 endHighResolutionTimer(U32 time[2])
  132. {
  133. return 1;
  134. }
  135. #endif
  136. Profiler::Profiler()
  137. {
  138. mMaxStackDepth = MaxStackDepth;
  139. mCurrentHash = 0;
  140. mCurrentProfilerData = (ProfilerData *) malloc(sizeof(ProfilerData));
  141. mCurrentProfilerData->mRoot = NULL;
  142. mCurrentProfilerData->mNextForRoot = NULL;
  143. mCurrentProfilerData->mNextProfilerData = NULL;
  144. mCurrentProfilerData->mNextHash = NULL;
  145. mCurrentProfilerData->mParent = NULL;
  146. mCurrentProfilerData->mNextSibling = NULL;
  147. mCurrentProfilerData->mFirstChild = NULL;
  148. mCurrentProfilerData->mLastSeenProfiler = NULL;
  149. mCurrentProfilerData->mHash = 0;
  150. mCurrentProfilerData->mSubDepth = 0;
  151. mCurrentProfilerData->mInvokeCount = 0;
  152. mCurrentProfilerData->mTotalTime = 0;
  153. mCurrentProfilerData->mSubTime = 0;
  154. mRootProfilerData = mCurrentProfilerData;
  155. for(U32 i = 0; i < ProfilerData::HashTableSize; i++)
  156. mCurrentProfilerData->mChildHash[i] = 0;
  157. mProfileList = NULL;
  158. mEnabled = false;
  159. mStackDepth = 0;
  160. mNextEnable = false;
  161. gProfiler = this;
  162. mDumpToConsole = false;
  163. mDumpToFile = false;
  164. mDumpFileName[0] = '\0';
  165. #ifdef TORQUE_MULTITHREAD
  166. gMainThread = ThreadManager::getCurrentThreadId();
  167. #endif
  168. }
  169. Profiler::~Profiler()
  170. {
  171. reset();
  172. free(mRootProfilerData);
  173. gProfiler = NULL;
  174. }
  175. void Profiler::reset()
  176. {
  177. mEnabled = false; // in case we're in a profiler call.
  178. while(mProfileList)
  179. {
  180. free(mProfileList);
  181. mProfileList = NULL;
  182. }
  183. for(ProfilerRootData *walk = ProfilerRootData::sRootList; walk; walk = walk->mNextRoot)
  184. {
  185. walk->mFirstProfilerData = 0;
  186. walk->mTotalTime = 0;
  187. walk->mSubTime = 0;
  188. walk->mTotalInvokeCount = 0;
  189. }
  190. mCurrentProfilerData = mRootProfilerData;
  191. mCurrentProfilerData->mNextForRoot = 0;
  192. mCurrentProfilerData->mFirstChild = 0;
  193. for(U32 i = 0; i < ProfilerData::HashTableSize; i++)
  194. mCurrentProfilerData->mChildHash[i] = 0;
  195. mCurrentProfilerData->mInvokeCount = 0;
  196. mCurrentProfilerData->mTotalTime = 0;
  197. mCurrentProfilerData->mSubTime = 0;
  198. mCurrentProfilerData->mSubDepth = 0;
  199. mCurrentProfilerData->mLastSeenProfiler = 0;
  200. }
  201. static Profiler aProfiler; // allocate the global profiler
  202. ProfilerRootData::ProfilerRootData(const char *name)
  203. {
  204. for(ProfilerRootData *walk = sRootList; walk; walk = walk->mNextRoot)
  205. if(!dStrcmp(walk->mName, name))
  206. Platform::debugBreak();
  207. mName = name;
  208. mNameHash = _StringTable::hashString(name);
  209. mNextRoot = sRootList;
  210. sRootList = this;
  211. mTotalTime = 0;
  212. mTotalInvokeCount = 0;
  213. mFirstProfilerData = NULL;
  214. mEnabled = true;
  215. }
  216. void Profiler::validate()
  217. {
  218. for(ProfilerRootData *walk = ProfilerRootData::sRootList; walk; walk = walk->mNextRoot)
  219. {
  220. for(ProfilerData *dp = walk->mFirstProfilerData; dp; dp = dp->mNextForRoot)
  221. {
  222. if(dp->mRoot != walk)
  223. Platform::debugBreak();
  224. // check if it's in the parent's list...
  225. ProfilerData *wk;
  226. for(wk = dp->mParent->mFirstChild; wk; wk = wk->mNextSibling)
  227. if(wk == dp)
  228. break;
  229. if(!wk)
  230. Platform::debugBreak();
  231. for(wk = dp->mParent->mChildHash[walk->mNameHash & (ProfilerData::HashTableSize - 1)] ;
  232. wk; wk = wk->mNextHash)
  233. if(wk == dp)
  234. break;
  235. if(!wk)
  236. Platform::debugBreak();
  237. }
  238. }
  239. }
  240. void Profiler::hashPush(ProfilerRootData *root)
  241. {
  242. #ifdef TORQUE_MULTITHREAD
  243. // Ignore non-main-thread profiler activity.
  244. if(! ThreadManager::isCurrentThread(gMainThread) )
  245. return;
  246. #endif
  247. mStackDepth++;
  248. AssertFatal(mStackDepth <= (S32)mMaxStackDepth,
  249. "Stack overflow in profiler. You may have mismatched PROFILE_START and PROFILE_ENDs");
  250. if(!mEnabled)
  251. return;
  252. ProfilerData *nextProfiler = NULL;
  253. if(!root->mEnabled || mCurrentProfilerData->mRoot == root)
  254. {
  255. mCurrentProfilerData->mSubDepth++;
  256. return;
  257. }
  258. if(mCurrentProfilerData->mLastSeenProfiler &&
  259. mCurrentProfilerData->mLastSeenProfiler->mRoot == root)
  260. nextProfiler = mCurrentProfilerData->mLastSeenProfiler;
  261. if(!nextProfiler)
  262. {
  263. // first see if it's in the hash table...
  264. U32 index = root->mNameHash & (ProfilerData::HashTableSize - 1);
  265. nextProfiler = mCurrentProfilerData->mChildHash[index];
  266. while(nextProfiler)
  267. {
  268. if(nextProfiler->mRoot == root)
  269. break;
  270. nextProfiler = nextProfiler->mNextHash;
  271. }
  272. if(!nextProfiler)
  273. {
  274. nextProfiler = (ProfilerData *) malloc(sizeof(ProfilerData));
  275. for(U32 i = 0; i < ProfilerData::HashTableSize; i++)
  276. nextProfiler->mChildHash[i] = 0;
  277. nextProfiler->mRoot = root;
  278. nextProfiler->mNextForRoot = root->mFirstProfilerData;
  279. root->mFirstProfilerData = nextProfiler;
  280. nextProfiler->mNextProfilerData = mProfileList;
  281. mProfileList = nextProfiler;
  282. nextProfiler->mNextHash = mCurrentProfilerData->mChildHash[index];
  283. mCurrentProfilerData->mChildHash[index] = nextProfiler;
  284. nextProfiler->mParent = mCurrentProfilerData;
  285. nextProfiler->mNextSibling = mCurrentProfilerData->mFirstChild;
  286. mCurrentProfilerData->mFirstChild = nextProfiler;
  287. nextProfiler->mFirstChild = NULL;
  288. nextProfiler->mLastSeenProfiler = NULL;
  289. nextProfiler->mHash = root->mNameHash;
  290. nextProfiler->mInvokeCount = 0;
  291. nextProfiler->mTotalTime = 0;
  292. nextProfiler->mSubTime = 0;
  293. nextProfiler->mSubDepth = 0;
  294. }
  295. }
  296. root->mTotalInvokeCount++;
  297. nextProfiler->mInvokeCount++;
  298. startHighResolutionTimer(nextProfiler->mStartTime);
  299. mCurrentProfilerData->mLastSeenProfiler = nextProfiler;
  300. mCurrentProfilerData = nextProfiler;
  301. }
  302. void Profiler::enable(bool enabled)
  303. {
  304. mNextEnable = enabled;
  305. if ( enabled )
  306. Con::printf( "Profiler is on." );
  307. else
  308. Con::printf("Profiler is off." );
  309. }
  310. void Profiler::dumpToConsole()
  311. {
  312. mDumpToConsole = true;
  313. mDumpToFile = false;
  314. mDumpFileName[0] = '\0';
  315. }
  316. void Profiler::dumpToFile(const char* fileName)
  317. {
  318. AssertFatal(dStrlen(fileName) < DumpFileNameLength, "Error, dump filename too long");
  319. mDumpToFile = true;
  320. mDumpToConsole = false;
  321. dStrcpy(mDumpFileName, fileName);
  322. }
  323. void Profiler::hashPop()
  324. {
  325. #ifdef TORQUE_MULTITHREAD
  326. // Ignore non-main-thread profiler activity.
  327. if(! ThreadManager::isCurrentThread(gMainThread) )
  328. return;
  329. #endif
  330. mStackDepth--;
  331. AssertFatal(mStackDepth >= 0, "Stack underflow in profiler. You may have mismatched PROFILE_START and PROFILE_ENDs");
  332. if(mEnabled)
  333. {
  334. if(mCurrentProfilerData->mSubDepth)
  335. {
  336. mCurrentProfilerData->mSubDepth--;
  337. return;
  338. }
  339. F64 fElapsed = endHighResolutionTimer(mCurrentProfilerData->mStartTime);
  340. mCurrentProfilerData->mTotalTime += fElapsed;
  341. mCurrentProfilerData->mParent->mSubTime += fElapsed; // mark it in the parent as well...
  342. mCurrentProfilerData->mRoot->mTotalTime += fElapsed;
  343. if(mCurrentProfilerData->mParent->mRoot)
  344. mCurrentProfilerData->mParent->mRoot->mSubTime += fElapsed; // mark it in the parent as well...
  345. mCurrentProfilerData = mCurrentProfilerData->mParent;
  346. }
  347. if(mStackDepth == 0)
  348. {
  349. // apply the next enable...
  350. if(mDumpToConsole || mDumpToFile)
  351. {
  352. dump();
  353. startHighResolutionTimer(mCurrentProfilerData->mStartTime);
  354. }
  355. if(!mEnabled && mNextEnable)
  356. startHighResolutionTimer(mCurrentProfilerData->mStartTime);
  357. mEnabled = mNextEnable;
  358. }
  359. }
  360. static S32 QSORT_CALLBACK rootDataCompare(const void *s1, const void *s2)
  361. {
  362. const ProfilerRootData *r1 = *((ProfilerRootData **) s1);
  363. const ProfilerRootData *r2 = *((ProfilerRootData **) s2);
  364. return (S32)((r2->mTotalTime - r2->mSubTime) - (r1->mTotalTime - r1->mSubTime));
  365. }
  366. static void profilerDataDumpRecurse(ProfilerData *data, char *buffer, U32 bufferLen, F64 totalTime)
  367. {
  368. // dump out this one:
  369. Con::printf("%7.3f %7.3f %8d %s%s",
  370. 100 * data->mTotalTime / totalTime,
  371. 100 * (data->mTotalTime - data->mSubTime) / totalTime,
  372. data->mInvokeCount,
  373. buffer,
  374. data->mRoot ? data->mRoot->mName : "ROOT" );
  375. data->mTotalTime = 0;
  376. data->mSubTime = 0;
  377. data->mInvokeCount = 0;
  378. buffer[bufferLen] = ' ';
  379. buffer[bufferLen+1] = ' ';
  380. buffer[bufferLen+2] = 0;
  381. // sort data's children...
  382. ProfilerData *list = NULL;
  383. while(data->mFirstChild)
  384. {
  385. ProfilerData *ins = data->mFirstChild;
  386. data->mFirstChild = ins->mNextSibling;
  387. ProfilerData **walk = &list;
  388. while(*walk && (*walk)->mTotalTime > ins->mTotalTime)
  389. walk = &(*walk)->mNextSibling;
  390. ins->mNextSibling = *walk;
  391. *walk = ins;
  392. }
  393. data->mFirstChild = list;
  394. while(list)
  395. {
  396. if(list->mInvokeCount)
  397. profilerDataDumpRecurse(list, buffer, bufferLen + 2, totalTime);
  398. list = list->mNextSibling;
  399. }
  400. buffer[bufferLen] = 0;
  401. }
  402. static void profilerDataDumpRecurseFile(ProfilerData *data, char *buffer, U32 bufferLen, F64 totalTime, FileStream& fws)
  403. {
  404. char pbuffer[256];
  405. dSprintf(pbuffer, 255, "%7.3f %7.3f %8d %s%s\n",
  406. 100 * data->mTotalTime / totalTime,
  407. 100 * (data->mTotalTime - data->mSubTime) / totalTime,
  408. data->mInvokeCount,
  409. buffer,
  410. data->mRoot ? data->mRoot->mName : "ROOT" );
  411. fws.write(dStrlen(pbuffer), pbuffer);
  412. data->mTotalTime = 0;
  413. data->mSubTime = 0;
  414. data->mInvokeCount = 0;
  415. buffer[bufferLen] = ' ';
  416. buffer[bufferLen+1] = ' ';
  417. buffer[bufferLen+2] = 0;
  418. // sort data's children...
  419. ProfilerData *list = NULL;
  420. while(data->mFirstChild)
  421. {
  422. ProfilerData *ins = data->mFirstChild;
  423. data->mFirstChild = ins->mNextSibling;
  424. ProfilerData **walk = &list;
  425. while(*walk && (*walk)->mTotalTime > ins->mTotalTime)
  426. walk = &(*walk)->mNextSibling;
  427. ins->mNextSibling = *walk;
  428. *walk = ins;
  429. }
  430. data->mFirstChild = list;
  431. while(list)
  432. {
  433. if(list->mInvokeCount)
  434. profilerDataDumpRecurseFile(list, buffer, bufferLen + 2, totalTime, fws);
  435. list = list->mNextSibling;
  436. }
  437. buffer[bufferLen] = 0;
  438. }
  439. void Profiler::dump()
  440. {
  441. bool enableSave = mEnabled;
  442. mEnabled = false;
  443. mStackDepth++;
  444. // may have some profiled calls... gotta turn em off.
  445. Vector<ProfilerRootData *> rootVector;
  446. F64 totalTime = 0;
  447. for(ProfilerRootData *walk = ProfilerRootData::sRootList; walk; walk = walk->mNextRoot)
  448. {
  449. totalTime += walk->mTotalTime - walk->mSubTime;
  450. rootVector.push_back(walk);
  451. }
  452. //-Mat no sort, makes it easier to compare
  453. dQsort((void *)rootVector.address(), rootVector.size(), sizeof(ProfilerRootData *), rootDataCompare);
  454. if (mDumpToConsole == true)
  455. {
  456. Con::printf("Profiler Data Dump:");
  457. Con::printf("Ordered by non-sub total time -");
  458. Con::printf("%%NSTime %% Time Invoke # Name");
  459. for(U32 i = 0; i < (U32)rootVector.size(); i++)
  460. {
  461. Con::printf("%7.3f %7.3f %8d %s",
  462. 100 * (rootVector[i]->mTotalTime - rootVector[i]->mSubTime) / totalTime,
  463. 100 * rootVector[i]->mTotalTime / totalTime,
  464. rootVector[i]->mTotalInvokeCount,
  465. rootVector[i]->mName);
  466. rootVector[i]->mTotalInvokeCount = 0;
  467. rootVector[i]->mTotalTime = 0;
  468. rootVector[i]->mSubTime = 0;
  469. }
  470. Con::printf("");
  471. Con::printf("Ordered by stack trace total time -");
  472. Con::printf("%% Time %% NSTime Invoke # Name");
  473. mCurrentProfilerData->mTotalTime = endHighResolutionTimer(mCurrentProfilerData->mStartTime);
  474. char depthBuffer[MaxStackDepth * 2 + 1];
  475. depthBuffer[0] = 0;
  476. profilerDataDumpRecurse(mCurrentProfilerData, depthBuffer, 0, totalTime);
  477. mEnabled = enableSave;
  478. mStackDepth--;
  479. }
  480. else if (mDumpToFile == true && mDumpFileName[0] != '\0')
  481. {
  482. FileStream fws;
  483. bool success = fws.open(mDumpFileName, FileStream::Write);
  484. AssertFatal(success, "Nuts! Cannot write profile dump to specified file!");
  485. char buffer[1024];
  486. dStrcpy(buffer, "Profiler Data Dump:\n");
  487. fws.write(dStrlen(buffer), buffer);
  488. dStrcpy(buffer, "Ordered by non-sub total time -\n");
  489. fws.write(dStrlen(buffer), buffer);
  490. dStrcpy(buffer, "%%NSTime %% Time Invoke # Name\n");
  491. fws.write(dStrlen(buffer), buffer);
  492. for(U32 i = 0; i < (U32)rootVector.size(); i++)
  493. {
  494. dSprintf(buffer, 1023, "%7.3f %7.3f %8d %s\n",
  495. 100 * (rootVector[i]->mTotalTime - rootVector[i]->mSubTime) / totalTime,
  496. 100 * rootVector[i]->mTotalTime / totalTime,
  497. rootVector[i]->mTotalInvokeCount,
  498. rootVector[i]->mName);
  499. fws.write(dStrlen(buffer), buffer);
  500. rootVector[i]->mTotalInvokeCount = 0;
  501. rootVector[i]->mTotalTime = 0;
  502. rootVector[i]->mSubTime = 0;
  503. }
  504. dStrcpy(buffer, "\nOrdered by non-sub total time -\n");
  505. fws.write(dStrlen(buffer), buffer);
  506. dStrcpy(buffer, "%%NSTime %% Time Invoke # Name\n");
  507. fws.write(dStrlen(buffer), buffer);
  508. mCurrentProfilerData->mTotalTime = endHighResolutionTimer(mCurrentProfilerData->mStartTime);
  509. char depthBuffer[MaxStackDepth * 2 + 1];
  510. depthBuffer[0] = 0;
  511. profilerDataDumpRecurseFile(mCurrentProfilerData, depthBuffer, 0, totalTime, fws);
  512. mEnabled = enableSave;
  513. mStackDepth--;
  514. fws.close();
  515. }
  516. mDumpToConsole = false;
  517. mDumpToFile = false;
  518. mDumpFileName[0] = '\0';
  519. }
  520. void Profiler::enableMarker(const char *marker, bool enable)
  521. {
  522. reset();
  523. U32 markerLen = dStrlen(marker);
  524. if(markerLen == 0)
  525. return;
  526. bool sn = marker[markerLen - 1] == '*';
  527. for(ProfilerRootData *data = ProfilerRootData::sRootList; data; data = data->mNextRoot)
  528. {
  529. if(sn)
  530. {
  531. if(!dStrncmp(marker, data->mName, markerLen - 1))
  532. data->mEnabled = enable;
  533. }
  534. else
  535. {
  536. if(!dStrcmp(marker, data->mName))
  537. data->mEnabled = enable;
  538. }
  539. }
  540. }
  541. #endif