enprofilertests.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793
  1. class EnProfilerTests : TestFramework
  2. {
  3. //! Remember this, so we can restore the previous state before the test!
  4. bool m_bWasProfilerEnabled;
  5. //---------------------------------------------------------------------------
  6. // Ctor - Decides the tests to run
  7. //---------------------------------------------------------------------------
  8. void EnProfilerTests()
  9. {
  10. m_bWasProfilerEnabled = EnProfiler.IsEnabledC();
  11. AddInitTest("TestToggling");
  12. AddInitTest("TestTogglingImmediate");
  13. AddInitTest("TestSetFlags");
  14. AddInitTest("TestClearFlags");
  15. AddInitTest("TestAddFlags");
  16. AddInitTest("TestModule");
  17. AddInitTest("TestClassTimeData");
  18. AddInitTest("TestClassCountData");
  19. AddInitTest("TestFuncTimeData");
  20. AddInitTest("TestFuncCountData");
  21. }
  22. //---------------------------------------------------------------------------
  23. // Dtor
  24. //---------------------------------------------------------------------------
  25. void ~EnProfilerTests()
  26. {
  27. EnProfiler.Enable(m_bWasProfilerEnabled, true);
  28. }
  29. //---------------------------------------------------------------------------
  30. // Tests
  31. //---------------------------------------------------------------------------
  32. // Test toggling state
  33. TFResult TestToggling()
  34. {
  35. bool currentlyEnabled = EnProfiler.IsEnabledP();
  36. EnProfiler.Enable(!currentlyEnabled);
  37. if (Assert(currentlyEnabled != EnProfiler.IsEnabledP()))
  38. {
  39. EnProfiler.Enable(currentlyEnabled);
  40. return BTFR(Assert(currentlyEnabled == EnProfiler.IsEnabledP()));
  41. }
  42. return NTFR(TFR.FAIL);
  43. }
  44. //---------------------------------------------------------------------------
  45. // Test toggling immediate state
  46. TFResult TestTogglingImmediate()
  47. {
  48. bool currentlyEnabled = EnProfiler.IsEnabledC();
  49. EnProfiler.Enable(!currentlyEnabled, true);
  50. if (Assert(currentlyEnabled != EnProfiler.IsEnabledC()))
  51. {
  52. EnProfiler.Enable(currentlyEnabled, true);
  53. return BTFR(Assert(currentlyEnabled == EnProfiler.IsEnabledC()));
  54. }
  55. return NTFR(TFR.FAIL);
  56. }
  57. //---------------------------------------------------------------------------
  58. // Test SetFlags/GetFlags
  59. TFResult TestSetFlags()
  60. {
  61. int currentFlags = EnProfiler.GetFlags();
  62. for (int i = 0; i < EnumTools.GetEnumSize(EnProfilerFlags); ++i)
  63. {
  64. int flags = EnumTools.GetEnumValue(EnProfilerFlags, i);
  65. EnProfiler.SetFlags(flags);
  66. if (!Assert(EnProfiler.GetFlags() == flags))
  67. {
  68. EnProfiler.SetFlags(currentFlags);
  69. return NTFR(TFR.FAIL);
  70. }
  71. for (int j = 0; j < EnumTools.GetEnumSize(EnProfilerFlags); ++j)
  72. {
  73. flags |= EnumTools.GetEnumValue(EnProfilerFlags, j);
  74. EnProfiler.SetFlags(flags);
  75. if (!Assert(EnProfiler.GetFlags() == flags))
  76. {
  77. EnProfiler.SetFlags(currentFlags);
  78. return NTFR(TFR.FAIL);
  79. }
  80. }
  81. }
  82. // Let's test some bogus
  83. EnProfiler.SetFlags(-333);
  84. int bogusFlags = EnProfiler.GetFlags();
  85. bogusFlags &= ~EnProfilerFlags.ALL;
  86. if (!Assert(bogusFlags == 0))
  87. {
  88. EnProfiler.SetFlags(currentFlags);
  89. return NTFR(TFR.FAIL);
  90. }
  91. bogusFlags = EnProfiler.SetFlags(6003);
  92. bogusFlags &= ~EnProfilerFlags.ALL;
  93. if (!Assert(bogusFlags == 0))
  94. {
  95. EnProfiler.SetFlags(currentFlags);
  96. return NTFR(TFR.FAIL);
  97. }
  98. // Reset
  99. EnProfiler.SetFlags(currentFlags);
  100. return NTFR(TFR.SUCCESS);
  101. }
  102. //---------------------------------------------------------------------------
  103. // Test removing of flags
  104. TFResult TestClearFlags()
  105. {
  106. int currentFlags = EnProfiler.GetFlags();
  107. EnProfiler.SetFlags(EnProfilerFlags.RECURSIVE);
  108. if (!Assert(EnProfiler.RemoveFlags(EnProfilerFlags.RECURSIVE) == EnProfilerFlags.NONE))
  109. {
  110. EnProfiler.SetFlags(currentFlags);
  111. return NTFR(TFR.FAIL);
  112. }
  113. EnProfiler.SetFlags(EnProfilerFlags.RECURSIVE | EnProfilerFlags.RESET);
  114. EnProfiler.RemoveFlags(EnProfilerFlags.RECURSIVE | EnProfilerFlags.RESET);
  115. if (!Assert(EnProfiler.GetFlags() == EnProfilerFlags.NONE))
  116. {
  117. EnProfiler.SetFlags(currentFlags);
  118. return NTFR(TFR.FAIL);
  119. }
  120. EnProfiler.SetFlags(EnProfilerFlags.RECURSIVE | EnProfilerFlags.RESET);
  121. EnProfiler.ClearFlags();
  122. if (!Assert(EnProfiler.GetFlags() == EnProfilerFlags.NONE))
  123. {
  124. EnProfiler.SetFlags(currentFlags);
  125. return NTFR(TFR.FAIL);
  126. }
  127. // Reset
  128. EnProfiler.SetFlags(currentFlags);
  129. return NTFR(TFR.SUCCESS);
  130. }
  131. //---------------------------------------------------------------------------
  132. // Test adding of flags
  133. TFResult TestAddFlags()
  134. {
  135. int currentFlags = EnProfiler.GetFlags();
  136. EnProfiler.ClearFlags();
  137. // Return should match resulting flags
  138. if (!Assert(EnProfiler.AddFlags(EnProfilerFlags.RESET) == EnProfiler.GetFlags()))
  139. {
  140. EnProfiler.SetFlags(currentFlags);
  141. return NTFR(TFR.FAIL);
  142. }
  143. if (!Assert(EnProfiler.GetFlags() == EnProfilerFlags.RESET))
  144. {
  145. EnProfiler.SetFlags(currentFlags);
  146. return NTFR(TFR.FAIL);
  147. }
  148. if (!Assert(EnProfiler.AddFlags(EnProfilerFlags.RECURSIVE) == (EnProfilerFlags.RESET | EnProfilerFlags.RECURSIVE)))
  149. {
  150. EnProfiler.SetFlags(currentFlags);
  151. return NTFR(TFR.FAIL);
  152. }
  153. // Reset
  154. EnProfiler.SetFlags(currentFlags);
  155. return NTFR(TFR.SUCCESS);
  156. }
  157. //---------------------------------------------------------------------------
  158. // Test module
  159. TFResult TestModule()
  160. {
  161. // File lives in Game, use it while testing
  162. const EnProfilerModule eptModule = EnProfilerModule.GAME;
  163. // This was added at the same time as this API, so check if it works as well
  164. string nameOfCurrentModule = Type().GetModule();
  165. if (!Assert(nameOfCurrentModule != ""))
  166. {
  167. return NTFR(TFR.FAIL);
  168. }
  169. // We know we are in Game, so use it as a test
  170. EnProfilerModule currentModule;
  171. if (!Assert(EnProfiler.NameToModule(nameOfCurrentModule, currentModule)))
  172. {
  173. return NTFR(TFR.FAIL);
  174. }
  175. if (!Assert(currentModule == eptModule))
  176. {
  177. return NTFR(TFR.FAIL);
  178. }
  179. // Test if setting and getting works
  180. EnProfilerModule currentlyProfiledModule = EnProfiler.GetModule();
  181. EnProfiler.SetModule(eptModule);
  182. if (!Assert(EnProfiler.GetModule() == eptModule))
  183. {
  184. EnProfiler.SetModule(currentlyProfiledModule);
  185. return NTFR(TFR.FAIL);
  186. }
  187. // Data to restore
  188. int currentFlags = EnProfiler.GetFlags();
  189. bool wasEnabled = EnProfiler.RequestImmediateData();
  190. // Make sure we are only profiling Game and that the data is clean
  191. // Only valid for the Get...Per... methods, as they need to be sorted
  192. EnProfiler.RemoveFlags(EnProfilerFlags.RECURSIVE);
  193. // GetTickTime() returns in seconds, so gather the results in seconds too
  194. int resolution = EnProfiler.GetTimeResolution();
  195. EnProfiler.SetTimeResolution(1);
  196. // Time to sleeb
  197. float previousTime = EnProfiler.GetTimeOfFunc("Sleep", Type(), true);
  198. float timeSlept = Sleep(0.3);
  199. float postTime = EnProfiler.GetTimeOfFunc("Sleep", Type(), true);
  200. float diff = postTime - previousTime - timeSlept;
  201. // Restore
  202. EnProfiler.SetTimeResolution(resolution);
  203. // We called the function, so it must have some time
  204. if (!Assert(postTime > 0))
  205. {
  206. EnProfiler.SetFlags(currentFlags);
  207. if (!wasEnabled)
  208. EnProfiler.Enable(false, true);
  209. EnProfiler.SetModule(currentlyProfiledModule);
  210. return NTFR(TFR.FAIL);
  211. }
  212. if (!Assert(diff < 0.00001))
  213. {
  214. EnProfiler.SetFlags(currentFlags);
  215. if (!wasEnabled)
  216. EnProfiler.Enable(false, true);
  217. EnProfiler.SetModule(currentlyProfiledModule);
  218. return NTFR(TFR.FAIL);
  219. }
  220. // Clean the session
  221. EnProfiler.ResetSession(true);
  222. // Something from a different module should not get sorted, so just fire something from a different module
  223. for (int i = 0; i < 1000; ++i)
  224. {
  225. EnumTools.StringToEnum(EnProfilerModule, "MISSION_CUSTOM");
  226. }
  227. // Sort and gather the data and validate if it is correct
  228. EnProfiler.SortData();
  229. array<ref EnProfilerTimeFuncPair> timePerFunc = {};
  230. EnProfiler.GetTimePerFunc(timePerFunc);
  231. Debug.TFLog("Game fncs:", this, "TestModule");
  232. int funcCount = timePerFunc.Count();
  233. for (int j = 0; j < funcCount; ++j)
  234. {
  235. EnProfilerTimeFuncPair tfp = timePerFunc[j];
  236. Debug.TFLog(string.Format(" time: %1 | fnc: %2", tfp.param1, tfp.param2), this, "TestModule");
  237. // We are currently profiling Game, so this Core function shouldn't be present
  238. if (!Assert(tfp.param2 != "EnumTools::StringToEnum"))
  239. {
  240. EnProfiler.SetFlags(currentFlags);
  241. if (!wasEnabled)
  242. EnProfiler.Enable(false, true);
  243. EnProfiler.SetModule(currentlyProfiledModule);
  244. return NTFR(TFR.FAIL);
  245. }
  246. }
  247. array<ref EnProfilerTimeClassPair> timePerClass = {};
  248. EnProfiler.GetTimePerClass(timePerClass);
  249. int classCount = timePerClass.Count();
  250. for (int k = 0; k < classCount; ++k)
  251. {
  252. typename type = timePerClass[k].param2;
  253. EnProfilerModule classModule;
  254. if (!Assert(EnProfiler.NameToModule(type.GetModule(), classModule)))
  255. {
  256. EnProfiler.SetFlags(currentFlags);
  257. if (!wasEnabled)
  258. EnProfiler.Enable(false, true);
  259. EnProfiler.SetModule(currentlyProfiledModule);
  260. return NTFR(TFR.FAIL);
  261. }
  262. // Only classes from Game should be present
  263. if (!Assert(classModule == eptModule))
  264. {
  265. EnProfiler.SetFlags(currentFlags);
  266. if (!wasEnabled)
  267. EnProfiler.Enable(false, true);
  268. EnProfiler.SetModule(currentlyProfiledModule);
  269. return NTFR(TFR.FAIL);
  270. }
  271. }
  272. // Now let's check if we can gather the data of what we called earlier by switching the profiled module without resetting the session
  273. EnProfiler.SetModule(EnProfilerModule.CORE, false);
  274. EnProfiler.SortData();
  275. timePerFunc.Clear(); // Let's reuse the array, but the Get...Per... methods only appends to the array, clearing is our responsibility
  276. EnProfiler.GetTimePerFunc(timePerFunc);
  277. bool found = false;
  278. Debug.TFLog("Core fncs:", this, "TestModule");
  279. funcCount = timePerFunc.Count();
  280. for (int l = 0; l < funcCount; ++l)
  281. {
  282. EnProfilerTimeFuncPair tfpc = timePerFunc[l];
  283. Debug.TFLog(string.Format(" time: %1 | fnc: %2", tfpc.param1, tfpc.param2), this, "TestModule");
  284. // We are currently profiling Core, so this Core function should be present
  285. if (tfpc.param2 == "EnumTools::StringToEnum")
  286. {
  287. found = true;
  288. break;
  289. }
  290. }
  291. Assert(found);
  292. // Test some bogus
  293. EnProfilerModule mod = EnProfiler.GetModule();
  294. EnProfiler.SetModule(-333);
  295. bool success = Assert(EnProfiler.GetModule() == mod);
  296. EnProfiler.SetModule(6003);
  297. success &= Assert(EnProfiler.GetModule() == mod);
  298. EnProfiler.SetFlags(currentFlags);
  299. EnProfiler.SetModule(currentlyProfiledModule);
  300. if (!wasEnabled)
  301. EnProfiler.Enable(false, true);
  302. return BTFR(success && found);
  303. }
  304. //---------------------------------------------------------------------------
  305. // Test to see if class time data is correct
  306. TFResult TestClassTimeData()
  307. {
  308. // We should restore this when done
  309. int resolution = EnProfiler.GetTimeResolution();
  310. bool wasEnabled = EnProfiler.RequestImmediateData();
  311. // GetTickTime() returns in seconds, so gather the results in seconds too
  312. EnProfiler.SetTimeResolution(1);
  313. // Create the classes
  314. EPTHelperClass clss = new EPTHelperClass();
  315. // Time to stress
  316. float previousTime = EnProfiler.GetTimeOfClass(clss.Type(), true);
  317. float timeStressed = clss.DoEverything();
  318. float postTime = EnProfiler.GetTimeOfClass(clss.Type(), true);
  319. float postTimeStatic = EnProfiler.GetTimeOfClass(StaticGetType(EPTHelperClass), true);
  320. float timeProfiled = postTime - previousTime;
  321. float diff = Math.AbsFloat(timeProfiled - timeStressed);
  322. Debug.TFLog(string.Format("Profiling result: stressed: %1 | profiled: %2 | diff: %3", timeStressed, timeProfiled, diff), this, "TestClassTimeData");
  323. // Restore
  324. EnProfiler.SetTimeResolution(resolution);
  325. if (!wasEnabled)
  326. EnProfiler.Enable(false, true);
  327. // We called the function, so it must have some time
  328. if (!Assert(postTime > 0))
  329. {
  330. return NTFR(TFR.FAIL);
  331. }
  332. if (!Assert(postTime == postTimeStatic))
  333. {
  334. return NTFR(TFR.FAIL);
  335. }
  336. if (!Assert(diff < 0.001))
  337. {
  338. return NTFR(TFR.FAIL);
  339. }
  340. return NTFR(TFR.SUCCESS);
  341. }
  342. //---------------------------------------------------------------------------
  343. // Test to see if class count data is correct
  344. TFResult TestClassCountData()
  345. {
  346. const int allocAmount = 9;
  347. const int releaseAmount = 6;
  348. int remainingAmount = allocAmount - releaseAmount;
  349. // We should restore this when done
  350. bool wasEnabled = EnProfiler.RequestImmediateData();
  351. // Time to test
  352. int previousAlloc = EnProfiler.GetAllocationsOfClass(StaticGetType(EPTHelperClass), true);
  353. int previousInstances = EnProfiler.GetInstancesOfClass(StaticGetType(EPTHelperClass), true);
  354. array<ref EPTHelperClass> instanceArr = {};
  355. for (int i = 0; i < allocAmount; ++i)
  356. {
  357. instanceArr.Insert(new EPTHelperClass());
  358. }
  359. for (int j = 0; j < releaseAmount; ++j)
  360. {
  361. delete instanceArr[j];
  362. }
  363. int postAlloc = EnProfiler.GetAllocationsOfClass(StaticGetType(EPTHelperClass), true);
  364. int postInstances = EnProfiler.GetInstancesOfClass(StaticGetType(EPTHelperClass), true);
  365. int alloced = postAlloc - previousAlloc;
  366. int instances = postInstances - previousInstances;
  367. Debug.TFLog(string.Format("Profiling result: alloc: %1 | instances: %2", alloced, instances), this, "TestClassCountData");
  368. // Restore
  369. if (!wasEnabled)
  370. EnProfiler.Enable(false, true);
  371. // Time to check
  372. if (!Assert(alloced == allocAmount))
  373. {
  374. return NTFR(TFR.FAIL);
  375. }
  376. if (!Assert(instances == remainingAmount))
  377. {
  378. return NTFR(TFR.FAIL);
  379. }
  380. return NTFR(TFR.SUCCESS);
  381. }
  382. //---------------------------------------------------------------------------
  383. // Test to see if func time data is correct
  384. TFResult TestFuncTimeData()
  385. {
  386. // We should restore this when done
  387. int resolution = EnProfiler.GetTimeResolution();
  388. bool wasEnabled = EnProfiler.RequestImmediateData();
  389. // GetTickTime() returns in seconds, so gather the results in seconds too
  390. EnProfiler.SetTimeResolution(1);
  391. // Time to stress
  392. float previousTime = EnProfiler.GetTimeOfFunc("StringFormat", Type(), true);
  393. float timeStressed = StringFormat();
  394. float postTime = EnProfiler.GetTimeOfFunc("StringFormat", Type(), true);
  395. float timeProfiled = postTime - previousTime;
  396. float diff = Math.AbsFloat(timeProfiled - timeStressed);
  397. float previousTime2 = EnProfiler.GetTimeOfFunc("StringConcat", Type(), true);
  398. float timeStressed2 = StringConcat();
  399. float postTime2 = EnProfiler.GetTimeOfFunc("StringConcat", Type(), true);
  400. float timeProfiled2 = postTime2 - previousTime2;
  401. float diff2 = Math.AbsFloat(timeProfiled2 - timeStressed2);
  402. Debug.TFLog(string.Format("Profiling result: StringFormat: %1 | StringConcat: %2", timeProfiled, timeProfiled2), this, "TestFuncTimeData");
  403. // Restore
  404. EnProfiler.SetTimeResolution(resolution);
  405. if (!wasEnabled)
  406. {
  407. EnProfiler.Enable(false, true);
  408. }
  409. // We called the function, so it must have some time
  410. if (!Assert(postTime > 0))
  411. {
  412. return NTFR(TFR.FAIL);
  413. }
  414. if (!Assert(diff < 0.001))
  415. {
  416. return NTFR(TFR.FAIL);
  417. }
  418. if (!Assert(postTime2 > 0))
  419. {
  420. return NTFR(TFR.FAIL);
  421. }
  422. if (!Assert(diff2 < 0.001))
  423. {
  424. return NTFR(TFR.FAIL);
  425. }
  426. // I know that string.Format is faster than additive concatenation
  427. if (!Assert(timeProfiled < timeProfiled2))
  428. {
  429. return NTFR(TFR.FAIL);
  430. }
  431. return NTFR(TFR.SUCCESS);
  432. }
  433. //---------------------------------------------------------------------------
  434. // Test to see if func count data is correct
  435. TFResult TestFuncCountData()
  436. {
  437. // We should restore this when done
  438. bool wasEnabled = EnProfiler.RequestImmediateData();
  439. // Time to count
  440. // - CallFunction
  441. int previousCountCF = EnProfiler.GetCountOfFunc("TestFuncCountDataHelper", Type(), true);
  442. GetGame().GameScript.CallFunction(this, "TestFuncCountDataHelper", null, 0);
  443. int postCountCF = EnProfiler.GetCountOfFunc("TestFuncCountDataHelper", Type(), true);
  444. int callCountCF = postCountCF - previousCountCF;
  445. // - CallFunctionParams
  446. int previousCountCFP = EnProfiler.GetCountOfFunc("TestFuncCountDataHelper", Type(), true);
  447. GetGame().GameScript.CallFunctionParams(this, "TestFuncCountDataHelper", null, null);
  448. int postCountCFP = EnProfiler.GetCountOfFunc("TestFuncCountDataHelper", Type(), true);
  449. int callCountCFP = postCountCFP - previousCountCFP;
  450. // - Regular call
  451. int previousCountRG = EnProfiler.GetCountOfFunc("TestFuncCountDataHelper", Type(), true);
  452. TestFuncCountDataHelper();
  453. int postCountRG = EnProfiler.GetCountOfFunc("TestFuncCountDataHelper", Type(), true);
  454. int callCountRG = postCountRG - previousCountRG;
  455. // - Call
  456. int previousCountC = EnProfiler.GetCountOfFunc("TestFuncCountDataHelper", Type(), true);
  457. GetGame().GameScript.Call(this, "TestFuncCountDataHelper", 0);
  458. int postCountC = EnProfiler.GetCountOfFunc("TestFuncCountDataHelper", Type(), true);
  459. int callCountC = postCountC - previousCountC;
  460. // - Garbage
  461. int callCountNon = EnProfiler.GetCountOfFunc("Non Existing Method", Type(), true);
  462. // - Static
  463. int previousCountS = EnProfiler.GetCountOfFunc("TestFuncCountDataHelperStatic", Type(), true);
  464. TestFuncCountDataHelperStatic();
  465. int postCountS = EnProfiler.GetCountOfFunc("TestFuncCountDataHelperStatic", Type(), true);
  466. int callCountS = postCountS - previousCountS;
  467. // - Global
  468. int previousCountG = EnProfiler.GetCountOfFuncG("GetDayZGame", true);
  469. GetDayZGame();
  470. int postCountG = EnProfiler.GetCountOfFuncG("GetDayZGame", true);
  471. int callCountG = postCountG - previousCountG;
  472. // - Global proto
  473. // Not tracked, so don't need to compare before and after, should always be 0
  474. ErrorEx("Testing global proto call", ErrorExSeverity.INFO);
  475. int callCountGP = EnProfiler.GetCountOfFuncG("ErrorEx", true);
  476. // - Static proto
  477. // Not tracked, so don't need to compare before and after, should always be 0
  478. int callCountSP = EnProfiler.GetCountOfFunc("GetCountOfFunc", StaticGetType(EnProfiler), true);
  479. // - proto
  480. // Not tracked, so don't need to compare before and after, should always be 0
  481. GetGame().GetHostName();
  482. int callCountP = EnProfiler.GetCountOfFunc("GetHostName", GetGame().Type(), true);
  483. // - proto native
  484. // Not tracked, so don't need to compare before and after, should always be 0
  485. GetGame().IsServer();
  486. int callCountPN = EnProfiler.GetCountOfFunc("IsServer", GetGame().Type(), true);
  487. // - static proto native
  488. // Not tracked, so don't need to compare before and after, should always be 0
  489. ErrorModuleHandler.GetInstance();
  490. int callCountSPN = EnProfiler.GetCountOfFunc("GetInstance", StaticGetType(ErrorModuleHandler), true);
  491. // Restore
  492. if (!wasEnabled)
  493. {
  494. EnProfiler.Enable(false, true);
  495. }
  496. // Do the checks
  497. // - CallFunction
  498. if (!Assert(callCountCF == 1))
  499. {
  500. return NTFR(TFR.FAIL);
  501. }
  502. // - CallFunctionParams
  503. if (!Assert(callCountCFP == 1))
  504. {
  505. return NTFR(TFR.FAIL);
  506. }
  507. // - Regular call
  508. if (!Assert(callCountRG == 1))
  509. {
  510. return NTFR(TFR.FAIL);
  511. }
  512. // - Call
  513. if (!Assert(callCountC == 1))
  514. {
  515. return NTFR(TFR.FAIL);
  516. }
  517. // - Garbage
  518. if (!Assert(callCountNon == -1))
  519. {
  520. return NTFR(TFR.FAIL);
  521. }
  522. // - Static
  523. if (!Assert(callCountS == 1))
  524. {
  525. return NTFR(TFR.FAIL);
  526. }
  527. // - Global
  528. if (!Assert(callCountG == 1))
  529. {
  530. return NTFR(TFR.FAIL);
  531. }
  532. // - Global proto
  533. if (!Assert(callCountGP == 0))
  534. {
  535. return NTFR(TFR.FAIL);
  536. }
  537. // - Static proto
  538. if (!Assert(callCountSP == 0))
  539. {
  540. return NTFR(TFR.FAIL);
  541. }
  542. // - proto
  543. if (!Assert(callCountP == 0))
  544. {
  545. return NTFR(TFR.FAIL);
  546. }
  547. // - proto native
  548. if (!Assert(callCountPN == 0))
  549. {
  550. return NTFR(TFR.FAIL);
  551. }
  552. // - static proto native
  553. if (!Assert(callCountSPN == 0))
  554. {
  555. return NTFR(TFR.FAIL);
  556. }
  557. return NTFR(TFR.SUCCESS);
  558. }
  559. //---------------------------------------------------------------------------
  560. // Helpers
  561. //---------------------------------------------------------------------------
  562. // Snore
  563. float Sleep(float timeS)
  564. {
  565. float startTime = GetGame().GetTickTime();
  566. while (GetGame().GetTickTime() - startTime < timeS)
  567. {
  568. // Zzz
  569. }
  570. return GetGame().GetTickTime() - startTime;
  571. }
  572. //---------------------------------------------------------------------------
  573. // Example stress method
  574. float StringFormat()
  575. {
  576. float startTime = GetGame().GetTickTime();
  577. for (int i = 0; i < 1000; ++i)
  578. {
  579. string example = string.Format("This %1 is %2 just %3 an %4 example %5", i, Type(), this, startTime, "lorem ipsum 1 2 3");
  580. }
  581. return GetGame().GetTickTime() - startTime;
  582. }
  583. //---------------------------------------------------------------------------
  584. // Example stress method 2
  585. float StringConcat()
  586. {
  587. float startTime = GetGame().GetTickTime();
  588. for (int i = 0; i < 1000; ++i)
  589. {
  590. string example = "This " + i + " is " + Type() + " just " + this + " an " + startTime + " example " + "lorem ipsum 1 2 3";
  591. }
  592. return GetGame().GetTickTime() - startTime;
  593. }
  594. //---------------------------------------------------------------------------
  595. // To make sure it is only ever called in that test
  596. void TestFuncCountDataHelper()
  597. {
  598. int dummy = 3;
  599. }
  600. //---------------------------------------------------------------------------
  601. // To make sure it is only ever called in that test
  602. static void TestFuncCountDataHelperStatic()
  603. {
  604. int dummy = 3;
  605. }
  606. }
  607. class EPTHelperClass
  608. {
  609. float Sleep2(float timeS)
  610. {
  611. float startTime = GetGame().GetTickTime();
  612. while (GetGame().GetTickTime() - startTime < timeS)
  613. {
  614. // Zzz
  615. }
  616. return GetGame().GetTickTime() - startTime;
  617. }
  618. float SleepAgain(float timeS)
  619. {
  620. float startTime = GetGame().GetTickTime();
  621. while (GetGame().GetTickTime() - startTime < timeS)
  622. {
  623. // Zzz
  624. }
  625. return GetGame().GetTickTime() - startTime;
  626. }
  627. float DoEverything()
  628. {
  629. float startTime = GetGame().GetTickTime();
  630. Sleep2(3);
  631. SleepAgain(3);
  632. return GetGame().GetTickTime() - startTime;
  633. }
  634. }