PerfTestThread.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Copyright (c) Electronic Arts Inc. All rights reserved.
  3. ///////////////////////////////////////////////////////////////////////////////
  4. #ifndef PERFTESTTHREAD_H
  5. #define PERFTESTTHREAD_H
  6. #include <eathread/eathread_thread.h>
  7. #include <benchmarkenvironment/results.h>
  8. #include <benchmarkenvironment/statistics.h>
  9. #include <EAIO/EAFileStream.h>
  10. #include <EAStdC/EASprintf.h>
  11. typedef intptr_t(*ThreadEntryFunction)(void*);
  12. void PerfTestThreadAtomic(benchmarkenvironment::Results &results, EA::IO::FileStream* pLogFileStream);
  13. void PerfTestThreadSemaphore(benchmarkenvironment::Results &results, EA::IO::FileStream* pLogFileStream);
  14. inline void WriteToLogFile(EA::IO::FileStream* pLogFile, const char* formatString, ...)
  15. {
  16. if(pLogFile)
  17. {
  18. const int kLogBufferSize = 256;
  19. char8_t buffer[kLogBufferSize];
  20. va_list arguments;
  21. va_start(arguments, formatString);
  22. int numCharsWritten = EA::StdC::Vsnprintf(buffer, kLogBufferSize, formatString, arguments);
  23. va_end(arguments);
  24. pLogFile->Write(buffer, numCharsWritten);
  25. }
  26. }
  27. inline void AddRowToResults(benchmarkenvironment::Results& results, benchmarkenvironment::Sample& sample, eastl::string testName)
  28. {
  29. results.Begin();
  30. results.Add(testName.c_str());
  31. results.Add(sample.GetMean());
  32. results.Add(sample.GetMin());
  33. results.Add(sample.GetMax());
  34. results.Add(sample.GetVariance());
  35. results.End();
  36. }
  37. #endif