PerfTestThread.cpp 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. ////////////////////////////////////////////////////////////////////////
  2. // PerfTestThread.cpp
  3. //
  4. // Copyright (c) 2014, Electronic Arts Inc. All rights reserved.
  5. ////////////////////////////////////////////////////////////////////////
  6. #include <benchmarkenvironment/test.h>
  7. #include <coreallocator/icoreallocator_interface.h>
  8. #include <EAMain/EAEntryPointMain.inl>
  9. #include <EAStdC/EAString.h>
  10. #include <EATest/EATest.h>
  11. #include <eathread/eathread.h>
  12. #include <MemoryMan/CoreAllocator.inl>
  13. #include <MemoryMan/MemoryMan.inl>
  14. #include "PerfTestThread.h"
  15. using namespace benchmarkenvironment;
  16. // TODO: Releases of benchmarkenvironmrnt with version numbers higher than 4.00
  17. // will include a new macro that will replace most of this code. Presently, that macro
  18. // cannot be used because it redefines operator new*.
  19. // The "BENCHMARKENVIRONMENT_TESTFUNCTION" macro redefines the new and new[] operators here, which causes a compiler error.
  20. // This code has been removed.
  21. EA_PREFIX_ALIGN(128) char gWorkMemory[BENCHMARKENVIRONMENT_WORKMEMORY_SIZE] EA_POSTFIX_ALIGN(128);
  22. EA_PREFIX_ALIGN(128) char gResultMemory[BENCHMARKENVIRONMENT_RESULTMEMORY_SIZE] EA_POSTFIX_ALIGN(128);
  23. int EAMain(int argc, char **argv)
  24. {
  25. Initialize(argc, argv, BENCHMARKENVIRONMENT_STRINGIZE(BENCHMARKENVIRONMENT_DEFAULT_TABLE_IDENTIFIER));
  26. SetFlagsValid();
  27. BenchmarkEnvironmentTestFunction(gWorkMemory, sizeof(gWorkMemory), gResultMemory, sizeof(gResultMemory));
  28. Complete(BENCHMARKENVIRONMENT_RESULTPASSED);
  29. return 0;
  30. }
  31. void BenchmarkEnvironmentTestFunction(Address /*workMemory*/, unsigned int /*workSize*/, Address resultMemory, unsigned int resultSize)
  32. {
  33. typedef void(*PerfTestFunction)(Results&, EA::IO::FileStream*);
  34. typedef eastl::vector<PerfTestFunction> PerfTestFunctions;
  35. PerfTestFunctions perfTestFunctions;
  36. perfTestFunctions.push_back(&PerfTestThreadAtomic);
  37. perfTestFunctions.push_back(&PerfTestThreadSemaphore);
  38. // EATHREAD_PERFORMANCE_LOG_FILENAME is set in the build file. Right now it should be ${config}-performance_log.txt
  39. EA::IO::FileStream performanceLog(EATHREAD_PERFORMANCE_LOG_FILENAME);
  40. if (!gIsAutomatedDeferredRun)
  41. {
  42. // If this is a local run, create a performance log for the evaluation function to look at.
  43. performanceLog.Open(EA::IO::kAccessFlagWrite, EA::IO::kCDCreateAlways);
  44. // This loggin is mostly here so that we have a way to know that this code is NOT running
  45. // in the build farm context. It could be removed once that has been confirmed.
  46. EA::UnitTest::Report("Local Execution -> Performance Logging Enabled\n");
  47. }
  48. // Outline the structure of the results table
  49. // We can do this out here because all of the tests will submit to the same table.
  50. Results resultsTable(resultMemory, resultSize);
  51. const int kNumColumns = 5;
  52. resultsTable.DescribeTableBegin(kNumColumns);
  53. resultsTable.AddStringField("Test Name");
  54. resultsTable.AddDoubleField("Mean", "s");
  55. resultsTable.AddDoubleField("Min", "s");
  56. resultsTable.AddDoubleField("Max", "s");
  57. resultsTable.AddDoubleField("Var", "s^2");
  58. resultsTable.DescribeTableEnd();
  59. for (unsigned int i = 0; i < perfTestFunctions.size(); ++i)
  60. {
  61. if (gIsAutomatedDeferredRun)
  62. perfTestFunctions[i](resultsTable, NULL);
  63. else
  64. perfTestFunctions[i](resultsTable, &performanceLog);
  65. }
  66. if (!gIsAutomatedDeferredRun)
  67. {
  68. performanceLog.Close();
  69. EA::UnitTest::Report("Log file written.\n");
  70. }
  71. return;
  72. }