CoreTracer.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Copyright (C) 2009-2021, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #pragma once
  6. #include <AnKi/Core/Common.h>
  7. #include <AnKi/Util/Thread.h>
  8. #include <AnKi/Util/Allocator.h>
  9. #include <AnKi/Util/List.h>
  10. #include <AnKi/Util/File.h>
  11. namespace anki {
  12. /// @addtogroup core
  13. /// @{
  14. /// A system that sits on top of the tracer and processes the counters and events.
  15. class CoreTracer
  16. {
  17. public:
  18. CoreTracer();
  19. ~CoreTracer();
  20. /// @param directory The directory to store the trace and counters.
  21. ANKI_USE_RESULT Error init(GenericMemoryPoolAllocator<U8> alloc, CString directory);
  22. /// It will flush everything.
  23. void flushFrame(U64 frame);
  24. private:
  25. class ThreadWorkItem;
  26. class PerFrameCounters;
  27. GenericMemoryPoolAllocator<U8> m_alloc;
  28. Thread m_thread;
  29. ConditionVariable m_cvar;
  30. Mutex m_mtx;
  31. DynamicArray<String> m_counterNames;
  32. IntrusiveList<PerFrameCounters> m_frameCounters;
  33. IntrusiveList<ThreadWorkItem> m_workItems; ///< Items for the thread to process.
  34. File m_traceJsonFile;
  35. File m_countersCsvFile;
  36. Bool m_quit = false;
  37. Error threadWorker();
  38. Error writeEvents(ThreadWorkItem& item);
  39. void gatherCounters(ThreadWorkItem& item);
  40. Error writeCountersForReal();
  41. };
  42. /// @}
  43. } // end namespace anki